rotating dice

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

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

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.

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();
}

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