Advertisement

Animation?

Started by June 13, 2003 03:15 AM
4 comments, last by Kronos259 21 years, 8 months ago
Hello again!.I have a question about animation.I have created a door and i want to open it (actually by pressing a button the two parts of the door will move along the x -axis).I have read NeHe tutorials and i am really having trouble doing what seems simple.Can anybody help me because it is getting really tiring. Thank you!
As you said: move two parts along the x-axis.
So what is your actual problem?
Advertisement
Well,i can get the idea but i cannot understand how i can make it look like the two parts are slowly moving till they stop.I want smooth movement with speed that i can adjust.
One way is to have 4 variables: flag, translate, transition, and speed.

The flag can be boolean: true for open, false for closed.

The translate is the amount you add to one door to open it, or subtract from the other door to open it.

The transition is a float between 0 and 1 that you multiply the translate variable by to position the door anywhere from closed to open.

The speed is a float that determines how much the door can move per time frame. 0.1 would take 10 frames to get from closed to open. 0.01 would take 100 frames. You might want it quick for little doors and slow for massive vault doors.

During each time frame:
If open is true and transition is less than 1 then add speed to transition.
If open is false and transition is greater than 0 then subtract speed from transition.

When drawing the door, make sure you add transition*translate to the X values.

If you have lots of doors then you''ll need an array to store these variables for each door. Or you can make them part of the door class or structure.

If you want sliding doors in any direction, then your translate variable should be a vector.

Hope that helps. Have fun.

-solo (my site)
-solo (my site)
Of course... the method I mentioned is very simple and the results won''t look as good as using acceleration and velocity in your door movements.

-solo (my site)
-solo (my site)
And you would like to rotate around the door`s corner right ?
Set a matrix there(in a X point),render the Vertex-X point and rotate instead of translating...offcourse with accel(might look like this->)
glRotatef(rot,0,1,0);
static float rotadd=10.0f;
float value=0.5f;
rot+=rotadd;
if (rotadd>0) rotadd-=value;//how fast
This "might" be it...or not

Relative Games - My apps

This topic is closed to new replies.

Advertisement