Difference between revisions of "User:Dora Gustafson/fixed 3D relation"
Jump to navigation
Jump to search
(One intermediate revision by the same user not shown) | |||
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> | ||
When you know position and rotation for two prims the relation can be computed like this: | When you know position and rotation for two prims the relation can be computed like this: | ||
< | <source lang="lsl2"> | ||
relativeRot = P2Rot / P1Rot; | relativeRot = P2Rot / P1Rot; | ||
relativePos = (P2Pos - P1Pos) / P1Rot; | relativePos = (P2Pos - P1Pos) / P1Rot; | ||
</ | </source> | ||
When you know the relation and position and rotation for prim 1 you can compute position and rotation for prim 2 like this | When you know the relation and position and rotation for prim 1 you can compute position and rotation for prim 2 like this | ||
< | <source lang="lsl2"> | ||
P2Rot = relativeRot * P1Rot; | P2Rot = relativeRot * P1Rot; | ||
P2Pos = P1Pos + relativePos * P1Rot; | P2Pos = P1Pos + relativePos * P1Rot; | ||
</ | </source> | ||
Likewise you can compute position and rotation for prim 1 when they are known for prim 2 | Likewise you can compute position and rotation for prim 1 when they are known for prim 2 | ||
< | <source lang="lsl2"> | ||
P1Rot = ZERO_ROTATION/relativeRot * P2Rot; | P1Rot = ZERO_ROTATION/relativeRot * P2Rot; | ||
P1Pos = P2Pos - relativePos/relativeRot * P2Rot; | P1Pos = P2Pos - relativePos/relativeRot * P2Rot; | ||
</ | </source> | ||
{{LSLC|Library}} | {{LSLC|Library}} |
Latest revision as of 12:42, 22 January 2015
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;