PDA

View Full Version : getting positon of an object



darkquest
12-28-2003, 06:45 AM
hi
i'm woundering are there any functions in opengl to get the coordinates of a object in 3D or do you just have to make a funtion that does this,

would a structure that gets the current and previous coordinate of a object work but updating it (this is for a game).

thanks

nexusone
12-28-2003, 07:07 AM
You can use the selection buffer to find what object you have clicked on, nehe.gamedev.net has a tutor on it.

But you also can just track each object with a variable as to its location, since you have to place the object's in your scene yourself anyway.

example:
// Define object location
typedef struct object_3D
{
GLfloat x1, y1 ,z1; // location current
GLfloat x2, y2 ,z2; // direction of travel
int rx,ry,rz; // Rotation of object
};



Originally posted by darkquest:
hi
i'm woundering are there any functions in opengl to get the coordinates of a object in 3D or do you just have to make a funtion that does this,

would a structure that gets the current and previous coordinate of a object work but updating it (this is for a game).

thanks



[This message has been edited by nexusone (edited 12-28-2003).]

JanHH
12-28-2003, 06:24 PM
a function like you requested cannot exist as OpenGL does not know objects. You only draw primitives, and OpenGL uses matrices to calculate the coordinates that have do be drawn. So a function like that is completely impossible.

Maybe you should start learning some OpenGL basics first?

Jan

dorbie
12-28-2003, 09:34 PM
Games update the position of objects and tell OpenGL where the objects are, not the other way around.

OpenGL draws stuff and that is all, do draw moving stuff typically software must be written to track and move the viewing position and objects in the scene.

mithun_daa
12-29-2003, 06:45 AM
u could use gluUnproject (pg 151 : red book)