Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

NasMan

Getting 3D Coordinates

This topic is 5124 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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() ?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!