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

## 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 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 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. :)

1. 1
2. 2
3. 3
4. 4
Rutin
16
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631415
• Total Posts
2999966
×