示例#1
0
        public static void DebugDrawAddForce(MyPhysicsBody physics, MyPhysicsForceType type, Vector3?force, Vector3D?position, Vector3?torque, bool persistent = false)
        {
            switch (type)
            {
            case MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE:
            {
                Vector3D pointFrom = position.Value + (physics.LinearVelocity * 0.01666667f);
                if (force != null)
                {
                    MyRenderProxy.DebugDrawArrow3D(pointFrom, pointFrom + (force.Value * 0.1f), Color.Blue, new Color?(Color.Red), false, 0.1, null, 0.5f, persistent);
                }
                if (torque == null)
                {
                    break;
                }
                MyRenderProxy.DebugDrawArrow3D(pointFrom, pointFrom + (torque.Value * 0.1f), Color.Blue, new Color?(Color.Purple), false, 0.1, null, 0.5f, persistent);
                return;
            }

            case MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE:
                if (physics.RigidBody != null)
                {
                    Matrix   rigidBodyMatrix = physics.RigidBody.GetRigidBodyMatrix();
                    Vector3D pointFrom       = physics.CenterOfMassWorld + (physics.LinearVelocity * 0.01666667f);
                    if (force != null)
                    {
                        MyRenderProxy.DebugDrawArrow3D(pointFrom, pointFrom + (Vector3.TransformNormal(force.Value, rigidBodyMatrix) * 0.1f), Color.Blue, new Color?(Color.Red), false, 0.1, null, 0.5f, persistent);
                    }
                    if (torque != null)
                    {
                        MyRenderProxy.DebugDrawArrow3D(pointFrom, pointFrom + (Vector3.TransformNormal(torque.Value, rigidBodyMatrix) * 0.1f), Color.Blue, new Color?(Color.Purple), false, 0.1, null, 0.5f, persistent);
                        return;
                    }
                }
                break;

            case MyPhysicsForceType.APPLY_WORLD_FORCE:
                if (position != null)
                {
                    Vector3D pointFrom = position.Value + (physics.LinearVelocity * 0.01666667f);
                    if (force != null)
                    {
                        MyRenderProxy.DebugDrawArrow3D(pointFrom, pointFrom + ((force.Value * 0.01666667f) * 0.1f), Color.Blue, new Color?(Color.Red), false, 0.1, null, 0.5f, persistent);
                    }
                }
                break;

            default:
                return;
            }
        }
示例#2
0
        /// <summary>
        /// Applies external force to the physics object.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="force">The force.</param>
        /// <param name="position">The position.</param>
        /// <param name="torque">The torque.</param>
        public void AddForce(MyPhysicsForceType type, Vector3?force, Vector3?position, Vector3?torque)
        {
            MyUtils.AssertIsValid(force);
            MyUtils.AssertIsValid(position);
            MyUtils.AssertIsValid(torque);

            switch (type)
            {
            case MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE:
            {
                Matrix tempM = rigidBody.Matrix;
                tempM.Translation = Vector3.Zero;

                if (force != null && !MyMwcUtils.IsZero(force.Value))
                {
                    Vector3 tmpForce = Vector3.Transform(force.Value, tempM);

                    this.rigidBody.ApplyForce(tmpForce);
                }

                if (torque != null && !MyMwcUtils.IsZero(torque.Value))
                {
                    Vector3 tmpTorque = Vector3.Transform(torque.Value, tempM);

                    this.rigidBody.ApplyTorque(tmpTorque);
                }
            }
            break;

            case MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE:
            {
                if (force.HasValue && position.HasValue)
                {
                    this.rigidBody.ApplyImpulse(force.Value, position.Value);
                }

                if (torque.HasValue)
                {
                    this.rigidBody.ApplyTorque(torque.Value);
                }
            }
            break;

            default:
            {
                Debug.Fail("Unhandled enum!");
            }
            break;
            }
        }
        /// <summary>
        /// Applies external force to the physics object.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="force">The force.</param>
        /// <param name="position">The position.</param>
        /// <param name="torque">The torque.</param>
        public override void AddForce(MyPhysicsForceType type, Vector3? force, Vector3D? position, Vector3? torque)
        {
            force.AssertIsValid();
            position.AssertIsValid();
            torque.AssertIsValid();

            System.Diagnostics.Debug.Assert(IsInWorld == true);

            if (IsStatic)
                return;

            switch (type)
            {
                case MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE:
                    {
                        if (RigidBody != null)
                        {
                            Matrix tempM = RigidBody.GetRigidBodyMatrix();
                            tempM.Translation = Vector3.Zero;

                            if (force != null && !MyUtils.IsZero(force.Value))
                            {
                                Vector3 tmpForce = Vector3.Transform(force.Value, tempM);

                                //RigidBody.Activate(true);
                                //RigidBody.ApplyForce(MyEngineConstants.PHYSICS_STEP_SIZE_IN_SECONDS, tmpForce * 0.0001f);
                                RigidBody.ApplyLinearImpulse(tmpForce * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * MyFakes.SIMULATION_SPEED);
                                //RigidBody.ApplyCentralImpulse(tmpForce);
                            }

                            if (torque != null && !MyUtils.IsZero(torque.Value))
                            {
                                Vector3 tmpTorque = Vector3.Transform(torque.Value, tempM);
                                //SharpDX.Vector3 tmpTorque = SharpDXHelper.ToSharpDX(torque.Value);

                                // RigidBody.Activate(true);
                                //RigidBody.UpdateInertiaTensor();
                                //RigidBody.ApplyTorque(MyEngineConstants.PHYSICS_STEP_SIZE_IN_SECONDS, tmpTorque * 0.0001f);
                                RigidBody.ApplyAngularImpulse(tmpTorque * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * MyFakes.SIMULATION_SPEED);
                                //RigidBody.ApplyTorqueImpulse(tmpTorque);
                            }
                        }
                        if (CharacterProxy != null)
                        {
                            Matrix tempM = Entity.WorldMatrix;
                            tempM.Translation = Vector3.Zero;

                            if (force != null && !MyUtils.IsZero(force.Value))
                            {
                                Vector3 tmpForce = Vector3.Transform(force.Value, tempM);

                                CharacterProxy.ApplyLinearImpulse(tmpForce * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * MyFakes.SIMULATION_SPEED);
                            }
                            if (torque != null && !MyUtils.IsZero(torque.Value))
                            {
                                Vector3 tmpTorque = Vector3.Transform(torque.Value, tempM);

                                CharacterProxy.ApplyAngularImpulse(tmpTorque * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * MyFakes.SIMULATION_SPEED);
                            }
                        }
                        if (Ragdoll != null && Ragdoll.IsAddedToWorld && !Ragdoll.IsKeyframed)
                        {
                            
                            foreach (var rigidBody in Ragdoll.RigidBodies)
                            {

                                if (rigidBody != null)
                                {
                                    Matrix tempM = rigidBody.GetRigidBodyMatrix();
                                    tempM.Translation = Vector3.Zero;                                    
                                    if (force != null && !MyUtils.IsZero(force.Value))
                                    {
                                        Vector3 tmpForce = Vector3.Transform(force.Value, tempM) * rigidBody.Mass / Ragdoll.Mass;

                                        //RigidBody.Activate(true);
                                        //RigidBody.ApplyForce(MyEngineConstants.PHYSICS_STEP_SIZE_IN_SECONDS, tmpForce * 0.0001f);
                                        rigidBody.ApplyLinearImpulse(tmpForce * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * MyFakes.SIMULATION_SPEED);
                                        //RigidBody.ApplyCentralImpulse(tmpForce);
                                    }

                                    if (torque != null && !MyUtils.IsZero(torque.Value))
                                    {
                                        Vector3 tmpTorque = Vector3.Transform(torque.Value, tempM) * rigidBody.Mass / Ragdoll.Mass;
                                        //SharpDX.Vector3 tmpTorque = SharpDXHelper.ToSharpDX(torque.Value);

                                        // RigidBody.Activate(true);
                                        //RigidBody.UpdateInertiaTensor();
                                        //RigidBody.ApplyTorque(MyEngineConstants.PHYSICS_STEP_SIZE_IN_SECONDS, tmpTorque * 0.0001f);
                                        rigidBody.ApplyAngularImpulse(tmpTorque * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * MyFakes.SIMULATION_SPEED);
                                        //RigidBody.ApplyTorqueImpulse(tmpTorque);
                                    }
                                }
                            }
                        }
                    }
                    break;
                case MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE:
                    {
                        if (RigidBody != null)
                        {
                            var offset = MyPhysics.Clusters.GetObjectOffset(ClusterObjectID);

                            if (force.HasValue && position.HasValue)
                            {
                                //this.RigidBody.ApplyImpulse(force.Value, position.Value);
                                //RigidBody.Activate(true);
                                RigidBody.ApplyPointImpulse(force.Value, (Vector3)(position.Value - offset));
                            }

                            if (torque.HasValue)
                            {
                                //RigidBody.Activate(true);
                                //RigidBody.ApplyTorque(MyEngineConstants.PHYSICS_STEP_SIZE_IN_SECONDS, torque.Value * 0.0001f);
                                RigidBody.ApplyAngularImpulse(torque.Value * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * MyFakes.SIMULATION_SPEED);
                            }
                        }

                        if (CharacterProxy != null && force.HasValue && position.HasValue)
                        {
                            CharacterProxy.ApplyLinearImpulse(force.Value);
                        }
                        if (Ragdoll != null && Ragdoll.IsAddedToWorld && !Ragdoll.IsKeyframed)
                        {
                            foreach (var rigidBody in Ragdoll.RigidBodies)
                            {
                                if (rigidBody != null)
                                {
                                    var offset = MyPhysics.Clusters.GetObjectOffset(ClusterObjectID);

                                    if (force.HasValue && position.HasValue)
                                    {
                                        //this.RigidBody.ApplyImpulse(force.Value, position.Value);
                                        //RigidBody.Activate(true);
                                        rigidBody.ApplyPointImpulse(force.Value * rigidBody.Mass / Ragdoll.Mass, (Vector3)(position.Value - offset));
                                    }

                                    if (torque.HasValue)
                                    {
                                        //RigidBody.Activate(true);
                                        //RigidBody.ApplyTorque(MyEngineConstants.PHYSICS_STEP_SIZE_IN_SECONDS, torque.Value * 0.0001f);
                                        rigidBody.ApplyAngularImpulse(torque.Value * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * MyFakes.SIMULATION_SPEED * rigidBody.Mass / Ragdoll.Mass);
                                    }
                                }
                            }
                        }
                    }
                    break;
                case MyPhysicsForceType.APPLY_WORLD_FORCE:
                    {
                        if (RigidBody != null)
                        {
                            var offset = MyPhysics.Clusters.GetObjectOffset(ClusterObjectID);

                            if (force != null && !MyUtils.IsZero(force.Value))
                            {
                                if (position.HasValue)
                                {
                                    Vector3 point = position.Value - offset;
                                    RigidBody.ApplyForce(MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS, force.Value, point);
                                }
                                else
                                    RigidBody.ApplyForce(MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS, force.Value);
                            }                                
                        }
                        if (Ragdoll != null && Ragdoll.IsAddedToWorld && !Ragdoll.IsKeyframed)
                        {
                            foreach (var rigidBody in Ragdoll.RigidBodies)
                            {
                                if (rigidBody != null)
                                {
                                    var offset = MyPhysics.Clusters.GetObjectOffset(ClusterObjectID);

                                    if (force != null && !MyUtils.IsZero(force.Value))
                                    {
                                        if (position.HasValue)
                                        {
                                            Vector3 point = position.Value - offset;
                                            rigidBody.ApplyForce(MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS, force.Value * rigidBody.Mass / Ragdoll.Mass, point);
                                        }
                                        else
                                            rigidBody.ApplyForce(MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS, force.Value * rigidBody.Mass / Ragdoll.Mass);
                                    }
                                }
                            }
                        }
                    }

                    break;
                default:
                    {
                        Debug.Fail("Unhandled enum!");
                    }
                    break;
            }
        }
示例#4
0
        /// <summary>
        /// Applies external force to the physics object.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="force">The force.</param>
        /// <param name="position">The position.</param>
        /// <param name="torque">The torque.</param>
        public override void AddForce(MyPhysicsForceType type, Vector3? force, Vector3D? position, Vector3? torque)
        {
            force.AssertIsValid();
            position.AssertIsValid();
            torque.AssertIsValid();

            System.Diagnostics.Debug.Assert(IsInWorld == true || IsWelded);

            if (IsStatic)
                return;

            Matrix transform;

            switch (type)
            {
                case MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE:
                    {
                        if (RigidBody != null)
                        {
                            transform = RigidBody.GetRigidBodyMatrix();
                            AddForceTorqueBody(force, torque, RigidBody, ref transform);
                        }
                        if (CharacterProxy != null)
                        {
                            transform = Entity.WorldMatrix;
                            AddForceTorqueBody(force, torque, CharacterProxy.GetHitRigidBody(), ref transform);
                        }
                        if (Ragdoll != null && Ragdoll.IsAddedToWorld && !Ragdoll.IsKeyframed)
                        {
                            transform = Entity.WorldMatrix;
                            ApplyForceTorqueOnRagdoll(force, torque, Ragdoll, ref transform);
                        }
                    }
                    break;
                case MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE:
                    {
                        ApplyImplusesWorld(force, position, torque, RigidBody);

                        if (CharacterProxy != null && force.HasValue && position.HasValue)
                        {
                            CharacterProxy.ApplyLinearImpulse(force.Value);
                        }
                        if (Ragdoll != null && Ragdoll.IsAddedToWorld && !Ragdoll.IsKeyframed)
                        {
                            ApplyImpuseOnRagdoll(force, position, torque, Ragdoll);
                        }
                    }
                    break;
                case MyPhysicsForceType.APPLY_WORLD_FORCE:
                    {
                        ApplyForceWorld(force, position, RigidBody);

                        if (Ragdoll != null && Ragdoll.IsAddedToWorld && !Ragdoll.IsKeyframed)
                        {
                            ApplyForceOnRagdoll(force, position, Ragdoll);
                        }
                    }

                    break;
                default:
                    {
                        Debug.Fail("Unhandled enum!");
                    }
                    break;
            }
        }
 /// <summary>
 /// Applies external force to the physics object.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="force">The force.</param>
 /// <param name="position">The position.</param>
 /// <param name="torque">The torque.</param>
 public abstract void AddForce(MyPhysicsForceType type, Vector3? force, Vector3D? position, Vector3? torque);
 /// <summary>
 /// Applies external force to the physics object.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="force">The force.</param>
 /// <param name="position">The position.</param>
 /// <param name="torque">The torque.</param>
 public abstract void AddForce(MyPhysicsForceType type, Vector3?force, Vector3D?position, Vector3?torque);
示例#7
0
        public static void DebugDrawAddForce(MyPhysicsBody physics, MyPhysicsForceType type, Vector3?force, Vector3D?position, Vector3?torque)
        {
            Matrix transform;

            const float scale = 0.1f;

            switch (type)
            {
            case MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE:
            {
                if (physics.RigidBody != null)
                {
                    transform = physics.RigidBody.GetRigidBodyMatrix();
                    Vector3D p = physics.CenterOfMassWorld + physics.LinearVelocity * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;        // ClusterToWorld(transform.Translation);//ClusterToWorld(transform.Translation);

                    if (force.HasValue)
                    {
                        Vector3 f = Vector3.TransformNormal(force.Value, transform) * scale;
                        MyRenderProxy.DebugDrawArrow3D(p, p + f, Color.Blue, Color.Red, false);
                    }
                    if (torque.HasValue)
                    {
                        Vector3 f = Vector3.TransformNormal(torque.Value, transform) * scale;
                        MyRenderProxy.DebugDrawArrow3D(p, p + f, Color.Blue, Color.Purple, false);
                    }
                }
            }
            break;

            case MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE:
            {
                Vector3D p = position.Value + physics.LinearVelocity * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;

                if (force.HasValue)
                {
                    MyRenderProxy.DebugDrawArrow3D(p, p + force.Value * scale, Color.Blue, Color.Red, false);
                }
                if (torque.HasValue)
                {
                    MyRenderProxy.DebugDrawArrow3D(p, p + torque.Value * scale, Color.Blue, Color.Purple, false);
                }
            }
            break;

            case MyPhysicsForceType.APPLY_WORLD_FORCE:
            {
                if (position.HasValue)
                {
                    Vector3D p = position.Value + physics.LinearVelocity * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;

                    if (force.HasValue)
                    {
                        MyRenderProxy.DebugDrawArrow3D(p, p + force.Value * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * scale, Color.Blue, Color.Red, false);
                    }
                }
            }

            break;

            default:
            {
                Debug.Fail("Unhandled enum!");
            }
            break;
            }
        }
示例#8
0
        private void DebugDrawAddForce(MyPhysicsForceType type, Vector3? force, Vector3D? position, Vector3? torque)
        {
            Matrix transform;

            const float scale = 0.1f; 
            switch (type)
            {
                case MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE:
                    {
                        if (RigidBody != null)
                        {
                            transform = RigidBody.GetRigidBodyMatrix();
                            Vector3D p = CenterOfMassWorld + LinearVelocity * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;// ClusterToWorld(transform.Translation);//ClusterToWorld(transform.Translation);

                            if(force.HasValue)
                            {
                                Vector3 f = Vector3.TransformNormal(force.Value, transform) * scale;
                                MyRenderProxy.DebugDrawArrow3D(p, p + f, Color.Blue, Color.Red, false);
                            }
                            if (torque.HasValue)
                            {
                                Vector3 f = Vector3.TransformNormal(torque.Value, transform) * scale;
                                MyRenderProxy.DebugDrawArrow3D(p, p + f, Color.Blue, Color.Purple, false);
                            }
                        }
                    }
                    break;
                case MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE:
                    {
                        Vector3D p = position.Value + LinearVelocity * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;

                        if (force.HasValue)
                        {
                            MyRenderProxy.DebugDrawArrow3D(p, p + force.Value * scale, Color.Blue, Color.Red, false);
                        }
                        if (torque.HasValue)
                        {
                            MyRenderProxy.DebugDrawArrow3D(p, p + torque.Value * scale, Color.Blue, Color.Purple, false);
                        }
                    }
                    break;
                case MyPhysicsForceType.APPLY_WORLD_FORCE:
                    {
                        if (position.HasValue)
                        {
                            Vector3D p = position.Value + LinearVelocity * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;

                            if (force.HasValue)
                            {
                                MyRenderProxy.DebugDrawArrow3D(p, p + force.Value * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * scale, Color.Blue, Color.Red, false);
                            }
                        }
                    }

                    break;
                default:
                    {
                        Debug.Fail("Unhandled enum!");
                    }
                    break;
            }
        }
示例#9
0
        /// <summary>
        /// Applies external force to the physics object.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="force">The force.</param>
        /// <param name="position">The position.</param>
        /// <param name="torque">The torque.</param>
        public void AddForce(MyPhysicsForceType type, Vector3? force, Vector3? position, Vector3? torque)
        {
            MyUtils.AssertIsValid(force);
            MyUtils.AssertIsValid(position);
            MyUtils.AssertIsValid(torque);

            switch (type)
            {
                case MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE:
                    {
                        Matrix tempM = rigidBody.Matrix;
                        tempM.Translation = Vector3.Zero;

                        if (force != null && !MyMwcUtils.IsZero(force.Value))
                        {
                            Vector3 tmpForce = Vector3.Transform(force.Value, tempM);

                            this.rigidBody.ApplyForce(tmpForce);
                        }

                        if (torque != null && !MyMwcUtils.IsZero(torque.Value))
                        {
                            Vector3 tmpTorque = Vector3.Transform(torque.Value, tempM);

                            this.rigidBody.ApplyTorque(tmpTorque);
                        }
                    }
                    break;
                case MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE:
                    {
                        if (force.HasValue && position.HasValue)
                        {
                            this.rigidBody.ApplyImpulse(force.Value, position.Value);
                        }

                        if (torque.HasValue)
                        {
                            this.rigidBody.ApplyTorque(torque.Value);
                        }
                    }
                    break;
                default:
                    {
                        Debug.Fail("Unhandled enum!");
                    }
                    break;
            }
        }