Followers 0

# Multiple Coordinate Systems

## 5 posts in this topic

I have been examing some games and sometimes it seems they have multiple coordinate systems. For example you have several sprites that have different world scales, and one group of sprites are "nested" or child of another goup of sprites - they have world coordinates relative to their parent's world. Is this possible? If so, how do you connect world spaces when you want to render the scene?

Thanks Edited by fs1
0

##### Share on other sites

Of course it's possible.

Chances are you don't want to do things like create every model with every possible weapon attached.  You want to create a base model, several base attack animations, and all the weapons seperate from the base models.  So you want to attach things together.

In 2d or 3d, the basics of this are that a matrix multiplication will take you from one coordinate space to another.  So you can chain multiple matrix multiplications together to create a hierarchy that takes you from the world space all the way to your object space (or the other way around).

weaponMatrix = IdentityMatrix * MatrixOfPlatformPlayerIsStandingOn * MatrixOfPlayerRelativeToPlatform * MatrixOfGunRelativeToPlayer;


But you probably don't want to hard-code this, so you can build a tree of parenting.  Each object holds a reference to its parent.  The gun is parented to the player at some offset from the player's hand.  The hand is at some offset based on the player's animation.  The player is parented to either the world, or a moving platform, or a vehicle, etc.  The platforms/vehicles are parented to the world.  To resolve that, you just recursively walk

Matrix myMatrix() {
if (hasParent) {
return parent->myMatrix() * relativeMatrix;
} else {
return absoluteMatrix;
}
}


You can make things more flexiable (read complicated) by also allowing the parents to hold more than one matrix (read animated bones) that you would retrieve instead of the base matrix of the parent.

1

##### Share on other sites
Ok, thanks. Interesting insights.

Now a quick question, once you draw both groups, with 2 different world matrix, how do you tell the engine that they are related and to calculate the composed 'world matrix' ?

I inspected some shaders and didn't find these composition (they have only their world matrix, but not their parent one). Is it done on the c++ side? Any hints?

Thanks!
0

##### Share on other sites

At some point the coordinates have to be converted to a common system for operations like rendering relative to one clients point of view or for projectile path resolution....   AI might be handled at several levels also - like an 'entity' object which has a swarm of sub-objects where the entity does alot of the AI processing and then the sub-objects behave at a lower (simpler/less CPU intensive) level.

Complications happen when there are multiple borders between the various local coordinate systems and other objects see/interact across several borders (And other objects see a different subset).  Some systems just flatten everything into one coordinate system for the part of the world actively operating and add or remove sections on-the-fly  (continuous world) doing the conversions only at the add/remove times

Usually vehicles with their own coordinate system and changing orientations/etc interacting with the larger world map have these issues  (notice many games DONT have such vehicles and its largely because of the complications)

1

##### Share on other sites

Very helpful. Thanks so much all !

0

## Create an account

Register a new account