tags:

views:

344

answers:

2

Hi ,

In my didactic openGL appl , I have some objects on the scene, and when I click on one of them I want my camera to look at that object. For that after I determine the clicked object , I compute the up , front and right vectors of the camera and then I need to be able to calculate the pitch, yaw, roll angles of the camera. However I am quite clueless about how could I do that , so any help would be great .

+1  A: 

You don't actually need to do all these calculations. simply use glLookAt(). it takes the position of the camera, the position of where you want to look and the up vector and orients the model view matrix accordingly.

If you really want do it the hard way, look at my answer to this question.

shoosh
I'd do it like this , if it were up to me.....but I'm supposed to learn more , by doing this way .
rantravee
+1  A: 

It is a matter of calculating backwards. From the front vector you should be able to deduce yaw and pitch relativly easy.

If your coordinate system has x and z as the floor

yaw = atan2(front.z, front.x);

The pitch can be calculated by normalizing front and using asin

front.normalize();
pitch = asin(front.y);

If I have time later I'll look into calculating the roll

Otherwise has shoosh a good suggestion to use gluLookAt

epatel