# How to calculate the view orientation ?

Hello,

I would kike to calcule the actual view orientation.
For that, I execute this code, to get the vertical of the observer and the normal to the plane of projection :

Visual3d_ViewOrientation *myViewOrientation = new Visual3d_ViewOrientation();
*myViewOrientation = myView->ViewOrientation();

Graphic3d_Vector *myViewRefUp = new Graphic3d_Vector();
Graphic3d_Vector *myViewRefPlane = new Graphic3d_Vector();

*myViewRefUp = myViewOrientation->ViewReferenceUp();
*myViewRefPlane = myViewOrientation->ViewReferencePlane();

Now I would like to calculate the three angles of my view, alpha, beta and gamma :
alpha = asin(myViewRefPlane->Y()) * 180 / Pi;
beta = asin(myViewRefUp->X()) * 180 / Pi;
gamma = asin(myViewRefUp->Y()) * 180 / Pi;

It seems to be wrong but I don't know which vector coordinates I must use to get the good view orientation.
Anybody can help me ?

Thank you Hi Mathieu,

I haven't checked your approach but can give an outline of my solution: After re-orienting the view query the OpenGL GL_MODELVIEW_MATRIX and use it to compute the orientation angles:

GLfloat matrix1;
glGetFloatv(GL_MODELVIEW_MATRIX, matrix1);

Matrix4 mat;
mat.element = matrix1;mat.element = matrix1;mat.element = matrix1;mat.element = 0;
mat.element = matrix1;mat.element = matrix1;mat.element = matrix1;mat.element = 0;
mat.element = matrix1;mat.element = matrix1;mat.element = matrix1;mat.element = 0;
mat.element = matrix1;mat.element = matrix1;mat.element = matrix1;mat.element = 1;

double tran;
int result = unmatrix(&mat, tran);

xAngle = tran * 180.0f / PI;
yAngle = tran * 180.0f / PI;
zAngle = -tran * 180.0f / PI;

The function unmatrix (decomposes the transformation matrix into a sequence of simple transformations) is described in Graphics Gems II and can be found at google books. The code is provided too at the book website.

So far it has worked for me.
Pawel Hi Pawel !

Thank you very much for your help.
It seems to be good but when I turn around the 'y' axis, xAngle is also modified.
I don't understand why, have you got the same behavior ?

Regards,

Mathieu Hi Mathieu,

Remember that the three angles you have obtained have to be applied sequentially. Hence, every rotation is to be considered in a coordinate system that resulted from the previous rotation.

Actually, the behaviour you describe could be right. However, to fully answer your question you would have to provide an exact description of your coordinate systems.

Pawel Thank you again for your help.

Now I think that I've a problem to identify my rotation axis... They might be different to my Triedron.
I'm still looking for a solution, I'll find ! :) I found the problem : it's me !

All is ok, like you said, I've to consider every rotation in a coordinate system that resulted from the previous rotation.

Thank you very much Pawel for your help !

Regards

Mathieu