Hi everyone! :slight_smile:
Hope everyone had a great weekend!

I am working on improving the performance of my game, and I am stuck with the following dilemma:

My game uses smooth camara animations, that is, the user by pressing keyboard controls can travel to different determined points in the world with a smooth animation that involves, velocity, and acceleration of the camera viewpoint.

To do this, I just use 3 glTranslate for each of the 3 axis, and 3 glRotate for each rotation axis.

However, I am not using glLookAt, I just move all the world to the opposite direcction of the user’s desired movement with glTranslate and glRotate (as stated above).

This works prefectly although, I am puzzled as why every camera tutorial (advanced/begginer/whatever) uses glLookAt plus a tons of cross product calculations!? Why do they do that!? Why should I even use glLookAt? :confused:

Can anyone tell me if I should change my camara method to improve performance or leave as it is, and why do people use glLookAt?!

Thanks so much everyone in advance!

Cheers! :slight_smile:

Camera transforms are never really a performance consideration. We’re only talking about a handful of operation to setup a view matrix against transforming possibly hundreds or even thousands of actors, skinning, and whatever else you may have going on in your world. It’s insignificant.

Use lookat or whatever you like, whatever is the most convenient for your application. It really makes no tangible difference from a performance perspective. I suggest you build yourself a decent matrix class… you’ll know what to do.

It actually seems that I am really missing something…

I read that in OpenGL it’s imposible to move the camera around, and that’s why all implementations simulate the movement of the camera by transforming the whole world to the opposite direction of the player movement, to simulate camera movement.

I read that that was how GlLookAt worked.

So then why do you talk about setting up a view matrix vs applying transformations?! And why should I need a matrix class?!

Could someone give me a bit of light!?
It’s very clear that I am missing something really important… but I don’t know what! :confused:

Thanks for your support!

Maybe what you’re missing is the math :wink:

There’s nothing magical going on, if that’s what you mean.

A matrix class/library is a fundamental part of any graphics programmers toolbox. If this isn’t clear to you now, it will be. OpenGL can hide the math from you by wrapping up the matrix stuff behind the scenes in the API, but it’s still going on. The sooner you understand the math, the sooner you won’t be confused.

The modelview matrix stores the viewing (camera) and model matrix transformations.

There is no difference between a viewing translation (5, 3, 4) and a model translation (-5, -3, -4), for example.

The main key difference is that if you had a light in WORLD space you’d position it when the viewing transformation was on the stack, and only the viewing transformation. So the difference is really a temporal one, or drawing order issue for certain specific features.

OpenGL has all the support you need to perform viewing transformations, it just has an inherent optimization by design where a single matrix is used to store both (and that matrix has a stack remember so you can always pop back to eye space if you choose to use it).

I wouldn’t sweat the details for something like viewing, it’s once a frame. I would try to avoid lookat but that’s just me. There are lots of ways to calculate viewing matrix and lookat needs a location and a target. I happen to think that’s encumbering for most 1st person stuff and pretty much gets in the way.

Remember if you know where you are and what you’re looking at then lookat is easy, BUT if you have 1st person (or maybe even a tethered view ) then you’re probably better off directly manipulating the modelview.

There is absolutely nothing wrong with your translate and rotates on the MODELVIEW matrix. Lookat is just a different means to a similar end.

Thanks guys!!! :slight_smile:
I can now sleep well! :smiley: