Skip to main content
gamedev.net
🔒 Locked

Problems with camera

Started by Lemmy 3 replies 400+ views
Original Post
Lemmy
Lemmy
I have following code to update the camera:
	D3DXMATRIX temp;
	D3DXMatrixTranslation(&matrix,position.x,position.y,position.z);
	D3DXQuaternionRotationYawPitchRoll(&rotate,angley,anglex,0.0f);
	D3DXMatrixRotationQuaternion(&temp,&rotate);
	D3DXMatrixMultiply(&matrix,&matrix,&temp);
	device->SetTransform(D3DTS_VIEW,&matrix);
 
Everything seems to be ok, but when I turn around near angley==PI, it will "invert" with x axis (when I go up it goes down, with angley==0 it behave normally) Does anybody has an idea what can be wrong?
g_fire_1983
g_fire_1983
Are you continually increasing angley beyond 360 degrees (2 pi)? Try making your angley reset itself to zero when you pass 360 degrees.
Lemmy
Lemmy
No it didn''t help.

I changed my update method to:

D3DXMATRIX temp;
D3DXMatrixIdentity(&temp);
device->SetTransform(D3DTS_WORLD,&temp);
D3DXQuaternionRotationYawPitchRoll(&rotate,angley,2.0f*D3DX_PI-anglex,0.0f);
D3DXMatrixAffineTransformation(&matrix,1.0f,NULL,&rotate,&position);
D3DXMatrixInverse(&matrix,NULL,&matrix);
device->SetTransform(D3DTS_VIEW,&matrix);

and I had to change nearly every method using move or rotate camera and now its ok
Lemmy
Lemmy
No it didn''t help.

I changed my update method to:

D3DXMATRIX temp;
D3DXMatrixIdentity(&temp);
device->SetTransform(D3DTS_WORLD,&temp);
D3DXQuaternionRotationYawPitchRoll(&rotate,angley,2.0f*D3DX_PI-anglex,0.0f);
D3DXMatrixAffineTransformation(&matrix,1.0f,NULL,&rotate,&position);
D3DXMatrixInverse(&matrix,NULL,&matrix);
device->SetTransform(D3DTS_VIEW,&matrix);

and I had to change nearly every method using move or rotate camera and now its ok
Laurent
Laurent
sounds like gimbal lock...



Laurent - http://www.lafaqmfc.com/
My little game: http://www.lafaqmfc.com/home/play_starshooter.htm

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.