Difference between revisions of "User:Dora Gustafson/fixed 3D relation"

From Second Life Wiki
Jump to navigation Jump to search
 
(2 intermediate revisions 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 keep the relation after one of the prims have moved<br>
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:
<lsl>
<source lang="lsl2">
relativeRot = P2Rot / P1Rot;
relativeRot = P2Rot / P1Rot;
relativePos = (P2Pos - P1Pos) / P1Rot;
relativePos = (P2Pos - P1Pos) / P1Rot;
</lsl>
</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
<lsl>
<source lang="lsl2">
P2Rot = relativeRot * P1Rot;
P2Rot = relativeRot * P1Rot;
P2Pos = P1Pos + relativePos * P1Rot;
P2Pos = P1Pos + relativePos * P1Rot;
</lsl>
</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
<lsl>
<source lang="lsl2">
P1Rot = ZERO_ROTATION/relativeRot * P2Rot;
P1Rot = ZERO_ROTATION/relativeRot * P2Rot;
P1Pos = P2Pos - relativePos/relativeRot * P2Rot;
P1Pos = P2Pos - relativePos/relativeRot * P2Rot;
</lsl>
</source>
{{LSLC|Library}}
{{LSLC|Library}}

Latest revision as of 13: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;