Jump to content
  • Advertisement
Sign in to follow this  
zlatko_bre_1985

Rotations

This topic is 4598 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
Advertisement
Can someone send me a his/her camera class or some class like mine 3D_class?

EDIT:
My mail is zveljkovic[at]gmail[dot]com

[Edited by - zlatko_bre_1985 on December 18, 2005 9:13:52 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
For the record -- we solved that in IRC. A solution was to lock the Up vector and to force the others to stay orthonormal to it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!