Reputation: 2096
0Could you please help me out with this scenario: I have a 3D world, and I want to position the camera in a first-person manner( the real purpose would be a first-person view from inside a spaceship, while travelling through an asteroid belt). What would be the parameters for glulookat in this case? I thought of:
gluLookAt(30, 30, 30, 0, 0, 0, 0, 1, 0);//the up vector would be normal y axis
Would this be correct?
Also if I want the camera to move along with the ship, how would that be done? When moving the ship I should also move the "eye" coordinates from glulookat? Something like the eye coordinates(the first 3 parametres of glulookat) should be the same with the ship coordinates?
Upvotes: 0
Views: 770
Reputation: 1912
The gluLookAt call you propose would position the camera at (30,30,30)
and point it at the origin.
gluLookAt(Ship_Position_X,Ship_Position_Y,Ship_Position_Z,
Ship_Forward_X,Ship_Forward_Y,Ship_Forward_Z,
0,1,0);
This is more like what you need. You'll have to call it every frame so that the camera will follow the ship's movement. If you want the ship to do a barrel roll, you'll have to have additional variables to track the up vector.
I like to have some kind of struct to hold co-ordinates so that I can overload gl functions to take them and write shorter function calls, e.g.
// roll your own glVec, or use a co-ordinate class provided by a library you happen to be using.
inline void gluLookAt(glVec position, glVec forward, glVec up)
{
gluLookAt(position.x,position.y,position.z,forward.x,forward.y,forward.z,up.x,up.y,up.z);
}
Upvotes: 1