private static void CreateTestArena() { float arenaSize = 40f; ProceduralCuboid a = new ProceduralCuboid(arenaSize, 1, arenaSize / 5); a.Translate(new Vector3(0, arenaSize / 5, arenaSize)); a.SetColor(Color.LightGray); ProceduralShape b = a.Clone(); b.Translate(new Vector3(0, 0, -arenaSize * 2)); ProceduralShape c = ProceduralShape.Combine(a, b); ProceduralShape d = b.Clone(); d.Transform(MonoMathHelper.RotateNinetyDegreesAroundUp(true)); ProceduralShape e = ProceduralShape.Combine(c, d); var side2 = e.Clone(); var side3 = e.Clone(); var side4 = e.Clone(); e.Translate(new Vector3(-arenaSize * 2, 0, 0)); side2.Transform(MonoMathHelper.RotateHundredEightyDegreesAroundUp(true)); side2.Translate(new Vector3(arenaSize * 2, 0, 0)); side3.Transform(MonoMathHelper.RotateNinetyDegreesAroundUp(true)); side3.Translate(new Vector3(0, 0, arenaSize * 2)); side4.Transform(MonoMathHelper.RotateNinetyDegreesAroundUp(false)); side4.Translate(new Vector3(0, 0, -arenaSize * 2)); var final = ProceduralShape.Combine(e, side2, side3, side4); var arenaObject = GameObjectFactory.CreateRenderableGameObjectFromShape(final, EffectLoader.LoadSM5Effect("flatshaded")); arenaObject.AddComponent(new StaticMeshColliderComponent(arenaObject, final.GetVertices(), final.GetIndicesAsInt().ToArray(), Vector3.Zero)); arenaObject.AddComponent(new ShadowCasterComponent()); SystemCore.GameObjectManager.AddAndInitialiseGameObject(arenaObject); }
private void GenerateWalls() { List <ProceduralCuboid> cuboids = new List <ProceduralCuboid>(); foreach (GameTile t in gameTiles) { //surrounded if (t.Neighbours.Count == 4) { continue; } bool northWallNeeded, southWallNeeded, westWallNeeded, eastWallNeeded; northWallNeeded = southWallNeeded = westWallNeeded = eastWallNeeded = true; foreach (GameTile n in t.Neighbours) { //it's north / south if (t.Center.X == n.Center.X) { if (t.Center.Z > n.Center.Z) { southWallNeeded = false; } else { northWallNeeded = false; } } //east / west neighbour if (t.Center.Z == n.Center.Z) { if (t.Center.X > n.Center.X) { westWallNeeded = false; } else { eastWallNeeded = false; } } } if (northWallNeeded) { Vector3 wallCenterPoint = t.Center + new Vector3(0, t.Scale / 2, t.Scale / 2 + 1); ProceduralCuboid cuboid = new ProceduralCuboid(t.Scale / 2, 1, t.Scale / 2); cuboid.Translate(wallCenterPoint); cuboids.Add(cuboid); // CreateWallObject(wallCenterPoint, cuboid); } if (southWallNeeded) { Vector3 wallCenterPoint = t.Center + new Vector3(0, t.Scale / 2, -t.Scale / 2 - 1); ProceduralCuboid cuboid = new ProceduralCuboid(t.Scale / 2, 1, t.Scale / 2); cuboid.Translate(wallCenterPoint); cuboids.Add(cuboid); // CreateWallObject(wallCenterPoint, cuboid); } if (eastWallNeeded) { Vector3 wallCenterPoint = t.Center + new Vector3(t.Scale / 2 + 1, t.Scale / 2, 0); ProceduralCuboid cuboid = new ProceduralCuboid(1, t.Scale / 2, t.Scale / 2); cuboid.Translate(wallCenterPoint); cuboids.Add(cuboid); // CreateWallObject(wallCenterPoint, cuboid); } if (westWallNeeded) { Vector3 wallCenterPoint = t.Center + new Vector3(-t.Scale / 2 - 1, t.Scale / 2, 0); ProceduralCuboid cuboid = new ProceduralCuboid(1, t.Scale / 2, t.Scale / 2); cuboid.Translate(wallCenterPoint); cuboids.Add(cuboid); // CreateWallObject(wallCenterPoint, cuboid); } } }
private void SetupVehicle() { float width = 2.5f; float height = 0.75f; float length = 4.5f; float scale = 1f; var vehicleShape = new ProceduralCuboid(width / 2 * scale, length / 2 * scale, height / 2 * scale); vehicleShape.Translate(new Vector3(0, 0.5f, 0)); vehicleShape.SetColor(Color.Red); vehicleObject = GameObjectFactory.CreateRenderableGameObjectFromShape(vehicleShape, EffectLoader.LoadSM5Effect("flatshaded")); vehicleObject.AddComponent(new ShadowCasterComponent()); SystemCore.GameObjectManager.AddAndInitialiseGameObject(vehicleObject); ProceduralSphere cyl = new ProceduralSphere(10, 10); cyl.Scale(0.375f * scale); //cyl.Transform(Matrix.CreateRotationZ(MathHelper.PiOver2)); wheel1 = GameObjectFactory.CreateRenderableGameObjectFromShape(cyl, EffectLoader.LoadSM5Effect("flatshaded")); SystemCore.GameObjectManager.AddAndInitialiseGameObject(wheel1); var bodies = new List <CompoundShapeEntry> { new CompoundShapeEntry(new BoxShape(width * scale, height * scale, length * scale), new BEPUutilities.Vector3(0, 0, 0), 60), //new CompoundShapeEntry(new BoxShape(2.5f, .3f, 2f), new BEPUutilities.Vector3(0, .75f / 2 + .3f / 2, .5f), 1) }; var body = new CompoundBody(bodies, 61); body.CollisionInformation.LocalPosition = new BEPUutilities.Vector3(0, .5f, 0); body.Position = new BEPUutilities.Vector3(10, 20, 10); testVehicle = new Vehicle(body); BEPUutilities.Quaternion localWheelRotation = BEPUutilities.Quaternion.Identity; BEPUutilities.Matrix wheelGraphicRotation = BEPUutilities.Matrix.Identity; testVehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f * scale, 0.2f * scale, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, BEPUutilities.Vector3.Down, 0.325f, new BEPUutilities.Vector3(-1.1f, -0.1f, 1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); testVehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f * scale, 0.2f * scale, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, BEPUutilities.Vector3.Down, 0.325f, new BEPUutilities.Vector3(-1.1f, -0.1f, -1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); testVehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f * scale, 0.2f * scale, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, BEPUutilities.Vector3.Down, 0.325f, new BEPUutilities.Vector3(1.1f, -0.1f, 1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); testVehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f * scale, 0.2f * scale, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, BEPUutilities.Vector3.Down, 0.325f, new BEPUutilities.Vector3(1.1f, -0.1f, -1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); foreach (Wheel wheel in testVehicle.Wheels) { //This is a cosmetic setting that makes it looks like the car doesn't have antilock brakes. wheel.Shape.FreezeWheelsWhileBraking = true; //By default, wheels use as many iterations as the space. By lowering it, //performance can be improved at the cost of a little accuracy. //However, because the suspension and friction are not really rigid, //the lowered accuracy is not so much of a problem. wheel.Suspension.SolverSettings.MaximumIterationCount = 1; wheel.Brake.SolverSettings.MaximumIterationCount = 1; wheel.SlidingFriction.SolverSettings.MaximumIterationCount = 1; wheel.DrivingMotor.SolverSettings.MaximumIterationCount = 1; } SystemCore.PhysicsSimulation.Add(testVehicle); }
private static GameObject CreateTestArena(float arenaSize) { ProceduralShapeBuilder floor = new ProceduralShapeBuilder(); floor.AddSquareFace(new Vector3(arenaSize, 0, arenaSize), new Vector3(-arenaSize, 0, arenaSize), new Vector3(arenaSize, 0, -arenaSize), new Vector3(-arenaSize, 0, -arenaSize)); ProceduralShape arenaFloor = floor.BakeShape(); arenaFloor.SetColor(Color.DarkOrange); ProceduralCuboid a = new ProceduralCuboid(arenaSize, 1, arenaSize / 5); a.Translate(new Vector3(0, arenaSize / 5, arenaSize)); a.SetColor(Color.LightGray); ProceduralShape b = a.Clone(); b.Translate(new Vector3(0, 0, -arenaSize * 2)); ProceduralShape c = ProceduralShape.Combine(a, b); ProceduralShape d = b.Clone(); d.Transform(MonoMathHelper.RotateNinetyDegreesAroundUp(true)); ProceduralShape e = ProceduralShape.Combine(arenaFloor, c, d); var side2 = e.Clone(); var side3 = e.Clone(); var side4 = e.Clone(); e.Translate(new Vector3(-arenaSize * 2, 0, 0)); side2.Transform(MonoMathHelper.RotateHundredEightyDegreesAroundUp(true)); side2.Translate(new Vector3(arenaSize * 2, 0, 0)); side3.Transform(MonoMathHelper.RotateNinetyDegreesAroundUp(true)); side3.Translate(new Vector3(0, 0, arenaSize * 2)); side4.Transform(MonoMathHelper.RotateNinetyDegreesAroundUp(false)); side4.Translate(new Vector3(0, 0, -arenaSize * 2)); var final = ProceduralShape.Combine(e, side2, side3, side4, arenaFloor); var arenaObject = GameObjectFactory.CreateRenderableGameObjectFromShape(final, EffectLoader.LoadSM5Effect("flatshaded")); arenaObject.AddComponent(new StaticMeshColliderComponent(arenaObject, final.GetVertices(), final.GetIndicesAsInt().ToArray())); // arenaObject.AddComponent(new RotatorComponent(Vector3.Up, 0.0001f)); SystemCore.GameObjectManager.AddAndInitialiseGameObject(arenaObject); LineBatch l = new LineBatch(new Vector3(-arenaSize, 0.1f, -arenaSize), new Vector3(-arenaSize, 0.1f, arenaSize), new Vector3(arenaSize, 0.1f, arenaSize), new Vector3(arenaSize, 0.1f, -arenaSize), new Vector3(-arenaSize, 0.1f, -arenaSize)); GameObject lineObject = SystemCore.GameObjectManager.AddLineBatchToScene(l); arenaObject.AddChild(lineObject); return(arenaObject); }