Click to See Complete Forum and Search --> : Timing Opengl
Jesse79
March 5th, 2004, 07:06 AM
hi there,
Anyone here know how to translate, scaling, rotate (Continuously) few objects with opengl timing?
for example:
1. translate sphere to (-8,3,5) from origin (from second-3 second to second-6)
2. Scale the cube 200% ( from second-5 to second-8)
All this stituation must run together with keyframming techniques...
thanks a lot
Assmaster
March 5th, 2004, 10:21 AM
First you need to make some kind of timer that you query once a frame so that you know how much time has passed since the last one. (For example using the HighPerformanceCounter in the WIN32 API) If you keep this value (in seconds for example) in a float of something, it's really just a matter of multiplying the frametime divided by the time you want it to spend getting there by the final position vector and add that to the current position vector before you render.
Something along these lines:float MovementTime = 4.0f;
float FrameTime = YourTimer.GetFrameTime();
static Vector3 CurrentPosition = 0.0f, 0.0f, 0.0f;
Vector3 FinalPosition = 2.0f, 2.0f, 0.0f;
if(whithin the time period you want the object to move)
{
CurrentPosition += FinalPosition * (FrameTime / MovementTime);
}
glTranslatef(CurrentPosition.x, CurrentPosition.y, CurrentPosition.z);
//Draw your object here.
Jesse79
March 5th, 2004, 10:46 AM
this is my object model (GLUT object)
what i need is
total time = 50 seconds
1. translate the sphere to (-10,10,10)
[ time second-3 to second-20]
2. rotate cube and torus on y (3 times) in each 5 sesond.
3. scale all object 200% (second-30 to second 50).
i will attach my programme... .. really thanks for helping:D :blush:
Assmaster
March 5th, 2004, 11:27 AM
I have attached the timer I use in a game I'm writing. Include the TimerWindowsHighPerf.h header in your cpp file and make a global timer object. (bl::TimerWindowsHighPerf g_Timer;)
At the start of your display function you should now call g_Timer.StartNewFrame() to let the timer know a new frame has been started. Now you can get the frame-time from the timer by calling the g_Timer.GetFrameTime() function. The total time can be found by making a static float and adding the frame-time each frame.
That should get you started.
As for the translating, if you didn't understand what I said in my previous post, you really should look into vector and matrix mathematics. That is the basis for almost everything you do within OpenGL, and it's imperative that you are familliar with it. Hope you have enough to get you started.
Assmaster
March 5th, 2004, 11:36 AM
Forgot: Remove the #include "../globals.h" line from the two headers I posted and add #include <windows.h> instead.
Jesse79
March 7th, 2004, 09:47 AM
i already try your solution that u have gave me.. But, i still cannot get the object animating with time per second.... Anyway TimeFrame is worked already... need your help to c where is my problem... i will attach my programme.
Assmaster
March 7th, 2004, 11:55 AM
I don't have a compiler that can take GLUT code at the moment, so I cant compile it, but I saw a couple of things you are doing wrong.
Firstly, you are calling the GetFramesPerSecond() function instead of GetFrameTime() from the Timer like you should. That will not (obiously) give you the time passed since the last frame, but rather the number of frames rendered per second. Change that.
Also, you check against the FrameTime variable to check if 30 seconds has passed yet. That will not work, since the FrameTime is only the number of seconds since the last frame was rendered, and that will (hopefully) never be 30. To accumulate the total time passed, make a static float inside the animate (or display) functions that you add the FrameTime to each frame. When that value is above 30, 30 seconds have passed.
Jesse79
March 7th, 2004, 12:14 PM
I already did some changes.. then i also attach glut library along with the programme... By the way do u have any messenger?
:confused: :blush:
Assmaster
March 7th, 2004, 01:16 PM
Okay.. I've made a new version of the Animation function that animates the teapot from point A to B. I hope that will help you understand how this works:void Animation()
{
// Tell the timer a new frame has been started:
g_Timer.StartNewFrame();
// Start and End time of the teapot animation:
float StartTime = 2.0f;
float EndTime = 5.0f;
// Time since last frame, and total rendering time:
float FrameTime = g_Timer.GetFrameTime();
static float TotalTime = 0.0f;
TotalTime += FrameTime;
// Start and end position of the teapot, as well as it's current position:
CVector3a StartPoint = {1, 0, -2};
CVector3a EndPoint = {4, 5, 0};
static CVector3a CurrentPos = StartPoint;
// If we're in the animation interval, animate:
if ((TotalTime > StartTime) && (TotalTime < EndTime))
{
CurrentPos.x += (EndPoint.x - StartPoint.x) * (FrameTime / (EndTime - StartTime));
CurrentPos.y += (EndPoint.y - StartPoint.y) * (FrameTime / (EndTime - StartTime));
CurrentPos.z += (EndPoint.z - StartPoint.z) * (FrameTime / (EndTime - StartTime));
}
// Translate and draw:
glTranslatef(CurrentPos.x, CurrentPos.y, CurrentPos.z);
glutWireTeapot(1);
}This is certainly not the most elegant way to do this, but you get the basic principle of framerate independent animation.
Jesse79
March 7th, 2004, 03:48 PM
IT'S WORK!!!!!!!PERFECT!!!
Jesse79
March 16th, 2004, 11:24 AM
this is my my load data programme.. i need to load a texture to my model... any idea regarding about this???
i attached my whole programme.....
thanks
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.