Exemplo n.º 1
0
void Square::buildModel() {
  int verticies = 6;
  vec3* points = new vec3[verticies];
  vec3* colors = new vec3[verticies];
  //front
  buildFace(points, 0,
      vec3(0.3,0.3,0.3), vec3(-0.3,0.3,0.3),
      vec3(-0.3,-0.3,0.3), vec3(0.3,-0.3,0.3));
  for(int i=0;i<verticies;i++)
    colors[i] = vec3(1,0,0); //red

  glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
  glBufferData(GL_ARRAY_BUFFER, verticies*sizeof(vec3), points, GL_STATIC_DRAW);
  vPosition = glGetAttribLocation(program, "vPosition");
  glEnableVertexAttribArray(vPosition);
  glVertexAttribPointer(vPosition, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));

  glBindBuffer(GL_ARRAY_BUFFER, buffers[1]);
  glBufferData(GL_ARRAY_BUFFER, verticies*sizeof(vec3), colors, GL_STATIC_DRAW);
  vColor = glGetAttribLocation(program, "vColor");
  glEnableVertexAttribArray(vColor);
  glVertexAttribPointer(vColor, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));

  delete[] points;
  delete[] colors;
}
Exemplo n.º 2
0
/**
 * This will build the 8 points of a cube given:
 *
 * vec4 cube - the center point of a cube
 * float radius - the distance from the center point to a corner on the cube
 *
 * The cube will be created in the following order. The points are
 * represented by numbers and the faces are preceded by 'f'.
 *
 *                                   2----3
 *       0---------------1           | f0 |
 *       |\      f0      |\          |    |
 *       | \             | \    2----0----1----3     +x=f1
 *       |  2---------------3   | f2 | f3 | f1 |     -x=f2
 *       |  |   f3       |  |   |    |    |    |     +y=f0
 * y     |f2|            |  |   6----4----5----7     -y=f4
 * |     |  |     f5     |f1|        | f4 |          +z=f5
 * |     |  |            |  |        |    |          -z=f3
 * O--x  4--|------------5  |        6----7
 *  \     \ |     f4      \ |        | f5 |
 *   z     \|              \|        |    |
 *          6---------------7        2----3
 */
void Menger::buildCube(vec3 cube, float radius) {
  vec4* verts = new vec4[8];
  int index = 0;
  for(int y=1; y>=-1; y-=2) {
    for(int z=-1; z<=1; z+=2) {
      for(int x=-1; x<=1; x+=2) {
        verts[index++] = vec4(cube + (vec3(x,y,z) * radius), 1.);
      }
    }
  }

  vec4* face = new vec4[4];

  face[0]=verts[2]; face[1]=verts[3]; face[2]=verts[1]; face[3] = verts[0];
  buildFace(face, 0);

  face[0]=verts[1]; face[1]=verts[3]; face[2]=verts[7]; face[3] = verts[5];
  buildFace(face, 1);

  face[0]=verts[2]; face[1]=verts[0]; face[2]=verts[4]; face[3] = verts[6];
  buildFace(face, 2);

  face[0]=verts[0]; face[1]=verts[1]; face[2]=verts[5]; face[3] = verts[4];
  buildFace(face, 3);

  face[0]=verts[4]; face[1]=verts[5]; face[2]=verts[7]; face[3] = verts[6];
  buildFace(face, 4);

  face[0]=verts[6]; face[1]=verts[7]; face[2]=verts[3]; face[3] = verts[2];
  buildFace(face, 5);

  delete[] face;
  delete[] verts;
}
Exemplo n.º 3
0
Face::Face(Facetype type, GameObject* parent, TopOrBottom p)
{
	typeOfFace = type;
	active = false;
	buildFace(parent, p);
}