Difference between revisions of "User:Dora Gustafson/fixed 3D relation"
Line 3: | Line 3: | ||
Two prims have a relative position and rotation between them<br> | Two prims have a relative position and rotation between them<br> | ||
The relative position and rotation is what I call the relation between the prims<br> | The relative position and rotation is what I call the relation between the prims<br> | ||
In scripting you often want to keep the relation after one | In scripting you often want to keep the relation after one or both prims have moved<br> | ||
A typical example is to rez a prim with a fixed relation to the rezzing prim<br> | A typical example is to rez a prim with a fixed relation to the rezzing prim<br> | ||
Revision as of 13:03, 12 September 2013
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: <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>