Objectives

Setup

Utils

Utils

Scene I

Model

Model

World I

World classes

Camera

struct World
{
  void initialize(std::string name, int width, int height);
  void keyPress(unsigned char ch);
  void start();
  void render();

  static World& GetInstance();
  static World  *s_World;

  GeometryMap   *renderables;
  Projectors     projectors;
  Camera         camera;
};
void World::render()
{
  glClearColor(0.0, 0.0, 0.0, 1.0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  if (projectors.isPerspective())
  {
    glLoadIdentity();
    camera.render();
  }
  //...
}
void World::keyPress(unsigned char ch)
{
  if (ch >= '1' &amp;&amp; ch <= '4')
  {
    projectors.keyPress(ch);
  }
  else
  {
    if (projectors.isPerspective())
    {
      camera.keyStroke(ch);
    }
  }
  glutPostRedisplay();
}

Scene II

Scene

Physics

Physics

Introduce these two classes into the physics folder: - cubeactor.h

These should build without incident

World II

World class

  //GeometryMap   *renderables;
  Scene         *scene;
  void tickAndRender();

In World implementation, we need to implement this function:

void World::tickAndRender()
{
  static clock_t lastTime = 0;

  if (lastTime == 0)
    lastTime = clock();

  clock_t currTime = clock();
  clock_t deltaTime = currTime - lastTime;
  float secondsDelta = (float)deltaTime/CLOCKS_PER_SEC;

  scene->tick(secondsDelta);

  glutPostRedisplay();
}
  //foreach (GeometryMap::value_type geometry, *renderables)
 // {
 //   geometry.second.render();
 // }
  scene->render();
void World::start()
{
  timerFunc(0);
  glutMainLoop();
}

Main

 // theWorld.renderables = &amp;model->entities;
  Scene *scene = new Scene (model);
  theWorld.scene = scene;
  theWorld.start();
void timerFunc(int value);
void timerFunc(int value)
{
  theWorld.tickAndRender();
  glutTimerFunc(50, timerFunc, 1);
}

Build and Test