Sign in to follow this  

Understanding the view matrix

This topic is 398 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'm trying to understand how the view matrix works and why would you create a lookAt matrix.

 

Right now my view matrix is setup to be as the inverse of the model matrix. So if I want to move left in the world, I would move the entire scene to the right and if I want to move to the forward, I move my entire scene backwards and so on.

 

So essentially my view matrix is just a simple translation and rotation matrix multiplied with each other.

 

That seems simple to understand, but going through ever article on the internet, I see people creating a lookAt matrix and I don't understand why? What is the point of the lookAt matrix? Why not just translate and rotate the world like I do? 

Share this post


Link to post
Share on other sites

Sounds like you have a pretty good grasp on what a View matrix is. The reason you're seeing LookAt everwhere is that most people, when they begin, do not have any concept of what a view matrix is.

 

A LookAt function is a convenient way to create a matrix that is at a specific place with a specific orientation or to have it point right at a given spot. It can be used any time that's needed. It's an easy way to set the View matrix to a specific spot and with a specific orientation. I've used it by having it look 1 unit in front of itself so that it points in a direction rather than looking at a specific spot. Alternately, you could take an identity matrix and orient it and position it using translation and rotation matrices, but that would be a little more difficult if you want it to face a specific point in 3D space or an object at that point. And it builds a matrix without using matrices; it's all vectors.

 

A lot of times, you'll see it where they create a brand new View matrix every frame using LookAt rather than using the same View matrix from frame to frame.

 

But as I've grown more experienced and have a deeper knowledge of the View matrix (and matrices in general), which you seem to already possess, I'm getting to the point where I don't use LookAt at all for much of anything. Most of my tutorials over the years used LookAt, but you can see the evolution over the years as I went from using vectors, then to LookAt, then using LookAt to set the matrix initially but use it frame to frame, and in my most recent stuff I probably don't use LookAt at all. I had to teach myself all this stuff, so no one explained it to me. I merely figured it out as I did it year after year. That's a big part of the reason I write tutorials; to make it easier for the next person that comes along.

 

So, I guess the short answer is that it's convenient and most people don't understand matrix algebra or the concept of a View matrix. For the most part, it sounds like you're doing it exactly the way you should be doing it, but the LookAt function is there if you ever need it. It's not just for the View matrix; you can use it with a model matrix too.

Edited by BBeck

Share this post


Link to post
Share on other sites

The LookAt function is an easy way to create the view matrix and used to convert from world space to view space. It can also be a good way to quickly set up the view of the camera if you're starting a new project, although a BBeck says there are other ways to create this matrix.

 

If you want to create your own LootAt function or understand how it creates a view matrix this could be helpful: http://www.3dgep.com/understanding-the-view-matrix/#The_View_Matrix

Share this post


Link to post
Share on other sites

This topic is 398 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this