Sign in to follow this  

Arbitrarily rotating cube algorithm

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

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