Пример #1
0
        float upStepMargin = .1f; //There's a little extra space above the maximum step height to start the obstruction and downcast test rays.  Helps when a step is very close to the max step height.

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructs a new step manager for a character.
        /// </summary>
        /// <param name="character">Character governed by the manager.</param>
        public StepManager(CharacterController character)
        {
            this.character = character;
            //The minimum step height is just barely above where the character would generally find the ground.
            //This helps avoid excess tests.
            minimumUpStepHeight = CollisionDetectionSettings.AllowedPenetration * 1.1f;// Math.Max(0, -.01f + character.Body.CollisionInformation.Shape.CollisionMargin * (1 - character.SupportFinder.sinMaximumSlope));
        }
 /// <summary>
 /// Constructs a new horizontal motion constraint.
 /// </summary>
 /// <param name="characterController">Character to be governed by this constraint.</param>
 public HorizontalMotionConstraint(CharacterController characterController)
 {
     this.character = characterController;
     CollectInvolvedEntities();
     //Compute the time it usually takes for the character to slow down while it has traction.
     tractionDecelerationTime = speed / (maximumForce * character.Body.InverseMass);
 }
Пример #3
0
 public Player(int userID)
 {
     _charCont = new CharacterController();
     _standing = true;
     _charCont.TeleportToPosition(new Vector3(100, 200, 100), 0.0f);
     Camera.Instance.Target = this;
     _userID = userID;
 }
 public CharacterCameraControlScheme(CharacterController character, Camera camera, DemosGame game)
     : base(camera, game)
 {
     Character = character;
     UseCameraSmoothing = true;
     StandingCameraOffset = 0.7f;
     CrouchingCameraOffset = 0.4f;
 }
 public BipedCollisionComponent(Actor owner)
     : base(owner)
 {
     mSimController = null;
     mHeight = 9.3f;
     mRadius = 1.7f;
     mMass = 9.0f;
 }
        /// <summary>
        /// Constructs the character and internal physics character controller.
        /// </summary>
        /// <param name="owningSpace">Space to add the character to.</param>
        /// <param name="camera">Camera to attach to the character.</param>
        /// <param name="game">The running game.</param>
        public CharacterControllerInput(Space owningSpace, Camera camera, DemosGame game)
        {
            CharacterController = new CharacterController();
            Camera = camera;
            CameraControlScheme = new CharacterCameraControlScheme(CharacterController, camera, game);

            Space = owningSpace;
        }
 /// <summary>
 /// Constructs a stance manager for a character.
 /// </summary>
 /// <param name="character">Character governed by the manager.</param>
 /// <param name="crouchingHeight">Crouching height of the character.</param>
 public StanceManager(CharacterController character, float crouchingHeight)
 {
     this.character = character;
     standingHeight = character.Body.Height;
     if (crouchingHeight < standingHeight)
         this.crouchingHeight = StandingHeight * .7f;
     else
         throw new ArgumentException("Crouching height must be less than standing height.");
 }
Пример #8
0
        /// <summary>
        /// Constructs the character and internal physics character controller.
        /// </summary>
        /// <param name="owningSpace">Space to add the character to.</param>
        /// <param name="cameraToUse">Camera to attach to the character.</param>
        public CharacterControllerInput(Space owningSpace, Camera cameraToUse)
        {
            CharacterController = new CharacterController();

            Space = owningSpace;
            Space.Add(CharacterController);

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

            SupportRayFilter = SupportRayFilterFunction;
        }
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public CharacterStressierTestDemo(DemosGame game)
            : base(game)
        {
            //Load in mesh data and create the group.
            Vector3[] staticTriangleVertices;
            int[] staticTriangleIndices;

            var playgroundModel = game.Content.Load<Model>("playground");
            //This is a little convenience method used to extract vertices and indices from a model.
            //It doesn't do anything special; any approach that gets valid vertices and indices will work.
            ModelDataExtractor.GetVerticesAndIndicesFromModel(playgroundModel, out staticTriangleVertices, out staticTriangleIndices);
            var meshShape = new InstancedMeshShape(staticTriangleVertices, staticTriangleIndices);
            var meshes = new List<Collidable>();

            var xSpacing = 400;
            var ySpacing = 400;
            var xCount = 11;
            var yCount = 11;
            for (int i = 0; i < xCount; i++)
            {
                for (int j = 0; j < yCount; j++)
                {
                    var staticMesh = new InstancedMesh(meshShape, new AffineTransform(Matrix3x3.Identity, new Vector3(-xSpacing * (xCount - 1) / 2 + i * xSpacing, 0, -ySpacing * (yCount - 1) / 2 + j * ySpacing)));
                    staticMesh.Sidedness = TriangleSidedness.Counterclockwise;
                    Space.Add(staticMesh);
                    //meshes.Add(staticMesh);
                    game.ModelDrawer.Add(staticMesh);
                }
            }
            //var group = new StaticGroup(meshes);
            //Space.Add(group);

            //To demonstrate, we'll be creating a set of static objects and giving them to a group to manage.
            var collidables = new List<Collidable>();

            //Start with a whole bunch of boxes.  These are entity collidables, but without entities!
            xSpacing = 25;
            ySpacing = 16;
            float zSpacing = 25;

            xCount = 25;
            yCount = 7;
            int zCount = 25;

            var random = new Random();
            for (int i = 0; i < xCount; i++)
            {
                for (int j = 0; j < yCount; j++)
                {
                    for (int k = 0; k < zCount; k++)
                    {
                        //Create a transform and the instance of the mesh.
                        var collidable = new ConvexCollidable<BoxShape>(new BoxShape((float)random.NextDouble() * 25 + 5.5f, (float)random.NextDouble() * 25 + 5.5f, (float)random.NextDouble() * 25 + 5.5f));

                        //This EntityCollidable isn't associated with an entity, so we must manually tell it where to sit by setting the WorldTransform.
                        //This also updates its bounding box.
                        collidable.WorldTransform = new RigidTransform(
                            new Vector3(i * xSpacing - xCount * xSpacing * .5f, j * ySpacing + -50, k * zSpacing - zCount * zSpacing * .5f),
                            Quaternion.CreateFromAxisAngle(Vector3.Normalize(new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble())), (float)random.NextDouble() * 100));

                        collidables.Add(collidable);
                        game.ModelDrawer.Add(collidable);
                    }
                }
            }
            var group = new StaticGroup(collidables);
            Space.Add(group);

            //Now drop the characters on it!
            var numColumns = 16;
            var numRows = 16;
            var numHigh = 16;
            float separation = 24;

            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        var character = new CharacterController();
                        character.Body.Position =
                            new Vector3(
                            separation * i - numRows * separation / 2,
                            50f + k * separation,
                            separation * j - numColumns * separation / 2);

                        characters.Add(character);

                        Space.Add(character);
                    }

            game.Camera.Position = new Vector3(0, 10, 40);

            //Dump some boxes on top of the characters for fun.
            numColumns = 16;
            numRows = 16;
            numHigh = 8;
            separation = 24;
            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        var toAdd = new Box(
                            new Vector3(
                            separation * i - numRows * separation / 2,
                            52f + k * separation,
                            separation * j - numColumns * separation / 2),
                            0.8f, 0.8f, 0.8f, 15);
                        toAdd.PositionUpdateMode = BEPUphysics.PositionUpdating.PositionUpdateMode.Continuous;

                        Space.Add(toAdd);
                    }
        }
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public CharacterStressTestDemo(DemosGame game)
            : base(game)
        {
            //Load in mesh data and create the group.
            Vector3[] staticTriangleVertices;
            int[] staticTriangleIndices;

            var playgroundModel = game.Content.Load<Model>("playground");
            //This is a little convenience method used to extract vertices and indices from a model.
            //It doesn't do anything special; any approach that gets valid vertices and indices will work.
            ModelDataExtractor.GetVerticesAndIndicesFromModel(playgroundModel, out staticTriangleVertices, out staticTriangleIndices);
            var meshShape = new InstancedMeshShape(staticTriangleVertices, staticTriangleIndices);
            var meshes = new List<Collidable>();

            var xSpacing = 400;
            var ySpacing = 400;
            var xCount = 11;
            var yCount = 11;
            for (int i = 0; i < xCount; i++)
            {
                for (int j = 0; j < yCount; j++)
                {
                    var staticMesh = new InstancedMesh(meshShape, new AffineTransform(Matrix3x3.Identity, new Vector3(-xSpacing * (xCount - 1) / 2 + i * xSpacing, 0, -ySpacing * (yCount - 1) / 2 + j * ySpacing)));
                    staticMesh.Sidedness = TriangleSidedness.Counterclockwise;
                    Space.Add(staticMesh);
                    //meshes.Add(staticMesh);
                    game.ModelDrawer.Add(staticMesh);
                }
            }
            //var group = new StaticGroup(meshes);
            //Space.Add(group);

            //Now drop the characters on it!
            var numColumns = 16;
            var numRows = 16;
            var numHigh = 8;
            float separation = 64;

            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        var character = new CharacterController();
                        character.Body.Position =
                            new Vector3(
                            separation * i - numRows * separation / 2,
                            40f + k * separation,
                            separation * j - numColumns * separation / 2);

                        characters.Add(character);

                        Space.Add(character);
                    }

            //Now drop the ball-characters on it!
            numColumns = 16;
            numRows = 16;
            numHigh = 8;
            separation = 64;
            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        var character = new SphereCharacterController();
                        character.Body.Position =
                            new Vector3(
                            separation * i - numRows * separation / 2,
                            48f + k * separation,
                            separation * j - numColumns * separation / 2);

                        sphereCharacters.Add(character);

                        Space.Add(character);
                    }

            game.Camera.Position = new Vector3(0, 10, 40);

            //Dump some boxes on top of the characters for fun.
            numColumns = 16;
            numRows = 16;
            numHigh = 8;
            separation = 64;
            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        var toAdd = new Box(
                            new Vector3(
                            separation * i - numRows * separation / 2,
                            52f + k * separation,
                            separation * j - numColumns * separation / 2),
                            0.8f, 0.8f, 0.8f, 15);
                        toAdd.PositionUpdateMode = BEPUphysics.PositionUpdating.PositionUpdateMode.Continuous;

                        Space.Add(toAdd);
                    }
        }
 /// <summary>
 /// Constructs a new horizontal motion constraint.
 /// </summary>
 /// <param name="characterController">Character to be governed by this constraint.</param>
 public HorizontalMotionConstraint(CharacterController characterController)
 {
     this.character = characterController;
     SpeedScale = 1;
     CollectInvolvedEntities();
 }
Пример #13
0
        protected override void ComponentsCreatedHandler(object sender, EventArgs e)
        {
            BipedControllerComponent bipedController = Owner.GetComponent<BipedControllerComponent>(ComponentType.Control);
            if (bipedController == null)
                throw new LevelManifestException("BipedCollisionComponents expect to be accompanied by BipedControllerComponents.");

            mSimController = bipedController.Controller;

            mSimController.StanceManager.StandingHeight = mHeight;
            mSimController.StanceManager.CrouchingHeight = mHeight * 0.5f;
            mSimController.BodyRadius = mRadius;
            mSimController.Body.Mass = mMass;

            base.ComponentsCreatedHandler(sender, e);

            mSimController.ViewDirection = BepuConverter.Convert(Vector3.Transform(Vector3.Forward, mTransformComponent.Orientation));
        }
Пример #14
0
 public override void Release()
 {
     mSimController = null;
     base.Release();
 }
Пример #15
0
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public CharacterStressTestDemo(DemosGame game)
            : base(game)
        {
            //Load in mesh data and create the group.
            Vector3[] staticTriangleVertices;
            int[] staticTriangleIndices;

            var playgroundModel = game.Content.Load<Model>("playground");
            //This is a little convenience method used to extract vertices and indices from a model.
            //It doesn't do anything special; any approach that gets valid vertices and indices will work.
            TriangleMesh.GetVerticesAndIndicesFromModel(playgroundModel, out staticTriangleVertices, out staticTriangleIndices);
            var staticMesh = new StaticMesh(staticTriangleVertices, staticTriangleIndices, new AffineTransform(Matrix3X3.CreateFromAxisAngle(Vector3.Up, MathHelper.Pi), new Vector3(0, -10, 0)));
            staticMesh.Sidedness = TriangleSidedness.Counterclockwise;

            Space.Add(staticMesh);
            game.ModelDrawer.Add(staticMesh);

            //Now drop the characters on it!
            var numColumns = 8;
            var numRows = 8;
            var numHigh = 8;
            float separation = 16;

            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        var character = new CharacterController();
                        character.Body.Position =
                            new Vector3(
                            separation * i - numRows * separation / 2,
                            40f + k * separation,
                            separation * j - numColumns * separation / 2);

                        characters.Add(character);

                        Space.Add(character);
                    }

            //Now drop the ball-characters on it!
            numColumns = 8;
            numRows = 8;
            numHigh = 8;
            separation = 16;
            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        var character = new SphereCharacterController();
                        character.Body.Position =
                            new Vector3(
                            separation * i - numRows * separation / 2,
                            48f + k * separation,
                            separation * j - numColumns * separation / 2);

                        sphereCharacters.Add(character);

                        Space.Add(character);
                    }

            game.Camera.Position = new Vector3(0, 10, 40);

            //Dump some boxes on top of the characters for fun.
            numColumns = 16;
            numRows = 16;
            numHigh = 1;
            separation = 8;
            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        var toAdd = new Box(
                            new Vector3(
                            separation * i - numRows * separation / 2,
                            52f + k * separation,
                            separation * j - numColumns * separation / 2),
                            2, 2, 2, 15);

                        Space.Add(toAdd);
                    }
        }
 /// <summary>
 /// Constructs a stance manager for a character.
 /// </summary>
 /// <param name="character">Character governed by the manager.</param>
 public StanceManager(CharacterController character)
 {
     this.character = character;
     StandingHeight = character.Body.Height;
     CrouchingHeight = StandingHeight * .7f;
 }
 /// <summary>
 /// Constructs a new vertical motion constraint.
 /// </summary>
 /// <param name="characterController">Character governed by the constraint.</param>
 public VerticalMotionConstraint(CharacterController characterController)
 {
     this.character = characterController;
 }
        public override void Initialize(ContentManager contentLoader, ComponentManifest manifest)
        {
            float jumpSpeed = 35.0f;
            if (manifest.Properties.ContainsKey(ManifestKeys.JUMP_SPEED))
                jumpSpeed = (float)(manifest.Properties[ManifestKeys.JUMP_SPEED]);

            float runSpeed = 32.0f;
            if (manifest.Properties.ContainsKey(ManifestKeys.RUN_SPEED))
                runSpeed = (float)(manifest.Properties[ManifestKeys.RUN_SPEED]);

            Controller = new CharacterController();

            JumpSpeed = jumpSpeed;
            RunSpeed = runSpeed;
            Controller.HorizontalMotionConstraint.SpeedScale = 1.0f;
            Controller.Body.CollisionInformation.CollisionRules.Group = GameResources.ActorManager.CharactersCollisionGroup;

            GameResources.ActorManager.PreAnimationUpdateStep += PreAnimationUpdateHandler;
            GameResources.ActorManager.PostAnimationUpdateStep += PostAnimationUpdateHandler;
        }