Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "Pieza_CurvaExt.h"
- #include <glew.h>
- #define _USE_MATH_DEFINES
- #include <math.h>
- #include "CurvaExterior.h"
- Pieza_CurvaExt::Pieza_CurvaExt(Material* mtl, GLfloat p, GLfloat m, GLfloat r0, GLfloat r1)
- {
- numFaces = 2 * (2 * (m+1) * p); // Number of faces
- numVertices = 2 * ((m+1)* (p + 1)); // Number of vertices
- vertices = new GLfloat[numVertices * 3];
- indexes = new GLushort[numFaces * 3];
- int verticesIndex = 0;
- int indexesIndex = 0;
- for (int i = 0; i <= p; i++)
- {
- GLfloat r = r0 + (r1 - r0)*i / p;
- for (int j = 0; j <= m; j++)
- {
- GLfloat mCos = (GLfloat)cos(2 * M_PI*j / m);
- GLfloat mSin = (GLfloat)sin(2 * M_PI*j / m);
- vertices[verticesIndex] = mCos * r;
- vertices[verticesIndex + 1] = 0.0f;
- vertices[verticesIndex + 2] = mSin * r;
- verticesIndex += 3;
- }
- }
- for (int i = 0; i < p; i++)
- {
- for (int j = 0; j <= m; j++)
- {
- indexes[indexesIndex] = m * i + j;
- indexes[indexesIndex + 1] = m * (i + 1) + j;
- indexes[indexesIndex + 2] = (m * (i + 1) + j + 1);
- indexesIndex += 3;
- indexes[indexesIndex] = m * i + j;
- indexes[indexesIndex + 1] = ( m * (i + 1) + j + 1);
- indexes[indexesIndex + 2] = ( m * i + j + 1);
- indexesIndex += 3;
- }
- }
- int base = verticesIndex / 3;
- for (int i = 0; i <= p; i++)
- {
- GLfloat r = r0 + (r1 - r0)*i / p;
- for (int j = 0; j <= m; j++)
- {
- GLfloat mCos = (GLfloat)cos((M_PI / 8)*j / m);
- GLfloat mSin = (GLfloat)sin((M_PI / 8)*j / m);
- vertices[verticesIndex] = mCos * r;
- vertices[verticesIndex + 1] = 0.0f;
- vertices[verticesIndex + 2] = mSin * r;
- verticesIndex += 3;
- }
- }
- for (int i = 0; i < p; i++)
- {
- for (int j = 0; j <= m; j++)
- {
- indexes[indexesIndex] = base + m * i + j;
- indexes[indexesIndex + 1] = base + (m * (i + 1) + j + 1);
- indexes[indexesIndex + 2] = base + m * (i + 1) + j;
- indexesIndex += 3;
- indexes[indexesIndex] = base + m * i + j;
- indexes[indexesIndex + 1] = base + (m * i + j + 1);
- indexes[indexesIndex + 2] = base + (m * (i + 1) + j + 1);
- indexesIndex += 3;
- }
- }
- InitBuffers();
- SetMaterial(mtl);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement