User:Dora Gustafson/fixed 3D relation

From Second Life Wiki
Jump to navigation Jump to search

Fixed 3D relation

Any prim in SL has a position and a rotation in space
Two prims have a relative position and rotation between them
The relative position and rotation is what I call the relation between the prims
In scripting you often want to keep the relation after one or both prims have moved
A typical example is to rez a prim with a fixed relation to the rezzing prim

When you know position and rotation for two prims the relation can be computed like this:

relativeRot = P2Rot / P1Rot;
relativePos = (P2Pos - P1Pos) / P1Rot;

When you know the relation and position and rotation for prim 1 you can compute position and rotation for prim 2 like this

P2Rot = relativeRot * P1Rot;
P2Pos = P1Pos + relativePos * P1Rot;

Likewise you can compute position and rotation for prim 1 when they are known for prim 2

P1Rot = ZERO_ROTATION/relativeRot * P2Rot;
P1Pos = P2Pos - relativePos/relativeRot * P2Rot;