• Advertisement
Sign in to follow this  

Spin the cube on 2 axes

This topic is 4668 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 All I have a cube centered at the origin. I am not gonna scale it nor translate it but I need to spin the cube around the x, y and z axes. here is what I do : device->setTransform(world, rot) where rot = quaternion to matrix4 (axisAngleToQuaternion(x-axis, angle)) each time I change the angle to make it spin. it works fine around a single axis. but I need the combined effect on 3 or 2 axes at the same time. I tied something like : rot = quat2mat4(current rot quat * axisAngleToQuaternion(x-axis, angle)) but I got a weird movement. I am almost sure that I do have quaternion multiplication and conversion to mat4 working fine. does any one see where I might be missing thanks allot, I appreciate your time.

Share this post


Link to post
Share on other sites
Advertisement
Since this is the DirectX forum, I'll assume you're using D3D and D3DX.

Try this:

float RotationAboutXAxis;
float RotationAboutYAxis; // Set these with your rotation values

D3DXMATRIX rot, m;

D3DXMatrixRotationY(&m, RotationAboutYAxis);
D3DXMatrixRotationX(&rot, RotationAboutXAxis);

rot *= m;

device->SetTransform(D3DTS_WORLD, &rot);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement