View Full Version : Find the track!

Gelero

08-20-2001, 08:52 AM

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!

http://www.opengl.org/discussion_boards/ubb/smile.gif

take care!

Morglum

08-20-2001, 09:06 AM

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.

Gelero

08-20-2001, 09:40 AM

im sorry about my english...

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...

Gelero

08-20-2001, 09:43 AM

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

DFrey

08-20-2001, 09:51 AM

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.

Gelero

08-20-2001, 09:53 AM

OK!

but HOW can i do that in Delphi5???

http://www.opengl.org/discussion_boards/ubb/biggrin.gif

DFrey

08-20-2001, 10:10 AM

You can use a high performance timer by using the Windows API. Specifically, QueryPerformanceCounter and QueryPerformanceFrequency. Do a search on MSDN (http://msdn.microsoft.com) to see how to use those, it's very easy.

Gelero

08-20-2001, 11:15 AM

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

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

Gelero

08-20-2001, 01:38 PM

UP!!!!

plz somebody help me!!!

Gelero

08-21-2001, 02:38 AM

UP!!!

qwert

08-21-2001, 03:17 AM

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 + t*v* (Bx-Ax)/d

Py = Ay + t*v* (By-Ay)/d

Pz = Az + t*v* (Bz-Az)/d

Hm.. I think I wasn't very clear, but it should do. http://www.opengl.org/discussion_boards/ubb/smile.gif

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

Gelero

08-21-2001, 03:40 AM

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).]

Gelero

08-21-2001, 04:59 AM

Originally posted by qwert:

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 + t*v* (Bx-Ax)/d

Py = Ay + t*v* (By-Ay)/d

Pz = Az + t*v* (Bz-Az)/d

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

qwert

08-21-2001, 05:34 AM

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

Gelero

08-21-2001, 08:02 AM

guys, you arent understanding me!! really!

http://www.opengl.org/discussion_boards/ubb/frown.gif

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..

http://www.opengl.org/discussion_boards/ubb/frown.gif

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

Nocturnal

08-21-2001, 12:23 PM

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;

Gelero

08-21-2001, 01:30 PM

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).]

Gelero

08-21-2001, 01:37 PM

.

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

qwert

08-21-2001, 09:25 PM

I never programmed with delphi, but I think what Nocturnal ment is: You've got a point A (Ax,Ay,Az) and a Point B(Bx,By,Bz). The Vector P (Path) would be:

Px = Bx-Ax

Py = By-Ay

Pz = Bz-Az

Gelero

08-22-2001, 02:19 AM

no... i dont think so...

i guess B - A is a CrossProduct of them...

but im not sure...

Px = Bx-Ax

Py = By-Ay

Pz = Bz-Az

This is not the operation for the cross product, it's vector subtraction and it gives you the direction vector (in this case) between A and B.

-Mezz

Gelero

08-22-2001, 04:27 AM

so... what crossproduct stands for ???

qwert

08-22-2001, 04:44 AM

With a CrossProduct you get the perpandecular(normal) Vector to two other vectors. (Works only if the the two vectors point not in the same or opposed direction)

In your case it's a vector from point A to Point B.

Gelero

08-22-2001, 05:14 AM

so, in my case, i dont need crossproduct..

right ??

which cases i have to use crossproduct ???

or it is useful??

qwert

08-22-2001, 05:23 AM

Yeah, right.

e.g.

If you want to implement the OpenGL-light, you have to calculate the normals for your objects due to have correct lighting-calculation for them (Setting for each vertex a normal with glNormal).

qwert

08-22-2001, 05:27 AM

Forgot:

Of course you calculate those normals with the crossproduct.

Gelero

08-22-2001, 05:29 AM

OK... i understand...

but what normals stands for, EXACTLY ???

coz, im calculating in my program but im not sure the reason.. just for the light system ???

Nocturnal

08-22-2001, 05:59 AM

A normal is the normal vector to a plane (or other surface). In the plane equation Ax + By + Cz + D = 0, [A,B,C] is the normal vector. Also called the surface normal.

See http://www.schorsch.com/kbase/glossary/normal_vector.html .

For example, for each point on a sphere, there is one tangent plane to that point, and thus one normal. (Actually, there are two planes and normals, one pointing out of the sphere and one pointing into the sphere, but the inner pointing normal is very rarely used.) In the case of a polygon, the normal remains constant for the entire polygon because the polygon has the same tangent plane for each point.

Surface normals are used by OpenGL to approximate lighting on smooth objects like spheres using flat polygons. Hence GL_FLAT vs GL_SMOOTH. (Bump maps change the surface normal on a per-texel basis.)

However, normals are irrelevant to your original question.

B[0] - A[0]

B[1] - A[1]

B[2] - A[2]

This looks correct.

If I meant cross product I would have written: P = B x A

P.S. I am pretty sure that gluLookAt uses the cross product internally.

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

Nocturnal

08-22-2001, 06:11 AM

Originally posted by Gelero:

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

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

Make sure your OpenGL code calls glLoadIdentity before using gluLookAt:

glLoadIdentity();

gluLookAt(...);

MofuX

08-23-2001, 03:41 AM

hey guys, du diddnt understand him!

the only thing he want to have is a code for a waypointsystem...

and this what he means speed is the step the make from one frame 2 another, right?

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

Px = Ax + t*v* (Bx-Ax)/d

Py = Ay + t*v* (By-Ay)/d

Pz = Az + t*v* (Bz-Az)/d

i think you can use this code, but dont know exactly...

it would be nice to get the cam rotation too, so that the cam looks 2 the waypoint next...

Gelero

08-23-2001, 03:48 AM

Originally posted by MofuX:

hey guys, du diddnt understand him!

the only thing he want to have is a code for a waypointsystem...

and this what he means speed is the step the make from one frame 2 another, right?

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

Px = Ax + t*v* (Bx-Ax)/d

Py = Ay + t*v* (By-Ay)/d

Pz = Az + t*v* (Bz-Az)/d

i think you can use this code, but dont know exactly...

it would be nice to get the cam rotation too, so that the cam looks 2 the waypoint next...

HEY !! where have you been ???

thats exactly what im looking for...

do you married with me ???

http://www.opengl.org/discussion_boards/ubb/biggrin.gif http://www.opengl.org/discussion_boards/ubb/biggrin.gif

by the way, tell me more about cam rotation plz...

http://www.opengl.org/discussion_boards/ubb/wink.gif

PS: anyway, thanks to the other guys that help me a lot!!

MofuX

08-23-2001, 07:10 AM

i cant tell you much becouse i'm looking my self on a waypointsystem like that...

have you got now any code which is running?

plz add me in icq:

94467954

Thats like the code qwert posted near the top of this thread...

If you know where you are heading, i.e. you know the point at which your camera will travel to next, you can use it as one of the parameters in the gluLookAt() function I think.

To avoid snapping your view to the next waypoint you will have to do some interpolating between the current view direction and the new view direction. Perhaps if you have the camera's forward vector and the vector between the camera and the next waypoint, you can rotate the view a few degrees each frame to make it smoother.

-Mezz

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.