Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / Yaw Rotation problems (DirectX, C++) Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
atomic2005

May 02, 2005, 04:39 AM

When I move forward/backwards the yaw rotation point stays the same.

How do you make it so the rotation axis moves with the object ?

  1.  
  2.         D3DXVECTOR3 g_vLook(0.0f, 0.0f, 1.0f);      
  3.         D3DXVECTOR3 g_vUp(0.0f, 1.0f, 0.0f);        
  4.         D3DXVECTOR3 g_vRight(1.0f, 0.0f, 0.0f);    
  5.         D3DXVECTOR3 g_vCameraPos(0.0f, 1.5f, 5.0f);
  6.  
  7.  
  8.         D3DXMATRIXA16 mtxRot;
  9.         D3DXMATRIXA16 mTrans;
  10.  
  11.         D3DXMatrixRotationAxis( &mtxRot, &D3DXVECTOR3(0,1,0), D3DXToRadian(m_fYaw / 3.0f) );
  12.         D3DXVec3TransformCoord( &g_vLook, &g_vLook, &mtxRot );
  13.         D3DXVec3TransformCoord( &g_vUp, &g_vUp, &mtxRot );
  14.  
  15.  
  16.         D3DXMATRIX view;
  17.         D3DXMatrixIdentity(&view);
  18.  
  19.  
  20.         D3DXMatrixTranslation(&mTrans, m_vPosition.x, m_vPosition.y, m_vPosition.z );
  21.            
  22.         D3DXVec3Normalize( &g_vLook, &g_vLook );
  23.         D3DXVec3Cross( &g_vRight, &g_vUp, &g_vLook );
  24.         D3DXVec3Normalize( &g_vRight, &g_vRight );
  25.         D3DXVec3Cross( &g_vUp, &g_vLook, &g_vRight );
  26.         D3DXVec3Normalize( &g_vUp, &g_vUp );
  27.  
  28.  
  29.         view._11 = g_vRight.x; view._12 = g_vUp.x; view._13 = g_vLook.x;
  30.         view._21 = g_vRight.y; view._22 = g_vUp.y; view._23 = g_vLook.y;
  31.         view._31 = g_vRight.z; view._32 = g_vUp.z; view._33 = g_vLook.z;
  32.  
  33.        view._41 =- D3DXVec3Dot( &g_vCameraPos, &g_vRight );
  34.        view._42 =- D3DXVec3Dot( &g_vCameraPos, &g_vUp    );
  35.        view._43 =- D3DXVec3Dot( &g_vCameraPos, &g_vLook  );
  36.  
  37.        D3DXMatrixMultiply(&view, &mTrans, &view);
  38.  
  39.        return view;
  40.  

 
Rui Martins

May 02, 2005, 05:15 AM

It seems you are doing a mess with this setup 8)

It looks like your camera look vector matches your object forward direction vector. To make this work, you just have to use local coord spaces, which is the same to say to transform your original matrix and keep the result for the following transform.

Basicly you need to rotate first and translate next. Currently you are doing the opposite.
- Rotate, transforms your World Space orientation into your local space orientation.
- Translate, transforms your world space origin into your local space origin.

It's usually easier to think with local coord spaces.

NOTE: if all the other code is correct (I don't know if it is, didn't check it and I don't use D3DX),
then if you change this

  1. D3DXMatrixMultiply(&view, &mTrans, &view);

To this
  1. D3DXMatrixMultiply(&view, &view, &mTrans);

You will get what you want.

WARNING: Remember that Rotation Transform always rotates arround origin !
Hope this doesn't confuse you more !8)

 
This thread contains 2 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.