Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Need help with Model View Projection with Quaternions

  1. #1
    Newbie Newbie
    Join Date
    Jan 2013
    Posts
    1

    Need help with Model View Projection with Quaternions

    Hi,

    I'm new to OpenGL and quaternions, but after doing some tutorials from opengl-tutorial, I'm trying to do the MVP with quats.

    With the MVP I get the expected rotated triangle. But with quats I get a different rotation (I would link to an image, but seems I can't).

    This is what I have in my C++ loop:
    Code :
    		// Send our transformation to the currently bound shader, 
    		// in the "MVP" uniform
    		glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
     
    		// Let's try the same Matrix in Quat
    		glm::quat qModel = glm::gtx::quaternion::toQuat(MVP);
    		glm::gtc::quaternion::normalize(qModel);
    		glUniform4f(qModelID, qModel.x, qModel.y, qModel.z, qModel.w);

    This is what I have in the shader:
    Code :
    // Values that stay constant for the whole mesh.
    uniform mat4 MVP;
     
    uniform vec4 qModel;
     
    //rotate vector, taken from kri engine
    vec3 qrot(vec4 q, vec3 v)	{
    	return v + 2.0*cross(q.xyz, cross(q.xyz,v) + q.w*v);
    }
     
     
    void main(){
     
    	// Output position of the vertex, in clip space : MVP * position
    	//gl_Position = MVP * vec4(vertexPosition_modelspace, 1);
     
    	gl_Position =  vec4(qrot(qModel, vertexPosition_modelspace),1);	
    }

    Like you can see, for now, I just want to converted the MVP matrix to a Quat and use it in the shader, but I'm messing something up.

    Any help would be appreciated.

    Many thanks.

  2. #2
    Junior Member Regular Contributor
    Join Date
    Dec 2009
    Posts
    198
    The MVP transformation is not a rotation, so you can't represent it with a quaternion.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •