Sign in to follow this  

rotation problem!

This topic is 4165 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 want to rotate my objects in my sample game.Here is my code.AXIS_U and AXIS_N are ok! But when i rotate object around AXIS_V, object rotate like rotate around Y axis(in world coordinate).But i want rotate local Y axis(AXIS_V).Why this problem occurs. // Rotation void Object::Rotation(int _axis, float _angle) { if(fabsf(_angle) < D3DX_16F_EPSILON || !(m_attribute & OBJECT_LIVE)) return; switch(_axis){ case AXIS_U: m_angle.x += _angle; m_angle.x = fmodf(m_angle.x, 2 *D3DX_PI); break; case AXIS_V: m_angle.y += _angle; m_angle.y = fmodf(m_angle.y, 2 *D3DX_PI); break; case AXIS_N: m_angle.z += _angle; m_angle.z = fmodf(m_angle.z, 2 *D3DX_PI); break; default: break; } return; } // and // Draw void Object::Draw() { if(!(m_attribute & OBJECT_VISIBLE) || !(m_attribute & OBJECT_LIVE)) return; char strDebugging[256]; D3DXMATRIX Translation, RotationX, RotationY, RotationZ; D3DXMatrixTranslation(&Translation, m_worldPos.x, m_worldPos.y, m_worldPos.z); Translation = (*D3DXMatrixRotationZ(&RotationZ, m_angle.z)) * (*D3DXMatrixRotationX(&RotationX, m_angle.x)) * (*D3DXMatrixRotationY(&RotationY, m_angle.y) * Translation); Device->SetTransform(D3DTS_WORLD, &Translation); ...... thanks !

Share this post


Link to post
Share on other sites
My guess is that the model's center is not at 0,0,0. You may try concatenating your matrices in the following order to see if it works a little better.

Mat = RotY*RotX*RotZ*Translation.

Share this post


Link to post
Share on other sites
Hi

I think You don't get the current angle at the points that You want to
rotate. This is the function that rotate the point around center. If You want to rotate the object call this function for each point of the object:

class CSurfacePt
{
///////////////////
double m_dX;
double m_dY;
double m_dZ;
};

/////////////////////////////////////////////////////////
void CSurfacePt::Rotate(double dZAngle, double dXAngle, double dYAngle)
{
//Rotation around Z
double dRXY = hypot(m_dX, m_dY);
double dTransXYAngle = dXYAngle + atan2(m_dY, m_dX);

m_dX = dRXY*cos(dTransXYAngle);
m_dY = dRXY*sin(dTransXYAngle);
//*************************

//Rotation around Y
double dRZX = hypot(m_dX, m_dZ);
double dTransZXAngle = dZXAngle + atan2(m_dZ, m_dX);

m_dX = dRZX*cos(dTransZXAngle);
m_dZ = dRZX*sin(dTransZXAngle);
//*************************

//Rotation around X
double dRZY = hypot(m_dZ, m_dY);
double dTransZYAngle = dZYAngle + atan2(m_dY, m_dZ);

m_dZ = dRZY*cos(dTransZYAngle);
m_dY = dRZY*sin(dTransZYAngle);
}

Share this post


Link to post
Share on other sites

This topic is 4165 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this