Advertisement
Guest User

CurvaMal

a guest
Jun 2nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include "Pieza_CurvaExt.h"
  3. #include <glew.h>
  4. #define _USE_MATH_DEFINES
  5. #include <math.h>
  6.  
  7. #include "CurvaExterior.h"
  8.  
  9.  
  10. Pieza_CurvaExt::Pieza_CurvaExt(Material* mtl, GLfloat p, GLfloat m, GLfloat r0, GLfloat r1)
  11. {
  12.         numFaces = 2 * (2 * (m+1) * p);      // Number of faces
  13.         numVertices = 2 * ((m+1)* (p + 1));  // Number of vertices
  14.         vertices = new GLfloat[numVertices * 3];
  15.         indexes = new GLushort[numFaces * 3];
  16.  
  17.         int verticesIndex = 0;
  18.         int indexesIndex = 0;
  19.  
  20.         for (int i = 0; i <= p; i++)
  21.         {
  22.             GLfloat r = r0 + (r1 - r0)*i / p;
  23.             for (int j = 0; j <= m; j++)
  24.             {
  25.                 GLfloat mCos = (GLfloat)cos(2 * M_PI*j / m);
  26.                 GLfloat mSin = (GLfloat)sin(2 * M_PI*j / m);
  27.                 vertices[verticesIndex] = mCos * r;
  28.                 vertices[verticesIndex + 1] = 0.0f;
  29.                     vertices[verticesIndex + 2] =  mSin * r;
  30.                 verticesIndex += 3;
  31.             }
  32.         }
  33.  
  34.         for (int i = 0; i < p; i++)
  35.         {
  36.             for (int j = 0; j <= m; j++)
  37.             {
  38.                 indexes[indexesIndex] = m * i + j;
  39.                 indexes[indexesIndex + 1] = m * (i + 1) + j;
  40.                 indexes[indexesIndex + 2] = (m * (i + 1) + j + 1);
  41.                 indexesIndex += 3;
  42.  
  43.                 indexes[indexesIndex] = m * i + j;
  44.                 indexes[indexesIndex + 1] = ( m * (i + 1) + j + 1);
  45.                 indexes[indexesIndex + 2] = ( m * i + j + 1);
  46.                 indexesIndex += 3;
  47.             }
  48.         }
  49.  
  50.         int base = verticesIndex / 3;
  51.  
  52.         for (int i = 0; i <= p; i++)
  53.         {
  54.             GLfloat r = r0 + (r1 - r0)*i / p;
  55.             for (int j = 0; j <= m; j++)
  56.             {
  57.                 GLfloat mCos = (GLfloat)cos((M_PI / 8)*j / m);
  58.                 GLfloat mSin = (GLfloat)sin((M_PI / 8)*j / m);
  59.                 vertices[verticesIndex] = mCos * r;
  60.                 vertices[verticesIndex + 1] =  0.0f;
  61.                 vertices[verticesIndex + 2] = mSin * r;
  62.                 verticesIndex += 3;
  63.             }
  64.         }
  65.  
  66.         for (int i = 0; i < p; i++)
  67.         {
  68.             for (int j = 0; j <= m; j++)
  69.             {
  70.                 indexes[indexesIndex] = base + m * i + j;
  71.                 indexes[indexesIndex + 1] = base + (m * (i + 1) + j + 1);
  72.                 indexes[indexesIndex + 2] = base + m * (i + 1) + j;
  73.                 indexesIndex += 3;
  74.  
  75.                 indexes[indexesIndex] = base + m * i + j;
  76.                 indexes[indexesIndex + 1] = base + (m * i + j + 1);
  77.                 indexes[indexesIndex + 2] = base + (m * (i + 1) + j + 1);
  78.                 indexesIndex += 3;
  79.             }
  80.         }
  81.  
  82.     InitBuffers();
  83.     SetMaterial(mtl);
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement