Jump to content
  • Advertisement
Sign in to follow this  

Arbitrarily rotating cube algorithm

This topic is 3776 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

I have a cube in my 3d world and would like to have it rotate arbitrarily and randomly always at the same speed. Lets say it starts by rolling on the x-axis...it could keep rotating in that direction or maybe it might start rotating along the z-axis too. I don't want it to be rotating one direction and then suddenly switch to another, i was hoping to figure out an algorithm that would make a smooth but random rotation, with all degrees of freedom.... Any cool ideas to get me started? Or maybe that wasn't clear, just let me know.

Share this post

Link to post
Share on other sites
ha, maybe i'll start by answering my own thread, i was thinking of having 3 rotate weights (x, y, and z) each of which could grow to a maximum of 1 or a minimum of -1.

x_rotate_weight = 1.0f;
y_rotate_weight = 0.0f;
z_rotate_weight = 0.0f;

then each frame applying the rotations:

cube.RotateX( x_rotate_weight );
cube.RotateY( y_rotate_weight );
cube.RotateZ( z_rotate_weight );

The rotate_weights can change as much as 0.001f or -0.001f each frame.
To make the rotation smooth I would probably set it so that 99.9% of the time the change continued in the direction it was going, but there always that 0.01% chance that the direction might change...

So, thousands of frames later the weight values could hypothetically be:

x_rotate_weight = 0.376f; //with a tendency to increase (+0.001f )
y_rotate_weight = 0.012f; //with a tendency to increase (+0.001f )
z_rotate_weight = -0.980f; //with a tendency to decrease (-0.001f )

That sounds pretty decent to me....

Share this post

Link to post
Share on other sites
You could use a direction vector, and interpolate towards this vector each step.
Simply normalize after interpolation so speed is constant.
Sounds like the easiest solution to me. :)

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!