#### Archived

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

# gluLookAt problem

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

## Recommended Posts

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:

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);

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

##### Share on other sites
first of all get the mathlib.h

there s a function called anglevectors( vec3_t angle,vec3_t forward,vec3_t right,vec3_t up)

O =(0,0,0)

do it like the following

origin=O- forward*distance

forward is the center vector
up the up vector and origin the eye vector of glulookat

that should work i think

##### Share on other sites
There are a *lot* of mathlib.h refrences on the ''net. Verify that the one from the published quake/quake2 source is what you''re talking about?

Also, can anyone tell me why the original code seems to move the view to the origin, looking out?

yckx

##### Share on other sites
yeah i am talking about the quake mathlib

##### Share on other sites
Ok, I''ve been looking at the anglevectors function. Between its definition and your post above, I think I *almost* see what you''re suggesting, but not quite. Could you try a more complete explanation, please? Thanks.

yckx

##### Share on other sites
Aha~! Found my problem. length, in the code above, should be the sqrt of what I was setting it to. My camera position was ending up close to (0, 0, 0) as a result. This is what happens when you haven''t used more than basic math in 2+ years ;P My head theory was right, I just wasn''t fully coding it....

Thanks for the heads up on mathlib.h, tho. It looks like it could be quite useful in other places.

yckx

1. 1
2. 2
3. 3
Rutin
19
4. 4
JoeJ
14
5. 5

• 14
• 9
• 23
• 9
• 32
• ### Forum Statistics

• Total Topics
632628
• Total Posts
3007515
• ### Who's Online (See full list)

There are no registered users currently online

×