Jump to content
  • Advertisement
Sign in to follow this  
Lidestro

gluLookAt - matrix ops

This topic is 4068 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 understood that there are two ways to manage your view point in a 3d enviroment: 1.) You can have a camera object wich you manually move around by calculating x, y and z values for for pos, look-at and up vectors througt 3d vector math. Then you give these values to gluLookAt to set you view point. You draw your objects at the same place and move your view point by changing the values you pass to gluLookAt. 2.) But I've also understood that the best way to manage 3d graphics is to use matrix operations, using glTranslate, glRotate, glScale etc. And you could also make the view point to appeare to move through series of call to these function. So why should one use the former of latter of thouse two alternatives? It feel more logical to use 1), it's more easally imagine a camera moving around. On the other hand, it takes a lot of manual calculations and matrix operations as in 2) feels like a 'neater' way to do it, maybe easier too... Dose anyone have an idea? And does anyone know where to find articles about these kind of more design related issuse, I've never found much of that around. /Lidestro

Share this post


Link to post
Share on other sites
Advertisement
gluLookAt is a utility function (glu stands for "GL utility" library) which constructs the transformation matrix for you. in short, number 1 and 2 are pretty much the same thing, unless you have some interesting circumstances... and I think you will know if and when you have those extenuating circumstances.

FOR WHAT ITS WORTH edit: gluLookAt subtracts your camera position from the "look-at" position, and gets a view vector. It then crosses that vector with the "up" vector (which usually is just given as <0, 1, 0> if you aren't upside down), to get the "right" vector. It then crosses the "right" vector with the view vector to get the true up vector. It normalizes all of them, and using those three othronormal vectors it constructs the correct transformation.

Share this post


Link to post
Share on other sites
Interesting!

But in the camera management I've seen using gluLookAt they have to use quite complex math to calculate their new look-at vectors. So seems easier just to do it with glRotate and glTransform. But maybe you have to calculate these vetors anyway to know which way to move...

/Jens

Share this post


Link to post
Share on other sites
Quote:
Original post by Lidestro
But in the camera management I've seen using gluLookAt they have to use quite complex math to calculate their new look-at vectors. So seems easier just to do it with glRotate and glTransform. But maybe you have to calculate these vetors anyway to know which way to move...


Well, I think it goes without saying that the nature of your camera system comes into play. If you aren't using a camera that is "looking at" particular places or things, then you may not want to use gluLookAt. Of course, you could always just keep a "lookat" view vector for your view orientation and rotate that vector around when your view moves, and still use gluLookAt.



Share this post


Link to post
Share on other sites
Hi,
I also have a problem with gluLookAt()
Im trying to make the camera move in all three axis(like the old "descent" game).

so I wrote the following code,
But after I rotate on too much axis it start to do wrong things.
(if I look 90 deg to the left I cant roll correctly ect.)
can someone please help me with that?

--------------------------------------

upX = sin(z_angle * pi /180);
upY = cos(z_angle * pi /180) * cos(x_angle * pi /180);
upZ = -sin(x_angle * pi /180);

lookX = x_loc + sin(y_angle * pi /180);
lookY = y_loc - sin(x_angle * pi /180);
lookZ = z_loc - cos(y_angle * pi /180) * cos(x_angle * pi /180);

gluLookAt(x_loc,y_loc,z_loc,lookX,lookY,lookZ,upX,upY,upZ);
// Rotating
if(keys[VK_NUMPAD9])
{
z_angle += 1.5f;
}
if(keys[VK_NUMPAD7])
{
z_angle -= 1.5f;
}
if(keys[VK_NUMPAD8])
{
x_angle += 1.5f;
}
if(keys[VK_NUMPAD2])
{
x_angle -= 1.5f;
}
if(keys[VK_NUMPAD6])
{
y_angle += 1.5f;
}
if(keys[VK_NUMPAD4])
{
y_angle -= 1.5f;
}
// Moving
// move fowards
if(keys[65])
{
z_loc -= 0.1 * cos(y_angle * pi /180) * cos(x_angle * pi /180);
x_loc += 0.1 * sin(y_angle * pi /180);
y_loc -= 0.1 * sin(x_angle * pi /180);
}
// move backwards
if(keys[90])
{
z_loc += 0.1 * cos(y_angle * pi /180) * cos(x_angle * pi /180);
x_loc -= 0.1 * sin(y_angle * pi /180);
y_loc += 0.1 * sin(x_angle * pi /180);
}
// Slides sides
if(keys[VK_NUMPAD1])
{
z_loc -= 0.1 * sin(y_angle * pi /180);
x_loc -= 0.1 * cos(y_angle * pi /180) * cos(z_angle * pi /180);
y_loc += 0.1 * sin(z_angle * pi /180);
}
if(keys[VK_NUMPAD3])
{
z_loc += 0.1 * sin(y_angle * pi /180);
x_loc += 0.1 * cos(y_angle * pi /180) * cos(z_angle * pi /180);
y_loc -= 0.1 * sin(z_angle * pi /180);
}
//Slides up/Down
if(keys[VK_ADD])
{
y_loc += 0.1 * cos(z_angle * pi /180) * cos(x_angle * pi /180);
x_loc += 0.1 * sin(z_angle * pi /180);
z_loc -= 0.1 * sin(x_angle * pi /180);
}
if(keys[VK_RETURN])
{
y_loc -= 0.1 * cos(z_angle * pi /180) * cos(x_angle * pi /180);
x_loc -= 0.1 * sin(z_angle * pi /180);
z_loc += 0.1 * sin(x_angle * pi /180);
}

Share this post


Link to post
Share on other sites
Hi.. I a beginner...

I want to use gluLookAt.. But I was confuse for fill the parameter. First x,y,z is for a position of camera i guess. But in second and third x,y,z what for?? I have read the MSDN help..but still confuse to implement. Can you help me to explain because i want to implement it..

Thanks

Share this post


Link to post
Share on other sites
Whenever you want to move or rotate your camera, just glRotatef() or glTranslatef() in the opposite. Or you could multiply the MODEL_VIEW matrix yourself with glMultMatrix().

Simple really, but make sure you translate last, otherwise you'll just rotate the whole world around 0, 0, 0

Using this method makes it easy to rotate on the Z axis, as you can use an angle instead of the Up vector thing in gluLookAt()

That's the way my camera works anyway..

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!