public void Begin() { Tables.Initialize(); CurrentBoard = Tables.InitialBoard; Content = new EpisodeContentManager(Main.EpisodeContent.ServiceProvider, "Content"); PieceTextures = new Texture2D[] { Content.Load<Texture2D>("blue-piece"), Content.Load<Texture2D>("white-piece") }; RenderContext = new RenderContext(Content.Load<Effect>("draw"), Main.GraphicsDevice); Camera = new FreeCamera(new Vector3(0.0f, -8.0f, 8.0f), Vector3.UnitY, Vector3.UnitZ, Main.GraphicsDevice.Viewport); Camera.Viewport = Main.GraphicsDevice.Viewport; Camera.LookAt(Vector3.Zero); RenderContext.Camera = Camera; SceneGraph = new Gem.Render.BranchNode(); Input.ClearBindings(); Input.AddAxis("MAIN", new MouseAxisBinding()); Main.Input.AddBinding("RIGHT", new KeyboardBinding(Keys.Right, KeyBindingType.Held)); Main.Input.AddBinding("LEFT", new KeyboardBinding(Keys.Left, KeyBindingType.Held)); Main.Input.AddBinding("UP", new KeyboardBinding(Keys.Up, KeyBindingType.Held)); Main.Input.AddBinding("DOWN", new KeyboardBinding(Keys.Down, KeyBindingType.Held)); Main.Input.AddBinding("CLICK", new MouseButtonBinding("LeftButton", KeyBindingType.Pressed)); Main.Input.AddBinding("CAMERA-DISTANCE-TOGGLE", new KeyboardBinding(Keys.R, KeyBindingType.Held)); Main.Input.AddBinding("EXIT", new KeyboardBinding(Keys.Escape, KeyBindingType.Pressed)); var hexMesh = Gem.Geo.Gen.CreateUnitPolygon(6); hexMesh = Gem.Geo.Gen.FacetCopy(Gem.Geo.Gen.TransformCopy(hexMesh, Matrix.CreateRotationZ((float)System.Math.PI / 2.0f))); Gem.Geo.Gen.ProjectTexture(hexMesh, new Vector3(1.0f, 1.0f, 0.0f), Vector3.UnitX * 2, Vector3.UnitY * 2); Gem.Geo.Gen.CalculateTangentsAndBiNormals(hexMesh); for (var x = 0; x < 19; ++x) { var hexNode = new NormalMapMeshNode() { Mesh = hexMesh, Texture = Content.Load<Texture2D>("hex"), NormalMap = Content.Load<Texture2D>("hex-normal"), }; hexNode.Orientation.Position = new Vector3(Tables.HexWorldPositions[x], 0.0f); SceneGraph.Add(hexNode); HexNodes.Add(hexNode); } var tetraMesh = Gem.Geo.Gen.CreateUnitPolygon(3); tetraMesh.verticies[0].Position = new Vector3(0.0f, 0.0f, 1.0f); Gem.Geo.Gen.Transform(tetraMesh, Matrix.CreateRotationZ((float)Math.PI)); tetraMesh = Gem.Geo.Gen.FacetCopy(tetraMesh); for (var i = 0; i < tetraMesh.indicies.Length; i += 3) { tetraMesh.verticies[tetraMesh.indicies[i]].TextureCoordinate = new Vector2(0.5f, 0); tetraMesh.verticies[tetraMesh.indicies[i + 1]].TextureCoordinate = new Vector2(1, 1); tetraMesh.verticies[tetraMesh.indicies[i + 2]].TextureCoordinate = new Vector2(0, 1); } Gem.Geo.Gen.CalculateTangentsAndBiNormals(tetraMesh); for (var x = 0; x < 36; ++x) { var tetraNode = new NormalMapMeshNode() { Mesh = tetraMesh, HiliteColor = new Vector3(1,0,0), HiliteMesh = tetraMesh, Hidden = true }; tetraNode.Orientation.Scale = new Vector3(0.4f, 0.4f, 0.4f); SceneGraph.Add(tetraNode); PieceNodes.Add(tetraNode); } for (var x = 0; x < 6; ++x) { var ghostNode = new NormalMapMeshNode() { Mesh = tetraMesh, HiliteColor = new Vector3(1, 0, 0), HiliteMesh = tetraMesh, Hidden = true, Alpha = 0.75f, Color = new Vector3(0.8f, 0.8f, 0.0f), }; ghostNode.Orientation.Scale = new Vector3(0.4f, 0.4f, 0.4f); SceneGraph.Add(ghostNode); GhostPieceNodes.Add(ghostNode); } var guiQuad = Gem.Geo.Gen.CreateQuad(); Gem.Geo.Gen.Transform(guiQuad, Matrix.CreateRotationX(Gem.Math.Angle.PI / 2.0f)); //Gem.Geo.Gen.Transform(guiQuad, Matrix.CreateRotationY(Gem.Math.Angle.PI)); Gem.Geo.Gen.Transform(guiQuad, Matrix.CreateScale(10.0f, 1.0f, 5.0f)); Gem.Geo.Gen.Transform(guiQuad, Matrix.CreateTranslation(0.0f, 0.0f, 2.0f)); Gui = new Gem.Gui.GuiSceneNode(guiQuad, Main.GraphicsDevice, 1024, 512); Gui.uiRoot.AddPropertySet(null, new Gem.Gui.GuiProperties { BackgroundColor = new Vector3(0, 0, 1), Transparent = true }); Gui.uiRoot.AddChild(new Gem.Gui.UIItem( "TURN-INDICATOR", new Gem.Gui.QuadShape(0, 0, 1, 1), new Gem.Gui.GuiProperties { Font = new Gem.Gui.BitmapFont(Content.Load<Texture2D>("small-font"), 6, 8, 6), TextOrigin = new Vector2(32, 32), TextColor = new Vector3(1, 0, 0), Label = "HELLO COERCEO", FontScale = 4.0f, Transparent = true })); Gui.uiRoot.AddChild(new Gem.Gui.UIItem( "TILE-COUNT", new Gem.Gui.QuadShape(0, 0, 1, 1), new Gem.Gui.GuiProperties { Font = new Gem.Gui.BitmapFont(Content.Load<Texture2D>("small-font"), 6, 8, 6), TextOrigin = new Vector2(32, 56), TextColor = new Vector3(1, 0, 0), Label = "TILE-COUNT", FontScale = 4.0f, Transparent = true })); Gui.uiRoot.AddChild(new Gem.Gui.UIItem( "STATS", new Gem.Gui.QuadShape(0, 0, 1, 1), new Gem.Gui.GuiProperties { Font = new Gem.Gui.BitmapFont(Content.Load<Texture2D>("small-font"), 6, 8, 6), TextOrigin = new Vector2(768, 32), TextColor = new Vector3(1, 0, 0), Label = "STATS", FontScale = 4.0f, Transparent = true })); Gui.RenderOnTop = true; Gui.DistanceBias = float.NegativeInfinity; SceneGraph.Add(Gui); PushInputState(new Input.TurnScheduler(PlayerTypes)); }
public void ShowPiece(NormalMapMeshNode Node, int Player, byte HexID, byte Triangle) { var angle = Triangle * (Gem.Math.Angle.PI2 / 6.0f); Node.Orientation.Orientation.Z = angle; Node.Orientation.Position = new Vector3(Tables.HexWorldPositions[HexID], 0.0f) + Vector3.Transform(new Vector3(0.0f, 0.56f, 0.0f), Matrix.CreateRotationZ(angle)); Node.Texture = PieceTextures[Player]; Node.Hidden = false; Node.Tag = new Coordinate(HexID, Triangle); }