Jump to content

How to move-rotate a child prim relative to another child prim?


Poltergeist Azarov
 Share

You are about to reply to a thread that has been inactive for 3520 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

        rotation PRIM2ROT=llList2Rot(llGetLinkPrimitiveParams(2,[PRIM_ROT_LOCAL]),0);        vector   PRIM2POS=llList2Vector(llGetLinkPrimitiveParams(2,[PRIM_POS_LOCAL]),0);                 rotation PRIM3ROT=llList2Rot(llGetLinkPrimitiveParams(3,[PRIM_ROT_LOCAL]),0);         vector   PRIM3POS=llList2Vector(llGetLinkPrimitiveParams(3,[PRIM_POS_LOCAL]),0);                         rotation relativeRot = PRIM3ROT / PRIM2ROT;        vector   relativePos = (PRIM3POS - PRIM2POS) / PRIM2ROT;               llSetLinkPrimitiveParamsFast(3,[PRIM_POS_LOCAL,relativePos,                                            PRIM_ROT_LOCAL,relativeRot]);

 For example, this does not do the expected behaviour. 

Link to comment
Share on other sites

You left out the calculation for prim 3

rotation PRIM2ROT=llList2Rot(llGetLinkPrimitiveParams(2,[PRIM_ROT_LOCAL]),0);vector   PRIM2POS=llList2Vector(llGetLinkPrimitiveParams(2,[PRIM_POS_LOCAL]),0);rotation PRIM3ROT=llList2Rot(llGetLinkPrimitiveParams(3,[PRIM_ROT_LOCAL]),0);vector   PRIM3POS=llList2Vector(llGetLinkPrimitiveParams(3,[PRIM_POS_LOCAL]),0);rotation relativeRot = PRIM3ROT / PRIM2ROT;vector   relativePos = (PRIM3POS - PRIM2POS) / PRIM2ROT;PRIM3ROT = relativeRot * PRIM2ROT;PRIM3POS = PRIM2POS + relativePos * PRIM2ROT;llSetLinkPrimitiveParamsFast(3,[PRIM_POS_LOCAL,PRIM3POS, PRIM_ROT_LOCAL,PRIM3ROT]);

The first 6 lines should be computed one time and the first 2 and the last 3 should be computed each time Prim 2 change position or rotation

This will give Prim 3 the same relation to Prim 2 no matter how prim 2 is rotated and moved

I hope this is helpful

:smileysurprised::):smileyvery-happy:

Link to comment
Share on other sites

This works great :) Thanks alot. I hope I can find a way to make it simpler more than below code. Since it costs alot this way just for a simple operation.

rotation PRIM2ROT;vector   PRIM2POS;rotation PRIM3ROT;vector   PRIM3POS;rotation PRIM4ROT;vector   PRIM4POS;rotation PRIM3RELROT;vector   PRIM3RELPOS;rotation PRIM4RELROT;vector   PRIM4RELPOS;list Relatives;default{    state_entry()    {        PRIM2ROT=llList2Rot(llGetLinkPrimitiveParams(2,[PRIM_ROT_LOCAL]),0);         PRIM2POS=llList2Vector(llGetLinkPrimitiveParams(2,[PRIM_POS_LOCAL]),0);                PRIM3ROT=llList2Rot(llGetLinkPrimitiveParams(3,[PRIM_ROT_LOCAL]),0);        PRIM3POS=llList2Vector(llGetLinkPrimitiveParams(3,[PRIM_POS_LOCAL]),0);                PRIM4ROT=llList2Rot(llGetLinkPrimitiveParams(4,[PRIM_ROT_LOCAL]),0);        PRIM4POS=llList2Vector(llGetLinkPrimitiveParams(4,[PRIM_POS_LOCAL]),0);                PRIM3RELROT=PRIM3ROT / PRIM2ROT; PRIM3RELPOS=(PRIM3POS - PRIM2POS) / PRIM2ROT;        PRIM4RELROT=PRIM4ROT / PRIM2ROT; PRIM4RELPOS=(PRIM4POS - PRIM2POS) / PRIM2ROT;                        }    touch_start(integer total_number) {               PRIM2ROT=llList2Rot   (llGetLinkPrimitiveParams(2,[PRIM_ROT_LOCAL]),0);        PRIM2POS=llList2Vector(llGetLinkPrimitiveParams(2,[PRIM_POS_LOCAL]),0);                PRIM3ROT = PRIM3RELROT * PRIM2ROT;        PRIM3POS = PRIM2POS + PRIM3RELPOS * PRIM2ROT;                PRIM4ROT = PRIM4RELROT * PRIM2ROT;        PRIM4POS = PRIM2POS + PRIM4RELPOS * PRIM2ROT;                llSetLinkPrimitiveParamsFast(3,[PRIM_POS_LOCAL,PRIM3POS, PRIM_ROT_LOCAL,PRIM3ROT,                    PRIM_LINK_TARGET,4, PRIM_POS_LOCAL,PRIM4POS, PRIM_ROT_LOCAL,PRIM4ROT]);    }}

 

Link to comment
Share on other sites

Pretty code you wrote:)

It certainly looks a lot, but you also gain a lot
The code is universal and will work in any case (within LSL limits)
It might be simplified for special cases, say zero rotations
When the relative rotation and position are constants they can be calculated in another script and written as constants
Code may be merged into fewer lines but I don't think that will make it any easier

:smileysurprised::):smileyvery-happy:

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3520 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...