public Tile() { info = new TileInfo(); tileSceneNode = null; renderable = null; init = false; loaded = false; bounds = new AxisAlignedBox(); boundsExt = new AxisAlignedBox(); //worldBounds = new AxisAlignedBox(); neighbors = new Tile[4]; }
public void DeformHeight( Vector3 deformationPoint, float modificationHeight, TileInfo info) { long pSize = Options.Instance.PageSize; long pX = info.PageX; long pZ = info.PageZ; long wL = Options.Instance.World_Width; long hL = Options.Instance.World_Height; // adjust x and z to be local to page long x = (long) ((deformationPoint.x ) - ((pX - wL * 0.5f) * (pSize))); long z = (long) ((deformationPoint.z ) - ((pZ - hL * 0.5f) * (pSize))); Data2D data = data2D[ pX ][ pZ ]; if ( data.IsLoaded ) { float h = data.DeformHeight (x, z, modificationHeight); // If we're on a page edge, we must duplicate the change on the // neighbour page (if it has one...) if (x == 0 && pX != 0) { data = data2D[ pX - 1 ][ pZ ]; if ( data.IsLoaded ) { data.SetHeight (Options.Instance.PageSize - 1, z, h); } } if (x == pSize - 1 && pX < wL - 1) { data = data2D[ pX + 1 ][ pZ ]; if ( data.IsLoaded ) { data.SetHeight (0, z, h); } } if (z == 0 && pZ != 0) { data = data2D[ pX ][ pZ - 1 ]; if ( data.IsLoaded ) { data.SetHeight (x, Options.Instance.PageSize - 1, h); } } if (z == pSize - 1 && pZ < hL - 1) { data = data2D[ pX ][ pZ + 1]; if ( data.IsLoaded ) { data.SetHeight (x, 0, h); } } } }
public float GetRealWorldHeight( float x, float z, TileInfo info) { // figure out which page the point is on long dataX = info.PageX; long dataZ = info.PageZ; if ( ! (data2D[ dataX ][ dataZ ].IsLoaded )) return 0.0f; Tile.Tile t = PageManager.Instance.GetPage (dataX, dataZ ).GetTile (info.TileX, info.TileZ); long Lod = 0; if (t != null && t.IsLoaded ) Lod = t.Renderable.RenderLevel; return GetRealPageHeight (x, z, dataX, dataZ, Lod); }
public void Release() { if (inUse && isLoaded) { if (neighbors[(int)Neighbor.South] != null) neighbors[(int)Neighbor.South].SetNeighbor(Neighbor.North, null); if (neighbors[(int)Neighbor.North] != null) neighbors[(int)Neighbor.North].SetNeighbor(Neighbor.South, null); if (neighbors[(int)Neighbor.West] != null) neighbors[(int)Neighbor.West].SetNeighbor(Neighbor.East, null); if (neighbors[(int)Neighbor.East] != null) neighbors[(int)Neighbor.East].SetNeighbor(Neighbor.West, null); for (uint i = 0; i < 4; i++ ) { neighbors[i] = null; } RenderableManager.Instance.FreeRenderable( this ); inUse = false; isLoaded = false; info = null; } }
public void Init( TileInfo Info ) { mustRender = false; info = Info; inFrustum = false; inUse = true; }
/** Initializes the LandScapeRenderable with the given options and the starting coordinates of this block. */ public Renderable() : base() { info = null; materialLODIndex = 0; neighbors = new Renderable[4]; for ( long i = 0; i < 4; i++ ) neighbors[ i ] = null; inUse = false; isLoaded = false; // Setup render op renderOp = new RenderOperation(); renderOp.vertexData = new VertexData(); renderOp.vertexData.vertexStart = 0; long tileSize = Options.Instance.TileSize; renderOp.vertexData.vertexCount = (int)((tileSize + 1) * (tileSize + 1)); box = new AxisAlignedBox(); // Vertex declaration VertexDeclaration decl = renderOp.vertexData.vertexDeclaration; VertexBufferBinding bind = renderOp.vertexData.vertexBufferBinding; HardwareVertexBuffer vbuf; // Vertex buffer #1, position // positions int offset = 0; decl.AddElement(POSITION, offset, VertexElementType.Float3, VertexElementSemantic.Position); offset += VertexElement.GetTypeSize(VertexElementType.Float3); if ( Options.Instance.Lit ) { decl.AddElement(POSITION, offset, VertexElementType.Float3, VertexElementSemantic.Normal); offset += VertexElement.GetTypeSize(VertexElementType.Float3); } decl.AddElement(POSITION, offset, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0); offset += VertexElement.GetTypeSize(VertexElementType.Float2); vbuf = HardwareBufferManager.Instance.CreateVertexBuffer( decl.GetVertexSize(POSITION), renderOp.vertexData.vertexCount, BufferUsage.StaticWriteOnly,false); bind.SetBinding(POSITION, vbuf); // if (Options.Instance.Lit) // { // offset = 0; // decl.AddElement(NORMAL, offset, VertexElementType.Float3, VertexElementSemantic.Normal); // offset += VertexElement.GetTypeSize(VertexElementType.Float3); // vbuf = HardwareBufferManager.Instance.CreateVertexBuffer( // decl.GetVertexSize(NORMAL), // renderOp.vertexData.vertexCount, // BufferUsage.StaticWriteOnly); // // bind.SetBinding(NORMAL, vbuf); // } // // offset = 0; // decl.AddElement(TEXCOORD, offset, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0); // offset += VertexElement.GetTypeSize(VertexElementType.Float2); // vbuf = HardwareBufferManager.Instance.CreateVertexBuffer( // decl.GetVertexSize(TEXCOORD), // renderOp.vertexData.vertexCount, // BufferUsage.StaticWriteOnly); // // bind.SetBinding(TEXCOORD, vbuf); // // // if (Options.Instance.Colored || // Options.Instance.Coverage_Vertex_Color || // Options.Instance.Base_Vertex_Color) // { // offset = 0; // decl.AddElement(COLORS, offset, VertexElementType.Float3, VertexElementSemantic.Diffuse); // offset += VertexElement.GetTypeSize(VertexElementType.Color); // vbuf = HardwareBufferManager.Instance.CreateVertexBuffer( // decl.GetVertexSize(COLORS), // renderOp.vertexData.vertexCount, // BufferUsage.StaticWriteOnly); // // bind.SetBinding(COLORS, vbuf); // } //No need to set the indexData since it is shared from IndexBuffer class renderOp.operationType = OperationType.TriangleList; renderOp.useIndices = true; renderOp.indexData = null; RenderLevel = Options.Instance.MaxRenderLevel / 2; }
public float GetHeightAbsolute(float x, float z, TileInfo info) { if ( heightData != null) { int pSize = (int)Options.Instance.PageSize; Vector3 scale = Options.Instance.Scale; // adjust x and z to be local to page int i_x = ((int)(x / scale.x) - ((int)(info.PageX - Options.Instance.World_Width * 0.5f) * (pSize))); int i_z = ((int)(z / scale.z) - ((int)(info.PageZ - Options.Instance.World_Height * 0.5f) * (pSize))); long arraypos = (long)(i_z * size + i_x); if (arraypos < maxArrayPos) return heightData[arraypos]; } return 0.0f; }
/** * Method that deform Height Data of the terrain. * \param &deformationPoint * Where modification is, in world coordinates * \param &modificationHeight * What modification do to terrain * \param info * Give some info on tile to * help coordinate system change */ public float DeformHeight( Vector3 deformationPoint, float modificationHeight, TileInfo info) { if ( heightData != null ) { int pSize = (int)Options.Instance.PageSize; // adjust x and z to be local to page int x = (int) ((deformationPoint.x ) - ((info.PageX - Options.Instance.World_Width * 0.5f) * (pSize))); int z = (int) ((deformationPoint.z ) - ((info.PageZ - Options.Instance.World_Height * 0.5f) * (pSize))); long arraypos = (long)(z * size + x); if (arraypos < maxArrayPos) { if ((heightData[arraypos] - modificationHeight) > 0.0f) heightData[arraypos] -= modificationHeight; else heightData[arraypos] = 0.0f; return heightData[arraypos]; } } return 0.0f; }