public void AddFloor(Vector3 LL, int height, int textureID) { VertexPositionNormalTexture lowerLeft, lowerRight, upperLeft, upperRight; LL = LL + Vector3.UnitZ * height * Constants.TILE_SIZE; lowerLeft = new VertexPositionNormalTexture(LL , Vector3.UnitZ, TCLL); lowerRight = new VertexPositionNormalTexture(LL + Vector3.UnitX * Constants.TILE_SIZE, Vector3.UnitZ, TCLR); upperLeft = new VertexPositionNormalTexture(LL + Vector3.UnitY * Constants.TILE_SIZE, Vector3.UnitZ, TCUL); upperRight = new VertexPositionNormalTexture(LL + (Vector3.UnitY+ Vector3.UnitX) * Constants.TILE_SIZE , Vector3.UnitZ, TCUR); if (height <= 1) { if (!FloorTextureGroups.ContainsKey(textureID)) { VertexGroup gp = new VertexGroup(TileList.GetTile(textureID)); gp.Technique = RendererAssetPool.UniversalEffect.Techniques.TexturedClamp; FloorTextureGroups.Add(textureID, gp); } FloorTextureGroups[textureID].Add(lowerLeft); FloorTextureGroups[textureID].Add(upperLeft); FloorTextureGroups[textureID].Add(lowerRight); FloorTextureGroups[textureID].Add(lowerRight); FloorTextureGroups[textureID].Add(upperLeft); FloorTextureGroups[textureID].Add(upperRight); } else { if (!WallTextureGroups.ContainsKey(textureID)) { VertexGroup gp = new VertexGroup(TileList.GetTile(textureID)); gp.TransparencyEnabled = true; gp.Technique = RendererAssetPool.UniversalEffect.Techniques.TexturedWrap; WallTextureGroups.Add(textureID, gp); } WallTextureGroups[textureID].Add(lowerLeft); WallTextureGroups[textureID].Add(upperLeft); WallTextureGroups[textureID].Add(lowerRight); WallTextureGroups[textureID].Add(lowerRight); WallTextureGroups[textureID].Add(upperLeft); WallTextureGroups[textureID].Add(upperRight); } }
/// <summary> /// Adds a new RendererVertexGroup entity to the scene /// </summary> /// <param name="_entity">The entity to add.</param> /// <param name="_layer">The layer to add it to, lower layers are drawn first.</param> /// <returns>The entity's unique ID.</returns> public int Add(VertexGroup _entity, int _layer) { int x = entityID.GetID(); entityList.Add(x, _entity); AddLayers(_layer); layers[_layer].Add(x, _entity); return x; }
public void AddWall(Vector3 LL, Vector3 normal, int tilesWide, int tilesHigh, int textureID) { VertexPositionNormalTexture lowerLeft, lowerRight, upperLeft, upperRight; Vector3 right = new Vector3( -normal.Y, normal.X, normal.Z); right.Normalize(); lowerLeft = new VertexPositionNormalTexture(LL, normal, TCLL * tilesHigh); lowerRight = new VertexPositionNormalTexture(LL + right * (tilesWide * Constants.TILE_SIZE), normal, TCLL * tilesHigh + TCUR * tilesWide); upperLeft = new VertexPositionNormalTexture(LL + Vector3.UnitZ * (tilesHigh * Constants.TILE_SIZE), normal, TCUL); upperRight = new VertexPositionNormalTexture(LL + Vector3.UnitZ * (tilesHigh * Constants.TILE_SIZE) + right * (tilesWide * Constants.TILE_SIZE), normal, TCUR * tilesWide); if (tilesHigh <= 1) { if (!NonTransWallTextureGroups.ContainsKey(textureID)) { VertexGroup gp = new VertexGroup(TileList.GetTile(textureID)); gp.Technique = RendererAssetPool.UniversalEffect.Techniques.TexturedWrap; NonTransWallTextureGroups.Add(textureID, gp); } NonTransWallTextureGroups[textureID].Add(lowerLeft); NonTransWallTextureGroups[textureID].Add(upperLeft); NonTransWallTextureGroups[textureID].Add(lowerRight); NonTransWallTextureGroups[textureID].Add(lowerRight); NonTransWallTextureGroups[textureID].Add(upperLeft); NonTransWallTextureGroups[textureID].Add(upperRight); } else { if (!WallTextureGroups.ContainsKey(textureID)) { VertexGroup gp = new VertexGroup(TileList.GetTile(textureID)); gp.Technique = RendererAssetPool.UniversalEffect.Techniques.TexturedWrap; gp.TransparencyEnabled = true; WallTextureGroups.Add(textureID, gp); } WallTextureGroups[textureID].Add(lowerLeft); WallTextureGroups[textureID].Add(upperLeft); WallTextureGroups[textureID].Add(lowerRight); WallTextureGroups[textureID].Add(lowerRight); WallTextureGroups[textureID].Add(upperLeft); WallTextureGroups[textureID].Add(upperRight); } }
/// <summary> /// Adds a VertexGroup object to the layer. /// </summary> /// <param name="_entityID">The id to assign to the VertexGroup.</param> /// <param name="_entity">The VertexGroup object.</param> public void Add(int _entityID, VertexGroup _entity) { entityDictionaryVertex.Add(_entityID, _entity); }
private void FillTiles() { Random random = new Random(); //Loads the tiles into the background array int height = 7, width = 7; int minHeight = -7, minWidth = -7; //string path = System.IO.Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location, "../../../../Content/"); Texture2D texture = Content.Load<Texture2D>("grid"); int tileSize = 64; Vector3 posUL = new Vector3(minWidth * tileSize, height * tileSize, 0); Vector3 posLL = new Vector3(minWidth * tileSize, minHeight * tileSize, 0); Vector3 posLR = new Vector3(width * tileSize, minHeight * tileSize, 0); Vector3 posUR = new Vector3(width * tileSize, height * tileSize, 0); VertexPositionNormalTexture UL = new VertexPositionNormalTexture(posUL, Vector3.UnitZ, Vector2.Zero); VertexPositionNormalTexture LL = new VertexPositionNormalTexture(posLL, Vector3.UnitZ, Vector2.UnitY * (height-minHeight)); VertexPositionNormalTexture UR = new VertexPositionNormalTexture(posUR, Vector3.UnitZ, Vector2.UnitX * (width-minWidth)); VertexPositionNormalTexture LR = new VertexPositionNormalTexture(posLR, Vector3.UnitZ, new Vector2((height-minHeight), (width-minWidth))); List<VertexPositionNormalTexture> list = new List<VertexPositionNormalTexture>(); list.Add(UL); list.Add(LR); list.Add(LL); list.Add(UR); list.Add(LR); list.Add(UL); VertexGroup group = new VertexGroup(texture, list); group.Technique = Renderer.RendererAssetPool.UniversalEffect.Techniques.TexturedWrap; group.Ready(); renderer.ActiveScene.Add(group, 0); }
/// <summary> /// Calculates parameters for tiles with height and creates DrawableTiles from them /// </summary> private void FillTiles() { Random random = new Random(); Dictionary<uint, int> borderTileCounter = new Dictionary<uint, int>(); for (uint y = 0; y < map.Height; y++) { if (borderTileCounter.ContainsKey(map.GetTile(0, y).ID) && map.GetTile(0, y).Height ==0) borderTileCounter[map.GetTile(0, y).ID]++; else if( map.GetTile(0, y).Height ==0) borderTileCounter.Add(map.GetTile(0, y).ID, 1); if (borderTileCounter.ContainsKey(map.GetTile(map.Width - 1, y).ID) && map.GetTile(map.Width - 1, y).Height == 0) borderTileCounter[map.GetTile(map.Width-1, y).ID]++; else if (map.GetTile(map.Width - 1, y).Height == 0) borderTileCounter.Add(map.GetTile(map.Width-1, y).ID, 1); } for (uint x = 0; x < map.Width-1; x++) { if (borderTileCounter.ContainsKey(map.GetTile(x, 0).ID) && map.GetTile(x, 0).Height ==0) borderTileCounter[map.GetTile(x, 0).ID]++; else if (map.GetTile(x, 0).Height == 0) borderTileCounter.Add(map.GetTile(x, 0).ID, 1); if (borderTileCounter.ContainsKey(map.GetTile(x, map.Height - 1).ID) && map.GetTile(x, map.Height - 1).Height == 0) borderTileCounter[map.GetTile(x, map.Height - 1).ID]++; else if (map.GetTile(x, map.Height - 1).Height == 0) borderTileCounter.Add(map.GetTile(x, map.Height - 1).ID, 1); } int maxValue = 0; uint maxValueTile = 0; foreach (KeyValuePair<uint, int> element in borderTileCounter) { if (element.Value > maxValue) { maxValue = element.Value; maxValueTile = element.Key; } } //Load floor float minX = -10000f; float maxX = 100000f; float minY = -100000f; float maxY = 10000f; float Xspread = (maxX - minX) / Constants.TILE_SIZE; float Yspread = (maxY - minY) / Constants.TILE_SIZE; List<VertexPositionNormalTexture> verts = new List<VertexPositionNormalTexture>(); verts.Add(new VertexPositionNormalTexture(new Vector3(minX, minY, -0.75f), Vector3.UnitZ, Vector2.UnitY * Yspread)); verts.Add(new VertexPositionNormalTexture(new Vector3(minX, maxY, -0.75f), Vector3.UnitZ, Vector2.Zero)); verts.Add(new VertexPositionNormalTexture(new Vector3(maxX, minY, -0.75f), Vector3.UnitZ, new Vector2(Xspread, Yspread))); verts.Add(new VertexPositionNormalTexture(new Vector3(maxX, maxY, -0.75f), Vector3.UnitZ, Vector2.UnitX * Xspread)); verts.Add(new VertexPositionNormalTexture(new Vector3(maxX, minY, -0.75f), Vector3.UnitZ, new Vector2(Xspread, Yspread))); verts.Add(new VertexPositionNormalTexture(new Vector3(minX, maxY, -0.75f), Vector3.UnitZ, Vector2.Zero)); VertexGroup floor = new VertexGroup(TileList.GetTile((int)maxValueTile), verts); floor.Technique = RendererAssetPool.UniversalEffect.Techniques.TexturedWrap; floor.CastsShadow = false; floor.TransparencyEnabled = false; floor.Ready(); renderer.ActiveScene.Add(floor, 0); //Loads the tiles into the background array for (uint y = 0; y < map.Height; y++) { for (uint x = 0; x < map.Width; x++) { Tile tempTile = map.GetTile(x, y); // Figure out the height of each tile in each direction relative to this one. int positionNorth = (int)(y - 1); int positionSouth = (int)(y + 1); int positionWest = (int)(x - 1); int positionEast = (int)(x + 1); if (positionNorth >= 0) tempTile.heightN = map.GetTile(x, y - 1).Height; if (positionSouth < map.Height) tempTile.heightS = map.GetTile(x, y + 1).Height; if (positionWest >= 0) tempTile.heightW = map.GetTile(x - 1, y).Height; if (positionEast < map.Width) tempTile.heightE = map.GetTile(x + 1, y).Height; map.SetTile(x, y, tempTile); Texture2D texture = TileList.GetTile((int)tempTile.ID); DrawableTile tile = new DrawableTile( texture, tempTile, (int)x, (int)y, tempTile.heightN, tempTile.heightW, tempTile.heightE, tempTile.heightS); Vector3 pos = new Vector3( x * Constants.TILE_SIZE + (Constants.TILE_SIZE / 2), -(y * Constants.TILE_SIZE + (Constants.TILE_SIZE / 2)), 0); if (tempTile.ObjectID != 0) { Model objectModel = TileList.GetObject(tempTile.ObjectID); Object3 newTileObj = new Object3(objectModel, pos + (Vector3.UnitZ * tempTile.Height * Constants.TILE_SIZE)); newTileObj.TransparencyEnabled = true; Scene.Add(newTileObj, 1); } switch (tempTile.EventID) { case 4: case 5: GameSession.Alliance team = tempTile.EventID == 4 ? GameSession.Alliance.RED : GameSession.Alliance.BLUE; if (currentGameMode == VTankObject.GameMode.CAPTURETHEFLAG) { Flags.AddFlag(team, pos); } break; case 8: case 9: case 10: if (currentGameMode == VTankObject.GameMode.CAPTURETHEBASE) { Bases.AddBase(GameSession.Alliance.BLUE, tempTile.EventID, pos); } break; case 11: case 12: case 13: if (currentGameMode == VTankObject.GameMode.CAPTURETHEBASE) { Bases.AddBase(GameSession.Alliance.RED, tempTile.EventID, pos); } break; default: break; } visibleTiles[y * map.Width + x] = tile; } } #region Make Flat Tiles for (uint y = 0; y < map.Height; y++) { for (uint x = 0; x < map.Width; x++) { Tile tempTile = map.GetTile(x, y); Vector3 pos = new Vector3(x * Constants.TILE_SIZE, (-(y + 1) * Constants.TILE_SIZE), 0); Tiles.AddFloor(pos, tempTile.Height, (int)tempTile.ID); } } #endregion #region Make North Walls int height = 0; int tileID = 0; int width = 0; int Hdir = 0; //Make north facing walls for (uint y = 0; y < map.Height; y++) { for (uint x = 0; x < map.Width; x++) { Tile tempTile = map.GetTile(x, y); if ((width == 0 || (tempTile.Height == height && tempTile.ID == tileID && Hdir == tempTile.heightN)) && (x + 1) < map.Width) { height = tempTile.Height; tileID = (int)tempTile.ID; Hdir = tempTile.heightN; width++; } else { if (height > Hdir) { Vector3 pos = new Vector3(x * Constants.TILE_SIZE, (-y * Constants.TILE_SIZE), 0); Tiles.AddWall(pos, Vector3.UnitY, width, height, tileID); } width = 1; height = tempTile.Height; tileID = (int)tempTile.ID; Hdir = tempTile.heightN; } } width = 0; } #endregion #region Make South Walls height = 0; tileID = 0; width = 0; Hdir = 0; uint startX = 0; //Make south facing walls for (uint y = 0; y < map.Height; y++) { for (uint x = 0; x < map.Width; x++) { Tile tempTile = map.GetTile(x, y); if ((width == 0 || (tempTile.Height == height && tempTile.ID == tileID && Hdir == tempTile.heightS)) && (x + 1) < map.Width) { if (width == 0) { startX = x; } height = tempTile.Height; tileID = (int)tempTile.ID; Hdir = tempTile.heightS; width++; } else { if (height > Hdir) { Vector3 pos = new Vector3(startX * Constants.TILE_SIZE, (-(y+1) * Constants.TILE_SIZE), 0); Tiles.AddWall(pos, -Vector3.UnitY, width, height, tileID); } width = 1; height = tempTile.Height; tileID = (int)tempTile.ID; Hdir = tempTile.heightS; startX = x; } } width = 0; } #endregion #region Make East Walls height = 0; tileID = 0; width = 0; Hdir = 0; //Make east facing walls for (uint x = 0; x < map.Width; x++) { for (uint y = 0; y < map.Height; y++) { Tile tempTile = map.GetTile(x, y); if ((width == 0 || (tempTile.Height == height && tempTile.ID == tileID && Hdir == tempTile.heightE)) && (y + 1) < map.Height) { height = tempTile.Height; tileID = (int)tempTile.ID; Hdir = tempTile.heightE; width++; } else { if (height > Hdir) { Vector3 pos = new Vector3((x+1) * Constants.TILE_SIZE, (-y * Constants.TILE_SIZE), 0); Tiles.AddWall(pos, Vector3.UnitX, width, height, tileID); } width = 1; height = tempTile.Height; tileID = (int)tempTile.ID; Hdir = tempTile.heightE; } } width = 0; } #endregion #region Make West Walls height = 0; tileID = 0; width = 0; Hdir = 0; uint startY = 0; //Make south facing walls for (uint x = 0; x < map.Width; x++) { for (uint y = 0; y < map.Height; y++) { Tile tempTile = map.GetTile(x, y); if ((width == 0 || (tempTile.Height == height && tempTile.ID == tileID && Hdir == tempTile.heightW)) && (y+1) < map.Height) { if (width == 0) { startY = y; } height = tempTile.Height; tileID = (int)tempTile.ID; Hdir = tempTile.heightW; width++; } else { if (height > Hdir) { Vector3 pos = new Vector3(x * Constants.TILE_SIZE, (-startY * Constants.TILE_SIZE), 0); Tiles.AddWall(pos, -Vector3.UnitX, width, height, tileID); } width = 1; height = tempTile.Height; tileID = (int)tempTile.ID; Hdir = tempTile.heightW; startY = y; } } width = 0; } #endregion Tiles.AllReady(); //////////////////////////////////////////// ///TODO:::: FOR EACH TILE GOING LEFT TO RIGHT // // IF height = height and tileID = tileID // if Hnorth = Hnorth // NorthWidth ++; // else // TexturedTileGroupManager.AddWall(lowerLeftNorth, Vector3.UnitY, NorthWidth, height, tileID) // NorthWidth = 0; // height = -1 // // if Hsouth = Hsouth // SouthWidth ++; // else // TexturedTileGroupManager.AddWall(lowerLeftSouth, -Vector3.UnitY, SouthhWidth, height, tileID) //etc }