# How do you develop the model matrix for an object?

This might be a misunderstanding on my part but let me give you my superficial understanding of Model-View-Projection pipeline and different coordinate systems. Then I will ask a question.

As we know, we might have many models in our scene. You might load vertex attributes for each using a model loader etc. When you load the coordinates, these are in object space or model space. So they describe the object wrt a local frame. We use model matrix to transform this to world space shared by all models, a global frame let's say.

After this, we are in a huge world space. We might think this as an endless Euclidean 3D space. Here coordinates may have any value. Somewhere in the world, we have a camera and these objects in the world have different coordinates wrt. camera's frame. This is where view matrix comes into play. After applying this transformation, coordinates are in view space. In the OpenGl world, we think like the camera lies at the origin. We specify a view frustum and we do (actually delay) the clipping etc.

After this we apply projection matrix and transform this viewing pyramid into a cube that spans [-1, 1] in all the axes. This is homogeneous coordinates and we do perspective divide, clipping etc. This is my view of the whole thing, roughly.

The question is, we have routines to generate view and projection transformations given the required parameters. But how about the model matrix? For example, I load a bunny model stored in an OBJ file. It might have a coordinate value like (32.657, -12.545, 8.444). In which space are these coordinates? If it's in the model space, what is the best strategy to develop a model matrix to put this object into world space? Another OBJ model of same bunny might have coordinates all lying in [-1, 1] range for example. Does this mean this object is already transformed with an MVP? Are those model matrices related to only skeletal, hierarchical models?

I think this is a strange question so I don't see this really mentioned anywhere. But this bugs me, leaves me with a superficial understanding of whole matter. I want to truly understand.

• The model matrix moves from model space to world space.
• The view matrix moves from world space to view space.
• The projection matrix moves from view space to clip space.

In which space are these coordinates?

Coordinates in model files are in model (or "object") space.

If it's in the model space, what is the best strategy to develop a model matrix to put this object into world space?

You do this when you decide you're going to render a particular instance of the model somewhere, oriented and scaled in some way. In the general sense you create a translation matrix based on the X, Y and Z in world space you want the object to appear, a rotation matrix based on how you want to orient the object in the world and a scaling matrix based on how you want to scale the object (if at all) and concatenate all three of these as appropriate via matrix multiplication.

You will generally create one such model matrix per instance you're going to draw in the world (whereas you'd probably create the view and projection matrices only once per frame).

Another OBJ model of same bunny might have coordinates all lying in [-1, 1] range for example. Does this mean this object is already transformed with an MVP?

No. It just means it's smaller (unless of course you choose to assume it's already transformed, which you can do, but that is of limited practical use).