public void UpdateStreched(Facet map) { Tile tile = (Tile)GameObject; if (tile.IsStretched || TextmapTextures.GetTextmapTexture(tile.TileData.TexID) == null || !TestStretched(tile.Position.X, tile.Position.Y, tile.Position.Z, true)) { tile.IsStretched = false; tile.MinZ = tile.Position.Z; } else { tile.IsStretched = true; tile.UpdateZ(map.GetTileZ(tile.Position.X, tile.Position.Y + 1), map.GetTileZ(tile.Position.X + 1, tile.Position.Y + 1), map.GetTileZ(tile.Position.X + 1, tile.Position.Y)); Vector3[,,] vec = new Vector3[3, 3, 4]; int i; int j; for (i = -1; i < 2; i++) { int curX = GameObject.Position.X + i; int curI = i + 1; for (j = -1; j < 2; j++) { int curY = GameObject.Position.Y + j; int curJ = j + 1; sbyte currentZ = map.GetTileZ(curX, curY); sbyte leftZ = map.GetTileZ(curX, curY + 1); sbyte rightZ = map.GetTileZ(curX + 1, curY); sbyte bottomZ = map.GetTileZ(curX + 1, curY + 1); if (currentZ == leftZ && currentZ == rightZ && currentZ == bottomZ) { for (int k = 0; k < 4; k++) { vec[curI, curJ, k] = new Vector3(0, 0, 1); } } else { vec[curI, curJ, 0] = new Vector3(-22.0f, 22.0f, (currentZ - rightZ) * 4); Merge(ref vec[curI, curJ, 0], -22.0f, -22.0f, (leftZ - currentZ) * 4); vec[curI, curJ, 0].Normalize(); vec[curI, curJ, 1] = new Vector3(22.0f, 22.0f, (rightZ - bottomZ) * 4); Merge(ref vec[curI, curJ, 1], -22.0f, 22.0f, (currentZ - rightZ) * 4); vec[curI, curJ, 1].Normalize(); vec[curI, curJ, 2] = new Vector3(22.0f, -22.0f, (bottomZ - leftZ) * 4); Merge(ref vec[curI, curJ, 2], 22.0f, 22.0f, (rightZ - bottomZ) * 4); vec[curI, curJ, 2].Normalize(); vec[curI, curJ, 3] = new Vector3(-22.0f, -22.0f, (leftZ - currentZ) * 4); Merge(ref vec[curI, curJ, 3], 22.0f, -22.0f, (bottomZ - leftZ) * 4); vec[curI, curJ, 3].Normalize(); } } } i = 1; j = 1; _normals[0] = vec[i - 1, j - 1, 2] + vec[i - 1, j, 1] + vec[i, j - 1, 3] + vec[i, j, 0]; _normals[0].Normalize(); _normals[1] = vec[i, j - 1, 2] + vec[i, j, 1] + vec[i + 1, j - 1, 3] + vec[i + 1, j, 0]; _normals[1].Normalize(); _normals[2] = vec[i, j, 2] + vec[i, j + 1, 1] + vec[i + 1, j, 3] + vec[i + 1, j + 1, 0]; _normals[2].Normalize(); _normals[3] = vec[i - 1, j, 2] + vec[i - 1, j + 1, 1] + vec[i, j, 3] + vec[i, j + 1, 0]; _normals[3].Normalize(); _vertex[0].Normal = _normals[0]; _vertex[1].Normal = _normals[1]; _vertex[3].Normal = _normals[2]; _vertex[2].Normal = _normals[3]; _vertex0_yOffset = new Vector3(22, -tile.Rectangle.Left, 0); _vertex1_yOffset = new Vector3(44, 22 - tile.Rectangle.Bottom, 0); _vertex2_yOffset = new Vector3(0, 22 - tile.Rectangle.Top, 0); _vertex3_yOffset = new Vector3(22, 44 - tile.Rectangle.Right, 0); } Vector3 hue = RenderExtentions.GetHueVector(GameObject.Hue); if (_vertex[0].Hue != hue) { _vertex[0].Hue = _vertex[1].Hue = _vertex[2].Hue = _vertex[3].Hue = hue; } }
private void UpdateStreched(Facet map) { //float[] surroundingTilesZ = new float[_surroundingIndexes.Length]; int i, j; //for (i = 0; i < _surroundingIndexes.Length; i++) // surroundingTilesZ[i] = map.GetTileZ((short)(GameObject.Position.X + _surroundingIndexes[i].X), (short)(GameObject.Position.Y + _surroundingIndexes[i].Y)); //sbyte currentZ_ = GameObject.Position.Z; //sbyte leftZ_ = (sbyte)surroundingTilesZ[6]; //sbyte rightZ_ = (sbyte)surroundingTilesZ[3]; //sbyte bottomZ_ = (sbyte)surroundingTilesZ[7]; //if (!(currentZ_ == leftZ_ && currentZ_ == rightZ_ && currentZ_ == bottomZ_)) //{ // Tile tile = (Tile)GameObject; // sbyte low = 0, high = 0; // sbyte sort = (sbyte)map.GetAverageZ(GameObject.Position.Z, leftZ_, rightZ_, bottomZ_, ref low, ref high); // tile.AverageZ = sort; // tile.MinZ = low; // tile.PriorityZ = (short)(sort - 1); // if (sort != SortZ) // { // SortZ = sort; // map.GetTile((short)GameObject.Position.X, (short)GameObject.Position.Y).ForceSort(); // } //} //_vertex0_yOffset = new Vector3(22, -(currentZ_ * 4), 0); //_vertex1_yOffset = new Vector3(44f, 22 - rightZ_ * 4, 0); //_vertex2_yOffset = new Vector3(0, 22 - leftZ_ * 4, 0); //_vertex3_yOffset = new Vector3(22, 44f - bottomZ_ * 4, 0); Tile tile = (Tile)GameObject; tile.UpdateZ(map.GetTileZ(tile.Position.X, tile.Position.Y + 1), map.GetTileZ(tile.Position.X + 1, tile.Position.Y + 1), map.GetTileZ(tile.Position.X + 1, tile.Position.Y)); tile.PriorityZ = (short)(tile.AverageZ - 1); Vector3[,,] vec = new Vector3[3, 3, 4]; for (i = -1; i < 2; i++) { int curX = GameObject.Position.X + i; int curI = i + 1; for (j = -1; j < 2; j++) { int curY = GameObject.Position.Y + j; int curJ = j + 1; sbyte currentZ = map.GetTileZ(curX, curY); sbyte leftZ = map.GetTileZ(curX, curY + 1); sbyte rightZ = map.GetTileZ(curX + 1, curY); sbyte bottomZ = map.GetTileZ(curX + 1, curY + 1); if (currentZ == leftZ && currentZ == rightZ && currentZ == bottomZ) { for (int k = 0; k < 4; k++) { vec[curI, curJ, k] = new Vector3(0, 0, 1); } } else { vec[curI, curJ, 0] = new Vector3(-22.0f, 22.0f, (currentZ - rightZ) * 4); Merge(ref vec[curI, curJ, 0], -22.0f, -22.0f, (leftZ - currentZ) * 4); vec[curI, curJ, 0].Normalize(); vec[curI, curJ, 1] = new Vector3(22.0f, 22.0f, (rightZ - bottomZ) * 4); Merge(ref vec[curI, curJ, 1], -22.0f, 22.0f, (currentZ - rightZ) * 4); vec[curI, curJ, 1].Normalize(); vec[curI, curJ, 2] = new Vector3(22.0f, -22.0f, (bottomZ - leftZ) * 4); Merge(ref vec[curI, curJ, 2], 22.0f, 22.0f, (rightZ - bottomZ) * 4); vec[curI, curJ, 2].Normalize(); vec[curI, curJ, 3] = new Vector3(-22.0f, -22.0f, (leftZ - currentZ) * 4); Merge(ref vec[curI, curJ, 3], 22.0f, -22.0f, (bottomZ - leftZ) * 4); vec[curI, curJ, 3].Normalize(); } } } i = 1; j = 1; _normals[0] = vec[i - 1, j - 1, 2] + vec[i - 1, j, 1] + vec[i, j - 1, 3] + vec[i, j, 0]; _normals[0].Normalize(); _normals[1] = vec[i, j - 1, 2] + vec[i, j, 1] + vec[i + 1, j - 1, 3] + vec[i + 1, j, 0]; _normals[1].Normalize(); _normals[2] = vec[i, j, 2] + vec[i, j + 1, 1] + vec[i + 1, j, 3] + vec[i + 1, j + 1, 0]; _normals[2].Normalize(); _normals[3] = vec[i - 1, j, 2] + vec[i - 1, j + 1, 1] + vec[i, j, 3] + vec[i, j + 1, 0]; _normals[3].Normalize(); //_normals[0] = CalculateNormal(surroundingTilesZ[2], surroundingTilesZ[3], surroundingTilesZ[0], surroundingTilesZ[6]); //_normals[1] = CalculateNormal(GameObject.Position.Z, surroundingTilesZ[4], surroundingTilesZ[1], surroundingTilesZ[7]); //_normals[2] = CalculateNormal(surroundingTilesZ[5], surroundingTilesZ[7], GameObject.Position.Z, surroundingTilesZ[9]); //_normals[3] = CalculateNormal(surroundingTilesZ[6], surroundingTilesZ[8], surroundingTilesZ[3], surroundingTilesZ[10]); _vertex[0].Normal = _normals[0]; _vertex[1].Normal = _normals[1]; _vertex[2].Normal = _normals[3]; _vertex[3].Normal = _normals[2]; //_vertex[0].TextureCoordinate = new Vector3(0, 0, 0); //_vertex[1].TextureCoordinate = new Vector3(0, 1, 0); //_vertex[2].TextureCoordinate = new Vector3(1, 0, 0); //_vertex[3].TextureCoordinate = new Vector3(1, 1, 0); _vertex0_yOffset = new Vector3(22, -tile.Rectangle.Left, 0); _vertex1_yOffset = new Vector3(44, 22 - tile.Rectangle.Bottom, 0); _vertex2_yOffset = new Vector3(0, 22 - tile.Rectangle.Top, 0); _vertex3_yOffset = new Vector3(22, 44 - tile.Rectangle.Right, 0); Vector3 hue = RenderExtentions.GetHueVector(GameObject.Hue); if (_vertex[0].Hue != hue) { _vertex[0].Hue = _vertex[1].Hue = _vertex[2].Hue = _vertex[3].Hue = hue; } }