Exemple #1
0
int main_test(){
  Context context;
  StopWatch swatch;
  World world;
  CameraControl ev;
  glPointSize(2.0);
  ev.cam.position = vec(0.0f,0.0f,5.0f);
  mouse_move_spawner.register_listener(&ev);
  key_event_handler.register_listener(&ev);
  
  FlatShader3D flat;
  flat.SetProjection(ProjectionMatrix(0.01,0.01,0.01,200000.0));
  
  GameObject * go = new GameObjectTest(context);
  
  go->GravityBound = false;
  go->aabb.pos[0] += 0.1;
  go->aabb.pos[2] += 0.1;
  go->aabb.pos[1] -= 4.0;
  go->aabb.size = vec(20.0,2.0,20.0);
  go->aabb.mass = 100000.0;
  go->Tetra.TRS = TMatrix(vec(10.0f,0.0f,10.0f)) * SMatrix(vec(10.0f,1.0f,10.0f));
  world.InsertObject(go);

  go = new GameObjectTest(context);
  go->GravityBound = false;
  go->aabb.size = vec(2.0,2.0,2.0);
  go->Tetra = Tetragon();
  world.InsertObject(go);
  VBO stars = context.Stars;
  while(true){
    Matrix<float,4> cameraMatrix;
    go->aabb.pos = -ev.cam.position.As<double>() - vec(0.0,0.0,0.0);
    print(go->aabb.pos);
    auto goList = world.GetNearbyObjects(vec(0.0,0.0,0.0),5000000.0);
    world.PhysicsUpdate(vec(0.0,0.0,0.0),500000,0.1);

    for(auto go : goList){
      go.Get()->DoUpdate(world);
    }

    //ev.cam.position = go->aabb.pos.As<float>() + vec(0.0f,-2.0f,0.0f);
    print(go->aabb.pos);
    swatch.Reset();
    swatch.Start();
    ClearBuffer(vec(0.0f,0.0f,0.0f,1.0f));
    cameraMatrix = ev.GetCamera().getTransformMatrix();
    /*cameraMatrix[3][0] = 0;
    cameraMatrix[3][1] = 0;
    cameraMatrix[3][2] = 0;
    */
    flat.SetCamera(cameraMatrix);   
    
    flat.SetModelView(Matrix<float,4>::Eye());
    context.StarColors.Bind(0);
    stars.BindBuffer(0);
    VertexBufferObject::DrawBuffers(DrawMethod::Points,100);
    flat.SetCamera(ev.GetCamera().getTransformMatrix());   
    goList = world.GetNearbyObjects(vec(0.0,0.0,0.0),5000000.0);
    for(auto go: goList){
      go.Get()->Draw(flat);
    }
    SwapBuffers();
    Sleep(1/30.0 - swatch.ElapsedSeconds());
  }
}