public Carrier() : base() { Color carrierColor = Color.Red; this.AddComponent(new CarrierController()); ProceduralShape body = new ProceduralCuboid(1f, 2f, 0.5f); body.SetColor(carrierColor); RenderGeometryComponent renderGeom = new RenderGeometryComponent(body); EffectRenderComponent effectComp = new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded")); ShadowCasterComponent shadowComp = new ShadowCasterComponent(); AddComponent(new PhysicsComponent(true, true, PhysicsMeshType.box)); AddComponent(renderGeom); AddComponent(effectComp); AddComponent(shadowComp); var conTower = new ProceduralCuboid(0.25f, 0.25f, 0.35f); conTower.SetColor(carrierColor); GameObject conT = GameObjectFactory.CreateRenderableGameObjectFromShape(conTower, EffectLoader.LoadSM5Effect("flatshaded")); conT.Transform.RelativeTransform.Translation = new Vector3(0.8f, 0.8f, 0); conT.AddComponent(new ShadowCasterComponent()); SystemCore.GameObjectManager.AddAndInitialiseGameObject(conT); AddChild(conT); }
private void CreateGameOfLifeBoard() { BasicEffect effect = new BasicEffect(SystemCore.GraphicsDevice); effect.LightingEnabled = false; effect.SpecularPower = 0; ProceduralCuboid cubeoid = new ProceduralCuboid(0.5f, 0.5f, 2); cubeoid.SetColor(Color.Gray); gameObjectArray = new GameObject[boardSize, boardSize]; for (int i = 0; i < boardSize; i++) { for (int j = 0; j < boardSize; j++) { var gameObject = GameObjectFactory.CreateRenderableGameObjectFromShape(cubeoid, EffectLoader.LoadSM5Effect("flatshaded")); gameObject.Transform.SetPosition(new Vector3(i, 0, j)); //gameObject.AddComponent(new ShadowCasterComponent()); gameObject.AddComponent(new LineRenderComponent(effect)); gameObject.AddComponent(new GameOfLifeComponent()); gameObject.AddComponent(new PhysicsComponent(true, false, PhysicsMeshType.box)); SystemCore.GameObjectManager.AddAndInitialiseGameObject(gameObject); gameObjectArray[i, j] = gameObject; if (RandomHelper.CoinToss()) { gameObject.GetComponent <GameOfLifeComponent>().ActivateCell(); } } } //gameObjectArray[5, 5].GetComponent<GameOfLifeComponent>().ActivateCell(); // gameObjectArray[5, 6].GetComponent<GameOfLifeComponent>().ActivateCell(); //gameObjectArray[5, 7].GetComponent<GameOfLifeComponent>().ActivateCell(); }
public Chopper() : base("chopper") { Color chopperColor = Color.Red; this.AddComponent(new ChopperController()); ProceduralShape body = new ProceduralCuboid(0.15f, 0.3f, 0.15f); body.SetColor(chopperColor); RenderGeometryComponent renderGeom = new RenderGeometryComponent(body); EffectRenderComponent effectComp = new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded")); ShadowCasterComponent shadowComp = new ShadowCasterComponent(); AddComponent(new PhysicsComponent(true, true, PhysicsMeshType.box)); AddComponent(renderGeom); AddComponent(effectComp); AddComponent(shadowComp); var rotorCuboid = new ProceduralCuboid(0.03f, 0.6f, 0.03f); rotorCuboid.SetColor(chopperColor); GameObject rotor = GameObjectFactory.CreateRenderableGameObjectFromShape(rotorCuboid, EffectLoader.LoadSM5Effect("flatshaded")); rotor.Transform.RelativeTransform.Translation = new Vector3(0, 0.2f, 0); rotor.AddComponent(new RotatorComponent(Vector3.Up, 0.1f)); rotor.AddComponent(new ShadowCasterComponent()); SystemCore.GameObjectManager.AddAndInitialiseGameObject(rotor); AddChild(rotor); }
private static void CreateWallObject(Vector3 wallCenterPoint, ProceduralCuboid cuboid) { cuboid.SetColor(RandomHelper.RandomColor); GameObject wallObject = GameObjectFactory.CreateRenderableGameObjectFromShape(cuboid, EffectLoader.LoadSM5Effect("flatshaded")); wallObject.Transform.Translate(wallCenterPoint); wallObject.AddComponent(new ShadowCasterComponent()); // wallObject.AddComponent(new StaticMeshColliderComponent()) SystemCore.GameObjectManager.AddAndInitialiseGameObject(wallObject); }
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); }
public override void OnInitialise() { SystemCore.CursorVisible = false; SystemCore.ActiveScene.SetUpBasicAmbientAndKey(); SystemCore.ActiveScene.SetDiffuseLightDir(0, new Vector3(1, 1, 1)); colorScheme = SystemCore.ActiveColorScheme; SystemCore.ActiveScene.FogEnabled = false; SystemCore.PhysicsSimulation.ForceUpdater.Gravity = new BEPUutilities.Vector3(0, -9.81f, 0); mouseCamera = new MouseFreeCamera(new Vector3(10, 10, 10)); SystemCore.SetActiveCamera(mouseCamera); var effect = EffectLoader.LoadSM5Effect("FlatShaded"); //ground plane var groundShape = new ProceduralCuboid(100, 100, 0.5f); groundShape.SetColor(colorScheme.Color5); var gameObjectPlane = new GameObject(); gameObjectPlane.AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(groundShape), BufferBuilder.IndexBufferBuild(groundShape), groundShape.PrimitiveCount)); gameObjectPlane.AddComponent(new EffectRenderComponent(effect)); var groundPhysicsComponent = new PhysicsComponent(false, true, PhysicsMeshType.box); gameObjectPlane.AddComponent(groundPhysicsComponent); SystemCore.GameObjectManager.AddAndInitialiseGameObject(gameObjectPlane); groundPhysicsComponent.PhysicsEntity.IsAffectedByGravity = false; var shape = new ProceduralCube(); shape.SetColor(colorScheme.Color4); for (int i = 0; i < 100; i++) { AddCube(shape, effect, RandomHelper.GetRandomVector3(new Vector3(-10, 2, -10), new Vector3(10, 20, 10))); } AddInputBindings(); base.OnInitialise(); }
public SpaceShip(PlayerIndex player, Color color, Microsoft.Xna.Framework.Vector3 position) { this.playerIndex = player; var shape = new ProceduralCuboid(1, 1, 1); shape.SetColor(color); ShipObject = new GameObject(); ShipObject.AddComponent(new RenderGeometryComponent(shape)); ShipObject.AddComponent(new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded"))); ShipObject.AddComponent(new ShadowCasterComponent()); SystemCore.GameObjectManager.AddAndInitialiseGameObject(ShipObject); //Build the ship var shipFuselage = new CompoundShapeEntry(new BoxShape(1, 1f, 1), new BEPUutilities.Vector3(0, 0, 0), 4); bodies = new List <CompoundShapeEntry>(); bodies.Add(shipFuselage); PhysicsBody = new CompoundBody(bodies, 10); PhysicsBody.Orientation = BEPUutilities.Quaternion.CreateFromAxisAngle(BEPUutilities.Vector3.Right, (float)Math.PI / 2) * BEPUutilities.Quaternion.CreateFromAxisAngle(BEPUutilities.Vector3.Forward, (float)Math.PI / 2); PhysicsBody.Position = position.ToBepuVector(); SystemCore.PhysicsSimulation.Add(PhysicsBody); PhysicsBody.IsAffectedByGravity = false; //used by the gravitational field to opt out of its effects PhysicsBody.Tag = "spaceship"; PhysicsBody.AngularDamping = 0.99f; PhysicsBody.LinearDamping = 0.99f; }
public DuneBuggy(PlayerIndex player, Color color, Microsoft.Xna.Framework.Vector3 position) { this.playerIndex = player; this.vehicle = VehicleFactory.Create(position.ToBepuVector()); SystemCore.PhysicsSimulation.Add(vehicle); var shape = new ProceduralCuboid(2.5f / 2, 4.5f / 2, .75f / 2); shape.SetColor(color); BuggyObject = GameObjectFactory.CreateRenderableGameObjectFromShape(shape, EffectLoader.LoadSM5Effect("flatshaded")); BuggyObject.AddComponent(new ShadowCasterComponent()); SystemCore.GameObjectManager.AddAndInitialiseGameObject(BuggyObject); wheels = new List <GameObject>(); foreach (Wheel w in vehicle.Wheels) { var cube = new ProceduralCube(); cube.SetColor(Color.Maroon); var wheel = GameObjectFactory.CreateRenderableGameObjectFromShape(cube, EffectLoader.LoadSM5Effect("flatshaded")); wheel.AddComponent(new ShadowCasterComponent()); var particles = new SquareParticleSystem(); wheel.AddComponent(particles); SystemCore.GameObjectManager.AddAndInitialiseGameObject(wheel); particles.settings.Duration = TimeSpan.FromSeconds(2f); wheels.Add(wheel); } uprightSpringConstraint = new UprightSpring(vehicle.Body, BEPUutilities.Vector3.Up, 0.1f, (float)Math.PI, 1000f); SystemCore.PhysicsSimulation.Add(uprightSpringConstraint); }
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); }
public override void OnInitialise() { SystemCore.CursorVisible = false; fpsLabel.Visible = true; SystemCore.ActiveScene.SetUpAmbientAndFullLightingRig(); float lightDistance = 80f; float fadeStart = 50; float fadeEnd = 100; SystemCore.ActiveScene.AddPointLight(new Vector3(lightDistance, 0, 0), new Color(0.1f, 0.5f, 0.1f, 1), fadeStart, fadeEnd, 1f, PointLightNumber.One); SystemCore.ActiveScene.AddPointLight(new Vector3(-lightDistance, 0, 0), Color.Blue, fadeStart, fadeEnd, 1f, PointLightNumber.Two); SystemCore.ActiveScene.AddPointLight(new Vector3(0, 0, -lightDistance), Color.White, fadeStart, fadeEnd, 1f, PointLightNumber.Three); SystemCore.ActiveScene.AddPointLight(new Vector3(0, 0, lightDistance), Color.Red, fadeStart, fadeEnd, 1f, PointLightNumber.Four); var effect = EffectLoader.LoadSM5Effect("FlatShaded"); SystemCore.ActiveScene.FogEnabled = false; mouseCamera = new MouseFreeCamera(new Vector3(0, 0, 0)); SystemCore.SetActiveCamera(mouseCamera); var shape = new ProceduralSphere(20, 20); shape.SetColor(Color.LightGray); for (int i = 0; i < 10; i++) { var gameObject = new GameObject(); gameObject.AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(shape), BufferBuilder.IndexBufferBuild(shape), shape.PrimitiveCount)); gameObject.AddComponent(new EffectRenderComponent(effect)); gameObject.Transform.SetPosition(RandomHelper.GetRandomVector3(Vector3.One * -100, Vector3.One * 100)); gameObject.AddComponent(new RotatorComponent(Vector3.Up)); gameObject.AddComponent(new ShadowCasterComponent()); SystemCore.GetSubsystem <GameObjectManager>().AddAndInitialiseGameObject(gameObject); gameObject.Transform.Scale = 5f; gameObject.Transform.Velocity = RandomHelper.GetRandomVector3(-Vector3.One, Vector3.One) * 0.01f; } AddInputBindings(); AddTestMario("Mario", Vector3.Zero); AddTestMario("RedGloss", new Vector3(20, 0, 0)); AddTestMario("RedMatt", new Vector3(-20, 0, 0)); AddTestMario("OrangeGloss", new Vector3(0, 0, -20)); AddTestMario("WoodenCrate", new Vector3(0, 0, 20)); crate = AddTestModel("Models/Crate", "WoodenCrate"); crate.Transform.SetPosition(new Vector3(100, 0, 50)); crate.Transform.Scale = 0.01f; var groundShape = new ProceduralCuboid(10, 10, 0.5f); groundShape.SetColor(Color.LightGray); var gameObjectPlane = new GameObject(); gameObjectPlane.AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(groundShape), BufferBuilder.IndexBufferBuild(groundShape), groundShape.PrimitiveCount)); gameObjectPlane.AddComponent(new EffectRenderComponent(effect)); gameObjectPlane.Transform.SetPosition(new Vector3(0, -20, 0)); gameObjectPlane.Transform.Scale = 10f; SystemCore.GameObjectManager.AddAndInitialiseGameObject(gameObjectPlane); Heightmap heightMap = new Heightmap(100, 1); var seaObject = heightMap.CreateRenderableHeightMap(Color.Blue, EffectLoader.LoadSM5Effect("water")); seaObject.Transform.SetPosition(new Vector3(0, 0, 0)); SystemCore.GameObjectManager.AddAndInitialiseGameObject(seaObject); base.OnInitialise(); }
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); }