How can I get view direction from the OpenGL ModelView Matrix?

前端 未结 2 1287
时光说笑
时光说笑 2020-12-19 19:43

I am writing a volume render program that constantly adjusts some plane geometry so it always faces the camera. The plane geometry rotates whenever the camera rotates in ord

相关标签:
2条回答
  • 2020-12-19 20:21

    You'll want to look at this picture @ http://db-in.com/images/local_vectors.jpg http://db-in.com/images/local_vectors.jpg

    The Direction-of-Flight ( DOF) is the 3rd row.

    GLfloat matrix[16]; 
    glGetFloatv( GL_MODELVIEW_MATRIX, matrix );
    
    float DOF[3];
    DOF[0] = matrix[  2 ]; // x
    DOF[1] = matrix[  6 ]; // y
    DOF[2] = matrix[ 10 ]; // z
    

    Reference:

    • http://blog.db-in.com/cameras-on-opengl-es-2-x/
    0 讨论(0)
  • 2020-12-19 20:45

    Instead of trying to follow the modelview matrix, to adjust your volume rasterizer's fragment impostor, you should just adjust the modelview matrix to your needs. OpenGL is not a scene graph, it's a drawing system and you can, and should change things however they suit you best.

    Of course if you must embedd the volume rasterization into a larger scene, it may be neccessary to extract certain info from the modelview matrix. The upper left 3×3 submatrix contains the composite rotation of models and view. The 3rd column contains the view rotated Z vector.

    0 讨论(0)
提交回复
热议问题