Advertisement Jump to content
Sign in to follow this  
master x

When to use lookAt function for a 3d game?

This topic is 2637 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 am working on a 3d game/engine in webGL (fully custom i only use the glMatrix library for some basic functions).
The game i am making will be 3th person (atleast the main view when playing) but for cutscenes or intro's i will need other camera types like free, orbiting etc.

For now the game camera is 1st person or freecamera depending on what i working on for testing.
For the camera i now simply do 2 rotates to the matix and then translate it.
Then i loop my objects, particles etc.
matrix = mat4.rotateX(matrix, * pi180); //not altered yet
matrix = mat4.rotateY(matrix, * pi180);
matrix = mat4.t(matrix,,,;

The lookAt function looks also nice, just give it a position eye and up vector and its rotated and translated (played with it)

1: is it normal or better to control the camera with lookAt function or are mine 3 lines above also common used? (keeping in mind a more advanced camera system).

(for now in the 1st person camera when walking i just add the player.speed to the cur position, when turning i make a yawRate what adds up on the camera yaw and put that directly in the matrix rotations and translate works fine, but an 3th person orbiting camera with this method is more complicated, aldo did succeed some months ago but the code just looks alien and not nice)

demo from some months ago: (camera is free on x,z) works probably only in firefox webgl enabled

Share this post

Link to post
Share on other sites
LookAt is highly useful when applying a camera to the view matrix. I pretty much always use whatever lookat function is available; righ tnow im using XNA and that has a matrix creation method called... Matrix.LookAt. My cameras consist of a position, a direction, an up vector, and an FOV, so my code to set the view and projection matrices looks like this,

ViewMatrix.Current = Matrix.CreateLookAt(

ProjectionMatrix.Current = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(list.Camera.FOV),this.GraphicsDevice.Viewport.AspectRatio, 0.2f, 65535f);

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!