public MiniPlanet(Vector3 startPosition, float planetRadius, IModule noiseModule, int heightMapVertCount, float heightMapScale, Color landColor, Color oceanColour, bool useAtmosphere = false, float innerAtmosphereRatio = 0.97f, float outerAtmosphereRatio = 1.1f, float atmosphericScale = 30, float groundScale = 20, float verticalScale = 1f) { this.verticalScale = verticalScale; this.startPosition = startPosition; this.planetRadius = planetRadius; this.noiseModule = noiseModule; this.heightMapVertCount = heightMapVertCount; this.heightMapScale = heightMapScale; this.originalHeightMapScale = heightMapScale; this.terrainColor = landColor; this.oceanColour = oceanColour; this.useAtmosphere = useAtmosphere; this.innerAtmosphereRatio = innerAtmosphereRatio; this.outerAtmosphereRatio = outerAtmosphereRatio; this.atmosphericScale = atmosphericScale; this.groundScale = groundScale; if (!useAtmosphere) { planetEffect = EffectLoader.LoadSM5Effect("flatshaded").Clone(); GenerateGeometry(); } else { GenerateAtmosphereAndGeometry(innerAtmosphereRatio, outerAtmosphereRatio, atmosphericScale, groundScale); } childPlanets = new List <MiniPlanet>(); }
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); }
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 void GenerateFloorObjectFromFloorShapes(List <GameTile> tiles) { GameObject finalFloorShape = new GameObject(); ProceduralShape finalShape = new ProceduralShape(); ProceduralPlane plane = new ProceduralPlane(); plane.SetColor(Color.LightGray.ChangeTone(RandomHelper.GetRandomInt(-20, 20))); plane.Scale(tiles[0].Scale); plane.Translate(tiles[0].Center); finalShape = plane; AddLineBatch(plane); for (int i = 1; i < tiles.Count; i++) { ProceduralPlane newPlane = new ProceduralPlane(); newPlane.SetColor(Color.LightGray.ChangeTone(RandomHelper.GetRandomInt(-20, 20))); newPlane.Scale(tiles[i].Scale); newPlane.Translate(tiles[i].Center); finalShape = ProceduralShape.Combine(finalShape, newPlane); AddLineBatch(newPlane); } finalFloorShape.AddComponent(new RenderGeometryComponent(finalShape)); finalFloorShape.AddComponent(new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded"))); finalFloorShape.AddComponent(new ShadowCasterComponent()); SystemCore.GameObjectManager.AddAndInitialiseGameObject(finalFloorShape); }
public void Initalise() { currentVertices = new List <Vector3>(); SystemCore.ActiveScene.SetUpAmbientAndFullLightingRig(); SystemCore.ActiveScene.AddPointLight(new Vector3(0, 15, 0), Color.White, 20, 20, 1, PointLightNumber.One); SystemCore.ActiveScene.AddPointLight(new Vector3(0, -15, 0), Color.White, 20, 20, 1, PointLightNumber.Two); SystemCore.ActiveScene.AddPointLight(new Vector3(0, 0, 15), Color.White, 20, 20, 1, PointLightNumber.Three); SystemCore.ActiveScene.AddPointLight(new Vector3(0, 0, -15), Color.White, 20, 20, 1, PointLightNumber.Four); SystemCore.AddNewUpdateRenderSubsystem(new SkyDome(Color.LightGray, Color.Gray, Color.DarkBlue)); shapeBuilder = new ProceduralShapeBuilder(); CurrentMode = EditMode.Voxel; shapesToBake = new Dictionary <GameObject.GameObject, ProceduralShape>(); cameraGameObject = new GameObject.GameObject("camera"); cameraGameObject.AddComponent(new ComponentCamera()); cameraGameObject.Transform.SetPosition(new Vector3(0, 0, 20)); cameraGameObject.Transform.SetLookAndUp(new Vector3(0, 0, -1), new Vector3(0, 1, 0)); SystemCore.GameObjectManager.AddAndInitialiseGameObject(cameraGameObject); SystemCore.SetActiveCamera(cameraGameObject.GetComponent <ComponentCamera>()); mouseCursor = GameObjectFactory.CreateRenderableGameObjectFromShape(new ProceduralCube(), EffectLoader.LoadSM5Effect("flatshaded")); SystemCore.GameObjectManager.AddAndInitialiseGameObject(mouseCursor); AddGUI(); }
public Player(Color?color, bool manualControl = false) { var shape = new ProceduralSphere(10, 10); if (color.HasValue) { PlayerColor = color.Value; shape.SetColor(color.Value); } if (!manualControl) { this.AddComponent(new PlayerControlComponent()); } else { this.AddComponent(new ManualControlComponent()); } this.AddComponent(new RenderGeometryComponent(shape)); this.AddComponent(new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded"))); this.AddComponent(new PhysicsComponent(true, true, PhysicsMeshType.sphere)); this.AddComponent(new ShadowCasterComponent()); Health = maxHealth; Weapons = new List <Weapon>(); Weapons.Add(WeaponFactory.CreatePistol()); CurrentWeapon = Weapons[0]; PlayerLabel = new Label(GUIFonts.Fonts["neurosmall"], ""); SystemCore.GUIManager.AddControl(PlayerLabel); }
private void SetUpGameWorld() { //AtmosphericScatteringGround float radius = 6000; earth = new Planet("earth", new Vector3(0, 0, 0), NoiseGenerator.FastPlanet(radius), EffectLoader.LoadSM5Effect("flatshaded").Clone(), radius, Color.DarkSeaGreen.ChangeTone(-100), Color.SaddleBrown, Color.SaddleBrown.ChangeTone(-10), 0); //earth.AddAtmosphere(); SystemCore.GameObjectManager.AddAndInitialiseGameObject(earth); mouseCamera.SetPositionAndLook(new Vector3(0, radius + 200, 0), (float)Math.PI, (float)-Math.PI / 5); duneBuggyOne = new DuneBuggy(PlayerIndex.One, Color.Red, new Vector3(0, radius + 100, 0)); spaceShipOne = new SpaceShip(PlayerIndex.One, Color.Red, new Vector3(0, radius + 200, 0)); field = new GravitationalField(new InfiniteForceFieldShape(), Vector3.Zero.ToBepuVector(), 100000 * radius, 100); SystemCore.PhysicsSimulation.Add(field); spaceShipOne.Activate(); duneBuggyCamera = new DuneBuggyPlanetCamera(duneBuggyOne); spaceShipCamera = new SpaceShipCamera(spaceShipOne); }
public static void ApplyMaterialComponent(GameObject go, string materialName) { var mat = matDictionary[materialName]; Effect effect = EffectLoader.LoadSM5Effect(mat.ShaderName).Clone(); EffectRenderComponent effectComponent = new EffectRenderComponent(effect); go.AddComponent(mat); go.AddComponent(effectComponent); }
private void GenerateAtmosphereAndGeometry(float innerAtmosphereRatio, float outerAtmosphereRatio, float atmosphericScale, float groundScale) { planetEffect = EffectLoader.LoadSM5Effect("AtmosphericScatteringGround").Clone(); groundScatteringHelper = new GroundScatteringHelper(planetEffect, planetRadius * outerAtmosphereRatio, planetRadius * innerAtmosphereRatio, groundScale); atmosphere = new Atmosphere(planetRadius * outerAtmosphereRatio, planetRadius * innerAtmosphereRatio, atmosphericScale); SystemCore.GameObjectManager.AddAndInitialiseGameObject(atmosphere); GenerateGeometry(); }
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 CreateLocalWorldObject(double id, string type, out GameObject worldObject, out DoomComponent component) { var shape = CreateShape(type); worldObject = GameObjectFactory.CreateRenderableGameObjectFromShape( shape, EffectLoader.LoadSM5Effect("flatshaded")); component = new DoomComponent(); worldObject.AddComponent(component); worldObject.ID = (int)id; SystemCore.GameObjectManager.AddAndInitialiseGameObject(worldObject); worldObjects.Add(worldObject.ID, worldObject); }
private void AddPhysicsCube() { ProceduralCube shape = new ProceduralCube(); var gameObject = new GameObject(); gameObject.AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(shape), BufferBuilder.IndexBufferBuild(shape), shape.PrimitiveCount)); gameObject.AddComponent(new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded"))); gameObject.AddComponent(new ShadowCasterComponent()); gameObject.AddComponent(new PhysicsComponent(true, true, PhysicsMeshType.box)); gameObject.Transform.SetPosition(RandomHelper.GetRandomVector3(10, 100)); SystemCore.GetSubsystem <GameObjectManager>().AddAndInitialiseGameObject(gameObject); }
public SimpleEnemy() { ProceduralCube shape = new ProceduralCube(); AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(shape), BufferBuilder.IndexBufferBuild(shape), shape.PrimitiveCount)); AddComponent(new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded"))); AddComponent(new ShadowCasterComponent()); var physicsComponent = new PhysicsComponent(true, true, PhysicsMeshType.box); AddComponent(physicsComponent); AddComponent(new SimpleEnemyComponent(physicsComponent)); }
public static GameObject CreateGradientSkyDomeObject(int complexity) { ProceduralSphere sphere = new ProceduralSphere(complexity, complexity); sphere.Indices = sphere.Indices.Reverse().ToArray(); var ob = new GameObject(); ob.Name = "skydome"; ob.AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(sphere), BufferBuilder.IndexBufferBuild(sphere), sphere.PrimitiveCount)); ob.AddComponent(new GradientSkyDomeRenderer(EffectLoader.LoadSM5Effect("skydome2"))); return(ob); }
public static GameObject CreateSkyDomeObject(Color color, int complexity, float scale) { ProceduralSphere sphere = new ProceduralSphere(complexity, complexity); sphere.Indices = sphere.Indices.Reverse().ToArray(); var ob = new GameObject(); ob.Name = "skydome"; ob.Transform.Scale = scale; sphere.SetColor(color); ob.AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(sphere), BufferBuilder.IndexBufferBuild(sphere), sphere.PrimitiveCount)); ob.AddComponent(new SkyDomeRenderer(EffectLoader.LoadSM5Effect("skydome"))); return(ob); }
public RenderTestScreen() : base() { SystemCore.CursorVisible = false; fpsLabel.Visible = true; SystemCore.ActiveScene.SetUpBasicAmbientAndKey(); var effect = EffectLoader.LoadSM5Effect("FlatShaded"); mouseCamera = new MouseFreeCamera(new Vector3(0, 0, 0)); SystemCore.SetActiveCamera(mouseCamera); var shape = new ProceduralSphere(20, 20); shape.SetColor(SystemCore.ActiveColorScheme.Color5); //create 100 cubes, add collision and collision visualiser components, give them random position and velocity for (int i = 0; i < 100; i++) { var gameObject = new GameObject(); gameObject.AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(shape), BufferBuilder.IndexBufferBuild(shape), shape.PrimitiveCount)); gameObject.AddComponent(new EffectRenderComponent(effect)); //gameObject.AddComponent(new BasicEffectRenderComponent(effect)); gameObject.Transform.SetPosition(RandomHelper.GetRandomVector3(Vector3.One * -100, Vector3.One * 100)); gameObject.AddComponent(new RotatorComponent(Vector3.Up)); SystemCore.GetSubsystem <GameObjectManager>().AddAndInitialiseGameObject(gameObject); gameObject.Transform.Scale = 5f; gameObject.Transform.Velocity = RandomHelper.GetRandomVector3(-Vector3.One, Vector3.One) * 0.01f; } AddInputBindings(); Model geoDesicModel = SystemCore.ContentManager.Load <Model>("Models/geodesic"); ProceduralShape geodesicShape = ModelMeshParser.GetShapeFromModelNoUVs(geoDesicModel); geodesicShape.Scale(20f); geodesicShape.InsideOut(); GameObject geoDesic = GameObjectFactory.CreateRenderableGameObjectFromShape(geodesicShape, EffectLoader.LoadSM5Effect("cockpitscreen")); SystemCore.GameObjectManager.AddAndInitialiseGameObject(geoDesic); }
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 Projectile(Vector3 position, Vector3 velocity, Weapon firingWeapon) { ProceduralSphereTwo projectileShape = new ProceduralSphereTwo(10); projectileShape.Scale(0.05f); AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(projectileShape), BufferBuilder.IndexBufferBuild(projectileShape), projectileShape.PrimitiveCount)); AddComponent(new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded"))); AddComponent(new PhysicsComponent(true, false, PhysicsMeshType.sphere)); AddComponent(new ProjectileComponent(firingWeapon)); SystemCore.GameObjectManager.AddAndInitialiseGameObject(this); Transform.SetPosition(position); Transform.Velocity = velocity; }
protected override void Initialise() { ProceduralSphereTwo playerShape = new ProceduralSphereTwo(10); playerShape.Scale(2f); AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(playerShape), BufferBuilder.IndexBufferBuild(playerShape), playerShape.PrimitiveCount)); AddComponent(new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded"))); AddComponent(new PhysicsComponent(true, false, PhysicsMeshType.sphere)); AddComponent(new SimpleEnemyAIController()); Name = "simpleenemy"; SystemCore.GameObjectManager.AddAndInitialiseGameObject(this); physicsComponent = GetComponent <PhysicsComponent>(); }
internal static void GenerateTestSystem(SolarSystemSettings solarSystemSettings) { StarHelper.CreateAndInitialiseSystemStar(ScaleHelper.Millions(1), StarHelper.BasicSunColor()); string planetShader = "flatshaded"; Planet earth = new Planet("earth", new Vector3d(ScaleHelper.Millions(20), 0, 0), NoiseGenerator.FastPlanet(6000), EffectLoader.LoadSM5Effect("AtmosphericScatteringGround").Clone(), 6000, Color.DarkSeaGreen.ChangeTone(-100), Color.SaddleBrown, Color.SaddleBrown.ChangeTone(-10), 0.000001f); earth.Orbit(Vector3d.Zero, ScaleHelper.Millions(20), ScaleHelper.Millionths(0.1f)); earth.AddAtmosphere(); SystemCore.GameObjectManager.AddAndInitialiseGameObject(earth); Planet moon = new Planet("moon", new Vector3d(ScaleHelper.Millions(20) + 20000, 0, 0), NoiseGenerator.Voronoi(0.02f), EffectLoader.LoadSM5Effect(planetShader).Clone(), 2000, Color.DarkGray.ChangeTone(10), Color.DarkGray, Color.DarkGray.ChangeTone(-10)); moon.Orbit(earth, 20000, ScaleHelper.Millionths(50f)); moon.orbitAngle = RandomHelper.GetRandomeAngle(); SystemCore.GameObjectManager.AddAndInitialiseGameObject(moon); Planet moon2 = new Planet("moon2", new Vector3d(ScaleHelper.Millions(20) + 40000, 0, 0), NoiseGenerator.RidgedMultiFractal(0.02f), EffectLoader.LoadSM5Effect(planetShader).Clone(), 1000, Color.SandyBrown.ChangeTone(-80), Color.SandyBrown.ChangeTone(-90), Color.SandyBrown.ChangeTone(-100)); moon2.Orbit(earth, 40000, ScaleHelper.Millionths(50f)); moon2.orbitAngle = RandomHelper.GetRandomeAngle(); SystemCore.GameObjectManager.AddAndInitialiseGameObject(moon2); Planet moon3 = new Planet("moon3", new Vector3d(ScaleHelper.Millions(20) + 45000, 0, 0), NoiseGenerator.RidgedMultiFractal(0.02f), EffectLoader.LoadSM5Effect(planetShader).Clone(), 500, Color.DarkSlateGray.ChangeTone(10), Color.DarkSlateGray, Color.DarkSlateGray.ChangeTone(-10)); moon3.Orbit(moon2, 5000, ScaleHelper.Millionths(50f)); moon3.orbitAngle = RandomHelper.GetRandomeAngle(); SystemCore.GameObjectManager.AddAndInitialiseGameObject(moon3); }
public override void OnInitialise() { base.OnInitialise(); SystemCore.ActiveScene.SetUpBasicAmbientAndKey(); mouseCamera.moveSpeed = 0.01f; ProceduralCube cube = new ProceduralCube(); cube.SetColor(Color.OrangeRed); testObject = GameObjectFactory.CreateRenderableGameObjectFromShape(cube, EffectLoader.LoadSM5Effect("flatshaded")); testObject.AddComponent(new RotatorComponent(Vector3.Up, 0.0001f)); SystemCore.GameObjectManager.AddAndInitialiseGameObject(testObject); ProceduralPlane plane = new ProceduralPlane(); plane.Scale(10f); plane.SetColor(Color.LightBlue); planeToDrawOn = GameObjectFactory.CreateRenderTextureSurface(plane, EffectLoader.LoadSM5Effect("rendertexturesurface")); planeToDrawOn.Transform.Rotate(Vector3.Forward, MathHelper.ToRadians(90)); planeToDrawOn.Transform.Rotate(Vector3.Left, MathHelper.ToRadians(-90)); //planeToDrawOn.Transform.Rotate(Vector3.Up, MathHelper.ToRadians(-90)); planeToDrawOn.Transform.SetPosition(new Vector3(-5, 0, 0)); GameObject.InitialiseAllComponents(planeToDrawOn); spriteBatch = new SpriteBatch(SystemCore.GraphicsDevice); renderTarget = new RenderTarget2D(SystemCore.GraphicsDevice, 500, 500); renderTextureCamera = new DummyCamera(); renderTextureCamera.SetPositionAndLookDir(new Vector3(-5, 0, 0), Vector3.Zero, Vector3.Up); SystemCore.AddCamera("renderTextureCamera", renderTextureCamera); var secondCube = GameObjectFactory.CreateRenderableGameObjectFromShape(new ProceduralCube(), EffectLoader.LoadSM5Effect("flatshaded")); secondCube.Transform.SetPosition(new Vector3(-20, 0, 0)); SystemCore.GameObjectManager.AddAndInitialiseGameObject(secondCube); font = SystemCore.ContentManager.Load <SpriteFont>("Fonts/neuropolitical"); }
private void UpdatePlayer(RestResponse x) { IDictionary <string, object> jsonValues = Json.JsonParser.FromJson(x.Content); //in doom, 0 degrees is East. Increased value turns us counter clockwise, so north is 90, west 180 etc var playerAngle = (double)jsonValues["angle"]; IDictionary <string, object> pos = jsonValues["position"] as IDictionary <string, object>; double xpos = (double)pos["x"]; double ypos = (double)pos["y"]; //create if first time if (playerObj == null) { playerObj = GameObjectFactory.CreateRenderableGameObjectFromShape( new ProceduralCube(), EffectLoader.LoadSM5Effect("flatshaded")); playerObj.Transform.Scale = 0.5f; var id = (double)jsonValues["id"]; playerObj.ID = (int)id; playerId = playerObj.ID; DoomComponent component = new DoomComponent(); component.DoomType = "Player"; component.HitVectorSize = 0.5f; playerObj.AddComponent(component); playerObj.AddComponent(new DoomMovementComponent(mapHandler, apiHandler)); playerObj.AddComponent(new DoomCombatComponent(mapHandler, apiHandler, worldObjects)); SystemCore.GameObjectManager.AddAndInitialiseGameObject(playerObj); } //remember to scale it appropriately. In doom, Z is up, but here it's Y, so swap those coords playerObj.Transform.SetPosition(new Vector3((float)xpos / mapHandler.scale, 0, (float)ypos / mapHandler.scale)); //turn us to face the appopriate angle float playerAngleInRadians = MathHelper.ToRadians((float)playerAngle); Vector3 headingVector = new Vector3((float)Math.Cos(playerAngleInRadians), 0, (float)Math.Sin(playerAngleInRadians)); playerObj.Transform.SetLookAndUp(headingVector, Vector3.Up); }
private void RehydrateShape(ProceduralShape shape) { //take the translation expressed in the verts, and switch it over to //the world transform so the physics collision works. //then translate back for when we bake out again. var midPoint = shape.GetMidPoint(); shape.Translate(-midPoint); var gameObj = GameObjectFactory.CreateRenderableGameObjectFromShape(shape, EffectLoader.LoadSM5Effect("flatshaded")); gameObj.Transform.Translate(midPoint); gameObj.AddComponent(new PhysicsComponent(false, false, PhysicsMeshType.box)); SystemCore.GameObjectManager.AddAndInitialiseGameObject(gameObj); shapesToBake.Add(gameObj, shape); shape.Translate(midPoint); }
public MainBase() { Health = 100; Size = 8; ProceduralCube shape = new ProceduralCube(); shape.Scale(Size); shape.SetColor(Color.Blue); AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(shape), BufferBuilder.IndexBufferBuild(shape), shape.PrimitiveCount)); AddComponent(new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded"))); AddComponent(new ShadowCasterComponent()); var physicsComponent = new PhysicsComponent(false, false, PhysicsMeshType.box); AddComponent(physicsComponent); SystemCore.GameObjectManager.AddAndInitialiseGameObject(this); GetComponent <PhysicsComponent>().PhysicsEntity.CollisionInformation.Events.DetectingInitialCollision += Events_DetectingInitialCollision; }
public override void OnInitialise() { SystemCore.CursorVisible = false; SystemCore.ActiveScene.AddKeyLight(Vector3.Up, Color.White, 1f, false); camera = new DummyOrthographicCamera(SystemCore.Viewport.Width / 10, SystemCore.Viewport.Height / 10, 0.3f, 50f); camera.World = Matrix.CreateWorld(new Vector3(0, 20, 0), new Vector3(0, -1, 0), new Vector3(0, 0, 1)); camera.View = Matrix.Invert(camera.World); SystemCore.SetActiveCamera(camera); var cube = new ProceduralCube(); cube.SetColor(Color.White); ball = GameObjectFactory.CreateRenderableGameObjectFromShape(cube, EffectLoader.LoadSM5Effect("flatshaded")); ball.Transform.SetPosition(Vector3.Zero); SystemCore.GameObjectManager.AddAndInitialiseGameObject(ball); base.OnInitialise(); }
protected override void Initialise() { ProceduralCube playerShape = new ProceduralCube(); playerShape.Scale(5f); AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(playerShape), BufferBuilder.IndexBufferBuild(playerShape), playerShape.PrimitiveCount)); AddComponent(new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded"))); AddComponent(new PhysicsComponent(true, false, PhysicsMeshType.box)); Name = "player"; AddComponent(new TopDownMouseAndKeyboardController()); SystemCore.GameObjectManager.AddAndInitialiseGameObject(this); physicsComponent = GetComponent <PhysicsComponent>(); base.Initialise(); }
public override void OnInitialise() { startPos = new Vector3(0, planetSize * 1.25f, 0); CollisionRules.DefaultCollisionRule = CollisionRule.NoSolver; SystemCore.ActiveScene.SetUpBasicAmbientAndKey(); SystemCore.AddNewUpdateRenderSubsystem(new SkyDome(Color.Black, Color.Black, Color.Black)); cameraGameObject = new GameObject("camera"); cameraGameObject.AddComponent(new ComponentCamera()); cameraGameObject.Transform.SetPosition(startPos); cameraGameObject.Transform.SetLookAndUp(new Vector3(1, 0, 0), new Vector3(0, 1, 0)); cameraGameObject.AddComponent(new MouseController()); SystemCore.GameObjectManager.AddAndInitialiseGameObject(cameraGameObject); SystemCore.SetActiveCamera(cameraGameObject.GetComponent <ComponentCamera>()); planets = new List <MiniPlanet>(); var shape = SimpleModelEditor.LoadShape("voxrocket"); if (shape != null) { testShip = GameObjectFactory.CreateRenderableGameObjectFromShape(shape, EffectLoader.LoadSM5Effect("flatshaded")); testShip.Transform.Rotate(Vector3.Up, -MathHelper.PiOver2); testShip.Transform.AbsoluteTransform.Translation = new Vector3(100, 0, 0); //testShip.AddComponent(new RotatorComponent(Vector3.Right, 0.001f)); SystemCore.GameObjectManager.AddAndInitialiseGameObject(testShip); } GenerateSystem(); base.OnInitialise(); }
public void AddVoxel(Color color) { if (!RenderGrid) { return; } if (currentbuildPoint.X < -modellingAreaSize / 2 || currentbuildPoint.X > modellingAreaSize / 2) { return; } if (currentbuildPoint.Y < -modellingAreaSize / 2 || currentbuildPoint.Y > modellingAreaSize / 2) { return; } if (currentbuildPoint.Z < -modellingAreaSize / 2 || currentbuildPoint.Z > modellingAreaSize / 2) { return; } ProceduralCube c = new ProceduralCube(); c.SetColor(color); //this object is for visualisation in the editor only. The procedural shape will be //cached and used to bake the final shape for serialization var tempObject = GameObjectFactory.CreateRenderableGameObjectFromShape(c, EffectLoader.LoadSM5Effect("flatshaded")); tempObject.AddComponent(new PhysicsComponent(false, false, PhysicsMeshType.box)); SystemCore.GameObjectManager.AddAndInitialiseGameObject(tempObject); tempObject.Transform.SetPosition(currentbuildPoint); //shape is translated c.Translate(currentbuildPoint); shapesToBake.Add(tempObject, c); }
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; }
private GameObject CreateHeightMapGameObject() { var heightMap = NoiseGenerator.CreateHeightMap(NoiseGenerator.RidgedMultiFractal(0.003f), 100, 1, 100, 1, 1, 1); return(heightMap.CreateRenderableHeightMap(Color.MonoGameOrange, EffectLoader.LoadSM5Effect("flatshaded"))); }