Objectives

Setup

Geometry

struct Geometry : public Renderable
{
 //...
  VertexGroup *vertexGroup;
  std::vector<Vector3> vertices;
  //...
};
struct Geometry : public Renderable
{
 //...
  VertexGroup *vertexGroup;
  std::vector<Vector3> vertices;
  //...
  void extractVertices();
};
void Geometry::extractVertices()
{
  int newIndex=0;
  foreach (Face &amp;face, faces)
  {
    vector<int> groupIndices = face.vertexIndices;
    face.vertexIndices.clear();
    foreach (int index, groupIndices)
    {
      Vector3 vertex(vertexGroup->vertices[index-1].X, vertexGroup->vertices[index-1].Y, vertexGroup->vertices[index-1].Z);
      vertices.push_back(vertex);
      face.vertexIndices.push_back(newIndex);
      newIndex++;
    }
  }
Geometry::Geometry(string groupName, istream&amp; is, VertexGroup*group)
: name(groupName), vertexGroup(group)
{
  //...
  extractVertices();
}
void Geometry::render()
{
  foreach (Face &amp;face, faces)
  {
    face.render(vertices);
  }
}

Face

void Face::render(std::vector <Vector3>&amp;vertexTable)
{
  vertexIndices.size() == 3?
     glBegin(GL_TRIANGLES)
    :glBegin(GL_QUADS);

  foreach (int index, vertexIndices)
  {
    glVertex3f( vertexTable[index-1].X,
                vertexTable[index-1].Y,
                vertexTable[index-1].Z );
  }
  glEnd();
}
void Face::render(std::vector <Vector3>&amp;vertexTable)
{
  vertexIndices.size() == 3?
     glBegin(GL_TRIANGLES)
    :glBegin(GL_QUADS);

  foreach (int index, vertexIndices)
  {
    glVertex3f( vertexTable[index].X,
                vertexTable[index].Y,
                vertexTable[index].Z );
  }
  glEnd();
}

utils

physics

Scene + Model

Exercises

Exercise 1

Exercise 2