Rotations

Started by
2 comments, last by Fruny 18 years, 4 months ago
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]
Serbia,Zrenjanin
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]
Serbia,Zrenjanin
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.
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.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement