Model Space & World Space & the World Matrix

This is a short and simple description of the difference between the game programming terms 'Model Space' and 'World Space' and how they work with a World Matrix.


When a 3D model is built in programs such as 3DS Max etc, the modelling program has a virtual environment setup to create the model, similar to how you have a virtual 3D environment in a game.


This modelling virtual space has its own co-ordinate system, again similar to how a game has its own co-ordinate system for positioning objects. The modelling space has it's own world centre at 0,0,0, and when a model is exported, all its vertices are positioned according to their position around this modelling space origin of 0,0,0.


This leads us to the term model space. The model is effectively in a whole world of its own, with its own co-ordinates and world centre. But we want the model to exist in a world where it is not alone, where it has to move and interact with other objects.


In your game environment, you have your own 3D virtual world space, as the models do, but this space is the 'master' space, where everything else has to exist according to the game world's rules. This is known as 'World Space'.


So we want to put models into our world. First we give our game model objects positions, rotations, scales, and in the end combine these into a World Matrix:



matWorld =
                Matrix.CreateScale(scales) *
                Matrix.CreateFromYawPitchRoll(
                    MathHelper.ToRadians(rotation.Y),
                    MathHelper.ToRadians(rotation.X),
                    MathHelper.ToRadians(rotation.Z)) *
                Matrix.CreateTranslation(position);


We do this so that when the graphics device, using whatever shading effect you've specified (e.g. BasicEffect, SkinnedEffect, your own custom Effect), has the necessary data to convert each model's vertex position from model space co-ordinates to your game world space co-ordinates.


So to recap:

  • Each model has its own model space from when it was created.
  • We have our own game world we want to put these models into.
  • We want to manipulate these models in games so we give our models positions, rotations and scales.
  • We put together these three aspects into a World Matrix.
  • We pass this World Matrix into a Shader/Effect so it can correctly draw our models in our game by converting from Model Space vertex positions to World Space positions.




Just to note:
The correct positioning of model around the modelling space origin is vital, otherwise you can end up with models appearing out of place in a game. For example, if modelling a character, you'd likely want to model your character standing above the 0,0,0 modelling space centre. If you have various characters with different heights it's easier when programming positions because all the characters would stand on the same plane, i.e. you would not have code offsets for height for each model to have them standing on the same ground. If you put the origin in the middle of the model, then you'd have the model's appearing to be stuck in the ground, if the model and ground were both at Y-axis position 0.


I hope this article helps clarify the two terms and set minds at ease.