Public Group

# Matricies and Projection Transforms

This topic is 2567 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm having some trouble understanding how to use various kinds of transforms, world transforms, view transforms, and projection transforms, and moreover mainly the last of the three. I have a basic grasp that view transforms are used for the essential "camera" for a viewpoint, but am having trouble grasping what world and projection transforms can, and are, used for. I've been crawling over the MSDN and DirectX documentation with still no luck understanding the underlying principles and uses. Can anyone give me some assistance with this? Thanks.

##### Share on other sites
I'll try. First I want to make sure you have the correct 10,000 ft view.

Let's start from the beginning: the model to render. Let it be a cube at the origin with points (1, 1, 1), (-1, -1, -1). This model is in model space, or object space.
First we need to put this object in the world. You do that by having a world matrix. You know matrix ~= functions, this function maps points in object space to objects in world space. The world matrix typically includes rotations and translations. I strongly suggest to not allow scaling. If you need scaling, at least make sure it's uniform.
So let's think at the matrix as an opaque entity with a rotation component and a translation component. The same cube with two different matrices will result in different points in the world.
This is typically used for "game entities" which needs to move around in the world. By contrast, world geometry is often pre-batched/pre-transformed, so its world matrix is typically identity.

Now that every object is where it wants to be we need to place the camera but we cannot. We can only move the world instead and this is quite the same thing. So we have a camera matrix which maps world-space to "camera space", more properly called eye space. This matrix is fairly similar to the world matrix.
Because of performance reasons, in the past it was typical to concatenate the world and camera matrix in a single matrix, which was called MODELVIEW. OpenGL had explicit notion of this matrix (math is the same for D3D). MODELVIEW is important when it comes for example to normal transformations (normals need to be mangled differently from points).

At this stage, all our points are "more or less" like they were in the beginning. We placed each object and then "offset" by a camera transform (it's very easy if you think in terms of translations only).

Then it comes the PROJECTION matrix (again this was an explicit OpenGL matrix). Let's think about perspective transform only for now. The perspective projection matrix will scale some points depending their distance from the camera, transforming from eye-space to clip-space. Ok, what this means?

Think at the spaces seen up to now. You can think at them as cubes. Think instead at the view frustum, which gets bigger and bigger as it moves away from the far plane.
[color="#ff0000"]Caution: approximation applies below, for gross explanation purposes. This quite different from what's going on, but I think it's a good analogy without involving the math.
Think at the two object space cubes. Suppose one ended being near the camera, and the other far. Think clip space coordinates like the relative position of the points wrt the camera-z plane in which they reside. If they are close, they'll end being on the NEAR plane. If far, they'll end in FAR plane. The NEAR plane edges might measure say 10 units in world space while the FAR plane might measure 100 units so the same cube would end up covering different "ratios" of the plane.
This is what the perspective transform does, it somehow "shrinks" the objects as they move away - no surprise here right? - because it must fit a perspective frustum into a cubic system and the only way to do this is to shrink the frustum according to distance, which implies shrinking the objects... This is non-rigid transform.
So, the more you move away, the more you shrink.

Again, for performance reasons, MODELVIEW and PROJECTION were usually concatenated in modelviewprojection (MVP) matrix.

Let's leave out tangent-space for the time being which in my opinion is very interesting but probably not what you need now.
Any problems up to this point?

##### Share on other sites

I'm having some trouble understanding how to use various kinds of transforms, world transforms, view transforms, and projection transforms, and moreover mainly the last of the three. I have a basic grasp that view transforms are used for the essential "camera" for a viewpoint, but am having trouble grasping what world and projection transforms can, and are, used for. I've been crawling over the MSDN and DirectX documentation with still no luck understanding the underlying principles and uses. Can anyone give me some assistance with this? Thanks.

World transform is probably the most easy to understand. It is used to "transform an object from object space to world space". That is, when you model a 3d object, you usually create it around origo. Without world transforms all your objects would be located more and less in the same spot and that isn't what you are after. With the world transforms, you can position and orient objects in the 3d space as you like. Remember that each of the object has their own world transform.

View transform practically describes the orientation and location of your camera. I won't go into the math details here, but you can find good examples on the net (and probably DX SDK). Anyway, using the view transform roughly does following: it transforms your 3d geometry from the world space to the view space. In the view space your camera location is 0,0,0 and it is looking always into a fixed direction (ie. forward). So in the sense of the view space, your camera stays still and the world moves around it.

Projection matrix is probably the most difficult part to understand. It does the following : it transforms the views space into a "box". The parts which are outside of the box are outside of the screen and can be clipped efficiently since. If you are familiar with view frustum (kind of a pyramid with bottom and top planes), you can imagine the the projection space as the frustum stretched to the shape of a box. The hard part is usually with clip space is that the vectors aren't 3d but 4d.

I hope this was helpful! Cheers!

##### Share on other sites
Thank you both for your replies. I have a much better grasp of these three matrices and their applications. Correct me if I'm wrong about the next few things I say:
1) The world transform, and its associated matrices, are used for rotations, translations, and (typically less so) scaling.
2) It can be used to position models into world space from their localised model space via rotating and translating the model.
3) The view transform represent "camera" or "eye" space. The "camera" never truly moves, but the world moves around it.
4) The projection matrix is analogous to a viewing frustum.

If that's accurate, then I think I've got a good (enough) grasp on these matrices. Thanks guys!

PS: I understand that tangent space is typically used to calculate textures and normals since it is based on vectors u and v and would maintain a constant n. I found a decent article on it, so I think I can go off of that.

##### Share on other sites
I would seriously recommend you to take a look at the book Real Time Rendering (third edition currently). It is the most agnostic book on graphics I have ever found, it does not get into the specifics of direct X or OpenGL, it doesn't assume any particular platform, it just tells you what each graphics related concept means and how it works beyond specific implementations, a person completely new to graphics could take a read of it and get much more knowledge than from the best DX cookbook around.

##### Share on other sites

I would seriously recommend you to take a look at the book Real Time Rendering (third edition currently). It is the most agnostic book on graphics I have ever found, it does not get into the specifics of direct X or OpenGL, it doesn't assume any particular platform, it just tells you what each graphics related concept means and how it works beyond specific implementations, a person completely new to graphics could take a read of it and get much more knowledge than from the best DX cookbook around.

Hey, thanks I'll look into that. I'm not completely new, it's just that these matrices have always thrown me for a loop.

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
11
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631776
• Total Posts
3002304
×