Sign in to follow this  

Rotations

This topic is 4380 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

HI!! I have been rewriting my project and i decided to split 3d orientation from my model class and camera to make one plugable 3D class that can be plugged anywhere where some object need to be in 3d space. I made some switches (By switches i mean bool variables): isRotationRelative (does model rotate around his local axis or global axis) ,isTranslationRelative (same as above but for moving ) ,isFixedHeight (Does it stay on some fixed Y-axis height) , and isUpright (To prevent rolling - needed for camera). I have done everything except last, models rotate ok, move rotate .. Problem is when I puted this class in camera and moving mouse in circles (calling MouseMove(float x,y) func ) the world rolls on the side of the circling. That's ok for relative movement and NOT isUpright but when i set isUpright to true strange thing happen ( model becomes extra thin (like 3dsprite)or extra fat depending on the mouse movement ) here is code for isRelativeMovement = true and isUpright = true
if (isUpright)
{
   if ( isRotationRelative )
   {
      D3DXMatrixRotationAxis(&ZmatYaw, &D3DXVECTOR3(0.0f,1.0f,0.0f), x * speedfactor * mouseSensitivity);
      D3DXMatrixRotationAxis(&ZmatPitch, &ZvRight, y * speedfactor * mouseSensitivity);
   }
....
This sets a Yaw and Pitch matrices. next i call
void Z_3D::ZregenerateBaseVectors()
{
   if (!D3DXMatrixIsIdentity(&ZmatYaw))
   {
      ZmatTemp *= ZmatYaw;
      D3DXVec3TransformCoord(&ZvLook, &ZvLook, &ZmatYaw); 
      D3DXVec3TransformCoord(&ZvRight, &ZvRight, &ZmatYaw); 
      D3DXMatrixIdentity(&ZmatYaw);
   };

   if (!D3DXMatrixIsIdentity(&ZmatPitch))
   {
      ZmatTemp *= ZmatPitch;
      D3DXVec3TransformCoord(&ZvLook, &ZvLook, &ZmatPitch); 
      D3DXVec3TransformCoord(&ZvUp, &ZvUp, &ZmatPitch); 
      D3DXMatrixIdentity(&ZmatPitch);
   };

   if (!D3DXMatrixIsIdentity(&ZmatRoll))
   {
      ZmatTemp *= ZmatRoll;
      D3DXVec3TransformCoord(&ZvRight, &ZvRight, &ZmatRoll); 
      D3DXVec3TransformCoord(&ZvUp, &ZvUp, &ZmatRoll); 
      D3DXMatrixIdentity(&ZmatRoll);
   };

   D3DXVec3Normalize(&ZvLook,&ZvLook);
   D3DXVec3Normalize(&ZvRight,&ZvRight);
   D3DXVec3Normalize(&ZvUp,&ZvUp);
};
AND AFTER THAT I CALL
void Z_3D::ZupdateMatrix()
{
   D3DXMatrixScaling(&ZmatScale,ZvScaling.x,ZvScaling.y,ZvScaling.z);

   ZmatRot = ZmatRot * ZmatTemp;

   if ( isFixedHeight )
      D3DXMatrixTranslation(&ZmatTrans,ZvPosition.x,fixedHeight,ZvPosition.z);
   else
      D3DXMatrixTranslation(&ZmatTrans,ZvPosition.x,ZvPosition.y,ZvPosition.z);

   D3DXMatrixScaling(&ZmatScale,ZvScaling.x,ZvScaling.y,ZvScaling.z);

   WorldMatrix = ZmatScale * ZmatRot * ZmatTrans;
	
   ZvTemp = D3DXVECTOR3(0.0f,0.0f,0.0f);
   D3DXMatrixIdentity(&ZmatTemp);
};
Can anyone help ? [Edited by - Fruny on December 18, 2005 9:54:19 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by zlatko_bre_1985
Can someone send me a his/her camera class or some class like mine 3D_class?
The camera/object class that I use in my demo test bed can be found here, if that would be of any help to you.

Share this post


Link to post
Share on other sites

This topic is 4380 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this