Sign in to follow this  

Spin the cube on 2 axes

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
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

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