Jump to content


Why ?!


  • You cannot reply to this topic
No replies to this topic

#1 stromhau

    New Member

  • Members
  • Pip
  • 7 posts

Posted 19 October 2006 - 10:23 AM

Hello,

Can anybody please explain this :

My openGL application contain a camera class and the camera support
rotating(roll,yaw and pitch) and move forward and backwards.
The rotating is done by multiplications of quarternions.
The problems started when i wanted the new forward vector after the rotations.

The code went something like this for the setView method:

void camera::setView(){


	//creates quarternions

        yaw=temp.RotateAboutAxis(yawdegree, yaxis);

	pitch=temp2.RotateAboutAxis(pitchdegree,xaxis);

	roll=temp3.RotateAboutAxis(rolldegree,zaxis);


	roll.Multiply(pitch); //multiply roll with pitch and put result in roll

	roll.Multiply(yaw); //multiply roll with yaw and put result in roll

	

	roll.ExportToMatrix(matrix); //make matrix from quarternion

	

	glMultMatrixf(matrix);

	float modelview[16];

	

	//get hold of current modelview matrix

	glGetFloatv(GL_MODELVIEW_MATRIX , modelview);

	

	// get following values to form new forwar vector

	double x=matrix[8];

	double y=matrix[9];

	double z=matrix[10];


	dir = dir.set(x,y,z);

	dir = dir.normalize(dir);

	

	dir = dir.mulSkalar(dir,speed);


	posX += dir.x;

	posY += dir.y;

	posZ += dir.z;

	

	// Translate to our new position.

	glTranslatef(-posX, -posY, posZ);


	}

This worked almost :) But went out of control after yaw degree got bigger.

After a lot of google i found a solution(at nehe) :

I didnt care about roll because roll dont change forward vector.
The y coordinate of the forward vector he gets from the pitch matrix at pos y. Then he does an "inverse" multiply of yaw and pitch(the rotation is done the other way : pitch*yaw) and then the x and z coords are in this matrix
at pos 8 and 10. Why does this work ?

Tommy,

working code :

void camera::setView(){


	yaw=temp.RotateAboutAxis(yawdegree, yaxis);

	pitch=temp2.RotateAboutAxis(pitchdegree,xaxis);

	roll=temp3.RotateAboutAxis(rolldegree,zaxis);


	roll.Multiply(pitch);

	roll.Multiply(yaw);

	

	roll.ExportToMatrix(matrix);

	

	glMultMatrixf(matrix);

	float modelview[16];

	

	float tempmatrix[16];

	

        pitch.ExportToMatrix(tempmatrix);

	double y=tempmatrix[9];


	yaw.Multiply(pitch);

	yaw.ExportToMatrix(tempmatrix);


	double x=tempmatrix[8];

	double z=tempmatrix[10];


	// set direction vector

	

	dir = dir.set(x,y,z);

	dir = dir.normalize(dir);

	

	dir = dir.mulSkalar(dir,speed);


       

	// Increment our position by the vector

	posX += dir.x;

	posY += dir.y;

	posZ += dir.z;

	

	// Translate to our new position.

	glTranslatef(-posX, -posY, posZ);


	

	}






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users