Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to make a character make an oscillation move. That is, the character will start by rotating to a certain angle, say 60 degrees, and then slowly come back to an upright position then rotate to the opposite direction for an angle less than 60, say 55, and do it all again until the rotation angle reaches zero and the character stops. Currently I'm trying to achieve this by declaring global variables and checking them with if blocks and changing their value by 1 degrees in those blocks so that each time the timer calls paintgl it decreases the angle by 1 degree and draws the object thus making it look like it's slowly rotating. I'm having trouble with stopping the character. This is the part of my code that handles it;

glRotatef(j,0,1,0);
glRotatef(k,0,1,0);

if(flag)
{
j = j + 2;
 if (j == 0)
 {
   k = 60;
   flag = !flag;

}
}

if(!flag)
{

k = k - 2;
if(k == 0)
{
    j = -60;
    flag = !flag;
}  
}

gluCylinder(player, 1,1,8,100,100); Here the cylinder is my character and the if blocks are increasing/decreasing the global variables j and k. j is initialized to -60 and k is initialized to 60.

what i want to do is to make the character lean to the ground for an angle by the click of a mouse and when the mouse is released, the character will slowly go upright and lean on to the other direction, then slowly go upright again and lean on to the first direction and so on.

How can I make this thing work and how can I stop it. Thanks in advance.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.