예제 #1
0
        public void botSetMap(string keyOfBot, LSL_List positions, LSL_List movementType, LSL_Integer flags)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Moderate, "botSetMap", m_host, "bot", m_itemID))
            {
                return;
            }
            List <Vector3> PositionsMap = new List <Vector3>();

            for (int i = 0; i < positions.Length; i++)
            {
                LSL_Vector pos = positions.GetVector3Item(i);
                PositionsMap.Add(new Vector3((float)pos.x, (float)pos.y, (float)pos.z));
            }
            List <TravelMode> TravelMap = new List <TravelMode>();

            for (int i = 0; i < movementType.Length; i++)
            {
                LSL_Integer travel = movementType.GetLSLIntegerItem(i);
                TravelMap.Add((TravelMode)travel.value);
            }

            IBotManager manager = World.RequestModuleInterface <IBotManager>();

            if (manager != null)
            {
                manager.SetBotMap(UUID.Parse(keyOfBot), PositionsMap, TravelMap, flags.value, m_host.OwnerID);
            }
        }
예제 #2
0
파일: Bot_API.cs 프로젝트: kow/Aurora-Sim
        public void botFindPath(string bot, LSL_Vector startPos, LSL_Vector endPos)
        {
            IBotManager manager = World.RequestModuleInterface <IBotManager> ();

            if (manager != null)
            {
                manager.FindPath(UUID.Parse(bot), new Vector3((float)startPos.x, (float)startPos.y, (float)startPos.z),
                                 new Vector3((float)endPos.x, (float)endPos.y, (float)endPos.z));
            }
        }
예제 #3
0
 public LSL_String botCreateBot(string FirstName, string LastName, string appearanceToClone, LSL_Vector startPos)
 {
     if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Moderate, "botCreateBot", m_host, "bot", m_itemID))
         return "";
     IBotManager manager = World.RequestModuleInterface<IBotManager>();
     if (manager != null)
         return
             new LSL_String(
                 manager.CreateAvatar(FirstName, LastName, m_host.ParentEntity.Scene,
                                      UUID.Parse(appearanceToClone), m_host.OwnerID,
                                      new Vector3((float) startPos.x, (float) startPos.y, (float) startPos.z)).
                     ToString());
     return new LSL_String("");
 }
예제 #4
0
        public void botSitObject(string bot, string objectID, LSL_Vector offset)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Moderate, "botTouchObject", m_host, "bot", m_itemID))
            {
                return;
            }
            IScenePresence sp = World.GetScenePresence(UUID.Parse(bot));

            if (sp == null)
            {
                return;
            }
            ISceneChildEntity child = World.GetSceneObjectPart(UUID.Parse(objectID));

            if (child == null)
            {
                throw new Exception("Failed to find entity to sit on");
            }

            sp.HandleAgentRequestSit(sp.ControllingClient, UUID.Parse(objectID),
                                     new Vector3((float)offset.x, (float)offset.y, (float)offset.z));
        }
예제 #5
0
파일: Bot_API.cs 프로젝트: kow/Aurora-Sim
        public void botSetMap(string keyOfBot, LSL_List positions, LSL_List movementType)
        {
            List <Vector3> PositionsMap = new List <Vector3>();

            for (int i = 0; i < positions.Length; i++)
            {
                LSL_Vector pos = positions.GetVector3Item(i);
                PositionsMap.Add(new Vector3((float)pos.x, (float)pos.y, (float)pos.z));
            }
            List <TravelMode> TravelMap = new List <TravelMode>();

            for (int i = 0; i < movementType.Length; i++)
            {
                LSL_Integer travel = movementType.GetLSLIntegerItem(i);
                TravelMap.Add((TravelMode)travel.value);
            }

            IBotManager manager = World.RequestModuleInterface <IBotManager>();

            if (manager != null)
            {
                manager.SetBotMap(UUID.Parse(keyOfBot), PositionsMap, TravelMap);
            }
        }
예제 #6
0
        protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector dimple, byte fudge)
        {
            ObjectShapePacket.ObjectDataBlock shapeBlock;

            shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);

            // profile/path swapped for a sphere
            shapeBlock.PathBegin = shapeBlock.ProfileBegin;
            shapeBlock.PathEnd = shapeBlock.ProfileEnd;

            shapeBlock.ProfileCurve += fudge;

            shapeBlock.PathScaleX = 100;
            shapeBlock.PathScaleY = 100;

            if (dimple.x < 0f)
            {
                dimple.x = 0f;
            }
            if (dimple.x > 1f)
            {
                dimple.x = 1f;
            }
            if (dimple.y < 0f)
            {
                dimple.y = 0f;
            }
            if (dimple.y > 1f)
            {
                dimple.y = 1f;
            }
            if (dimple.y - cut.x < 0.05f)
            {
                dimple.x = cut.y - 0.05f;
            }
            shapeBlock.ProfileBegin = (ushort)(50000 * dimple.x);
            shapeBlock.ProfileEnd   = (ushort)(50000 * (1 - dimple.y));

            part.Shape.SculptEntry = false;
            part.UpdateShape(shapeBlock);
        }
예제 #7
0
        protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist)
        {
            ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();

            if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
                holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
                holeshape != (int)ScriptBaseClass.PRIM_HOLE_SQUARE &&
                holeshape != (int)ScriptBaseClass.PRIM_HOLE_TRIANGLE)
            {
                holeshape = (int)ScriptBaseClass.PRIM_HOLE_DEFAULT;
            }
            shapeBlock.ProfileCurve = (byte)holeshape;
            if (cut.x < 0f)
            {
                cut.x = 0f;
            }
            if (cut.x > 1f)
            {
                cut.x = 1f;
            }
            if (cut.y < 0f)
            {
                cut.y = 0f;
            }
            if (cut.y > 1f)
            {
                cut.y = 1f;
            }
            if (cut.y - cut.x < 0.05f)
            {
                cut.x = cut.y - 0.05f;
                if (cut.x < 0.0f)
                {
                    cut.x = 0.0f;
                    cut.y = 0.05f;
                }
            }
            shapeBlock.ProfileBegin = (ushort)(50000 * cut.x);
            shapeBlock.ProfileEnd = (ushort)(50000 * (1 - cut.y));
            if (hollow < 0f)
            {
                hollow = 0f;
            }
            if (hollow > 0.95)
            {
                hollow = 0.95f;
            }
            shapeBlock.ProfileHollow = (ushort)(50000 * hollow);
            if (twist.x < -1.0f)
            {
                twist.x = -1.0f;
            }
            if (twist.x > 1.0f)
            {
                twist.x = 1.0f;
            }
            if (twist.y < -1.0f)
            {
                twist.y = -1.0f;
            }
            if (twist.y > 1.0f)
            {
                twist.y = 1.0f;
            }
            shapeBlock.PathTwistBegin = (sbyte)(100 * twist.x);
            shapeBlock.PathTwist = (sbyte)(100 * twist.y);

            shapeBlock.ObjectLocalID = part.LocalId;

            // retain pathcurve
            shapeBlock.PathCurve = part.Shape.PathCurve;

            part.Shape.SculptEntry = false;
            return shapeBlock;
        }
예제 #8
0
 public void llSetCameraAtOffset(LSL_Vector offset)
 {
     ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
     
     m_host.CameraAtOffset = new Vector3((float)offset.x, (float)offset.y, (float)offset.z);
 }
예제 #9
0
 //CFK 9/28: Most, but not all of the underlying plumbing between here and the physics modules is in
 //CFK 9/28: so these are not complete yet.
 public void llSetVehicleVectorParam(int param, LSL_Vector vec)
 {
     ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
     
     if (m_host.ParentGroup != null)
     {
         if (!m_host.ParentGroup.IsDeleted)
         {
             m_host.ParentGroup.RootPart.SetVehicleVectorParam(param,
                 new Vector3((float)vec.x, (float)vec.y, (float)vec.z));
         }
     }
 }
예제 #10
0
        private void SetParticleSystem(SceneObjectPart part, LSL_List rules)
        {
            if (rules.Length == 0)
            {
                part.RemoveParticleSystem();
                part.ParentGroup.HasGroupChanged = true;
            }
            else
            {
                Primitive.ParticleSystem prules = getNewParticleSystemWithSLDefaultValues();
                LSL_Vector tempv = new LSL_Vector();

                float tempf = 0;

                for (int i = 0; i < rules.Length; i += 2)
                {
                    LSL_Integer rule = rules.GetLSLIntegerItem(i);
                    if (rule == (int)ScriptBaseClass.PSYS_PART_FLAGS)
                    {
                        prules.PartDataFlags = (Primitive.ParticleSystem.ParticleDataFlags)(uint)rules.GetLSLIntegerItem(i + 1);
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_PART_START_COLOR)
                    {
                        tempv = rules.GetVector3Item(i + 1);
                        prules.PartStartColor.R = (float)tempv.x;
                        prules.PartStartColor.G = (float)tempv.y;
                        prules.PartStartColor.B = (float)tempv.z;
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_PART_START_ALPHA)
                    {
                        tempf = (float)rules.GetLSLFloatItem(i + 1);
                        prules.PartStartColor.A = tempf;
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_PART_END_COLOR)
                    {
                        tempv = rules.GetVector3Item(i + 1);
                        prules.PartEndColor.R = (float)tempv.x;
                        prules.PartEndColor.G = (float)tempv.y;
                        prules.PartEndColor.B = (float)tempv.z;
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_PART_END_ALPHA)
                    {
                        tempf = (float)rules.GetLSLFloatItem(i + 1);
                        prules.PartEndColor.A = tempf;
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_PART_START_SCALE)
                    {
                        tempv = rules.GetVector3Item(i + 1);
                        prules.PartStartScaleX = (float)tempv.x;
                        prules.PartStartScaleY = (float)tempv.y;
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_PART_END_SCALE)
                    {
                        tempv = rules.GetVector3Item(i + 1);
                        prules.PartEndScaleX = (float)tempv.x;
                        prules.PartEndScaleY = (float)tempv.y;
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_PART_MAX_AGE)
                    {
                        tempf = (float)rules.GetLSLFloatItem(i + 1);
                        prules.PartMaxAge = tempf;
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_SRC_ACCEL)
                    {
                        tempv = rules.GetVector3Item(i + 1);
                        prules.PartAcceleration.X = (float)tempv.x;
                        prules.PartAcceleration.Y = (float)tempv.y;
                        prules.PartAcceleration.Z = (float)tempv.z;
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_SRC_PATTERN)
                    {
                        int tmpi = (int)rules.GetLSLIntegerItem(i + 1);
                        prules.Pattern = (Primitive.ParticleSystem.SourcePattern)tmpi;
                    }

                    // PSYS_SRC_INNERANGLE and PSYS_SRC_ANGLE_BEGIN use the same variables. The
                    // PSYS_SRC_OUTERANGLE and PSYS_SRC_ANGLE_END also use the same variable. The
                    // client tells the difference between the two by looking at the 0x02 bit in
                    // the PartFlags variable.
                    else if (rule == (int)ScriptBaseClass.PSYS_SRC_INNERANGLE)
                    {
                        tempf = (float)rules.GetLSLFloatItem(i + 1);
                        prules.InnerAngle = (float)tempf;
                        prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_SRC_OUTERANGLE)
                    {
                        tempf = (float)rules.GetLSLFloatItem(i + 1);
                        prules.OuterAngle = (float)tempf;
                        prules.PartFlags &= 0xFFFFFFFD; // Make sure new angle format is off.
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_SRC_TEXTURE)
                    {
                        prules.Texture = KeyOrName(rules.GetLSLStringItem(i + 1));
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_SRC_BURST_RATE)
                    {
                        tempf = (float)rules.GetLSLFloatItem(i + 1);
                        prules.BurstRate = (float)tempf;
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_SRC_BURST_PART_COUNT)
                    {
                        prules.BurstPartCount = (byte)(int)rules.GetLSLIntegerItem(i + 1);
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_SRC_BURST_RADIUS)
                    {
                        tempf = (float)rules.GetLSLFloatItem(i + 1);
                        prules.BurstRadius = (float)tempf;
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MIN)
                    {
                        tempf = (float)rules.GetLSLFloatItem(i + 1);
                        prules.BurstSpeedMin = (float)tempf;
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_SRC_BURST_SPEED_MAX)
                    {
                        tempf = (float)rules.GetLSLFloatItem(i + 1);
                        prules.BurstSpeedMax = (float)tempf;
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_SRC_MAX_AGE)
                    {
                        tempf = (float)rules.GetLSLFloatItem(i + 1);
                        prules.MaxAge = (float)tempf;
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_SRC_TARGET_KEY)
                    {
                        UUID key = UUID.Zero;
                        if (UUID.TryParse(rules.Data[i + 1].ToString(), out key))
                        {
                            prules.Target = key;
                        }
                        else
                        {
                            prules.Target = part.UUID;
                        }
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_SRC_OMEGA)
                    {
                        // AL: This is an assumption, since it is the only thing that would match.
                        tempv = rules.GetVector3Item(i + 1);
                        prules.AngularVelocity.X = (float)tempv.x;
                        prules.AngularVelocity.Y = (float)tempv.y;
                        prules.AngularVelocity.Z = (float)tempv.z;
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_SRC_ANGLE_BEGIN)
                    {
                        tempf = (float)rules.GetLSLFloatItem(i + 1);
                        prules.InnerAngle = (float)tempf;
                        prules.PartFlags |= 0x02; // Set new angle format.
                    }

                    else if (rule == (int)ScriptBaseClass.PSYS_SRC_ANGLE_END)
                    {
                        tempf = (float)rules.GetLSLFloatItem(i + 1);
                        prules.OuterAngle = (float)tempf;
                        prules.PartFlags |= 0x02; // Set new angle format.
                    }
                }
                prules.CRC = 1;

                part.AddNewParticleSystem(prules);
                part.ParentGroup.HasGroupChanged = true;
            }
            part.ScheduleUpdate(PrimUpdateFlags.Particles);
        }
예제 #11
0
 public LSL_Vector llGroundContour(LSL_Vector offset)
 {
     ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
     
     LSL_Vector x = llGroundSlope(offset);
     return new LSL_Vector(-x.y, x.x, 0.0);
 }
예제 #12
0
        public void llPushObject(string target, LSL_Vector impulse, LSL_Vector ang_impulse, int local)
        {
            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
            
            bool pushrestricted = World.RegionInfo.RegionSettings.RestrictPushing;
            bool pushAllowed = false;

            bool pusheeIsAvatar = false;
            UUID targetID = UUID.Zero;

            if (!UUID.TryParse(target,out targetID))
                return;

            ScenePresence pusheeav = null;
            Vector3 PusheePos = Vector3.Zero;
            SceneObjectPart pusheeob = null;

            ScenePresence avatar = World.GetScenePresence(targetID);
            if (avatar != null)
            {
                pusheeIsAvatar = true;

                // Pushee doesn't have a physics actor
                if (avatar.PhysicsActor == null)
                    return;

                // Pushee is in GodMode this pushing object isn't owned by them
                if (avatar.GodLevel > 0 && m_host.OwnerID != targetID)
                    return;

                pusheeav = avatar;

                // Find pushee position
                // Pushee Linked?
                if (pusheeav.ParentID != UUID.Zero)
                {
                    SceneObjectPart parentobj = World.GetSceneObjectPart(pusheeav.ParentID);
                    if (parentobj != null)
                    {
                        PusheePos = parentobj.AbsolutePosition;
                    }
                    else
                    {
                        PusheePos = pusheeav.AbsolutePosition;
                    }
                }
                else
                {
                    PusheePos = pusheeav.AbsolutePosition;
                }
            }

            if (!pusheeIsAvatar)
            {
                // not an avatar so push is not affected by parcel flags
                pusheeob = World.GetSceneObjectPart((UUID)target);

                // We can't find object
                if (pusheeob == null)
                    return;

                // Object not pushable.  Not an attachment and has no physics component
                if (!pusheeob.IsAttachment && pusheeob.PhysActor == null)
                    return;

                PusheePos = pusheeob.AbsolutePosition;
                pushAllowed = true;
            }
            else
            {
                IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
                if (pushrestricted)
                {
                    if (parcelManagement != null)
                    {
                        ILandObject targetlandObj = parcelManagement.GetLandObject(PusheePos.X, PusheePos.Y);

                        // We didn't find the parcel but region is push restricted so assume it is NOT ok
                        if (targetlandObj == null)
                            return;

                        // Need provisions for Group Owned here
                        if (m_host.OwnerID == targetlandObj.LandData.OwnerID ||
                            targetlandObj.LandData.IsGroupOwned || m_host.OwnerID == targetID)
                        {
                            pushAllowed = true;
                        }
                    }
                }
                else
                {
                    if (parcelManagement != null)
                    {
                        ILandObject targetlandObj = parcelManagement.GetLandObject(PusheePos.X, PusheePos.Y);
                        if (targetlandObj == null)
                        {
                            // We didn't find the parcel but region isn't push restricted so assume it's ok
                            pushAllowed = true;
                        }
                        else
                        {
                            // Parcel push restriction
                            if ((targetlandObj.LandData.Flags & (uint)ParcelFlags.RestrictPushObject) == (uint)ParcelFlags.RestrictPushObject)
                            {
                                //This takes care of everything
                                pushAllowed = m_host.ParentGroup.Scene.Permissions.CanPushObject(m_host.OwnerID, targetlandObj);
                                // Need provisions for Group Owned here
                                /*if (m_host.OwnerID == targetlandObj.LandData.OwnerID || 
                                    targetlandObj.LandData.IsGroupOwned || 
                                    m_host.OwnerID == targetID)
                                {
                                    pushAllowed = true;
                                }*/

                                //ParcelFlags.RestrictPushObject
                                //pushAllowed = true;
                            }
                            else
                            {
                                // Parcel isn't push restricted
                                pushAllowed = true;
                            }
                        }
                    }
                }
            }
            if (pushAllowed)
            {
                float distance = (PusheePos - m_host.AbsolutePosition).Length();
                float distance_term = distance * distance * distance; // Script Energy
                float pusher_mass = m_host.GetMass();

                float PUSH_ATTENUATION_DISTANCE = 17f;
                float PUSH_ATTENUATION_SCALE = 5f;
                float distance_attenuation = 1f;
                if (distance > PUSH_ATTENUATION_DISTANCE)
                {
                    float normalized_units = 1f + (distance - PUSH_ATTENUATION_DISTANCE) / PUSH_ATTENUATION_SCALE;
                    distance_attenuation = 1f / normalized_units;
                }

                Vector3 applied_linear_impulse = new Vector3((float)impulse.x, (float)impulse.y, (float)impulse.z);
                {
                    float impulse_length = applied_linear_impulse.Length();

                    float desired_energy = impulse_length * pusher_mass;
                    if (desired_energy > 0f)
                        desired_energy += distance_term;

                    float scaling_factor = 1f;
                    scaling_factor *= distance_attenuation;
                    applied_linear_impulse *= scaling_factor;

                }
                if (pusheeIsAvatar)
                {
                    if (pusheeav != null)
                    {
                        if (pusheeav.PhysicsActor != null)
                        {
                            if (local != 0)
                            {
                                applied_linear_impulse *= m_host.GetWorldRotation();
                            }
                            //Put a limit on it...
                            int MaxPush = (int)pusheeav.PhysicsActor.Mass * 25;

                            if (applied_linear_impulse.X > 0 &&
                                Math.Abs(applied_linear_impulse.X) > MaxPush)
                                applied_linear_impulse.X = MaxPush;
                            if (applied_linear_impulse.X < 0 &&
                                Math.Abs(applied_linear_impulse.X) > MaxPush)
                                applied_linear_impulse.X = -MaxPush;

                            if (applied_linear_impulse.Y > 0 &&
                                Math.Abs(applied_linear_impulse.X) > MaxPush)
                                applied_linear_impulse.Y = MaxPush;
                            if (applied_linear_impulse.Y < 0 &&
                                Math.Abs(applied_linear_impulse.X) > MaxPush)
                                applied_linear_impulse.Y = -MaxPush;

                            if (applied_linear_impulse.Z > 0 &&
                                Math.Abs(applied_linear_impulse.X) > MaxPush)
                                applied_linear_impulse.Z = MaxPush;
                            if (applied_linear_impulse.Z < 0 &&
                                Math.Abs(applied_linear_impulse.Z) > MaxPush)
                                applied_linear_impulse.Z = -MaxPush;

                            pusheeav.PhysicsActor.AddForce(applied_linear_impulse, true);
                        }
                    }
                }
                else
                {
                    if (pusheeob != null)
                    {
                        if (pusheeob.PhysActor != null)
                        {
                            pusheeob.ApplyImpulse(applied_linear_impulse, local != 0);
                        }
                    }
                }
            }
        }
예제 #13
0
 public LSL_Float llWater(LSL_Vector offset)
 {
     ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
     
     return World.RegionInfo.RegionSettings.WaterHeight;
 }
예제 #14
0
        public LSL_String botCreateBot(string FirstName, string LastName, string appearanceToClone, LSL_Vector startPos)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.Moderate, "botCreateBot", m_host, "bot", m_itemID))
            {
                return("");
            }
            IBotManager manager = World.RequestModuleInterface <IBotManager>();

            if (manager != null)
            {
                return
                    (new LSL_String(
                         manager.CreateAvatar(FirstName, LastName, m_host.ParentEntity.Scene,
                                              UUID.Parse(appearanceToClone), m_host.OwnerID,
                                              new Vector3((float)startPos.x, (float)startPos.y, (float)startPos.z)).
                         ToString()));
            }
            return(new LSL_String(""));
        }
예제 #15
0
 public void aaSetEnv(LSL_String name, LSL_List value)
 {
     if (name == ScriptBaseClass.ENABLE_GRAVITY)
     {
         LSL_Integer enabled = value.GetLSLIntegerItem(0);
         float[]     grav    = m_host.ParentEntity.Scene.PhysicsScene.GetGravityForce();
         m_host.ParentEntity.Scene.PhysicsScene.SetGravityForce(enabled == 1, grav[0], grav[1], grav[2]);
     }
     else if (name == ScriptBaseClass.GRAVITY_FORCE_X)
     {
         LSL_Float f    = value.GetLSLFloatItem(0);
         float[]   grav = m_host.ParentEntity.Scene.PhysicsScene.GetGravityForce();
         m_host.ParentEntity.Scene.PhysicsScene.SetGravityForce(true, (float)f.value, grav[1], grav[2]);
     }
     else if (name == ScriptBaseClass.GRAVITY_FORCE_Y)
     {
         LSL_Float f    = value.GetLSLFloatItem(0);
         float[]   grav = m_host.ParentEntity.Scene.PhysicsScene.GetGravityForce();
         m_host.ParentEntity.Scene.PhysicsScene.SetGravityForce(true, grav[0], (float)f.value, grav[2]);
     }
     else if (name == ScriptBaseClass.GRAVITY_FORCE_Z)
     {
         LSL_Float f    = value.GetLSLFloatItem(0);
         float[]   grav = m_host.ParentEntity.Scene.PhysicsScene.GetGravityForce();
         m_host.ParentEntity.Scene.PhysicsScene.SetGravityForce(true, grav[0], grav[1], (float)f.value);
     }
     else if (name == ScriptBaseClass.ADD_GRAVITY_POINT)
     {
         LSL_Vector  pos       = value.GetVector3Item(0);
         LSL_Float   gravForce = value.GetLSLFloatItem(1);
         LSL_Float   radius    = value.GetLSLFloatItem(2);
         LSL_Integer ident     = value.GetLSLIntegerItem(3);
         float[]     grav      = m_host.ParentEntity.Scene.PhysicsScene.GetGravityForce();
         m_host.ParentEntity.Scene.PhysicsScene.AddGravityPoint(false,
                                                                new Vector3((float)pos.x, (float)pos.y,
                                                                            (float)pos.z),
                                                                0, 0, 0, (float)gravForce.value,
                                                                (float)radius.value, ident.value);
     }
     else if (name == ScriptBaseClass.ADD_GRAVITY_FORCE)
     {
         LSL_Vector  pos    = value.GetVector3Item(0);
         LSL_Float   xForce = value.GetLSLFloatItem(1);
         LSL_Float   yForce = value.GetLSLFloatItem(2);
         LSL_Float   zForce = value.GetLSLFloatItem(3);
         LSL_Float   radius = value.GetLSLFloatItem(4);
         LSL_Integer ident  = value.GetLSLIntegerItem(5);
         float[]     grav   = m_host.ParentEntity.Scene.PhysicsScene.GetGravityForce();
         m_host.ParentEntity.Scene.PhysicsScene.AddGravityPoint(true,
                                                                new Vector3((float)pos.x, (float)pos.y,
                                                                            (float)pos.z),
                                                                (float)xForce, (float)yForce, (float)zForce, 0,
                                                                (float)radius.value, ident.value);
     }
     else if (name == ScriptBaseClass.START_TIME_REVERSAL_SAVING)
     {
         IPhysicsStateModule physicsState = World.RequestModuleInterface <IPhysicsStateModule>();
         if (physicsState != null)
         {
             physicsState.StartSavingPhysicsTimeReversalStates();
         }
     }
     else if (name == ScriptBaseClass.STOP_TIME_REVERSAL_SAVING)
     {
         IPhysicsStateModule physicsState = World.RequestModuleInterface <IPhysicsStateModule>();
         if (physicsState != null)
         {
             physicsState.StopSavingPhysicsTimeReversalStates();
         }
     }
     else if (name == ScriptBaseClass.START_TIME_REVERSAL)
     {
         IPhysicsStateModule physicsState = World.RequestModuleInterface <IPhysicsStateModule>();
         if (physicsState != null)
         {
             physicsState.StartPhysicsTimeReversal();
         }
     }
     else if (name == ScriptBaseClass.STOP_TIME_REVERSAL)
     {
         IPhysicsStateModule physicsState = World.RequestModuleInterface <IPhysicsStateModule>();
         if (physicsState != null)
         {
             physicsState.StopPhysicsTimeReversal();
         }
     }
 }
예제 #16
0
 public LSL_Rotation llRotBetween(LSL_Vector a, LSL_Vector b)
 {
     ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
     //A and B should both be normalized
     
     LSL_Rotation rotBetween;
     // Check for zero vectors. If either is zero, return zero rotation. Otherwise,
     // continue calculation.
     if (a == new LSL_Vector(0.0f, 0.0f, 0.0f) || b == new LSL_Vector(0.0f, 0.0f, 0.0f))
     {
         rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
     }
     else
     {
         a = LSL_Vector.Norm(a);
         b = LSL_Vector.Norm(b);
         double dotProduct = LSL_Vector.Dot(a, b);
         // There are two degenerate cases possible. These are for vectors 180 or
         // 0 degrees apart. These have to be detected and handled individually.
         //
         // Check for vectors 180 degrees apart.
         // A dot product of -1 would mean the angle between vectors is 180 degrees.
         if (dotProduct < -0.9999999f)
         {
             // First assume X axis is orthogonal to the vectors.
             LSL_Vector orthoVector = new LSL_Vector(1.0f, 0.0f, 0.0f);
             orthoVector = orthoVector - a * (a.x / LSL_Vector.Dot(a, a));
             // Check for near zero vector. A very small non-zero number here will create
             // a rotation in an undesired direction.
             if (LSL_Vector.Mag(orthoVector) > 0.0001)
             {
                 rotBetween = new LSL_Rotation(orthoVector.x, orthoVector.y, orthoVector.z, 0.0f);
             }
             // If the magnitude of the vector was near zero, then assume the X axis is not
             // orthogonal and use the Z axis instead.
             else
             {
                 // Set 180 z rotation.
                 rotBetween = new LSL_Rotation(0.0f, 0.0f, 1.0f, 0.0f);
             }
         }
         // Check for parallel vectors.
         // A dot product of 1 would mean the angle between vectors is 0 degrees.
         else if (dotProduct > 0.9999999f)
         {
             // Set zero rotation.
             rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
         }
         else
         {
             // All special checks have been performed so get the axis of rotation.
             LSL_Vector crossProduct = LSL_Vector.Cross(a, b);
             // Quarternion s value is the length of the unit vector + dot product.
             double qs = 1.0 + dotProduct;
             rotBetween = new LSL_Rotation(crossProduct.x, crossProduct.y, crossProduct.z, qs);
             // Normalize the rotation.
             double mag = LSL_Rotation.Mag(rotBetween);
             // We shouldn't have to worry about a divide by zero here. The qs value will be
             // non-zero because we already know if we're here, then the dotProduct is not -1 so
             // qs will not be zero. Also, we've already handled the input vectors being zero so the
             // crossProduct vector should also not be zero.
             rotBetween.x = rotBetween.x / mag;
             rotBetween.y = rotBetween.y / mag;
             rotBetween.z = rotBetween.z / mag;
             rotBetween.s = rotBetween.s / mag;
             // Check for undefined values and set zero rotation if any found. This code might not actually be required
             // any longer since zero vectors are checked for at the top.
             if (Double.IsNaN(rotBetween.x) || Double.IsNaN(rotBetween.y) || Double.IsNaN(rotBetween.z) || Double.IsNaN(rotBetween.s))
             {
                 rotBetween = new LSL_Rotation(0.0f, 0.0f, 0.0f, 1.0f);
             }
         }
     }
     return rotBetween;
 }
예제 #17
0
        public LSL_List GetLinkPrimitiveParams(SceneObjectPart part, LSL_List rules)
        {
            LSL_List res = new LSL_List();
            int idx = 0;
            while (idx < rules.Length)
            {
                int code = (int)rules.GetLSLIntegerItem(idx++);
                int remain = rules.Length - idx;
                Primitive.TextureEntry tex = part.Shape.Textures;
                int face = 0;
                if (idx < rules.Length)
                    face = (int)rules.GetLSLIntegerItem(idx++);

                Primitive.TextureEntryFace texFace = tex.GetFace((uint)face);

                if (code == (int)ScriptBaseClass.PRIM_NAME)
                {
                    res.Add(new LSL_Integer(part.Name));
                }

                if (code == (int)ScriptBaseClass.PRIM_DESC)
                {
                    res.Add(new LSL_Integer(part.Description));
                }

                if (code == (int)ScriptBaseClass.PRIM_MATERIAL)
                {
                    res.Add(new LSL_Integer(part.Material));
                }

                if (code == (int)ScriptBaseClass.PRIM_PHYSICS)
                {
                    if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) != 0)
                        res.Add(new LSL_Integer(1));
                    else
                        res.Add(new LSL_Integer(0));
                }

                if (code == (int)ScriptBaseClass.PRIM_TEMP_ON_REZ)
                {
                    if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.TemporaryOnRez) != 0)
                        res.Add(new LSL_Integer(1));
                    else
                        res.Add(new LSL_Integer(0));
                }

                if (code == (int)ScriptBaseClass.PRIM_PHANTOM)
                {
                    if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) != 0)
                        res.Add(new LSL_Integer(1));
                    else
                        res.Add(new LSL_Integer(0));
                }

                if (code == (int)ScriptBaseClass.PRIM_POSITION)
                {
                    Vector3 tmp = part.AbsolutePosition;
                    LSL_Vector v = new LSL_Vector(tmp.X,
                                                  tmp.Y,
                                                  tmp.Z);
                    // For some reason, the part.AbsolutePosition.* values do not change if the
                    // linkset is rotated; they always reflect the child prim's world position
                    // as though the linkset is unrotated. This is incompatible behavior with SL's
                    // implementation, so will break scripts imported from there (not to mention it
                    // makes it more difficult to determine a child prim's actual inworld position).
                    if (part.ParentID != 0)
                        {
                        LSL_Rotation rtmp = llGetRootRotation();
                        LSL_Vector rpos = llGetRootPosition();
                        v = ((v - rpos) * rtmp) + rpos;
                        }
                    res.Add(v);
                }

                if (code == (int)ScriptBaseClass.PRIM_SIZE)
                {
                    Vector3 tmp = part.Scale;
                    res.Add(new LSL_Vector(tmp.X,
                                                  tmp.Y,
                                                  tmp.Z));
                }

                if (code == (int)ScriptBaseClass.PRIM_ROTATION)
                {
                    res.Add(GetPartRot(part));
                }

                if (code == (int)ScriptBaseClass.PRIM_TYPE)
                {
                    // implementing box
                    PrimitiveBaseShape Shape = part.Shape;
                    int primType = (int)part.GetPrimType();
                    res.Add(new LSL_Integer(primType));
                    double topshearx = (double)(sbyte)Shape.PathShearX / 100.0; // Fix negative values for PathShearX
                    double topsheary = (double)(sbyte)Shape.PathShearY / 100.0; // and PathShearY.
                    if (primType == ScriptBaseClass.PRIM_TYPE_BOX ||
                         ScriptBaseClass.PRIM_TYPE_CYLINDER ||
                         ScriptBaseClass.PRIM_TYPE_PRISM)
                    {
                        res.Add(new LSL_Integer(Shape.ProfileCurve));
                        res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
                        res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
                        res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
                        res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
                        res.Add(new LSL_Vector(topshearx, topsheary, 0));
                    }

                    if (primType == ScriptBaseClass.PRIM_TYPE_SPHERE)
                    {
                        res.Add(new LSL_Integer(Shape.ProfileCurve));
                        res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
                        res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
                        res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
                        res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
                    }

                    if (primType == ScriptBaseClass.PRIM_TYPE_SCULPT)
                    {
                        res.Add(Shape.SculptTexture.ToString());
                        res.Add(new LSL_Integer(Shape.SculptType));
                    }
                    if (primType == ScriptBaseClass.PRIM_TYPE_RING ||
                     ScriptBaseClass.PRIM_TYPE_TUBE ||
                     ScriptBaseClass.PRIM_TYPE_TORUS)
                    {
                        // holeshape
                        res.Add(new LSL_Integer(Shape.ProfileCurve));

                        // cut
                        res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));

                        // hollow
                        res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));

                        // twist
                        res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));

                        // vector holesize
                        res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));

                        // vector topshear
                        res.Add(new LSL_Vector(topshearx, topsheary, 0));

                        // vector profilecut
                        res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));

                        // vector tapera
                        res.Add(new LSL_Vector(Shape.PathTaperX / 100.0, Shape.PathTaperY / 100.0, 0));

                        // float revolutions
                        res.Add(new LSL_Float((Shape.PathRevolutions * 0.015) + 1.0)); // Slightly inaccurate, because an unsigned
                        // byte is being used to represent the entire
                        // range of floating-point values from 1.0
                        // through 4.0 (which is how SL does it). 

                        // float radiusoffset
                        res.Add(new LSL_Float(Shape.PathRadiusOffset / 100.0));

                        // float skew
                        res.Add(new LSL_Float(Shape.PathSkew / 100.0));
                    }
                }

                if (code == (int)ScriptBaseClass.PRIM_TEXTURE)
                {
                    if (remain < 1)
                        return res;

                    if (face == ScriptBaseClass.ALL_SIDES)
                    {
                        for (face = 0; face < GetNumberOfSides(part); face++)
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint)face);

                            res.Add(new LSL_String(texface.TextureID.ToString()));
                            res.Add(new LSL_Vector(texface.RepeatU,
                                                   texface.RepeatV,
                                                   0));
                            res.Add(new LSL_Vector(texface.OffsetU,
                                                   texface.OffsetV,
                                                   0));
                            res.Add(new LSL_Float(texface.Rotation));
                        }
                    }
                    else
                    {
                        if (face >= 0 && face < GetNumberOfSides(part))
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint)face);

                            res.Add(new LSL_String(texface.TextureID.ToString()));
                            res.Add(new LSL_Vector(texface.RepeatU,
                                                   texface.RepeatV,
                                                   0));
                            res.Add(new LSL_Vector(texface.OffsetU,
                                                   texface.OffsetV,
                                                   0));
                            res.Add(new LSL_Float(texface.Rotation));
                        }
                    }
                }

                if (code == (int)ScriptBaseClass.PRIM_COLOR)
                {
                    if (remain < 1)
                        return res;

                    tex = part.Shape.Textures;
                    Color4 texcolor;
                    if (face == ScriptBaseClass.ALL_SIDES)
                    {
                        for (face = 0; face < GetNumberOfSides(part); face++)
                        {
                            texcolor = tex.GetFace((uint)face).RGBA;
                            res.Add(new LSL_Vector(texcolor.R,
                                                   texcolor.G,
                                                   texcolor.B));
                            res.Add(new LSL_Float(texcolor.A));
                        }
                    }
                    else
                    {
                        texcolor = tex.GetFace((uint)face).RGBA;
                        res.Add(new LSL_Vector(texcolor.R,
                                               texcolor.G,
                                               texcolor.B));
                        res.Add(new LSL_Float(texcolor.A));
                    }
                }

                if (code == (int)ScriptBaseClass.PRIM_BUMP_SHINY)
                {
                    if (remain < 1)
                        return res;

                    face = (int)rules.GetLSLIntegerItem(idx++);
                    texFace = tex.GetFace((uint)face);

                    if (face == ScriptBaseClass.ALL_SIDES)
                    {
                        for (face = 0; face < GetNumberOfSides(part); face++)
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                            // Convert Shininess to PRIM_SHINY_*
                            res.Add(new LSL_Integer((uint)texface.Shiny >> 6));
                            // PRIM_BUMP_*
                            res.Add(new LSL_Integer((int)texface.Bump));
                        }
                    }
                    else
                    {
                        if (face >= 0 && face < GetNumberOfSides(part))
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                            // Convert Shininess to PRIM_SHINY_*
                            res.Add(new LSL_Integer((uint)texface.Shiny >> 6));
                            // PRIM_BUMP_*
                            res.Add(new LSL_Integer((int)texface.Bump));
                        }
                    }
                }

                if (code == (int)ScriptBaseClass.PRIM_FULLBRIGHT)
                {
                    if (remain < 1)
                        return res;

                    face = (int)rules.GetLSLIntegerItem(idx++);
                    tex = part.Shape.Textures;
                    if (face == ScriptBaseClass.ALL_SIDES)
                    {
                        for (face = 0; face < GetNumberOfSides(part); face++)
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                            res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
                        }
                    }
                    else
                    {
                        if (face >= 0 && face < GetNumberOfSides(part))
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                            res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
                        }
                    }
                }

                if (code == (int)ScriptBaseClass.PRIM_FLEXIBLE)
                {
                    PrimitiveBaseShape shape = part.Shape;

                    if (shape.FlexiEntry)
                        res.Add(new LSL_Integer(1));              // active
                    else
                        res.Add(new LSL_Integer(0));
                    res.Add(new LSL_Integer(shape.FlexiSoftness));// softness
                    res.Add(new LSL_Float(shape.FlexiGravity));   // gravity
                    res.Add(new LSL_Float(shape.FlexiDrag));      // friction
                    res.Add(new LSL_Float(shape.FlexiWind));      // wind
                    res.Add(new LSL_Float(shape.FlexiTension));   // tension
                    res.Add(new LSL_Vector(shape.FlexiForceX,       // force
                                           shape.FlexiForceY,
                                           shape.FlexiForceZ));
                }

                if (code == (int)ScriptBaseClass.PRIM_TEXGEN)
                {
                    if (remain < 1)
                        return res;

                    face = (int)rules.GetLSLIntegerItem(idx++);
                    if (face == ScriptBaseClass.ALL_SIDES)
                    {
                        for (face = 0; face < GetNumberOfSides(part); face++)
                        {
                            MappingType texgen = tex.GetFace((uint)face).TexMapType;
                            // Convert MappingType to PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR etc.
                            res.Add(new LSL_Integer((uint)texgen >> 1));
                        }
                    }
                    else
                    {
                        if (face >= 0 && face < GetNumberOfSides(part))
                        {
                            MappingType texgen = tex.GetFace((uint)face).TexMapType;
                            res.Add(new LSL_Integer((uint)texgen >> 1));
                        }
                    }
                }

                if (code == (int)ScriptBaseClass.PRIM_POINT_LIGHT)
                {
                    PrimitiveBaseShape shape = part.Shape;

                    if (shape.LightEntry)
                        res.Add(new LSL_Integer(1));              // active
                    else
                        res.Add(new LSL_Integer(0));
                    res.Add(new LSL_Vector(shape.LightColorR,       // color
                                           shape.LightColorG,
                                           shape.LightColorB));
                    res.Add(new LSL_Float(shape.LightIntensity)); // intensity
                    res.Add(new LSL_Float(shape.LightRadius));    // radius
                    res.Add(new LSL_Float(shape.LightFalloff));   // falloff
                }

                if (code == (int)ScriptBaseClass.PRIM_GLOW)
                {
                    if (remain < 1)
                        return res;

                    face = (int)rules.GetLSLIntegerItem(idx++);
                    if (face == ScriptBaseClass.ALL_SIDES)
                    {
                        for (face = 0; face < GetNumberOfSides(part); face++)
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                            res.Add(new LSL_Float(texface.Glow));
                        }
                    }
                    else
                    {
                        if (face >= 0 && face < GetNumberOfSides(part))
                        {
                            Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                            res.Add(new LSL_Float(texface.Glow));
                        }
                    }
                }

                if (code == (int)ScriptBaseClass.PRIM_TEXT)
                {
                    Color4 textColor = part.GetTextColor();
                    res.Add(part.Text);
                    res.Add(new LSL_Vector(textColor.R,
                                           textColor.G,
                                           textColor.B));
                    res.Add(new LSL_Float(textColor.A));
                }
                if (code == (int)ScriptBaseClass.PRIM_ROT_LOCAL)
                {
                    Quaternion rtmp = part.RotationOffset;
                    res.Add(new LSL_Rotation(rtmp.X, rtmp.Y, rtmp.Z, rtmp.W));
                }
            }
            return res;
        }
예제 #18
0
        /* The new / changed functions were tested with the following LSL script:

        default
        {
            state_entry()
            {
                rotation rot = llEuler2Rot(<0,70,0> * DEG_TO_RAD);

                llOwnerSay("to get here, we rotate over: "+ (string) llRot2Axis(rot));
                llOwnerSay("and we rotate for: "+ (llRot2Angle(rot) * RAD_TO_DEG));

                // convert back and forth between quaternion <-> vector and angle

                rotation newrot = llAxisAngle2Rot(llRot2Axis(rot),llRot2Angle(rot));

                llOwnerSay("Old rotation was: "+(string) rot);
                llOwnerSay("re-converted rotation is: "+(string) newrot);

                llSetRot(rot);  // to check the parameters in the prim
            }
        }
        */

        // Xantor 29/apr/2008
        // Returns rotation described by rotating angle radians about axis.
        // q = cos(a/2) + i (x * sin(a/2)) + j (y * sin(a/2)) + k (z * sin(a/2))
        public LSL_Rotation llAxisAngle2Rot(LSL_Vector axis, double angle)
        {
            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
            

            double x, y, z, s, t;

            s = Math.Cos(angle * 0.5);
            t = Math.Sin(angle * 0.5); // temp value to avoid 2 more sin() calcs
            x = axis.x * t;
            y = axis.y * t;
            z = axis.z * t;

            return new LSL_Rotation(x,y,z,s);
        }
예제 #19
0
        public LSL_Vector llGroundNormal(LSL_Vector offset)
        {
            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
            
            Vector3 pos = m_host.GetWorldPosition() + new Vector3((float)offset.x,
                                                                (float)offset.y,
                                                                (float)offset.z);
            ITerrainChannel heightmap = World.RequestModuleInterface<ITerrainChannel>();
            // Clamp to valid position
            if (pos.X < 0)
                pos.X = 0;
            else if (pos.X >= heightmap.Width)
                pos.X = heightmap.Width - 1;
            if (pos.Y < 0)
                pos.Y = 0;
            else if (pos.Y >= heightmap.Height)
                pos.Y = heightmap.Height - 1;

            //Find two points in addition to the position to define a plane
            Vector3 p0 = new Vector3(pos.X, pos.Y,
                                     (float)heightmap[(int)pos.X, (int)pos.Y]);
            Vector3 p1 = new Vector3();
            Vector3 p2 = new Vector3();
            if ((pos.X + 1.0f) >= heightmap.Width)
                p1 = new Vector3(pos.X + 1.0f, pos.Y,
                            (float)heightmap[(int)pos.X, (int)pos.Y]);
            else
                p1 = new Vector3(pos.X + 1.0f, pos.Y,
                            (float)heightmap[(int)(pos.X + 1.0f), (int)pos.Y]);
            if ((pos.Y + 1.0f) >= heightmap.Height)
                p2 = new Vector3(pos.X, pos.Y + 1.0f,
                            (float)heightmap[(int)pos.X, (int)pos.Y]);
            else
                p2 = new Vector3(pos.X, pos.Y + 1.0f,
                            (float)heightmap[(int)pos.X, (int)(pos.Y + 1.0f)]);

            //Find normalized vectors from p0 to p1 and p0 to p2
            Vector3 v0 = new Vector3(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
            Vector3 v1 = new Vector3(p2.X - p0.X, p2.Y - p0.Y, p2.Z - p0.Z);
//            v0.Normalize();
//            v1.Normalize();

            //Find the cross product of the vectors (the slope normal).
            Vector3 vsn = new Vector3();
            vsn.X = (v0.Y * v1.Z) - (v0.Z * v1.Y);
            vsn.Y = (v0.Z * v1.X) - (v0.X * v1.Z);
            vsn.Z = (v0.X * v1.Y) - (v0.Y * v1.X);
            vsn.Normalize();
            //I believe the crossproduct of two normalized vectors is a normalized vector so
            //this normalization may be overkill
            // then don't normalize them just the result

            return new LSL_Vector(vsn.X, vsn.Y, vsn.Z);
        }
예제 #20
0
 protected LSL_Vector GetTextureOffset(SceneObjectPart part, int face)
 {
     Primitive.TextureEntry tex = part.Shape.Textures;
     LSL_Vector offset = new LSL_Vector();
     if (face == ScriptBaseClass.ALL_SIDES)
     {
         face = 0;
     }
     if (face >= 0 && face < GetNumberOfSides(part))
     {
         offset.x = tex.GetFace((uint)face).OffsetU;
         offset.y = tex.GetFace((uint)face).OffsetV;
         offset.z = 0.0;
         return offset;
     }
     else
     {
         return offset;
     }
 }
예제 #21
0
        /* From wiki:
        The Euler angle vector (in radians) is converted to a rotation by doing the rotations around the 3 axes
        in Z, Y, X order. So llEuler2Rot(<1.0, 2.0, 3.0> * DEG_TO_RAD) generates a rotation by taking the zero rotation,
        a vector pointing along the X axis, first rotating it 3 degrees around the global Z axis, then rotating the resulting
        vector 2 degrees around the global Y axis, and finally rotating that 1 degree around the global X axis.
        */

        /* How we arrived at this llEuler2Rot
         *
         * Experiment in SL to determine conventions:
         *   llEuler2Rot(<PI,0,0>)=<1,0,0,0>
         *   llEuler2Rot(<0,PI,0>)=<0,1,0,0>
         *   llEuler2Rot(<0,0,PI>)=<0,0,1,0>
         *
         * Important facts about Quaternions
         *  - multiplication is non-commutative (a*b != b*a)
         *  - http://en.wikipedia.org/wiki/Quaternion#Basis_multiplication
         *
         * Above SL experiment gives (c1,c2,c3,s1,s2,s3 as defined in our llEuler2Rot):
         *   Qx = c1+i*s1
         *   Qy = c2+j*s2;
         *   Qz = c3+k*s3;
         *
         * Rotations applied in order (from above) Z, Y, X
         * Q = (Qz * Qy) * Qx
         * ((c1+i*s1)*(c2+j*s2))*(c3+k*s3)
         * (c1*c2+i*s1*c2+j*c1*s2+ij*s1*s2)*(c3+k*s3)
         * (c1*c2+i*s1*c2+j*c1*s2+k*s1*s2)*(c3+k*s3)
         * c1*c2*c3+i*s1*c2*c3+j*c1*s2*c3+k*s1*s2*c3+k*c1*c2*s3+ik*s1*c2*s3+jk*c1*s2*s3+kk*s1*s2*s3
         * c1*c2*c3+i*s1*c2*c3+j*c1*s2*c3+k*s1*s2*c3+k*c1*c2*s3 -j*s1*c2*s3 +i*c1*s2*s3   -s1*s2*s3
         * regroup: x=i*(s1*c2*c3+c1*s2*s3)
         *          y=j*(c1*s2*c3-s1*c2*s3)
         *          z=k*(s1*s2*c3+c1*c2*s3)
         *          s=   c1*c2*c3-s1*s2*s3
         *
         * This implementation agrees with the functions found here:
         * http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryRotationFunctions
         * And with the results in SL.
         *
         * It's also possible to calculate llEuler2Rot by direct multiplication of
         * the Qz, Qy, and Qx vectors (as above - and done in the "accurate" function
         * from the wiki).
         * Apparently in some cases this is better from a numerical precision perspective?
         */

        public LSL_Rotation llEuler2Rot(LSL_Vector v)
        {
            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
            

            double x,y,z,s;

            double c1 = Math.Cos(v.x * 0.5);
            double c2 = Math.Cos(v.y * 0.5);
            double c3 = Math.Cos(v.z * 0.5);
            double s1 = Math.Sin(v.x * 0.5);
            double s2 = Math.Sin(v.y * 0.5);
            double s3 = Math.Sin(v.z * 0.5);

            x = s1 * c2 * c3 + c1 * s2 * s3;
            y = c1 * s2 * c3 - s1 * c2 * s3;
            z = s1 * s2 * c3 + c1 * c2 * s3;
            s = c1 * c2 * c3 - s1 * s2 * s3;

            return new LSL_Rotation(x, y, z, s);
        }
예제 #22
0
 //This next group are vector operations involving squaring and square root. ckrinke
 public LSL_Float llVecMag(LSL_Vector v)
 {
     ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
     
     return LSL_Vector.Mag(v);
 }
예제 #23
0
        public LSL_Rotation llAxes2Rot(LSL_Vector fwd, LSL_Vector left, LSL_Vector up)
        {
            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
            
            double s;
            double tr = fwd.x + left.y + up.z + 1.0;

            if (tr >= 1.0)
            {
                s = 0.5 / Math.Sqrt(tr);
                return new LSL_Rotation(
                        (left.z - up.y) * s,
                        (up.x - fwd.z) * s,
                        (fwd.y - left.x) * s,
                        0.25 / s);
            }
            else
            {
                double max = (left.y > up.z) ? left.y : up.z;

                if (max < fwd.x)
                {
                    s = Math.Sqrt(fwd.x - (left.y + up.z) + 1.0);
                    double x = s * 0.5;
                    s = 0.5 / s;
                    return new LSL_Rotation(
                            x,
                            (fwd.y + left.x) * s,
                            (up.x + fwd.z) * s,
                            (left.z - up.y) * s);
                }
                else if (max == left.y)
                {
                    s = Math.Sqrt(left.y - (up.z + fwd.x) + 1.0);
                    double y = s * 0.5;
                    s = 0.5 / s;
                    return new LSL_Rotation(
                            (fwd.y + left.x) * s,
                            y,
                            (left.z + up.y) * s,
                            (up.x - fwd.z) * s);
                }
                else
                {
                    s = Math.Sqrt(up.z - (fwd.x + left.y) + 1.0);
                    double z = s * 0.5;
                    s = 0.5 / s;
                    return new LSL_Rotation(
                            (up.x + fwd.z) * s,
                            (left.z + up.y) * s,
                            z,
                            (fwd.y - left.x) * s);
                }
            }
        }
예제 #24
0
 public LSL_Vector llVecNorm(LSL_Vector v)
 {
     ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
     return LSL_Vector.Norm(v);
 }
예제 #25
0
        public void llSitTarget(LSL_Vector offset, LSL_Rotation rot)
        {
            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
            
            // LSL quaternions can normalize to 0, normal Quaternions can't.
            if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0)
                rot.z = 1; // ZERO_ROTATION = 0,0,0,1

            m_host.SitTargetPosition = new Vector3((float)offset.x, (float)offset.y, (float)offset.z);
            m_host.SitTargetOrientation = Rot2Quaternion(rot);
            m_host.ParentGroup.HasGroupChanged = true;
        }
예제 #26
0
 public LSL_Float llVecDist(LSL_Vector a, LSL_Vector b)
 {
     ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
     
     double dx = a.x - b.x;
     double dy = a.y - b.y;
     double dz = a.z - b.z;
     return Math.Sqrt(dx * dx + dy * dy + dz * dz);
 }
예제 #27
0
        public LSL_Integer llScriptDanger(LSL_Vector pos)
        {
            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");

            bool result = m_ScriptEngine.PipeEventsForScript(m_host, new Vector3((float)pos.x, (float)pos.y, (float)pos.z));
            if (result)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
예제 #28
0
        public LSL_Integer llEdgeOfWorld(LSL_Vector pos, LSL_Vector dir)
        {
            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
            

            // edge will be used to pass the Region Coordinates offset
            // we want to check for a neighboring sim
            LSL_Vector edge = new LSL_Vector(0, 0, 0);

            if (dir.x == 0)
            {
                if (dir.y == 0)
                {
                    // Direction vector is 0,0 so return
                    // false since we're staying in the sim
                    return 0;
                }
                else
                {
                    // Y is the only valid direction
                    edge.y = dir.y / Math.Abs(dir.y);
                }
            }
            else
            {
                LSL_Float mag;
                if (dir.x > 0)
                {
                    mag = (World.RegionInfo.RegionSizeX - pos.x) / dir.x;
                }
                else
                {
                    mag = (pos.x/dir.x);
                }

                mag = Math.Abs(mag);

                edge.y = pos.y + (dir.y * mag);

                if (edge.y > World.RegionInfo.RegionSizeY || edge.y < 0)
                {
                    // Y goes out of bounds first
                    edge.y = dir.y / Math.Abs(dir.y);
                }
                else
                {
                    // X goes out of bounds first or its a corner exit
                    edge.y = 0;
                    edge.x = dir.x / Math.Abs(dir.x);
                }
            }
            INeighborService service = World.RequestModuleInterface<INeighborService>();
            List<GridRegion> neighbors = new List<GridRegion>();
            if (service != null)
            {
                neighbors = service.GetNeighbors(World.RegionInfo);
            }

            int neighborX = World.RegionInfo.RegionLocX + (int)dir.x;
            int neighborY = World.RegionInfo.RegionLocY + (int)dir.y;

            foreach (GridRegion sri in neighbors)
            {
                if (sri.RegionLocX == neighborX && sri.RegionLocY == neighborY)
                    return 0;
            }

            return 1;
        }
예제 #29
0
        protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector taper_b, LSL_Vector topshear, byte fudge)
        {
            ObjectShapePacket.ObjectDataBlock shapeBlock;

            shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);

            shapeBlock.ProfileCurve += fudge;

            if (taper_b.x < 0f)
            {
                taper_b.x = 0f;
            }
            if (taper_b.x > 2f)
            {
                taper_b.x = 2f;
            }
            if (taper_b.y < 0f)
            {
                taper_b.y = 0f;
            }
            if (taper_b.y > 2f)
            {
                taper_b.y = 2f;
            }
            shapeBlock.PathScaleX = (byte)(100 * (2.0 - taper_b.x));
            shapeBlock.PathScaleY = (byte)(100 * (2.0 - taper_b.y));
            if (topshear.x < -0.5f)
            {
                topshear.x = -0.5f;
            }
            if (topshear.x > 0.5f)
            {
                topshear.x = 0.5f;
            }
            if (topshear.y < -0.5f)
            {
                topshear.y = -0.5f;
            }
            if (topshear.y > 0.5f)
            {
                topshear.y = 0.5f;
            }
            shapeBlock.PathShearX = (byte)(100 * topshear.x);
            shapeBlock.PathShearY = (byte)(100 * topshear.y);

            part.Shape.SculptEntry = false;
            part.UpdateShape(shapeBlock);
        }
예제 #30
0
 public void llTriggerSoundLimited(string sound, double volume, LSL_Vector top_north_east,
                                   LSL_Vector bottom_south_west)
 {
     ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
     
     float radius1 = (float)llVecDist(llGetPos(), top_north_east);
     float radius2 = (float)llVecDist(llGetPos(), bottom_south_west);
     float radius = Math.Abs(radius1 - radius2);
     m_host.SendSound(KeyOrName(sound).ToString(), volume, true, 0, radius, false, false);
 }
예제 #31
0
        protected void SetPrimitiveShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, LSL_Vector holesize, LSL_Vector topshear, LSL_Vector profilecut, LSL_Vector taper_a, float revolutions, float radiusoffset, float skew, byte fudge)
        {
            ObjectShapePacket.ObjectDataBlock shapeBlock;

            shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist);

            shapeBlock.ProfileCurve += fudge;

            // profile/path swapped for a torrus, tube, ring
            shapeBlock.PathBegin = shapeBlock.ProfileBegin;
            shapeBlock.PathEnd = shapeBlock.ProfileEnd;

            if (holesize.x < 0.05f)
            {
                holesize.x = 0.05f;
            }
            if (holesize.x > 1f)
            {
                holesize.x = 1f;
            }
            if (holesize.y < 0.05f)
            {
                holesize.y = 0.05f;
            }
            if (holesize.y > 0.5f)
            {
                holesize.y = 0.5f;
            }
            shapeBlock.PathScaleX = (byte)(100 * (2 - holesize.x));
            shapeBlock.PathScaleY = (byte)(100 * (2 - holesize.y));
            if (topshear.x < -0.5f)
            {
                topshear.x = -0.5f;
            }
            if (topshear.x > 0.5f)
            {
                topshear.x = 0.5f;
            }
            if (topshear.y < -0.5f)
            {
                topshear.y = -0.5f;
            }
            if (topshear.y > 0.5f)
            {
                topshear.y = 0.5f;
            }
            shapeBlock.PathShearX = (byte)(100 * topshear.x);
            shapeBlock.PathShearY = (byte)(100 * topshear.y);
            if (profilecut.x < 0f)
            {
                profilecut.x = 0f;
            }
            if (profilecut.x > 1f)
            {
                profilecut.x = 1f;
            }
            if (profilecut.y < 0f)
            {
                profilecut.y = 0f;
            }
            if (profilecut.y > 1f)
            {
                profilecut.y = 1f;
            }
            if (profilecut.y - profilecut.x < 0.05f)
            {
                profilecut.x = profilecut.y - 0.05f;
                if (profilecut.x < 0.0f)
                {
                    profilecut.x = 0.0f;
                    profilecut.y = 0.05f;
                }
            }
            shapeBlock.ProfileBegin = (ushort)(50000 * profilecut.x);
            shapeBlock.ProfileEnd = (ushort)(50000 * (1 - profilecut.y));
            if (taper_a.x < -1f)
            {
                taper_a.x = -1f;
            }
            if (taper_a.x > 1f)
            {
                taper_a.x = 1f;
            }
            if (taper_a.y < -1f)
            {
                taper_a.y = -1f;
            }
            if (taper_a.y > 1f)
            {
                taper_a.y = 1f;
            }
            shapeBlock.PathTaperX = (sbyte)(100 * taper_a.x);
            shapeBlock.PathTaperY = (sbyte)(100 * taper_a.y);
            if (revolutions < 1f)
            {
                revolutions = 1f;
            }
            if (revolutions > 4f)
            {
                revolutions = 4f;
            }
            shapeBlock.PathRevolutions = (byte)(66.666667 * (revolutions - 1.0));
            // limits on radiusoffset depend on revolutions and hole size (how?) seems like the maximum range is 0 to 1
            if (radiusoffset < 0f)
            {
                radiusoffset = 0f;
            }
            if (radiusoffset > 1f)
            {
                radiusoffset = 1f;
            }
            shapeBlock.PathRadiusOffset = (sbyte)(100 * radiusoffset);
            if (skew < -0.95f)
            {
                skew = -0.95f;
            }
            if (skew > 0.95f)
            {
                skew = 0.95f;
            }
            shapeBlock.PathSkew = (sbyte)(100 * skew);

            part.Shape.SculptEntry = false;
            part.UpdateShape(shapeBlock);
        }
예제 #32
0
        public LSL_String llGetLandOwnerAt(LSL_Vector pos)
        {
            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");

            IParcelManagementModule parcelManagement = World.RequestModuleInterface<IParcelManagementModule>();
            if (parcelManagement != null)
            {
                ILandObject land = parcelManagement.GetLandObject((float)pos.x, (float)pos.y);
                if (land != null)
                    return land.LandData.OwnerID.ToString();
            }
            return UUID.Zero.ToString();
        }
예제 #33
0
        /// <summary>
        /// A partial implementation.
        /// http://lslwiki.net/lslwiki/wakka.php?wakka=llGetBoundingBox
        /// So far only valid for standing/flying/ground sitting avatars and single prim objects.
        /// If the object has multiple prims and/or a sitting avatar then the bounding
        /// box is for the root prim only.
        /// </summary>
        public LSL_List llGetBoundingBox(string obj)
        {
            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
            
            UUID objID = UUID.Zero;
            LSL_List result = new LSL_List();
            if (!UUID.TryParse(obj, out objID))
            {
                result.Add(new LSL_Vector());
                result.Add(new LSL_Vector());
                return result;
            }
            ScenePresence presence = World.GetScenePresence(objID);
            if (presence != null)
            {
                if (presence.ParentID == UUID.Zero) // not sat on an object
                {
                    LSL_Vector lower;
                    LSL_Vector upper;
                    if (presence.Animator.Animations.DefaultAnimation.AnimID 
                        == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"])
                    {
                        // This is for ground sitting avatars
                        float height = presence.Appearance.AvatarHeight / 2.66666667f;
                        lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f);
                        upper = new LSL_Vector(0.3375f, 0.45f, 0.0f);
                    }
                    else
                    {
                        // This is for standing/flying avatars
                        float height = presence.Appearance.AvatarHeight / 2.0f;
                        lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f);
                        upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f);
                    }
                    result.Add(lower);
                    result.Add(upper);
                    return result;
                }
                else
                {
                    // sitting on an object so we need the bounding box of that
                    // which should include the avatar so set the UUID to the
                    // UUID of the object the avatar is sat on and allow it to fall through
                    // to processing an object
                    SceneObjectPart p = World.GetSceneObjectPart(presence.ParentID);
                    objID = p.UUID;
                }
            }
            SceneObjectPart part = World.GetSceneObjectPart(objID);
            // Currently only works for single prims without a sitting avatar
            if (part != null)
            {
                Vector3 halfSize = part.Scale * 0.5f;
                LSL_Vector lower = new LSL_Vector(halfSize.X * -1.0f, halfSize.Y * -1.0f, halfSize.Z * -1.0f);
                LSL_Vector upper = new LSL_Vector(halfSize.X, halfSize.Y, halfSize.Z);
                result.Add(lower);
                result.Add(upper);
                return result;
            }

            // Not found so return empty values
            result.Add(new LSL_Vector());
            result.Add(new LSL_Vector());
            return result;
        }
예제 #34
0
 /// <summary>
 /// According to http://lslwiki.net/lslwiki/wakka.php?wakka=llGetAgentSize
 /// only the height of avatars vary and that says:
 /// Width (x) and depth (y) are constant. (0.45m and 0.6m respectively).
 /// </summary>
 public LSL_Vector llGetAgentSize(string id)
 {
     ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
     
     ScenePresence avatar = World.GetScenePresence((UUID)id);
     LSL_Vector agentSize;
     if (avatar == null || avatar.IsChildAgent) // Fail if not in the same region
     {
         agentSize = ScriptBaseClass.ZERO_VECTOR;
     }
     else
     {
         agentSize = new LSL_Vector(0.45, 0.6, avatar.Appearance.AvatarHeight);
     }
     return agentSize;
 }
예제 #35
0
        public LSL_Key llRequestSimulatorData(string simulator, int data)
        {
            UUID tid = UUID.Zero;

            try
            {
                ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");

                string reply = String.Empty;

                GridRegion info;

                if (World.RegionInfo.RegionName == simulator)
                    info = new GridRegion(World.RegionInfo);
                else
                    info = World.GridService.GetRegionByName(World.RegionInfo.ScopeID, simulator);

                switch (data)
                {
                    case 5: // DATA_SIM_POS
                        if (info == null)
                        {
                            break;
                        }
                        reply = new LSL_Vector(
                            info.RegionLocX,
                            info.RegionLocY,
                            0).ToString();
                        break;
                    case 6: // DATA_SIM_STATUS
                        if (info != null)
                            reply = "up"; // Duh!
                        else
                            reply = "unknown";
                        break;
                    case 7: // DATA_SIM_RATING
                        if (info == null)
                        {
                            break;
                        }
                        uint access = Util.ConvertAccessLevelToMaturity(info.Access);
                        if (access == 0)
                            reply = "PG";
                        else if (access == 1)
                            reply = "MATURE";
                        else if (access == 2)
                            reply = "ADULT";
                        else
                            reply = "UNKNOWN";
                        break;
                    case 128:
                        ScriptProtection.CheckThreatLevel(ThreatLevel.High, "llRequestSimulatorData", m_host, "LSL");
                        reply = "OpenSim";
                        break;
                    default:
                        break;
                }
                UUID rq = UUID.Random();

                DataserverPlugin dataserverPlugin = (DataserverPlugin)m_ScriptEngine.GetScriptPlugin("Dataserver");

                tid = dataserverPlugin.RegisterRequest(m_host.UUID, m_itemID, rq.ToString());

                dataserverPlugin.AddReply(rq.ToString(), reply, 1000);
            }
            catch (Exception)
            {
                //m_log.Error("[LSL_API]: llRequestSimulatorData" + e.ToString());
            }

            ScriptSleep(1000);
            return (LSL_Key)tid.ToString();
        }
예제 #36
0
        public LSL_Vector llGroundSlope(LSL_Vector offset)
        {
            ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL");
            
            //Get the slope normal.  This gives us the equation of the plane tangent to the slope.
            LSL_Vector vsn = llGroundNormal(offset);

            //Plug the x,y coordinates of the slope normal into the equation of the plane to get
            //the height of that point on the plane.  The resulting vector gives the slope.
            Vector3 vsl = new Vector3();
            vsl.X = (float)vsn.x;
            vsl.Y = (float)vsn.y;
            vsl.Z = (float)(((vsn.x * vsn.x) + (vsn.y * vsn.y)) / (-1 * vsn.z));
            vsl.Normalize();
            //Normalization might be overkill here

            return new LSL_Vector(vsl.X, vsl.Y, vsl.Z);
        }