Skip to main content
gamedev.net
🔒 Locked

Getting 3D Coordinates

Started by NasMan Jun 10, 2004 at 7:34 AM 4 replies 700+ views
Original Post
NasMan
NasMan
Hello, I’ve go an app with objects moving around. I’m trying to understand how to move the camera around to stay fixed on one certain object. I’m having trouble with this. How would one grab an objects 3D coordinates at a given time? That is…I want to move the camera to one object, hold for a minute and move to another object. I don’t know how to get the 3D coordinates of the objects. Any help would be appreciated. Thanks
okonomiyaki
okonomiyaki
Well, this depends on how your scene is set up. The coordinates of your objects have got to be somewhere, whether it''s translating the objects or changing a vertex buffer.
Most likely you translate your objects around. You have to store each object''s coordinate to pass to glTranslate. Can you make it so you can get each object''s stored coordinates somehow, maybe object->GetCoordinates() ?
NasMan
NasMan
Sorry for the newbie stuff...
Yes, I am moving the objects around using glTranslate. For a given object I basically doing...
glPushMatrix();
glRotatef...
glTranslated...
glPopMatrix();

I'm tried putting a gluLookAt within the above block but it doesn't seem to make a difference, or change the view.
I think my problem is is that I have the coordinates within the Push and Pop block above, but when I do the gluLookAt outside of this block, the coordinates are no longer valid because I'm no longer within that Push/Pop block. Can someone tell me how this may be done?
Thanks

[edited by - NasMan on June 10, 2004 10:41:31 AM]
okonomiyaki
okonomiyaki
Hm, it's a little hard understanding what you want to do.
Lets say you have an object defined about an origin (0,0,0). Just say a sphere with center (0,0,0). Now, in your world, if you want the sphere to be at the point (50,0,0), you would do

sphere::Render() {
glPush();
glTranslatef(50.0f, 0.0f, 0.0f);
Draw();
glPop();
}


Now, say you want the camera to look at the object, using the lookat function:


sphere::Render() {
gluLookAt - 0.0f, 0.0f, 0.0f, 50.0f, 0.0f, 0.0f - //I don't know the parameters
glPush();
glTranslatef(50.0f, 0.0f, 0.0f);
Draw();
glPop();
}


As I said, I don't know the parameters to gluLookAt, I assumed that position vector is first, and then the lookat vector is second.

edit: I think that's how it works. I could be wrong, I've never done anything intensive with perspective.

[edited by - okonomiyaki on June 10, 2004 1:20:40 PM]
NasMan
NasMan
You''re on the right track. That''s basically what I''m trying to do. I''ve got a sphere rotating in a scene and I want the camera to be just behind it and follow it around its rotation. Your example is very similar. Here''s basically (similar) what I''ve tried...

sphere::Render() {
gluLookAt(f(x),f(y),0.0, 0.0,0.0,0.0, 0.0,1.0,0.0);
glPush();
glTranslatef(f(x), f(y), 0.0f);
Draw();
glPop();
}

But this does not give the results I need. The view seems to be going where I don''t want it to.
Thanks

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.