public Planet(string name, string bufname, float radius, TerrainCache cache) : base(name) { face = new TerrainFace[6]; for (int i = 0; i < 6; i++) { face[i] = new TerrainFace(name + "_" + i, (TerrainFaceIndex)i, radius, cache); face[i].heightDataBufferName = bufname; } }
public TerrainFace(string name, TerrainFaceIndex faceIndex, float radius, TerrainCache cache) : base(name) { Initialize("TerrainFace"); cur_cntr = cntr++; this.cache = cache; uint v0 = 0, v1 = 0, v2 = 0; switch (faceIndex) { case TerrainFaceIndex.Top: normal = new Vector3(0, 1, 0); v0 = 0; v1 = 2; v2 = 1; break; case TerrainFaceIndex.Bottom: normal = new Vector3(0, -1, 0); v0 = 0; v1 = 2; v2 = 1; break; case TerrainFaceIndex.Front: normal = new Vector3(0, 0, 1); v0 = 0; v1 = 1; v2 = 2; break; case TerrainFaceIndex.Back: normal = new Vector3(0, 0, -1); v0 = 0; v1 = 1; v2 = 2; break; case TerrainFaceIndex.Left: normal = new Vector3(1, 0, 0); v0 = 1; v1 = 2; v2 = 0; break; case TerrainFaceIndex.Right: normal = new Vector3(-1, 0, 0); v0 = 1; v1 = 2; v2 = 0; break; } unsafe { pushConstantsLen = 4 * 4 + 4 * 4 + 4; pushConstants = Marshal.AllocHGlobal((int)pushConstantsLen); float *f_ptr = (float *)pushConstants; uint * ui_ptr = (uint *)f_ptr; f_ptr[0] = normal.X; f_ptr[1] = normal.Y; f_ptr[2] = normal.Z; f_ptr[3] = 0.0f; ui_ptr[4] = v0; ui_ptr[5] = v1; ui_ptr[6] = v2; f_ptr[7] = radius; ui_ptr[8] = (uint)faceIndex * 2049 * 2049; } }