Пример #1
0
        /// <summary>
        /// Constructs the query manager for a character.
        /// </summary>
        /// <param name="character">Character to manage queries for.</param>
        public QueryManager(CylinderCharacterController character)
        {
            this.character = character;
            //We can share the real shape with the 'current' query object.
            queryObject = new ConvexCollidable<CylinderShape>(character.Body.CollisionInformation.Shape);
            //Share the collision rules between the main body and its query objects.  That way, the character's queries return valid results.
            queryObject.CollisionRules = character.Body.CollisionInformation.CollisionRules;

            SupportRayFilter = SupportRayFilterFunction;
        }
Пример #2
0
        // position and rotation come from world parm file, which we dont have access to here
        /*public PhysicsObject(PhysicsType physicsType, Model model, Vector3 position, float mass)
        {
            this.physicsType = physicsType;
            int id = idCounter++;

            if (DisableMass)
                mass = -1.0f;

            switch (physicsType)
            {
                case PhysicsType.Box:
                    spaceObject = PhysicsHelpers.ModelToPhysicsBox(model, position, mass);
                    // boxes contain a broadphase entry which is what shows up in ray casts, so we need to make sure its tag is set to the right id
                    // this will need to be done fore anything that is an ibroadphaseentryowner
                    ((IBroadPhaseEntryOwner)spaceObject).Entry.Tag = id;
                    break;
                case PhysicsType.StaticMesh:
                    spaceObject = PhysicsHelpers.ModelToStaticMesh(model, new BEPUphysics.MathExtensions.AffineTransform(position));
                    //staticmesh's are not ibroadphaseentryowners...they will turn directly on the raycast, so nothing else to set the tag on
                    break;
                case PhysicsType.None:
                    spaceObject = null;
                    this.position = position;
                    return;
            }

            spaceObject.Tag = id;
            Stage.ActiveStage.GetQB<PhysicsQB>().Space.Add(spaceObject);
        }*/
        /// <summary>
        /// Create a physics object
        /// </summary>
        /// <param name="actor">Actor that we are attached to</param>
        /// <param name="Parm">Actor's parm file</param>
        /// <param name="model">Actors model (so we can size the collider)</param>
        /// <param name="position">Position (from world parm)</param>
        /// <param name="rotation">Rotation (from world parm)</param>
        public PhysicsObject(Actor actor, ParameterSet Parm, Model model, Vector3 position, Vector3 rotation, Stage stage)
        {
            // **rotation comes in from file as ( pitch, yaw, roll )**

            this.actor = actor;
            this.physicsType = GameLib.PhysicsObject.PhysicsTypeFromString(Parm.GetString("PhysicsType"));
            this.position = position;
            this.rotation = Matrix.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z);

            if (ForceStaticMesh)
                this.physicsType = PhysicsType.StaticMesh;

            switch (this.physicsType)
            {
                case PhysicsType.Box:
                    {
                        float mass;
                        if (DisableMass)
                            mass = -1.0f;
                        else
                            mass = Parm.GetFloat("Mass");
                        BEPUphysics.Entities.Entity entity = PhysicsHelpers.ModelToPhysicsBox(model, position, mass, rotation.X, rotation.Y, rotation.Z);
                        entity.CollisionInformation.OwningActor = actor;
                        spaceObject = entity;
                        break;
                    }
                case PhysicsType.StaticMesh:
                    BEPUphysics.Collidables.StaticMesh mesh = PhysicsHelpers.ModelToStaticMesh(model, new BEPUphysics.MathExtensions.AffineTransform(Quaternion.CreateFromRotationMatrix( this.rotation ), position));
                    mesh.OwningActor = actor;
                    spaceObject = mesh;
                    break;
                case PhysicsType.Character:
                    {
                        float mass = Parm.GetFloat("Mass");
                        float scaleRadius = 1.0f;
                        if (Parm.HasParm("ScaleRadius"))
                            scaleRadius = Parm.GetFloat("ScaleRadius");
                        characterController = PhysicsHelpers.ModelToCharacterController(model, position, mass, scaleRadius);
                        spaceObject = characterController.Body;
                        characterController.Body.CollisionInformation.OwningActor = actor;
                        stage.GetQB<PhysicsQB>().AddToSpace(CharacterController);
                        return;
                    }
                case PhysicsType.CylinderCharacter:
                    {
                        float mass = Parm.GetFloat("Mass");
                        float scaleRadius = 1.0f;
                        if (Parm.HasParm("ScaleRadius"))
                            scaleRadius = Parm.GetFloat("ScaleRadius");
                        if (Parm.HasParm("ColliderDims"))
                        {
                            Vector2 v = Parm.GetVector2("ColliderDims");
                            cylinderCharController = new CylinderCharacterController(position, v.Y, v.X, mass);
                        }
                        else
                            cylinderCharController = PhysicsHelpers.ModelToCylinderCharacterController(model, position, mass, scaleRadius);
                        cylinderCharController.Body.Orientation = Quaternion.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z);
                        spaceObject = cylinderCharController.Body;
                        cylinderCharController.Body.CollisionInformation.OwningActor = actor;
                        stage.GetQB<PhysicsQB>().AddToSpace(cylinderCharController);
                        return;
                    }
                case PhysicsType.TriggerVolume:
                    {
                        DetectorVolume detectorVolume = new DetectorVolume(PhysicsHelpers.ModelToTriangleMesh(model, position));
                        detectorVolume.OwningActor = actor;
                        spaceObject = detectorVolume;
                        detectorVolume.EntityBeganTouching += new EntityBeginsTouchingVolumeEventHandler(detectorVolume_EntityBeganTouching);
                        detectorVolume.EntityStoppedTouching += new EntityStopsTouchingVolumeEventHandler(detectorVolume_EntityStoppedTouching);
                        break;
                    }
                case PhysicsType.None:
                    spaceObject = null;
                    this.position = position;
                    this.rotation = Matrix.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z);
                    return;
            }

            stage.GetQB<PhysicsQB>().AddToSpace(spaceObject);
        }
Пример #3
0
        public void Kill()
        {
            PhysicsQB physicsQB = Stage.ActiveStage.GetQB<PhysicsQB>();
            if (characterController != null && characterController.Space != null)
            {
                physicsQB.RemoveFromSpace(characterController);
                characterController = null;
            }

            if (cylinderCharController != null && cylinderCharController.Space != null)
            {
                physicsQB.RemoveFromSpace(cylinderCharController);
                cylinderCharController = null;
            }

            if (spaceObject != null && spaceObject.Space != null)
            {
                physicsQB.RemoveFromSpace(spaceObject);
                spaceObject = null;
            }
        }
 /// <summary>
 /// Constructs a new vertical motion constraint.
 /// </summary>
 /// <param name="characterController">Character governed by the constraint.</param>
 public VerticalMotionConstraint(CylinderCharacterController characterController)
 {
     this.character = characterController;
 }
 /// <summary>
 /// Constructs a new horizontal motion constraint.
 /// </summary>
 /// <param name="characterController">Character to be governed by this constraint.</param>
 public HorizontalMotionConstraint(CylinderCharacterController characterController)
 {
     this.character = characterController;
     CollectInvolvedEntities();
 }