OpenSim.Region.ScriptEngine.Shared.Api.LSL_Api.llLookAt C# (CSharp) Method

llLookAt() public method

public llLookAt ( OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3 target, double strength, double damping ) : void
target OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3
strength double
damping double
return void
        public void llLookAt(LSL_Vector target, double strength, double damping)
        {
            m_host.AddScriptLPS(1);

            // Get the normalized vector to the target
            LSL_Vector from = llGetPos();

             // normalized direction to target
            LSL_Vector dir = llVecNorm(target - from);

            // use vertical to help compute left axis
//            LSL_Vector up = new LSL_Vector(0.0, 0.0, 1.0);
            // find normalized left axis parallel to horizon
//            LSL_Vector left = llVecNorm(LSL_Vector.Cross(up, dir));
            
            LSL_Vector left = new LSL_Vector(-dir.y, dir.x, 0.0f);
            left = llVecNorm(left);
            // make up orthogonal to left and dir
            LSL_Vector up  = LSL_Vector.Cross(dir, left);

            // compute rotation based on orthogonal axes
            // and rotate so Z points to target with X below horizont
            LSL_Rotation rot = new LSL_Rotation(0.0, 0.707107, 0.0, 0.707107) * llAxes2Rot(dir, left, up);

            SceneObjectGroup sog = m_host.ParentGroup;
            if(sog == null || sog.IsDeleted)
                return;

            if (!sog.UsesPhysics || sog.IsAttachment)
            {
                // Do nothing if either value is 0 (this has been checked in SL)
                if (strength <= 0.0 || damping <= 0.0)
                    return;

                llSetLocalRot(rot);
            }
            else
            {
                if (strength == 0)
                {
                    llSetLocalRot(rot);
                    return;
                }

                sog.StartLookAt(rot, (float)strength, (float)damping);
            }
        }
LSL_Api