Sign in to follow this  
Maverick_24

Arbitrarily rotating cube algorithm

Recommended Posts

Maverick_24    100
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
Maverick_24    100
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
Rasmadrak    196
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

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