View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# What is the fastest way to transform rigid body space

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1Finalspace  Members

Posted 25 July 2014 - 04:45 AM

Hi there,

currently my 2D rigidbody physics system uses world-space positions/rotations for mostly everything, even the contact points are in world-space.

It works fine, but i think its not good for performance to have everything in world-space and to transform all the bodies*vertices for each frame. Therefore i want to know, what is the fastest way to transform one bodys space into another bodys space.

My thought about that is that i treat one body A (The reference body) as static without any rotation at all and transform the other body (incident body B) into that space like this:

Offset position for bodyA = position of body B - postion of body A

Offset rotation for bodyA = rotation of body B - rotation of body A

Then i just add the offsets to bodyA position and rotation - and calculate separating axis, support points, contact points, all that stuff and leave it in that local space. After that, the contact manifold+points must be converted back into the space of the incident body - would this work, or is there some better way?

C#, Java, JavaScript are nice languages - Very Easy to code with - BUT it shakes your brain when you swap back to C or any other low level language...

### #2haegarr  Members

Posted 25 July 2014 - 09:09 AM

If you think in homogeneous transformation matrices, then (using column vectors here) the placement of a model in the world is

P := T * R

where T denotes the position (as translation from the origin) and R denotes the orientation (as rotation from the identity rotation).

The inverse of this

P-1 = R-1 * T-1

defines the backward way from the world into the model local space.

So now, coming from model local space 1 and going into model local space 2 means

( R2-1 * T2-1 ) * ( T1 * R1 )

== R2-1 * ( T2-1 * T1 ) * R1

What can be seen from this is that subtracting the position of model 2 from model 1 is okay because of both transformations lie side by side, but subtracting rotation is not because both transformations are separated by translation.

As ever in such a situation, working with matrices is better than using components.

Edited by haegarr, 25 July 2014 - 09:10 AM.