PDA

View Full Version : rotating dice



Raymond
04-15-2016, 08:45 PM
how do i make a cube or dice rotate slowly ? like animation ? like for example when i press on 1 the dice animate from face to another slowly

reaktor24
04-16-2016, 04:08 AM
With a rotation matrix. Simple.

Raymond
04-16-2016, 08:50 AM
With a rotation matrix. Simple.

no i mean automatic like animation when i make a rotation matrix it rotates in time ... what i want is that i want to see it rotating slowly :D

Cornix
04-16-2016, 09:14 AM
Obviously you have to perform the rotation again and again over time then.
You must have some kind of main loop. Find out how much time has gone by between two updates of your loop and use this time to create the rotation matrix for your 3D object.

reaktor24
04-16-2016, 09:23 AM
Do you want it to move in 90 degree chunks but slowly? Is that correct? If it is then just have a rotation variable which holds the current angle and when a key is pressed simply keep increasing the angle until it reaches the desired location. Here is a quick bit of pseudocode to get you started.


if(keypress == true)
{
animate = true; // have this in your key checking function
}

if(animate == true)
{
angle += 1.0f; // have this in your update game variables function
}

if(angle == 90.0f)
{
animate = false;
}

render(void)
{
rotate(angle, 0, 1, 0); // rotate the dice based on the current angle etc.
drawDice();
}

wotnot
04-16-2016, 02:28 PM
For a constant rotation speed (or simply efficient execution) check the time on each loop e.g.


Do
Check tickcount
Has 1/24th second elapsed since last frame?
If so:
Calculate required rotation during elapsed time since rotation start
Apply that rotation
If not:
Calculate time remaining before next frame is due
thread.sleep for that amount of time
Loop