Jump to content
  • Advertisement

Archived

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

yckx

gluLookAt problem

This topic is 5829 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

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 this post


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

pass your angle into this function then calculate your origin with

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!