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]