Original Post
I''ve got a box, centered on the origin, which I can spin using the cursor keys, and I''ve used:
gluLookAt(0, 0, 45, 0, 0, 0, 0, 1, 0);
to set up the viewpoint far enough away in the pos z axis to see it. After I had that, I put a small object on the surface of the cube and set the cursor keys to move it around on the surface.
I want to be able to rotate the view so that the player model always stays centered in the window as it''s moving around. This is what I have:
When I replace the above gluLookAt line with this bit of code, the view somehow ends up at the origin, looking out from the center of the cube, although it otherwise follows the player like it should.
I know I should probably use quats or something--but right now I''m just experimenting, and I don''t understand why the view should jump from outside the cube with the single gluLookAt call to inside it with the player-tracking code. Can anybody help me out?
Thanks
ycks
BaseObj* p = objmgr->Player;
Vector3 dir;
dir.x = p->posx - 14; //hacks to get the cube
dir.y = 15 - p->posy; //and associated models
dir.z = p->posz + 15; //centered on the origin
float length = (dir.x * dir.x) + (dir.y * dir.y) + (dir.z * dir.z);
dir.x = dir.x / length * 45.0f;
dir.y = dir.y / length * 45.0f;
dir.z = dir.z / length * 45.0f;
gluLookAt(-dir.x, -dir.y, -dir.z, 0, 0, 0, 0, 1, 0);