Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Xeno

Check my camera rotation/transeltion function

This topic is 6908 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

/*-------------------------------------------*/ /*RotateCamera */ /*-------------------------------------------*/ void Rotate::RotateCamera(LPDIRECT3DDEVICE7 &D3DDevice,D3DVECTOR NewPos , float XAngle ,float YAngle , float ZAngle) { D3DMATRIX matView; D3DMATRIX matTemp; D3DMATRIX matRot; D3DUtil_SetTranslateMatrix(matView,NewPos); D3DUtil_SetIdentityMatrix(matRot); if(XAngle // YAngle // ZAngle) { D3DUtil_SetRotateXMatrix(matTemp,XAngle*g_DEGTORAD); D3DMath_MatrixMultiply(matRot,matRot,matTemp); D3DUtil_SetRotateYMatrix(matTemp,YAngle*g_DEGTORAD); D3DMath_MatrixMultiply(matRot,matRot,matTemp); D3DUtil_SetRotateZMatrix(matTemp,ZAngle*g_DEGTORAD); D3DMath_MatrixMultiply(matRot,matRot,matTemp); } D3DMath_MatrixMultiply(matView,matRot,matView); D3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW,&matView); } does the function ok? is there any bugs? because its woring very strange, why when i rotating it about any axis - its rotating around the world origin and not around the camera origin ? thanks a lot! Posted By Xeno. Kobe Bryant - "Just believe in yourself"

Share this post


Link to post
Share on other sites
Advertisement
That''s because you''re building a matrix for transforming camera coordinates to world coordinates, what you should do is build a matrix that transforms world coordinates to camera coordinates.

You may also get a better result if you change the order of the x,y,z rotations to y,x,z. It''s a bit hard to explain why this is better but you''ll find that it works better with the euler angles that you use (yaw(yAngle),pitch(xAngle),roll(zAngle))

I believe the below function will work as you intended it.


void Rotate::RotateCamera(LPDIRECT3DDEVICE7 &D3DDevice,D3DVECTOR NewPos , float XAngle ,float YAngle , float ZAngle)
{
D3DMATRIX matView;
D3DMATRIX matTemp;
D3DMATRIX matRot;


D3DUtil_SetTranslateMatrix(matView,-NewPos);
D3DUtil_SetIdentityMatrix(matRot);


if(XAngle // YAngle // ZAngle)
{
D3DUtil_SetRotateYMatrix(matTemp,-YAngle*g_DEGTORAD);
D3DMath_MatrixMultiply(matRot,matTemp,matRot);
D3DUtil_SetRotateXMatrix(matTemp,-XAngle*g_DEGTORAD);
D3DMath_MatrixMultiply(matRot,matTemp,matRot);
D3DUtil_SetRotateZMatrix(matTemp,-ZAngle*g_DEGTORAD);
D3DMath_MatrixMultiply(matRot,matTemp,matRot);
}


D3DMath_MatrixMultiply(matView,matView,matRot);
D3DDevice->SetTransform(D3DTRANSFORMSTATE_VIEW,&matView);
}






- WitchLord

Share this post


Link to post
Share on other sites
how i build a matrix that transforms world coordinates to camera coordinates?

Thanks


Posted By Xeno.
Kobe Bryant - "Just believe in yourself"

Share this post


Link to post
Share on other sites
Anyone???
Thanks

Posted By Xeno.
Kobe Bryant - "Just believe in yourself"

Share this post


Link to post
Share on other sites
If you read my post you should already know as I told you. Examine my source code. No, it is not the same as yours, I have modified yours to build the world-to-camera matrix. If I didn''t make any mistakes you should be able to exchange your code for mine and your program should work perfectly.

But if it is theory you want:

The world-to-camera matrix (a.k.a. view matrix) is computed by first translating the world and camera so that the camera is at the origin. Then rotate the world and camera so that the camera faces in the direction of the z-axis.


- WitchLord

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sorry , i was sure its same function
but thanks anyway its work now

Posted By Xeno.
Kobe Bryant - "Just believe in yourself"

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!