User:Dora Gustafson/fixed 3D relation

From Second Life Wiki
< User:Dora Gustafson
Revision as of 10:07, 2 July 2013 by Dora Gustafson (talk | contribs) (fixed relation computations)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 keep the relation after one of the 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: <lsl> relativeRot = P2Rot / P1Rot; relativePos = (P2Pos - P1Pos) / P1Rot; </lsl> When you know the relation and position and rotation for prim 1 you can compute position and rotation for prim 2 like this <lsl> P2Rot = relativeRot * P1Rot; P2Pos = P1Pos + relativePos * P1Rot; </lsl> Likewise you can compute position and rotation for prim 1 when they are known for prim 2 <lsl> P1Rot = ZERO_ROTATION/relativeRot * P2Rot; P1Pos = P2Pos - relativePos/relativeRot * P2Rot; </lsl>