View Full Version : Put Camera at Moving's Object's Position
01-17-2010, 10:15 AM
I need help. I'm trying to track a moving object's position. I am using "glGetFloatv(GL_CURRENT_RASTER_POSITION, posParams);" to track the object's position.
Then I have "gluLookAt(0,0,0,posParams,posParams,posParams,0,1,0);" in my display function. I want the camera to be positioned where the object is.
But my world is not displaying correctly.
What am I doing wrong? Maybe I'm not using glGetFloatv correctly?
01-17-2010, 02:43 PM
What is your 'object', how do You draw it?
Do You use any glRasterPos calls, or render some bitmap text?
If not, you probably didn's set raster position at all.
01-17-2010, 06:54 PM
No, I'm thinking now that GL_CURRENT_RASTER_POSITION is not the correct parameter that I should be using.
My moving object is just a square drawn with GL_POINTS.
Do you know which function I should be using to track it to get the coordinates of its position to use in gluLookAt?
01-17-2010, 07:10 PM
Surely you have your "objects's" position in your code somewhere? If your object is a square drawn with GL_POINTS then your object's position could be the center of that square, or the position of it's "head" or "eyes".
What you also need in order to use gluLookAt is the "Up" vector for your view. This would normally be the "Up" of your object. You also need a place to look at. That would typically be along your "object's" view vector.
Your post is very unclear as to what you want to achieve / are doing. But taking a stab at it, assuming your square is sitting on the floor and sliding around and you want to see it's view as it moves in an environment then your Up vector would be as you have it in the last three elements of gluLookAt. Your eye position should be your objects position and go in the first three elements of gluLookAt, and the second three elements of gluLookAt should be a point directly in-front of your object in it's direction of travel. A crude way to get the last one is to add a few frames worth of velocity onto your objects position.
01-17-2010, 07:19 PM
I know its initial position, but I want the camera to follow it. I want a first person view (like the moving square is a car). So I need to continually track the square's position as it moves (which happens by pressing the arrow keys)
01-17-2010, 07:24 PM
Track it from a static position or follow it like a chase camera?
The principal is the same except if you have a fixed position to "watch" from that will simply go into the first coordinate in gluLookAt.
If it's a chase camera then you need to track the earlier positions of your car and choose one a reasonable distance back along that list for your camera's position (put it in the first coordinate in gluLookAt). A simpler method is to move backwards along your car's view vector so you are behind it and your camera will appear to be stuck on a stick on the back of your car.
The second coordinate in gluLookAt should always be your car's position, and the last one should be a vector perpendicular to the surface your car is on.
01-17-2010, 07:57 PM
I know its initial position, but I want the camera to follow it.
Do you not know what its position is later? You are, after all, telling OpenGL where to draw it later, so you must on some level know where you're drawing it.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.