Check my camera rotation/transeltion function

Started by
5 comments, last by Xeno 23 years, 11 months ago
/*-------------------------------------------*/ /*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"

------------------------------- Goblineye Entertainment------------------------------

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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

how i build a matrix that transforms world coordinates to camera coordinates?

Thanks


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

------------------------------- Goblineye Entertainment------------------------------

Anyone???
Thanks

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

------------------------------- Goblineye Entertainment------------------------------

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

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Sorry , i was sure its same function
but thanks anyway its work now

Posted By Xeno.
Kobe Bryant - "Just believe in yourself"
What''s a camera??

This topic is closed to new replies.

Advertisement