public void AddData(VertexIndexData vertexIndexData) { int _count = this.VertexList.Count; this.VertexList.AddRange(vertexIndexData.VertexList); foreach (short index in vertexIndexData.IndexList) { this.IndexList.Add((short)(index + _count)); } }
/// <summary> /// Generates vertex and index information for this block. /// </summary> public VertexIndexData GenerateVertices(Room CurrentRoom, Vector3 Position) { Vector3 MasterBottomLeftFront = new Vector3(Size, Size, Size) * Position; Vector3 MasterTopRightBack = MasterBottomLeftFront + new Vector3(Size, Size, Size); Vector3 topLeftFront = new Vector3(MasterBottomLeftFront.X, MasterBottomLeftFront.Y, MasterTopRightBack.Z); Vector3 bottomLeftFront = MasterBottomLeftFront; Vector3 topRightFront = new Vector3(MasterTopRightBack.X, MasterBottomLeftFront.Y, MasterTopRightBack.Z); Vector3 bottomRightFront = new Vector3(MasterTopRightBack.X, MasterBottomLeftFront.Y, MasterBottomLeftFront.Z); Vector3 topLeftBack = new Vector3(MasterBottomLeftFront.X, MasterTopRightBack.Y, MasterTopRightBack.Z); Vector3 bottomLeftBack = new Vector3(MasterBottomLeftFront.X, MasterTopRightBack.Y, MasterBottomLeftFront.Z); Vector3 topRightBack = MasterTopRightBack; Vector3 bottomRightBack = new Vector3(MasterTopRightBack.X, MasterTopRightBack.Y, MasterBottomLeftFront.Z); Vector3 frontNormal = new Vector3(0.0f, -1.0f, 0.0f); Vector3 backNormal = new Vector3(0.0f, 1.0f, 0.0f); Vector3 topNormal = new Vector3(0.0f, 0.0f, 1.0f); Vector3 bottomNormal = new Vector3(0.0f, 0.0f, -1.0f); Vector3 leftNormal = new Vector3(-1.0f, 0.0f, 0.0f); Vector3 rightNormal = new Vector3(1.0f, 0.0f, 0.0f); VertexIndexData _returnData = new VertexIndexData(); if (Position.Y > 0) if (CurrentRoom.GetGridBlock((int)Position.X, (int)Position.Y - 1, (int)Position.Z).Culling == false) { if (Tex[0] > 0) _returnData.AddData(PrimHelper.GenerateWallVertices(bottomLeftFront, topRightFront, frontNormal, TilesetMain.Tiles[Tex[0]])); } if (Position.Y < CurrentRoom.Depth - 1) if (CurrentRoom.GetGridBlock((int)Position.X, (int)Position.Y + 1, (int)Position.Z).Culling == false) { if (Tex[1] > 0) _returnData.AddData(PrimHelper.GenerateWallVertices(bottomRightBack, topLeftBack, backNormal, TilesetMain.Tiles[Tex[2]])); } if (Position.X > 0) if (CurrentRoom.GetGridBlock((int)Position.X - 1, (int)Position.Y, (int)Position.Z).Culling == false) { if (Tex[2] > 0) _returnData.AddData(PrimHelper.GenerateWallVertices(bottomLeftBack, topLeftFront, leftNormal, TilesetMain.Tiles[Tex[3]])); } if (Position.X < CurrentRoom.Width - 1) if (CurrentRoom.GetGridBlock((int)Position.X + 1, (int)Position.Y, (int)Position.Z).Culling == false) { if (Tex[3] > 0) _returnData.AddData(PrimHelper.GenerateWallVertices(bottomRightFront, topRightBack, rightNormal, TilesetMain.Tiles[Tex[1]])); } if (Position.Z > 0) if (CurrentRoom.GetGridBlock((int)Position.X, (int)Position.Y, (int)Position.Z - 1).Culling == false) { if (Tex[4] > 0) _returnData.AddData(PrimHelper.GenerateFloorVertices(bottomLeftBack, bottomRightFront, bottomNormal, TilesetMain.Tiles[Tex[4]])); } if (Position.Z < CurrentRoom.Height - 1) if (CurrentRoom.GetGridBlock((int)Position.X, (int)Position.Y, (int)Position.Z + 1).Culling == false) { if (Tex[5] > 0) _returnData.AddData(PrimHelper.GenerateFloorVertices(topLeftFront, topRightBack, topNormal, TilesetMain.Tiles[Tex[5]])); } return _returnData; }
public void Draw(PrimManager PrimManager, Vector3 BottomLeft, float Size) { Vector3 MasterBottomLeftFront = BottomLeft; Vector3 MasterTopRightBack = MasterBottomLeftFront + new Vector3(Size, Size, Size); Vector3 topLeftFront = new Vector3(MasterBottomLeftFront.X, MasterBottomLeftFront.Y, MasterTopRightBack.Z); Vector3 bottomLeftFront = MasterBottomLeftFront; Vector3 topRightFront = new Vector3(MasterTopRightBack.X, MasterBottomLeftFront.Y, MasterTopRightBack.Z); Vector3 bottomRightFront = new Vector3(MasterTopRightBack.X, MasterBottomLeftFront.Y, MasterBottomLeftFront.Z); Vector3 topLeftBack = new Vector3(MasterBottomLeftFront.X, MasterTopRightBack.Y, MasterTopRightBack.Z); Vector3 bottomLeftBack = new Vector3(MasterBottomLeftFront.X, MasterTopRightBack.Y, MasterBottomLeftFront.Z); Vector3 topRightBack = MasterTopRightBack; Vector3 bottomRightBack = new Vector3(MasterTopRightBack.X, MasterTopRightBack.Y, MasterBottomLeftFront.Z); Vector3 frontNormal = new Vector3(0.0f, -1.0f, 0.0f); Vector3 backNormal = new Vector3(0.0f, 1.0f, 0.0f); Vector3 topNormal = new Vector3(0.0f, 0.0f, 1.0f); Vector3 bottomNormal = new Vector3(0.0f, 0.0f, -1.0f); Vector3 leftNormal = new Vector3(-1.0f, 0.0f, 0.0f); Vector3 rightNormal = new Vector3(1.0f, 0.0f, 0.0f); VertexIndexData _returnData = new VertexIndexData(); _returnData.AddData(PrimHelper.GenerateWallVertices(bottomLeftFront, topRightFront, frontNormal, TilesetMain.Tiles[Tex[0]])); _returnData.AddData(PrimHelper.GenerateWallVertices(bottomRightBack, topLeftBack, backNormal, TilesetMain.Tiles[Tex[2]])); _returnData.AddData(PrimHelper.GenerateWallVertices(bottomLeftBack, topLeftFront, leftNormal, TilesetMain.Tiles[Tex[3]])); _returnData.AddData(PrimHelper.GenerateWallVertices(bottomRightFront, topRightBack, rightNormal, TilesetMain.Tiles[Tex[1]])); _returnData.AddData(PrimHelper.GenerateFloorVertices(bottomLeftBack, bottomRightFront, bottomNormal, TilesetMain.Tiles[Tex[4]])); _returnData.AddData(PrimHelper.GenerateFloorVertices(topLeftFront, topRightBack, topNormal, TilesetMain.Tiles[Tex[5]])); PrimManager.DrawVertices(_returnData, TilesetMain.TextureMain); }
/// <summary> /// Draws the vertices using current settings. /// </summary> public void DrawVertices(VertexIndexData vertexIndexData, Texture2D texture) { myEffect.Texture = texture; DrawVertices(vertexIndexData.VertexArray, vertexIndexData.IndexArray); }
/// <summary> /// Clears the current vertices and generates a new representation /// of the room in vertices. /// </summary> public void UpdateRoomVertices() { VertexData = new VertexIndexData(); for (int d = Depth - 1; d >= 0; d--) { for (int h = 0; h < Height; h++) { for (int w = 0; w < Width; w++) { int _num = GridArray[w, d, h]; if (_num > 1) VertexData.AddData(BlockSet.Blocks[GridArray[w, d, h]].GenerateVertices(this, new Vector3(w, d, h))); } } } }
public override void Draw3D(Engine engine) { // Draws the grid at the ZLevel indicated. engine.primManager.DrawLines(PrimHelper.GenerateGridVertices( new Vector3(0, 0, ZLevel * Block.Size + 0.5f), Vector3.UnitX * Block.Size, Vector3.UnitY * Block.Size, engine.room.Width, engine.room.Depth, Color.Blue)); // Draws the verticle line indicators. Vector3 _pos = Cursor3D * Block.Size; engine.primManager.DrawLines(PrimHelper.GenerateLineVertices( new Vector3(_pos.X, _pos.Y, 0), new Vector3(_pos.X, _pos.Y, engine.room.Height * Block.Size), Color.White)); engine.primManager.DrawLines(PrimHelper.GenerateLineVertices( new Vector3(_pos.X + Block.Size, _pos.Y, 0), new Vector3(_pos.X + Block.Size, _pos.Y, engine.room.Height * Block.Size), Color.White)); engine.primManager.DrawLines(PrimHelper.GenerateLineVertices( new Vector3(_pos.X, _pos.Y + Block.Size, 0), new Vector3(_pos.X, _pos.Y + Block.Size, engine.room.Height * Block.Size), Color.White)); engine.primManager.DrawLines(PrimHelper.GenerateLineVertices( new Vector3(_pos.X + Block.Size, _pos.Y + Block.Size, 0), new Vector3(_pos.X + Block.Size, _pos.Y + Block.Size, engine.room.Height * Block.Size), Color.White)); engine.primManager.SetDepthBuffer(false); engine.primManager.DrawLines(PrimHelper.GenerateWireCubeVertices(Cursor3D * Block.Size, (Cursor3D + new Vector3(1, 1, 1)) * Block.Size, Color.Red)); engine.primManager.SetDepthBuffer(true); // Draws null blocks if necessary. if (DrawNull) { // Draws the null solids. engine.primManager.myEffect.Alpha = 0.5f; // Draws invisible null blocks. VertexIndexData _data = new VertexIndexData(); TextureData _tex = engine.room.BlockSet.TilesetMain.Tiles[0]; for (int w = 0; w < engine.room.Width; w++) { for (int d = 0; d < engine.room.Depth; d++) { for (int h = 0; h < engine.room.Height; h++) { if (engine.room.GridArray[w, d, h] == 1) { _data.AddData(PrimHelper.GenerateCubeVertices(new Vector3(w, d, h) * Block.Size, new Vector3(w + 1, d + 1, h + 1) * Block.Size, _tex)); } } } } if (_data.VertexList.Count != 0) engine.primManager.DrawVertices(_data, _tex.TextureMain); // Resets alpha. engine.primManager.myEffect.Alpha = 1f; } }
public static void DrawCube(PrimManager PrimManager, Vector3 BottomLeftFront, Vector3 TopRightBack, TextureData Tex) { VertexIndexData _cube = PrimHelper.GenerateCubeVertices(BottomLeftFront, TopRightBack, Tex); PrimManager.DrawVertices(_cube, Tex.TextureMain); }