コード例 #1
0
 /// <summary>
 /// Constructs a new horizontal motion constraint.
 /// </summary>
 /// <param name="characterController">Character to be governed by this constraint.</param>
 public HorizontalMotionConstraint(SphereCharacterController 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);
 }
コード例 #2
0
 public SphereCharacterObject(Vector3 position, Matrix rotation, float radius, float scale = 1, float YAlignement = 0, float mass = 10)
 {
     this.scale = new Vector3(scale);
     this.rotation = rotation;
     this.YAlignement = YAlignement * scale;
     this.characterController = new SphereCharacterController(position, radius * scale, mass);            
     this.entity = characterController.Body;
 }
コード例 #3
0
        /// <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 SphereCharacterControllerInput(Space owningSpace, Camera camera, DemosGame game)
        {
            CharacterController = new SphereCharacterController();
            CameraControlScheme = new FixedOffsetCameraControlScheme(CharacterController.Body, camera, game);

            Space = owningSpace;
            Space.Add(CharacterController);
        }
コード例 #4
0
        /// <summary>
        /// Constructs the query manager for a character.
        /// </summary>
        /// <param name="character">Character to manage queries for.</param>
        public QueryManager(SphereCharacterController character)
        {
            this.character = character;
            //We can share the real shape with the 'current' query object.
            queryObject = new ConvexCollidable<SphereShape>(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;
        }
コード例 #5
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 SphereCharacterControllerInput(Space owningSpace, Camera cameraToUse)
        {
            CharacterController = new SphereCharacterController();

            Space = owningSpace;
            Space.Add(CharacterController);

            Camera = cameraToUse;
            Deactivate();
        }
コード例 #6
0
        /// <summary>
        /// Constructs the query manager for a character.
        /// </summary>
        /// <param name="character">Character to manage queries for.</param>
        public QueryManager(SphereCharacterController character)
        {
            this.character = character;
            //We can share the real shape with the 'current' query object.
            queryObject = new ConvexCollidable <SphereShape>(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;
        }
コード例 #7
0
 /// <summary>
 /// Constructs a new horizontal motion constraint.
 /// </summary>
 /// <param name="characterController">Character to be governed by this constraint.</param>
 public HorizontalMotionConstraint(SphereCharacterController characterController)
 {
     this.character = characterController;
     SpeedScale = 1;
     CollectInvolvedEntities();
 }
コード例 #8
0
 /// <summary>
 /// Constructs a new vertical motion constraint.
 /// </summary>
 /// <param name="characterController">Character governed by the constraint.</param>
 public VerticalMotionConstraint(SphereCharacterController characterController)
 {
     this.character = characterController;
 }
コード例 #9
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.
            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);
                    }
        }
コード例 #10
0
 /// <summary>
 /// Constructs a new horizontal motion constraint.
 /// </summary>
 /// <param name="characterController">Character to be governed by this constraint.</param>
 public HorizontalMotionConstraint(SphereCharacterController 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);
 }
コード例 #11
0
 /// <summary>
 /// Constructs a new vertical motion constraint.
 /// </summary>
 /// <param name="characterController">Character governed by the constraint.</param>
 public VerticalMotionConstraint(SphereCharacterController characterController)
 {
     this.character = characterController;
 }
コード例 #12
0
 /// <summary>
 /// Constructs a new support finder.
 /// </summary>
 /// <param name="character">Character to analyze.</param>
 public SupportFinder(SphereCharacterController character)
 {
     this.character = character;
 }
コード例 #13
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);
                    }
        }