Archived

This topic is now archived and is closed to further replies.

minerjr

Rotating Camera 90 degrees

Recommended Posts

Hello, I am working on a simple 3d dungeon. My problem is when I try to rotate my camera it keeps on messing up my view, my picture gets eventually reversed. Here is my camera code. I am using dx 7.0. My m_fAbgle is equal to 0.5f * 3.141592654f, and I keep inscreasing by that same value so I can rotate 90 degrees. D3DXMatrixIsIdentity(&TMatrix[1]); D3DXMatrixIsIdentity(&TMatrix[0]); D3DXMatrixTranslation(&TMatrix[1], 0.0f, 0.0f, z_axis); D3DXMatrixRotationYawPitchRoll( &TMatrix[0], -m_fAngle, 0.0f, 0.0f ); D3DXMatrixMultiply( &TMatrix[0], &TMatrix[0], &TMatrix[1] ); m_pD3DDev->SetTransform(D3DTRANSFORMSTATE_VIEW,TMatrix[0]); I am not sure what my problem is but I appreciate any help people can give me. Minerjr

Share this post


Link to post
Share on other sites
Maybe this code will help you :


void DX8_Camera_Rotate (S3DX8_Device* pDevice,S3DX8_Camera *pCamera,int direction, float degrees)
{

float fTemp;

pCamera->update =TRUE;
switch (direction)
{

case X_AXIS :

fTemp = Get_Degrees (pCamera->m_Pitch);
fTemp += degrees;
pCamera->m_Pitch= Get_Radian (fTemp);
break;
case Y_AXIS :
fTemp = Get_Degrees (pCamera->m_Yaw);
fTemp += degrees;
pCamera->m_Yaw= Get_Radian (fTemp);

break;

case Z_AXIS :
fTemp = Get_Degrees (pCamera->m_Roll);
fTemp += degrees;
pCamera->m_Roll= Get_Radian (fTemp);



}
DX8_Camera_Render (pDevice,pCamera);
pCamera->m_Roll=pCamera->m_Yaw=pCamera->m_Pitch=0;

}


float Get_Degrees (float radian)
{
float degrees;

if (radian == 0)
return 0;
degrees = radian*(float)57.295;

if (degrees >=360)
{
degrees = degrees-360;


}
return degrees;



}
float Get_Radian (float degrees)
{

float radian;

if (degrees == 0)
return 0;

if (degrees >=360)
{
degrees = degrees-360;


}

radian = degrees / (float)57.295;

return radian;



}

Share this post


Link to post
Share on other sites
Just for the information, not that it''ll fix your problem, but D3DXMatrixIsIdentity doesn''t make its parameter the identity matrix; instead it checks to see if its parameter is the identity matrix.

Share this post


Link to post
Share on other sites
Melraidin''s right; if you wanted to set a matrix to identity, you should use D3DXMatrixIdentity(...).

However, you do not need to initialize your matrices to identity; functions like D3DXMatrixTranslation() and D3DXMatrixRotationYawPitchRoll() initialize their output matrices properly without needing you to prep them first.

--Hoozit.

Share this post


Link to post
Share on other sites