void DemoCamera::SetViewMatrix(int width, int height)
{
	// set the view port for this render section
	glViewport(0, 0, (GLint) width, (GLint) height);

	// set the projection matrix
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	//m_backPlane = 10000.0f;
	gluPerspective(m_fov * 180.0f / 3.1416f, GLfloat (width) /GLfloat(height), m_frontPlane, m_backPlane);

	// set the model view matrix 
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	dVector pointOfInterest (m_matrix.m_posit + m_matrix.m_front);
	gluLookAt(m_matrix.m_posit.m_x, m_matrix.m_posit.m_y, m_matrix.m_posit.m_z, 
		      pointOfInterest.m_x, pointOfInterest.m_y, pointOfInterest.m_z, 
			  m_matrix.m_up.m_x, m_matrix.m_up.m_y, m_matrix.m_up.m_z);	


	glGetIntegerv(GL_VIEWPORT, (GLint*)&m_viewport); 
	glGetDoublev(GL_MODELVIEW_MATRIX, m_modelViewMatrix); 
	glGetDoublev(GL_PROJECTION_MATRIX, m_projectionViewMatrix); 
}
//------------------------------------------------------------------------------
//!
bool
CameraManipulator::onPointerPress( const Event& ev )
{
   _mode = 0;

   if( !camera() || !viewport()->world() ) return false;

   // Picking.
   if( ev.value() == 1 && Core::isKeyPressed( Key::SHIFT ) )
   {
      Rayf ray(
         camera()->position(),
         viewport()->direction( ev.position() )
      );
      Intersector::Hit hit;
      if( Intersector::trace( viewport()->world(), ray, hit ) )
      {
         pointOfInterest( hit._pos );
         return true;
      }
   }

   _mode          = ev.value();
   _grabPos       = ev.position();
   _ref           = camera()->referential();
   _grabPoi       = _poi;
   _secondaryAxis = _ref.orientation().getAxisX();

   if( Core::isKeyPressed( Key::ALT ) )
   {
      const int altModes[] = { 1, 2, 3, 2 };
      _mode = altModes[_mode % 4];
   }

   Vec3f y = _ref.orientation().getAxisY();

   if( _primaryAxis.dot( y ) < 0 )
   {
      _direction = -1.0f;
   }
   else
   {
      _direction =  1.0f;
   }

   const Mat4f& mat = viewport()->cameraMatrix();
   Vec3f tc  = mat | _poi;
   Vec3f tc2 = mat | ( _poi + y );
   _scale = 1.0f / ( tc2 - tc ).length();
   return true;
}