/// <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(); Camera = camera; CameraControlScheme = new FixedOffsetCameraControlScheme(CharacterController.Body, camera, game); Space = owningSpace; }
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; }
/// <summary> /// Constructs a new demo. /// </summary> /// <param name="game">Game owning this demo.</param> public CharacterAddRemoveStressTestDemo(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 = 3; var yCount = 3; 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 = 8; var numRows = 8; var numHigh = 8; float separation = 8; 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 = 8; 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 = 8; numRows = 8; numHigh = 8; 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), 0.8f, 0.8f, 0.8f, 15); toAdd.PositionUpdateMode = BEPUphysics.PositionUpdating.PositionUpdateMode.Continuous; Space.Add(toAdd); } } } }