Пример #1
0
 void HandleNodeCollision(NodeCollisionEventArgs args)
 {
     foreach (var contact in args.Contacts)
     {
         // If contact is below node center and mostly vertical, assume it's a ground contact
         if (contact.ContactPosition.Y < (Node.Position.Y + 1.0f))
         {
             float level = Math.Abs(contact.ContactNormal.Y);
             if (level > 0.75)
             {
                 onGround = true;
             }
         }
     }
 }
Пример #2
0
        void HandleNodeCollision(NodeCollisionEventArgs args)
        {
            // Get the other colliding body, make sure it is moving (has nonzero mass)
            RigidBody otherBody = args.OtherBody;

            if (otherBody.Mass > 0.0f)
            {
                // We do not need the physics components in the AnimatedModel's root scene node anymore
                Node.RemoveComponent <RigidBody>();
                Node.RemoveComponent <CollisionShape>();

                // Create RigidBody & CollisionShape components to bones
                CreateRagdollBone("Bip01_Pelvis", ShapeType.Box, new Vector3(0.3f, 0.2f, 0.25f), new Vector3(0.0f, 0.0f, 0.0f),
                                  new Quaternion(0.0f, 0.0f, 0.0f));
                CreateRagdollBone("Bip01_Spine1", ShapeType.Box, new Vector3(0.35f, 0.2f, 0.3f), new Vector3(0.15f, 0.0f, 0.0f),
                                  new Quaternion(0.0f, 0.0f, 0.0f));
                CreateRagdollBone("Bip01_L_Thigh", ShapeType.Capsule, new Vector3(0.175f, 0.45f, 0.175f), new Vector3(0.25f, 0.0f, 0.0f),
                                  new Quaternion(0.0f, 0.0f, 90.0f));
                CreateRagdollBone("Bip01_R_Thigh", ShapeType.Capsule, new Vector3(0.175f, 0.45f, 0.175f), new Vector3(0.25f, 0.0f, 0.0f),
                                  new Quaternion(0.0f, 0.0f, 90.0f));
                CreateRagdollBone("Bip01_L_Calf", ShapeType.Capsule, new Vector3(0.15f, 0.55f, 0.15f), new Vector3(0.25f, 0.0f, 0.0f),
                                  new Quaternion(0.0f, 0.0f, 90.0f));
                CreateRagdollBone("Bip01_R_Calf", ShapeType.Capsule, new Vector3(0.15f, 0.55f, 0.15f), new Vector3(0.25f, 0.0f, 0.0f),
                                  new Quaternion(0.0f, 0.0f, 90.0f));
                CreateRagdollBone("Bip01_Head", ShapeType.Box, new Vector3(0.2f, 0.2f, 0.2f), new Vector3(0.1f, 0.0f, 0.0f),
                                  new Quaternion(0.0f, 0.0f, 0.0f));
                CreateRagdollBone("Bip01_L_UpperArm", ShapeType.Capsule, new Vector3(0.15f, 0.35f, 0.15f), new Vector3(0.1f, 0.0f, 0.0f),
                                  new Quaternion(0.0f, 0.0f, 90.0f));
                CreateRagdollBone("Bip01_R_UpperArm", ShapeType.Capsule, new Vector3(0.15f, 0.35f, 0.15f), new Vector3(0.1f, 0.0f, 0.0f),
                                  new Quaternion(0.0f, 0.0f, 90.0f));
                CreateRagdollBone("Bip01_L_Forearm", ShapeType.Capsule, new Vector3(0.125f, 0.4f, 0.125f), new Vector3(0.2f, 0.0f, 0.0f),
                                  new Quaternion(0.0f, 0.0f, 90.0f));
                CreateRagdollBone("Bip01_R_Forearm", ShapeType.Capsule, new Vector3(0.125f, 0.4f, 0.125f), new Vector3(0.2f, 0.0f, 0.0f),
                                  new Quaternion(0.0f, 0.0f, 90.0f));

                Vector3 back    = new Vector3(0f, 0f, -1f);
                Vector3 forward = new Vector3(0f, 0f, 1f);
                Vector3 left    = new Vector3(-1f, 0f, 0f);
                Vector3 down    = new Vector3(0f, -1f, 0f);
                Vector3 up      = new Vector3(0f, 1f, 0f);

                // Create Constraints between bones
                CreateRagdollConstraint("Bip01_L_Thigh", "Bip01_Pelvis", ConstraintType.ConeTwist, back, forward,
                                        new Vector2(45.0f, 45.0f), Vector2.Zero);
                CreateRagdollConstraint("Bip01_R_Thigh", "Bip01_Pelvis", ConstraintType.ConeTwist, back, forward,
                                        new Vector2(45.0f, 45.0f), Vector2.Zero);
                CreateRagdollConstraint("Bip01_L_Calf", "Bip01_L_Thigh", ConstraintType.Hinge, back, back,
                                        new Vector2(90.0f, 0.0f), Vector2.Zero);
                CreateRagdollConstraint("Bip01_R_Calf", "Bip01_R_Thigh", ConstraintType.Hinge, back, back,
                                        new Vector2(90.0f, 0.0f), Vector2.Zero);
                CreateRagdollConstraint("Bip01_Spine1", "Bip01_Pelvis", ConstraintType.Hinge, forward, forward,
                                        new Vector2(45.0f, 0.0f), new Vector2(-10.0f, 0.0f));
                CreateRagdollConstraint("Bip01_Head", "Bip01_Spine1", ConstraintType.ConeTwist, left, left,
                                        new Vector2(0.0f, 30.0f), Vector2.Zero);
                CreateRagdollConstraint("Bip01_L_UpperArm", "Bip01_Spine1", ConstraintType.ConeTwist, down, up,
                                        new Vector2(45.0f, 45.0f), Vector2.Zero, false);
                CreateRagdollConstraint("Bip01_R_UpperArm", "Bip01_Spine1", ConstraintType.ConeTwist, down, up,
                                        new Vector2(45.0f, 45.0f), Vector2.Zero, false);
                CreateRagdollConstraint("Bip01_L_Forearm", "Bip01_L_UpperArm", ConstraintType.Hinge, back, back,
                                        new Vector2(90.0f, 0.0f), Vector2.Zero);
                CreateRagdollConstraint("Bip01_R_Forearm", "Bip01_R_UpperArm", ConstraintType.Hinge, back, back,
                                        new Vector2(90.0f, 0.0f), Vector2.Zero);

                // Disable keyframe animation from all bones so that they will not interfere with the ragdoll
                AnimatedModel model    = GetComponent <AnimatedModel>();
                Skeleton      skeleton = model.Skeleton;
                for (uint i = 0; i < skeleton.NumBones; ++i)
                {
                    //var offset = Marshal.OffsetOf(typeof(Bone), "_animated");
                    skeleton.GetBoneSafe(i).Animated = false;
                }

                // Finally remove self from the scene node. Note that this must be the last operation performed in the function
                Remove();
            }
        }
Пример #3
0
		void HandleNodeCollision(NodeCollisionEventArgs args)
		{
			foreach (var contact in args.Contacts)
			{
				// If contact is below node center and mostly vertical, assume it's a ground contact
				if (contact.ContactPosition.Y < (Node.Position.Y + 1.0f))
				{
					float level = Math.Abs(contact.ContactNormal.Y);
					if (level > 0.75)
						onGround = true;
				}
			}
		}
Пример #4
0
		void HandleNodeCollision(NodeCollisionEventArgs args)
		{
			// Get the other colliding body, make sure it is moving (has nonzero mass)
			RigidBody otherBody = args.OtherBody;

			if (otherBody.Mass > 0.0f)
			{
				// We do not need the physics components in the AnimatedModel's root scene node anymore
				Node.RemoveComponent<RigidBody>();
				Node.RemoveComponent<CollisionShape>();
		
				// Create RigidBody & CollisionShape components to bones
				CreateRagdollBone("Bip01_Pelvis", ShapeType.Box, new Vector3(0.3f, 0.2f, 0.25f), new Vector3(0.0f, 0.0f, 0.0f),
					new Quaternion(0.0f, 0.0f, 0.0f));
				CreateRagdollBone("Bip01_Spine1", ShapeType.Box, new Vector3(0.35f, 0.2f, 0.3f), new Vector3(0.15f, 0.0f, 0.0f),
					new Quaternion(0.0f, 0.0f, 0.0f));
				CreateRagdollBone("Bip01_L_Thigh", ShapeType.Capsule, new Vector3(0.175f, 0.45f, 0.175f), new Vector3(0.25f, 0.0f, 0.0f),
					new Quaternion(0.0f, 0.0f, 90.0f));
				CreateRagdollBone("Bip01_R_Thigh", ShapeType.Capsule, new Vector3(0.175f, 0.45f, 0.175f), new Vector3(0.25f, 0.0f, 0.0f),
					new Quaternion(0.0f, 0.0f, 90.0f));
				CreateRagdollBone("Bip01_L_Calf", ShapeType.Capsule, new Vector3(0.15f, 0.55f, 0.15f), new Vector3(0.25f, 0.0f, 0.0f),
					new Quaternion(0.0f, 0.0f, 90.0f));
				CreateRagdollBone("Bip01_R_Calf", ShapeType.Capsule, new Vector3(0.15f, 0.55f, 0.15f), new Vector3(0.25f, 0.0f, 0.0f),
					new Quaternion(0.0f, 0.0f, 90.0f));
				CreateRagdollBone("Bip01_Head", ShapeType.Box, new Vector3(0.2f, 0.2f, 0.2f), new Vector3(0.1f, 0.0f, 0.0f),
					new Quaternion(0.0f, 0.0f, 0.0f));
				CreateRagdollBone("Bip01_L_UpperArm", ShapeType.Capsule, new Vector3(0.15f, 0.35f, 0.15f), new Vector3(0.1f, 0.0f, 0.0f),
					new Quaternion(0.0f, 0.0f, 90.0f));
				CreateRagdollBone("Bip01_R_UpperArm", ShapeType.Capsule, new Vector3(0.15f, 0.35f, 0.15f), new Vector3(0.1f, 0.0f, 0.0f),
					new Quaternion(0.0f, 0.0f, 90.0f));
				CreateRagdollBone("Bip01_L_Forearm", ShapeType.Capsule, new Vector3(0.125f, 0.4f, 0.125f), new Vector3(0.2f, 0.0f, 0.0f),
					new Quaternion(0.0f, 0.0f, 90.0f));
				CreateRagdollBone("Bip01_R_Forearm", ShapeType.Capsule, new Vector3(0.125f, 0.4f, 0.125f), new Vector3(0.2f, 0.0f, 0.0f),
					new Quaternion(0.0f, 0.0f, 90.0f));
		
				Vector3 back = new Vector3(0f, 0f, -1f);
				Vector3 forward = new Vector3(0f, 0f, 1f);
				Vector3 left = new Vector3(-1f, 0f, 0f);
				Vector3 down = new Vector3(0f, -1f, 0f);
				Vector3 up = new Vector3(0f, 1f, 0f);

				// Create Constraints between bones
				CreateRagdollConstraint("Bip01_L_Thigh", "Bip01_Pelvis", ConstraintType.ConeTwist, back, forward,
					new Vector2(45.0f, 45.0f), Vector2.Zero);
				CreateRagdollConstraint("Bip01_R_Thigh", "Bip01_Pelvis", ConstraintType.ConeTwist, back, forward,
					new Vector2(45.0f, 45.0f), Vector2.Zero);
				CreateRagdollConstraint("Bip01_L_Calf", "Bip01_L_Thigh", ConstraintType.Hinge, back, back,
					new Vector2(90.0f, 0.0f), Vector2.Zero);
				CreateRagdollConstraint("Bip01_R_Calf", "Bip01_R_Thigh", ConstraintType.Hinge, back, back,
					new Vector2(90.0f, 0.0f), Vector2.Zero);
				CreateRagdollConstraint("Bip01_Spine1", "Bip01_Pelvis", ConstraintType.Hinge, forward, forward,
					new Vector2(45.0f, 0.0f), new Vector2(-10.0f, 0.0f));
				CreateRagdollConstraint("Bip01_Head", "Bip01_Spine1", ConstraintType.ConeTwist, left, left,
					new Vector2(0.0f, 30.0f), Vector2.Zero);
				CreateRagdollConstraint("Bip01_L_UpperArm", "Bip01_Spine1", ConstraintType.ConeTwist, down, up,
					new Vector2(45.0f, 45.0f), Vector2.Zero, false);
				CreateRagdollConstraint("Bip01_R_UpperArm", "Bip01_Spine1", ConstraintType.ConeTwist, down, up,
					new Vector2(45.0f, 45.0f), Vector2.Zero, false);
				CreateRagdollConstraint("Bip01_L_Forearm", "Bip01_L_UpperArm", ConstraintType.Hinge, back, back,
					new Vector2(90.0f, 0.0f), Vector2.Zero);
				CreateRagdollConstraint("Bip01_R_Forearm", "Bip01_R_UpperArm", ConstraintType.Hinge, back, back,
					new Vector2(90.0f, 0.0f), Vector2.Zero);
		
				// Disable keyframe animation from all bones so that they will not interfere with the ragdoll
				AnimatedModel model = GetComponent<AnimatedModel>();
				Skeleton skeleton = model.Skeleton;
				for (uint i = 0; i < skeleton.NumBones; ++i)
				{
					//var offset = Marshal.OffsetOf(typeof(Bone), "_animated");
					skeleton.GetBoneSafe(i).Animated = false;
				}
		
				// Finally remove self from the scene node. Note that this must be the last operation performed in the function
				Remove();
			}
		}
Пример #5
0
        private void HandleNodeCollision(NodeCollisionEventArgs obj)
        {
            RigidBody body      = obj.Body;
            Node      node      = body.Node;
            String    name      = node.Name;
            RigidBody otherBody = obj.OtherBody;
            Node      otherNode = otherBody.Node;
            String    otherName = otherNode.Name;

            // Detect if there is ground within stepping range
            if (obj.Trigger)
            {
                if (name == "DropDetect")
                {
                    dropDetected_ = false;
                    return;
                }

                if (name == "StandDetect")
                {
                    okToStand_ = false;
                    return;
                }

                if (name == "GroundDetect")
                {
                    nearGround_ = true;
                    return;
                }
            }

            // Filter out collisions with DropDetect as otherNode, for some reason this can cause a crouch-jump glitch ?
            if (otherName == "DropDetect")
            {
                // dropDetected_ = false;
                return;
            }

            if (otherName == "StandDetect")
            {
                return;
            }

            if (otherName == "GroundDetect")
            {
                return;
            }

            /*if (name != "Character")
             *  return;*/

            Vector3        vel      = body.LinearVelocity;
            float          YY       = (Node.Position.Y);
            CollisionShape colShape = Node.GetComponent <CollisionShape>();
            float          height   = colShape.Position.Y;

            foreach (var contacts in obj.Contacts)
            {
                Vector3 contactPosition = contacts.ContactPosition;
                Vector3 contactNormal   = contacts.ContactNormal;
                float   contactDistance = contacts.ContactDistance;
                float   contactImpulse  = contacts.ContactImpulse;

                // Prevent bounce from corner impact
                if (contactImpulse > 200.0f)
                {
                    highImpulseDetected_ = true;
                }


                // If contact is below node center and mostly vertical, assume it's a ground contact
                if (contactPosition.Y < YY + height)
                {
                    float level = Math.Abs(contactNormal.Y);
                    if (level > 0.75)
                    {
                        onGround_ = true;
                    }
                }
            }
        }
Пример #6
0
 //TODO: Should be BeginRendering event
 private void HandleRenderUpdate(NodeCollisionEventArgs obj)
 {
 }