Reflect() публичный статический Метод

public static Reflect ( Vector3D, inDirection, Vector3D, inNormal ) : Vector3D,
inDirection Vector3D,
inNormal Vector3D,
Результат Vector3D,
Пример #1
0
        public void Reflect()
        {
            var v = new Vector3D(1, 1, 1);

            Assert.AreEqual(v, v.Reflect(new Vector3D(0, 0, 0)));
            Assert.AreEqual(new Vector3D(1, -1, 1), v.Reflect(new Vector3D(0, 1, 0)));
        }
        public void Reflect_Tests()
        {
            var v1 = new Vector3D(1, 0, 0);
            var n  = new Vector3D(-1, 0, 0);

            v1.Reflect(n);
            Assert.AreEqual(-1, v1.X);
            Assert.AreEqual(0, v1.Y);

            v1 = new Vector3D(1, 1, 0);
            v1.Reflect(n);
            Assert.AreEqual(-1, v1.X);
            Assert.AreEqual(1, v1.Y);

            v1 = new Vector3D(-1, 1, 0);
            v1.Reflect(n);
            Assert.AreEqual(1, v1.X);
            Assert.AreEqual(1, v1.Y);

            v1 = new Vector3D(-1, 1, 0);
            var oldL = v1.Length();

            v1.Reflect(n, 0.7);
            var l = System.Math.Round(v1.Length(), 2);

            Assert.AreEqual(System.Math.Round(oldL * 0.7, 2), l);
        }
Пример #3
0
        public void Vector3ReflectTest3()
        {
            Vector3D <float> n    = new Vector3D <float>(0.45f, 1.28f, 0.86f);
            Vector3D <float> temp = new Vector3D <float>(1.28f, 0.45f, 0.01f);
            // find a perpendicular vector of n
            Vector3D <float> a = Vector3D.Cross(temp, n);

            Vector3D <float> expected = a;
            Vector3D <float> actual   = Vector3D.Reflect(a, n);

            Assert.True(MathHelper.Equal(expected, actual), "Vector3D<float>f.Reflect did not return the expected value.");
        }
Пример #4
0
        public void Vector3ReflectTest2()
        {
            Vector3D <float> n = new Vector3D <float>(0.45f, 1.28f, 0.86f);

            n = Vector3D.Normalize(n);
            Vector3D <float> a = -n;

            Vector3D <float> expected = n;
            Vector3D <float> actual   = Vector3D.Reflect(a, n);

            Assert.True(MathHelper.Equal(expected, actual), "Vector3D<float>f.Reflect did not return the expected value.");
        }
        static void CreateBasicHitSmallParticles(ref Vector3D hitPoint, ref Vector3 normal, ref Vector3D direction, IMyEntity physObject, MyEntity weapon, float scale, MyEntity ownerEntity = null)
        {
            Vector3D reflectedDirection = Vector3D.Reflect(direction, normal);
            MyUtilRandomVector3ByDeviatingVector randomVector = new MyUtilRandomVector3ByDeviatingVector(reflectedDirection);

            if (MySector.MainCamera.GetDistanceWithFOV(hitPoint) < 100)
            {
                MyParticleEffect effect;
                if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.Hit_BasicAmmoSmall, out effect))
                {
                    MatrixD dirMatrix = MatrixD.CreateFromDir(reflectedDirection);
                    effect.WorldMatrix = MatrixD.CreateWorld(hitPoint, dirMatrix.Forward, dirMatrix.Up);
                    effect.UserScale   = scale;
                }
            }
        }
Пример #6
0
        public static void CreateBasicHitParticles(string effectName, ref Vector3D hitPoint, ref Vector3 normal, ref Vector3D direction, IMyEntity physObject, MyEntity weapon, float scale, MyEntity ownerEntity = null)
        {
            Vector3D reflectedDirection = Vector3D.Reflect(direction, normal);
            MyUtilRandomVector3ByDeviatingVector randomVector = new MyUtilRandomVector3ByDeviatingVector(reflectedDirection);

            MyParticleEffect effect;

            if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.Hit_BasicAmmoSmall, out effect))
            {
                MatrixD dirMatrix = MatrixD.CreateFromDir(normal);
                effect.WorldMatrix = MatrixD.CreateWorld(hitPoint, dirMatrix.Forward, dirMatrix.Up);

                //VRageRender.MyRenderProxy.DebugDrawSphere(hitPoint, 0.1f, Color.Wheat, 1, false);
                // VRageRender.MyRenderProxy.DebugDrawAxis(effect.WorldMatrix, 5, false);

                effect.UserScale = scale;
            }
        }
Пример #7
0
        /// <summary>
        /// Calculate propper direction for meteorits. Everytime above horizon.
        /// </summary>
        /// <param name="direction"></param>
        /// <returns></returns>
        private static Vector3 GetCorrectedDirection(Vector3 direction)
        {
            var currDir = direction;

            if (m_currentTarget == null)
            {
                return(currDir);
            }

            var tgtPos = m_currentTarget.Value.Center;

            MyMeteorShower.m_tgtPos = tgtPos;

            if (!MyGravityProviderSystem.IsPositionInNaturalGravity(tgtPos))
            {
                return(currDir);
            }

            var pltTgtDir = -Vector3D.Normalize(MyGravityProviderSystem.CalculateNaturalGravityInPoint(tgtPos));
            var tmpVec    = Vector3D.Normalize(Vector3D.Cross(pltTgtDir, currDir));
            var mirror    = Vector3D.Normalize(Vector3D.Cross(tmpVec, pltTgtDir));

            MyMeteorShower.m_mirrorDir = mirror;
            MyMeteorShower.m_pltTgtDir = pltTgtDir;
            MyMeteorShower.m_normalSun = tmpVec;

            double horizonRatio = pltTgtDir.Dot(currDir);

            //below down horizon
            if (horizonRatio < -HORIZON_ANGLE_FROM_ZENITH_RATIO)
            {
                return(Vector3D.Reflect(-currDir, mirror));
            }

            // between below and above horizon (prohi
            if (horizonRatio < HORIZON_ANGLE_FROM_ZENITH_RATIO)
            {
                MatrixD tmpMat = MatrixD.CreateFromAxisAngle(tmpVec, -Math.Asin(HORIZON_ANGLE_FROM_ZENITH_RATIO));
                return(Vector3D.Transform(mirror, tmpMat));
            }

            // above 20 Degree above horizon
            return(currDir);
        }
Пример #8
0
        public void Vector3ReflectTest()
        {
            Vector3D <float> a = Vector3D.Normalize(new Vector3D <float>(1.0f, 1.0f, 1.0f));

            // Reflect on XZ plane.
            Vector3D <float> n        = new Vector3D <float>(0.0f, 1.0f, 0.0f);
            Vector3D <float> expected = new Vector3D <float>(a.X, -a.Y, a.Z);
            Vector3D <float> actual   = Vector3D.Reflect(a, n);

            Assert.True(MathHelper.Equal(expected, actual), "Vector3D<float>f.Reflect did not return the expected value.");

            // Reflect on XY plane.
            n        = new Vector3D <float>(0.0f, 0.0f, 1.0f);
            expected = new Vector3D <float>(a.X, a.Y, -a.Z);
            actual   = Vector3D.Reflect(a, n);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3D<float>f.Reflect did not return the expected value.");

            // Reflect on YZ plane.
            n        = new Vector3D <float>(1.0f, 0.0f, 0.0f);
            expected = new Vector3D <float>(-a.X, a.Y, a.Z);
            actual   = Vector3D.Reflect(a, n);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3D<float>f.Reflect did not return the expected value.");
        }
Пример #9
0
		public void Reflect()
		{
			var v = new Vector3D(1, 1, 1);
			Assert.AreEqual(v, v.Reflect(new Vector3D(0, 0, 0)));
			Assert.AreEqual(new Vector3D(1, -1, 1), v.Reflect(new Vector3D(0, 1, 0)));
		}
Пример #10
0
            double CAF_DIST_TO_TARGET;                            //Outputs distance to target

            void CollectAndFire2(Vector3D INPUT_POINT, double INPUT_VELOCITY, double INPUT_MAX_VELOCITY, Vector3D REFPOS, IMyRemoteControl RC)
            {
                //Function Initialisation
                //--------------------------------------------------------------------
                if (C_A_F_HASRUN == false)
                {
                    //Initialise Classes And Basic System
                    CAF2_FORWARD = new Thrust_info(RC.WorldMatrix.Forward, myGridTerminal, RC.CubeGrid);
                    CAF2_UP      = new Thrust_info(RC.WorldMatrix.Up, myGridTerminal, RC.CubeGrid);
                    CAF2_RIGHT   = new Thrust_info(RC.WorldMatrix.Right, myGridTerminal, RC.CubeGrid);
                    CAFTHI       = new List <Thrust_info>()
                    {
                        CAF2_FORWARD, CAF2_UP, CAF2_RIGHT
                    };
                    myGridTerminal.GetBlocksOfType <IMyThrust>(CAF2_THRUST, block => block.CubeGrid == RC.CubeGrid);
                    C_A_F_HASRUN = true;

                    //Initialises Braking Component
                    foreach (var item in CAFTHI)
                    {
                        CAF2_BRAKING_COUNT = (item.PositiveMaxForce < CAF2_BRAKING_COUNT) ? item.PositiveMaxForce : CAF2_BRAKING_COUNT;
                        CAF2_BRAKING_COUNT = (item.NegativeMaxForce < CAF2_BRAKING_COUNT) ? item.PositiveMaxForce : CAF2_BRAKING_COUNT;
                    }
                }
                //Generating Maths To Point and decelleration information etc.
                //--------------------------------------------------------------------
                double   SHIPMASS     = Convert.ToDouble(RC.CalculateShipMass().PhysicalMass);
                Vector3D INPUT_VECTOR = Vector3D.Normalize(INPUT_POINT - REFPOS);
                double   VELOCITY     = RC.GetShipSpeed();

                CAF_DIST_TO_TARGET     = (REFPOS - INPUT_POINT).Length();
                CAF_SHIP_DECELLERATION = 0.75 * (CAF2_BRAKING_COUNT / SHIPMASS);
                CAF_STOPPING_DIST      = (((VELOCITY * VELOCITY) - (INPUT_VELOCITY * INPUT_VELOCITY))) / (2 * CAF_SHIP_DECELLERATION);

                //If Within Stopping Distance Halts Programme
                //--------------------------------------------
                if (!(CAF_DIST_TO_TARGET > (CAF_STOPPING_DIST + 0.25)) || CAF_DIST_TO_TARGET < 0.25 || VELOCITY > INPUT_MAX_VELOCITY)
                {
                    foreach (var thruster in CAF2_THRUST)
                    {
                        (thruster as IMyThrust).ThrustOverride = 0;
                    }
                    return;
                }
                //dev notes, this is the most major source of discontinuity between theorised system response

                //Reflects Vector To Cancel Orbiting
                //------------------------------------
                Vector3D DRIFT_VECTOR   = Vector3D.Normalize(RC.GetShipVelocities().LinearVelocity + RC.WorldMatrix.Forward * 0.00001);
                Vector3D R_DRIFT_VECTOR = -1 * Vector3D.Normalize(Vector3D.Reflect(DRIFT_VECTOR, INPUT_VECTOR));

                R_DRIFT_VECTOR = ((Vector3D.Dot(R_DRIFT_VECTOR, INPUT_VECTOR) < -0.3)) ? 0 * R_DRIFT_VECTOR : R_DRIFT_VECTOR;
                INPUT_VECTOR   = Vector3D.Normalize((4 * R_DRIFT_VECTOR) + INPUT_VECTOR);

                //Components Of Input Vector In FUR Axis
                //----------------------------------------
                double F_COMP_IN = Vector_Projection(INPUT_VECTOR, RC.WorldMatrix.Forward);
                double U_COMP_IN = Vector_Projection(INPUT_VECTOR, RC.WorldMatrix.Up);
                double R_COMP_IN = Vector_Projection(INPUT_VECTOR, RC.WorldMatrix.Right);

                //Calculate MAX Allowable in Each Axis & Length
                //-----------------------------------------------
                double F_COMP_MAX = (F_COMP_IN > 0) ? CAF2_FORWARD.PositiveMaxForce : -1 * CAF2_FORWARD.NegativeMaxForce;
                double U_COMP_MAX = (U_COMP_IN > 0) ? CAF2_UP.PositiveMaxForce : -1 * CAF2_UP.NegativeMaxForce;
                double R_COMP_MAX = (R_COMP_IN > 0) ? CAF2_RIGHT.PositiveMaxForce : -1 * CAF2_RIGHT.NegativeMaxForce;
                double MAX_FORCE  = Math.Sqrt(F_COMP_MAX * F_COMP_MAX + U_COMP_MAX * U_COMP_MAX + R_COMP_MAX * R_COMP_MAX);

                //Apply Length to Input Components and Calculates Smallest Multiplier
                //--------------------------------------------------------------------
                double F_COMP_PROJ = F_COMP_IN * MAX_FORCE;
                double U_COMP_PROJ = U_COMP_IN * MAX_FORCE;
                double R_COMP_PROJ = R_COMP_IN * MAX_FORCE;
                double MULTIPLIER  = 1;

                MULTIPLIER = (F_COMP_MAX / F_COMP_PROJ < MULTIPLIER) ? F_COMP_MAX / F_COMP_PROJ : MULTIPLIER;
                MULTIPLIER = (U_COMP_MAX / U_COMP_PROJ < MULTIPLIER) ? U_COMP_MAX / U_COMP_PROJ : MULTIPLIER;
                MULTIPLIER = (R_COMP_MAX / R_COMP_PROJ < MULTIPLIER) ? R_COMP_MAX / R_COMP_PROJ : MULTIPLIER;

                //Calculate Multiplied Components
                //---------------------------------
                CAF2_FORWARD.VCF = ((F_COMP_PROJ * MULTIPLIER) / F_COMP_MAX) * Math.Sign(F_COMP_MAX);
                CAF2_UP.VCF      = ((U_COMP_PROJ * MULTIPLIER) / U_COMP_MAX) * Math.Sign(U_COMP_MAX);
                CAF2_RIGHT.VCF   = ((R_COMP_PROJ * MULTIPLIER) / R_COMP_MAX) * Math.Sign(R_COMP_MAX);

                //Runs System Thrust Application
                //----------------------------------
                Dictionary <IMyThrust, float> THRUSTVALUES = new Dictionary <IMyThrust, float>();

                foreach (var thruster in CAF2_THRUST)
                {
                    THRUSTVALUES.Add((thruster as IMyThrust), 0f);
                }

                foreach (var THRUSTSYSTM in CAFTHI)
                {
                    List <IMyThrust> POSTHRUST = THRUSTSYSTM.PositiveThrusters;
                    List <IMyThrust> NEGTHRUST = THRUSTSYSTM.NegativeThrusters;
                    if (THRUSTSYSTM.VCF < 0)
                    {
                        POSTHRUST = THRUSTSYSTM.NegativeThrusters; NEGTHRUST = THRUSTSYSTM.PositiveThrusters;
                    }
                    foreach (var thruster in POSTHRUST)
                    {
                        THRUSTVALUES[thruster as IMyThrust] = (float)(Math.Abs(THRUSTSYSTM.VCF)) * (thruster as IMyThrust).MaxThrust;
                    }
                    foreach (var thruster in NEGTHRUST)
                    {
                        THRUSTVALUES[thruster as IMyThrust] = 1;
                    }                                                                               //(float)0.01001;}
                    foreach (var thruster in THRUSTVALUES)
                    {
                        thruster.Key.ThrustOverride = thruster.Value;
                    }                                                                                        //thruster.Key.ThrustOverride = thruster.Value;
                }
            }
Пример #11
0
            //Primary Generic Functions
            //==========================

            //Use For General Drone Flying:
            void RC_Manager(Vector3D TARGET, IMyRemoteControl RC, bool TURN_ONLY)
            {
                //Uses Rotation Control To Handle Max Rotational Velocity
                //---------------------------------------------------------
                if (RC.GetShipVelocities().AngularVelocity.AbsMax() > PrecisionMaxAngularVel)
                {
                    print("转动速度放缓"); RC.SetAutoPilotEnabled(false); return;
                }
                //Setup Of Common Variables
                //--------------------------------------------
                Vector3D DronePosition   = RC.GetPosition();
                Vector3D Drone_To_Target = Vector3D.Normalize(TARGET - DronePosition);
                //Override Direction Detection
                //-------------------------------
                double To_Target_Angle = Vector3D.Dot(Vector3D.Normalize(RC.GetShipVelocities().LinearVelocity), Drone_To_Target);
                double Ship_Velocity   = RC.GetShipVelocities().LinearVelocity.Length();

                //Turn Only: (Will drift ship automatically)
                //--------------------------------------------

                /*List<MyWaypointInfo> way = new List<MyWaypointInfo>();
                 *      RC.GetWaypointInfo(way);
                 *      if (way.Count>0)
                 *      {
                 *          if (way[0].Coords!= TARGET)
                 *          {
                 *              //RC.ApplyAction("AutoPilot_Off");
                 *              //RC.ClearWaypoints();
                 *          }
                 *      }*/

                if (TURN_ONLY)
                {
                    //if (way.Count <1)
                    {
                        RC.ClearWaypoints();
                        GYRO.GyroOverride = false;
                        RC.AddWaypoint(TARGET, "母船起点");
                        RC.FlightMode = FlightMode.OneWay;
                        RC.Direction  = Base6Directions.Direction.Forward;
                        RC.ApplyAction("AutoPilot_On");
                        RC.ApplyAction("CollisionAvoidance_Off");
                        RC.ControlThrusters = false;
                    }
                    return;
                }
                //Drift Cancellation Enabled:
                //-----------------------------
                if (To_Target_Angle < 0.4 && Ship_Velocity > 3)
                {
                    //Aim Gyro To Reflected Vector
                    Vector3D DRIFT_VECTOR           = Vector3D.Normalize(RC.GetShipVelocities().LinearVelocity);
                    Vector3D REFLECTED_DRIFT_VECTOR = -1 * (Vector3D.Normalize(Vector3D.Reflect(DRIFT_VECTOR, Drone_To_Target)));
                    Vector3D AIMPINGPOS             = (-1 * DRIFT_VECTOR * 500) + DronePosition;

                    //if (way.Count < 1 )
                    {
                        RC.ClearWaypoints();
                        GYRO.GyroOverride = false;
                        RC.AddWaypoint(AIMPINGPOS, "AIMPINGPOS");
                        RC.SpeedLimit = 100;
                        RC.FlightMode = FlightMode.OneWay;
                        RC.Direction  = Base6Directions.Direction.Forward;
                        RC.ApplyAction("AutoPilot_On");
                        RC.ApplyAction("CollisionAvoidance_Off");
                    }
                }

                //System Standard Operation:
                //---------------------------
                else
                {
                    //Assign To RC, Clear And Refresh Command
                    List <ITerminalAction> action = new List <ITerminalAction>();
                    RC.GetActions(action);
                    RC.ControlThrusters = true;
                    RC.ClearWaypoints();
                    GYRO.GyroOverride = false;
                    RC.AddWaypoint(TARGET, "目标");
                    RC.SpeedLimit = 100;
                    RC.FlightMode = FlightMode.OneWay;
                    RC.Direction  = Base6Directions.Direction.Forward;
                    RC.ApplyAction("AutoPilot_On");
                    RC.ApplyAction("DockingMode_Off");
                    RC.ApplyAction("CollisionAvoidance_On");
                }
            }
Пример #12
0
        public override void Handle()
        {
            if (!PluginSettings.Instance.ExclusionZonesEnabled)
            {
                return;
            }

            MyEntity[] entities = MyEntities.GetEntities().ToArray();
            if (entities.Length == 0)
            {
                NoGrief.Log.Info("Failed to get entity list in exclusion zone update. Skipping update.");
                return;
            }

            foreach (SettingsExclusionItem item in PluginSettings.Instance.ExclusionItems)
            {
                if (!item.Enabled)
                {
                    continue;
                }

                if (!_redirectedEntites.ContainsKey(item.EntityId))
                {
                    _redirectedEntites.Add(item.EntityId, new HashSet <long>());
                }

                MyEntity grid;
                if (!MyEntities.TryGetEntityById(item.EntityId, out grid))
                {
                    continue;
                }

                bool init = item.ContainsEntities.Count == 0;

                //zones don't work on moving entities
                if (!Vector3.IsZero(grid.Physics.LinearVelocity) || !Vector3.IsZero(grid.Physics.AngularVelocity))
                {
                    continue;
                }

                var sphere = new BoundingSphereD(grid.Center(), item.Radius);

                if (init)
                {
                    foreach (MyEntity entity in entities)
                    {
                        if (sphere.Contains(entity.PositionComp.WorldVolume) == ContainmentType.Contains)
                        {
                            item.ContainsEntities.Add(entity.EntityId);
                        }
                    }
                    if (item.TransportAdd)
                    {
                        item.AllowedEntities = item.ContainsEntities.ToList();
                    }
                }

                var outerSphere = new BoundingSphereD(sphere.Center, sphere.Radius + 50);

                var approaching = new HashSet <long>();
                foreach (MyEntity entity in entities)
                {
                    if (entity?.Physics == null)
                    {
                        continue;
                    }

                    if (entity.Closed || entity.MarkedForClose)
                    {
                        continue;
                    }

                    if (entity is MyVoxelBase)
                    {
                        continue;
                    }

                    if (entity is MyAmmoBase)
                    {
                        continue;
                    }

                    //entity is trying to enter the exclusion zone. push them away
                    if (outerSphere.Contains(entity.Center()) != ContainmentType.Disjoint && !item.ContainsEntities.Contains(entity.EntityId))
                    {
                        approaching.Add(entity.EntityId);
                        MyPlayer controller = MySession.Static.Players.GetControllingPlayer(entity);
                        try
                        {
                            if (controller?.Client != null)
                            {
                                if (!string.IsNullOrEmpty(item.FactionTag) && MySession.Static.Factions.GetPlayerFaction(controller.Identity.IdentityId).Tag == item.FactionTag)
                                {
                                    ExcludeEntities(entity, item);
                                    if (item.TransportAdd && !item.AllowedPlayers.Contains(controller.Client.SteamUserId))
                                    {
                                        item.AllowedPlayers.Add(controller.Client.SteamUserId);
                                    }
                                    continue;
                                }

                                if (item.AllowAdmins && controller.IsAdmin)
                                {
                                    ExcludeEntities(entity, item);
                                    continue;
                                }

                                if (item.AllowedPlayers.Contains(controller.Client.SteamUserId))
                                {
                                    ExcludeEntities(entity, item);
                                    continue;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            NoGrief.Log.Error(ex);
                        }

                        if (item.AllowedEntities.Contains(entity.EntityId))
                        {
                            ExcludeEntities(entity, item);
                            continue;
                        }

                        Vector3D direction = Vector3D.Normalize(entity.Center() - sphere.Center);
                        Vector3D velocity  = entity.Physics.LinearVelocity;
                        if (Vector3D.IsZero(velocity))
                        {
                            velocity += direction;
                        }

                        if (!_redirectedEntites[item.EntityId].Contains(entity.EntityId))
                        {
                            _redirectedEntites[item.EntityId].Add(entity.EntityId);

                            Vector3D forceDir = Vector3D.Reflect(Vector3D.Normalize(velocity), direction);
                            //Vector3D force = forceDir * (velocity.Length()+10) * entity.Physics.Mass * 5 + -entity.Physics.LinearAcceleration * entity.Physics.Mass;
                            //if (!force.IsValid())
                            //{
                            //    NoGrief.Log.Error("Invalid Force");
                            //    continue;
                            //}
                            if (controller?.Client != null && !string.IsNullOrEmpty(item.ExclusionMessage))
                            {
                                Communication.Notification(controller.Client.SteamUserId, MyFontEnum.White, 10000, item.ExclusionMessage);
                            }
                            if (!(entity is MyCharacter))
                            {
                                Vector3 force = forceDir * velocity.Length() * entity.Physics.Mass * 60 * 1.5;
                                force += entity.Physics.LinearAcceleration.Length() * entity.Physics.Mass * 60;
                                Wrapper.BeginGameAction(() => entity.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, force, entity.Physics.CenterOfMassWorld, Vector3.Zero));
                            }
                            else
                            {
                                //characres require a different method
                                var      character     = (MyCharacter)entity;
                                Vector3D bodyDirection = -Vector3D.Normalize(Vector3D.Transform(direction, character.PositionComp.WorldMatrixInvScaled));
                                Vector3D bodyForce     = bodyDirection * character.Physics.LinearVelocity.Length() * character.Physics.Mass * 60 * 1.5;
                                bodyForce += character.Physics.LinearAcceleration.Length() * character.Physics.Mass * 60;
                                Wrapper.BeginGameAction(() => character.Physics.AddForce(MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, bodyForce, character.Center(), Vector3.Zero));
                            }
                        }
                        if (sphere.Contains(entity.Center()) != ContainmentType.Disjoint)
                        {
                            if (!(entity is MyCharacter))
                            {
                                Vector3D force = direction * (velocity.Length() + 5) * entity.Physics.Mass * 60 * 2;
                                force += entity.Physics.LinearAcceleration.Length() * entity.Physics.Mass * 60;
                                Wrapper.BeginGameAction(() => entity.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_FORCE, force, entity.Physics.CenterOfMassWorld, Vector3.Zero));
                            }
                            else
                            {
                                var      character     = (MyCharacter)entity;
                                Vector3D bodyDirection = -Vector3D.Normalize(Vector3D.Transform(direction, character.PositionComp.WorldMatrixInvScaled));
                                Vector3D bodyForce     = bodyDirection * (character.Physics.LinearVelocity.Length() + 5) * character.Physics.Mass * 60 * 2;
                                bodyForce += character.Physics.LinearAcceleration.Length() * character.Physics.Mass * 60;
                                Wrapper.BeginGameAction(() => character.Physics.AddForce(MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, bodyForce, character.Center(), Vector3.Zero));
                            }
                        }
                    }
                }

                var toRemove = new List <long>();
                //TODO: We're searching the dictionary way too much. Do something about it later
                foreach (long id in _redirectedEntites[item.EntityId])
                {
                    if (!approaching.Contains(id))
                    {
                        toRemove.Add(id);
                    }
                }
                foreach (long rem in toRemove)
                {
                    _redirectedEntites[item.EntityId].Remove(rem);
                }
            }
        }
Пример #13
0
 public static LuaVector3D Reflect(LuaVector3D v, LuaVector3D m)
 {
     return(new LuaVector3D(Vector3D.Reflect(v.vec, m.vec)));
 }