salahzar icon

ReceiverWorkingOS

salahzar | PRO | 02/05/22 08:02:54 PM UTC | 0 ⭐ | 11772 👁️ | Never ⏰ | []
LScript |

2.32 KB

|

None

|

0 👍

/

0 👎

integer     CHANNEL         = -1;
 
//vector      base_initial_pos;
rotation    base_initial_rot;
 
vector      object_initial_pos;
rotation    object_initial_rot;
 
 
 
list parsecmd(string msg)
{
    return llParseStringKeepNulls(msg,["|"],["|"]);
}
rotate_around_point(rotation rot, vector pos)
{
    vector center = pos;
    vector point = object_initial_pos;
    // divide current rotation by the initial_rotation
    // gives the actual rotation made
    
    rotation diffrot = rot / base_initial_rot;
    
    // get actual rotation in radians
    vector eulero = llRot2Euler(diffrot);
    float theta = eulero.z;
    
    vector object_pos = llGetPos();
    // according to https://academo.org/demos/rotation-about-point/
    llOwnerSay("Rotating by "+(string)(RAD_TO_DEG*theta));
    
    // 1) first we need to get transform such that center is the center of coordinate
    float sin = llSin(theta);
    float cos = llCos(theta);
 
    // translate point back to origin:
    float px = point.x - center.x;
    float py = point.y - center.y;
 
    // rotate point this is the core of rotation
    float xnew = px * cos - py * sin;
    float ynew = px * sin + py * cos;
 
    // translate point back:
    float px = xnew + center.x;
    float py = ynew + center.y;
    vector newpos =  <px,py,point.z>;
    //llOwnerSay("rotated by "+(string)(theta*RAD_TO_DEG)+" degrees ");
    llSetLinkPrimitiveParamsFast( LINK_THIS, [
        PRIM_POSITION, newpos, 
        PRIM_ROTATION, object_initial_rot*diffrot]);
}
 
default
{
    state_entry()
    {
        llListen(CHANNEL,"","","");
    }
    listen(integer channel, string name, key id, string msg)
    {
        list result=parsecmd(msg);
        llOwnerSay(llList2CSV(result));
        string cmd = llList2String(result,0);
        vector pos = llList2Vector(result,1);
        rotation rot = llList2Rot(result,2);
        if(cmd=="RESET")
        {
            llOwnerSay("Reset");            
            
            base_initial_rot = rot;
            //base_initial_pos = pos;
            object_initial_pos = llGetPos();
            object_initial_rot = llGetRot();
            
        }
        if(cmd=="ROTATED") 
        {
            //llOwnerSay("Rotated");
            rotate_around_point(rot,pos);
        }
        
 
    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎