public void update(float dt) { if (this.isAlive() == false) { this.life = (float)Math2.randomNumber(0.0d, 2.0d); this.position = new Vector3(0f, 0f, 0f); return; } //this.position.Add(this.velocity.X * dt, this.velocity.Y * dt, this.velocity.Z * dt); //this.position.Add(0f, -((float)(Earth.Gravity)) * dt, 0f); this.life -= dt; if (this.angle != 0.0f) { this.texture.SetRotation(this.texture.GetRotationAngle() + (this.angle * dt)); } }
private bool loadContent() { //Core.Shader.Init(); frustum = new Frustum(); cube = new VBOCube[10]; for (int i = 0; i < maxCubes; i++) { cube[i] = new VBOCube(i); cube[i].setColor(new ColorRGBA(180, 20, 20, 0)); cube[i].setPosition(new Vector3((float)Math2.randomNumber(0, 25), 0, (float)Math2.randomNumber(0, 25))); } cube[0].setPosition(Vector3.Zero); earth = new Planet(); return(true); }
public Terrain(Vector3 centerPos, Vector3 axisX, Vector3 axisZ, int LODLevels, int terrainSize, int patchSize, float planetRadius, int textureID, string heightmapURL) { if ((!Math2.IsPowerOfTwo(terrainSize - 1)) || (!Math2.IsPowerOfTwo(patchSize - 1))) { Core.ErrorExit("Error: (Class: Terrain) Patch size must be 2^x+1 and terrain size must be 2^x+1"); } if (!File.Exists(heightmapURL)) { Core.ErrorExit("Error: (Class: Terrain) heightmap not found!"); } Bitmap bitmap = new Bitmap(heightmapURL); texID = textureID; lodLevels = LODLevels; tSize = terrainSize; pSize = patchSize; radius = planetRadius; // Number of patches per row ppR = (terrainSize - 1) / patchSize; // Temp arrays to ease the vertex and uv calculation Vector3[] vertArray = new Vector3[terrainSize * terrainSize]; Vector2[] uvArray = new Vector2[terrainSize * terrainSize]; int index = 0; float height = 0; for (int z = 0; z < terrainSize; z++) { for (int x = 0; x < terrainSize; x++) { index = (z * terrainSize) + x; // Since the heightmap is in greyscales, we can use any color channel if ((x < bitmap.Height) && (z < bitmap.Width)) { height = bitmap.GetPixel(x, z).R *heightMult; } //vertArray[index] = new Vector3(x, height, z); vertArray[index] = new Vector3(centerPos + (axisX) * ((x)) //+ (axisY / terrainScale) * ((terrainSize) / terrainScale) + (axisZ) * ((z))); vertArray[index] = GenerateCubeToSphereCoordinates(vertArray[index], height); // calculate uv coordinates for that vertex point uvArray[index] = new Vector2((float)(1.0 / terrainSize * x), (float)(1.0 / terrainSize * z)); } } // Vertices array holds all terrain vertices multiplied by the 3 coordinates (x, y and z) vertices = new List <Vector3>(); index = 0; foreach (Vector3 vert in vertArray) { vertices.Add(vert); } // UV array array holds all uv texture coordinates multiplied by the 2 coordinates (u and v) uvCoor = new List <Vector2>(); index = 0; foreach (Vector2 vert in uvArray) { uvCoor.Add(vert); } indicesCount = new int[(int)Math.Pow(2, lodLevels - 1) + 1]; indexBuffer = new int[(int)Math.Pow(2, lodLevels - 1) + 1]; // this array stores the indice count for the bridges - for the case Resolution-To-Resolution and the case Resolution-To-(Resolution-1) bridgeIndicesCount = new int[2, (int)Math.Pow(2, lodLevels - 1) + 1]; // this array stores all bridges buffers. 4 bridges to the same resolution, 4 bridges to a lower resolution. bridgeIndexBuffer = new int[(int)Math.Pow(2, lodLevels - 1) + 1, 8]; for (int i = 1; i <= lodLevels; i++) { int resolution = (int)Math.Pow(2, i - 1); // calculate indices count for every lod level int currLevel = 0, lastLevel = 0; if (i == 1) { // there are 3 indices per triangle and 2 triangle to make a polygon indicesCount[i] = ((patchSize) * (patchSize) * 3 * 2); } else { currLevel = resolution; lastLevel = resolution - (int)Math.Pow(2, i - 2); indicesCount[currLevel] = indicesCount[lastLevel] / 4; } // assign the index buffer ids and then calculate and create the index buffers BuildIndices(resolution); // calculate the 8 bridges bridgeIndicesCount[0, resolution] = ((pSize - 1) / resolution) * 3 * 2; // top bridge (to same level) BuildDefaultHoriBridge(resolution, true); // right bridge (to same level) BuildDefaultVertBridge(resolution, false); // bottom bridge (to same level) BuildDefaultHoriBridge(resolution, false); // left bridge (to same level) BuildDefaultVertBridge(resolution, true); bridgeIndicesCount[1, resolution] = ((((pSize - 1) / (resolution * 2)) * 3) - 2) * 3; // top bridge (to lower level) BuildLowerHoriBridge(resolution, true); // right bridge (to lower level) BuildLowerVertBridge(resolution, false); // bottom bridge (to lower level) BuildLowerHoriBridge(resolution, false); // left bridge (to lower level) BuildLowerVertBridge(resolution, true); } Debug.Trace("(Class: Terrain) Terrain created"); }