예제 #1
0
void Window::notify() {
  Vector v_right = v_up->cross_product(*v_vpn);
  
  /* Parallel orthogonal projection matrix */
  double _ft[][4] = {
                     {v_right.x(),   v_right.y(),   v_right.z(),   .0},
                     {v_up->x(),     v_up->y(),     v_up->z(),     .0},
                     {v_vpn->x(),    v_vpn->y(),    v_vpn->z(),    .0},
                     {v_translation->x(), v_translation->y(), v_translation->z(), 1.0}
                    };
  Matrix* translate_and_rotate = new Matrix(_ft);
  /* ---------- */

  /* Perspective projection matrix */
  double d = 10.0;
  double _p[][4] = {
                     {1.0,  .0,   .0,   .0    },
                     { .0, 1.0,   .0,   .0    },
                     { .0,  .0,  1.0, -1.0 / d},
                     { .0,  .0,   .0,   .0    }
                   };
  Matrix* perspective = new Matrix(_p);
  Matrix* all_perspective = Transformations::multiply(translate_and_rotate, perspective);
  /* ---------- */

  // This fake display file MUST NOT have a window attached!
  DisplayFile* fakeDisplay = new DisplayFile();
  for(GeometricObjectIterator it = displayFile->begin(); it < displayFile->end(); ++it) {
    GeometricObject* fakeObject = (*it)->clone();

    if(projection == "orthogonal") {
      fakeObject->transform(translate_and_rotate);
    }
    if(projection == "perspective") {
      fakeObject->transform(all_perspective);
      fakeObject->planeW0();
    }
 
    fakeDisplay->add_object(fakeObject);
  }

  // Send the fake objects to the ViewPort
  for(std::vector<ViewPort*>::iterator it = view_ports.begin(); it < view_ports.end(); ++it) {
    (*it)->notify(fakeDisplay->begin(), fakeDisplay->end());
  }

  delete translate_and_rotate;
  delete all_perspective;
  delete perspective;
}