void Object::BuildTriangleStrip(const GLuint& perRow, const GLuint& perColumn) { /* 0, 1 1, 1 | 2, 1 3, 1 0, 0 1, 0 | 2, 0 3, 0 | 0, 0 1, 0 | 2, 0 3, 0 0,-1 1,-1 | 2,-1 3,-1 */ int numValuesPerRow = (2 + (2 * perRow)) *3, numDegenValues = 2 * 3; uint numValues = (numValuesPerRow + numDegenValues) * perColumn; GLfloat *vertices = new GLfloat[numValues]; // TODO memset(vertices, 0, sizeof(GLfloat) * numValues); for(int i = 0, x = 0, y = 0; i < numValues; ++x) { vertices[i] = x; vertices[++i] = y + 1; vertices[++i] = 0; vertices[++i] = x; vertices[++i] = y; vertices[++i] = 0; if((++i) % numValuesPerRow == 0) { vertices[i] = x; vertices[++i] = y; vertices[++i] = 0; vertices[++i] = x; vertices[++i] = y; vertices[++i] = 0; numValuesPerRow += numDegenValues; i +=1; x = -1; --y; } } /*GLfloat *vertices = new GLfloat[numVertices]; vertices[0] = 0.0f; vertices[1] = 1.0f; vertices[2] = 0.0f; vertices[3] = 0.0f; vertices[4] = 0.0f; vertices[5] = 0.0f; vertices[6] = 1.0f; vertices[7] = 1.0f; vertices[8] = 0.0f; vertices[9] = 1.0f; vertices[10] = 0.0f; vertices[11] = 0.0f; vertices[12] = 1.0f; vertices[13] = 0.0f; vertices[14] = 0.0f; vertices[15] = 1.0f; vertices[16] = 0.0f; vertices[17] = 0.0f; vertices[18] = 0.0f; vertices[19] = 0.0f; vertices[20] = 0.0f; vertices[21] = 0.0f; vertices[22] = -1.0f; vertices[23] = 0.0f; vertices[24] = 1.0f; vertices[25] = 0.0f; vertices[26] = 0.0f; vertices[27] = 1.0f; vertices[28] = -1.0f; vertices[29] = 0.0f;*/ numIndices = numValues/3; this->renderMode = GL_TRIANGLE_STRIP; LoadTriangles(vertices, vertices); delete [] vertices; }
void Plane::BuildTriangles(const GLuint& perRow, const GLuint& perColumn){ static bool built = false; if(built){ fprintf(stderr, "Failed to build triangles. Object already built!\n"); return; } built = true; int numValuesPerRow = 18 * perRow; int numValues = 18 * perRow * perColumn; GLfloat *vertices = new GLfloat[numValues]; for(int i = 0, x = 0, y = 0; i < numValues; ++x){ vertices[i] = x + 0.0f; vertices[++i] = y + 1.0f; vertices[++i] = 0.0f; vertices[++i] = x + 0.0f; vertices[++i] = y + 0.0f; vertices[++i] = 0.0f; vertices[++i] = x + 1.0f; vertices[++i] = y + 1.0f; vertices[++i] = 0.0f; vertices[++i] = x + 1.0f; vertices[++i] = y + 0.0f; vertices[++i] = 0.0f; vertices[++i] = x + 1.0f; vertices[++i] = y + 1.0f; vertices[++i] = 0.0f; vertices[++i] = x + 0.0f; vertices[++i] = y + 0.0f; vertices[++i] = 0.0f; if(++i % numValuesPerRow == 0){ x = -1; --y; } } int numUvValuesPerRow = 12 * perRow; int numUvValues = 12 * perRow * perColumn; GLfloat *uvs = new GLfloat[numUvValues]; for(int i = 0, u = 0, v = 0; i < numUvValues; ++u){ uvs[i] = u + 0.625f; uvs[++i] = -v - 0.9166f; uvs[++i] = u + 0.625f; uvs[++i] = -v - 1.0f; uvs[++i] = u + 0.6875f; uvs[++i] = -v - 0.9166f; uvs[++i] = u + 0.6875f; uvs[++i] = -v - 1.0f; uvs[++i] = u + 0.6875f; uvs[++i] = -v - 0.9166f; uvs[++i] = u + 0.625f; uvs[++i] = -v - 1.0f; if(++i % numUvValuesPerRow == 0){ u = -1; ++v; } } mNumUVs = numUvValues/2; mNumIndices = numValues/3; mRenderMode = GL_TRIANGLES; LoadTriangles(vertices, uvs); }
void Object::BuildTriangles(const GLuint& perRow, const GLuint& perColumn) { int numValuesPerRow = 18 * perRow; int numValues = 18 * perRow * perColumn; GLfloat *vertices = new GLfloat[numValues]; for(int i = 0, x = 0, y = 0; i < numValues; ++x) { vertices[i] = x; vertices[++i] = y + 1; vertices[++i] = 0; vertices[++i] = x; vertices[++i] = y; vertices[++i] = 0; vertices[++i] = x + 1; vertices[++i] = y + 1; vertices[++i] = 0; vertices[++i] = x + 1; vertices[++i] = y; vertices[++i] = 0; vertices[++i] = x + 1; vertices[++i] = y + 1; vertices[++i] = 0; vertices[++i] = x; vertices[++i] = y; vertices[++i] = 0; if(++i % numValuesPerRow == 0) { x = -1; --y; } } int numUvValuesPerRow = 12 * perRow; int numUvValues = 12 * perRow * perColumn; GLfloat *uvs = new GLfloat[numUvValues]; for(int i = 0, u = 0, v = 0; i < numUvValues; ++u) { uvs[i] = u + 0.625f; uvs[++i] = -v - 0.9166; uvs[++i] = u + 0.625f; uvs[++i] = -v - 1; uvs[++i] = u + 0.6875f; uvs[++i] = -v - 0.9166; uvs[++i] = u + 0.6875f; uvs[++i] = -v - 1; uvs[++i] = u + 0.6875f; uvs[++i] = -v - 0.9166; uvs[++i] = u + 0.625f; uvs[++i] = -v - 1; if(++i % numUvValuesPerRow == 0) { u = -1; ++v; } } //0,1 //0,0 //U: 0.625 - 0.0625 0.625 //V: 1 - 0.0833 0.625 - 0.0833 //U: 0.625 - 0.0625 0.625 //V: 1 1 numUVs = numUvValues/2; numIndices = numValues/3; this->renderMode = GL_TRIANGLES; LoadTriangles(vertices, uvs); delete [] vertices; delete [] uvs; }