# Find the track!

hey guys, whats up again ???

ok… i ll be happy, if someone help me to figure out this…

ok… i have my camera location(x,y,z)(im using glulookat) and i want to go to another location, like ( random(x), random(y), random(z)), ok???

how can i find the coordinates beetween those points ??? OHHH, and i have the camera.speed, ok ???

thanx boys!

take care!

I’m not sure that I’ve understood the question. however if you know the initial position and the speed, why don’t you simply integrate, that is, if your camera is at (x0, y0, z0) at time t0, and the camera’s speed is (vx, vy, vz), then at time t the position (x,y,z) is :
x = x0 + (t - t0)*vx;
y = y0 + (t - t0)*vy;
z = z0 + (t - t0)*vz;
If the speed is not constant, just decompose your motion in elementary short motions, in each of them the speed could be thought as constant.

i ll try to explain better…

i have my initial camera’s position…
for example (0.0, 0.0, 0.0), oK ???

now, i want to go to another position… like ( 10.0, 5.0, 5.0 ), ok ???
and i have only one speed, although i can have 3… the vx, vy, vz.
whatever!

i just want to know to calculate the coordinates of each position, frame by frame while my
camera doesnt reach the final coordinate… (10.0, 5.0, 5.0 )
so, if i have a higher speed, less frame to reach that point… slower speed -> more frames to reach…

and how can i get the actual time t???

Typically in a real-time animation, you get the time from the system itself. Get the current time which has (on PCs) millisecond precision, or use a high performance timer to get microsecond precision.

OK!
but HOW can i do that in Delphi5???

You can use a high performance timer by using the Windows API. Specifically, QueryPerformanceCounter and QueryPerformanceFrequency. Do a search on MSDN to see how to use those, it’s very easy.

OK! i tried… but the camera goes to another direction completely weird…

can you help meeee??!?!?!?!

UP!!!
plz somebody help me!!!

UP!!!

OK, I’ll try…

Let’s call teh starting point A, and the point to reach B.
The distance between:

d = sqrt( (Bx-Ax)^2 + (By-Ay)^2 + (Bz-Az)^2 )

supposing the speed is in v = */sec, you’ll reach the point in d/v seconds.

In a time t, you position would be

Px = Ax + tv (Bx-Ax)/d
Py = Ay + tv (By-Ay)/d
Pz = Az + tv (Bz-Az)/d

Hm… I think I wasn’t very clear, but it should do.

When using gluLookAt() don’t you have to specify a forward and an up vector as well?

Is that why your camera is going weird because you havent recalculated them with the new position?

-Mezz

yeah… maybe… but how can i recalculate this ???

BUT i really dont think this affect the path…

[This message has been edited by Gelero (edited 08-21-2001).]

Originally posted by qwert:
[b]

supposing the speed is in v = */sec, you’ll reach the point in d/v seconds.

In a time t, you position would be

Px = Ax + tv (Bx-Ax)/d
Py = Ay + tv (By-Ay)/d
Pz = Az + tv (Bz-Az)/d

[/b]

ok… almost there… what does it mean speed = v = */sec ???

and t??? how can i find time t?? is the difference beetween Initialtime( found when program start ) and time(now!!) ???

Finding t is easy - just ask the system.

If you get your system’s time when you start moving, store it, then get it in subsequent frames you should be able to calculate the time for the object’s movement path.

-Mezz

There are is no metric system in opengl.
1 could be 1m or 1km. If you consider 1 as 1m, then the speed is your [speed]m/sec.

only “t” was wrong. I meant dt (delta t). The difference in time between current time (with current point) and the time when “current” point was at Point A.

Hope that helps

guys, you arent understanding me!! really!

qwert, thanks for the help…

let me explain it again…
my camera is in origin… (0.0, 0.0, 0.0), ok ???

now… my camera wants to go up… 10 points, ok ???
so, the final position is ( 0.0, 10.0, 0.0 ), ok ???

so, imagine a line, connecting these points…
ok… the line is made by other points, right ??? (a large number of them that we ever wonder before!) ok…

now, my camera always look to ( 0.0, 0.0, -10.0 ). so… when my camera gets 10 on Y axis its looks down, am I correct ??? i guess so…

what i want to know is make my camera, using some kind of speed, “walk” through those line’s points until reach the final point ( 0.0, 10.0, 0.0 )…
AND when its get there, stop by!!!

ufffffff…

plz… help me to figure out this damn situation…

[This message has been edited by Gelero (edited 08-21-2001).]

Some quick pseudo-code for you:

dt = 20; // your choice: how long it takes to move from A to B
initial_time = clock(); // or some other timing function
final_time = initial_time + dt;
Path = B - A; // path, A, and B are vectors/points

while (clock() < final_time)
{
Position = A + (clock()-initial_time)/dt * Path; // Position is another vector
gluLookAt(Position.x, …);
Render(…);
}

Position = B;

Originally posted by Nocturnal:
Path = B - A; // path, A, and B are vectors/points

sorry my stupidity, but DELPHI doesnt accept that operation so when you do B - A is
like
B[0] - A[0]
B[1] - A[1]
B[2] - A[2]

[This message has been edited by Gelero (edited 08-21-2001).]

[This message has been edited by Gelero (edited 08-22-2001).]

.

[This message has been edited by Gelero (edited 08-21-2001).]