core/vgui/vgui_camera.cxx
Go to the documentation of this file.
00001 // This is core/vgui/vgui_camera.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \author Geoffrey Cross, Oxford RRG
00008 // \date   03 Nov 99
00009 // \brief  See vgui_camera.h for a description of this file.
00010 
00011 #include "vgui_camera.h"
00012 #include <vnl/vnl_vector_fixed.h>
00013 #include <vnl/vnl_matrix_fixed.h>
00014 
00015 //----------------------------------------------------------------------------
00016 //: Plug this matrix into a vgui_loader_tableau.
00017 //  Note: this will return a GL_PROJECTION_MATRIX with the assumption that
00018 //  you have a Euclidean reconstruction.  The result is that the front and
00019 //  back clipping planes will be PARALLEL (note: not projective frame!) to
00020 //  the image plane.
00021 vnl_matrix_fixed<double,3,4> vgui_camera::get_glprojmatrix(int imagesizex,
00022                                                            int imagesizey) const
00023 {
00024   vnl_matrix_fixed<double,3,4> C;
00025 
00026   // undo the viewport transformation.
00027   C(0,0)= 2.0/imagesizex; C(0,1)= 0;               C(0,2)= 0; C(0,3)= -1;
00028   C(1,0)= 0;              C(1,1)= -2.0/imagesizey; C(1,2)= 0; C(1,3)= 1;
00029   C(2,0)= 0;              C(2,1)= 0;               C(2,2)= 2; C(2,3)= -1;
00030 
00031   // the projection matrix sets the first, second and fourth row of the
00032   //   GL_PROJECTION_MATRIX.  The third row defines the front and back
00033   //   z-axis clipping planes.
00034   vnl_matrix_fixed<double,4,4> Pinit;
00035 
00036   Pinit.set_row( 0, pmatrix.get_row(0));
00037   Pinit.set_row( 1, pmatrix.get_row(1));
00038   Pinit.set_row( 3, pmatrix.get_row(2));
00039 
00040   Pinit(2,0)= 0;
00041   Pinit(2,1)= 0;
00042   Pinit(2,2)= 0;
00043   Pinit(2,3)= 0;
00044 
00045   vnl_matrix_fixed<double,3,4> P = C*Pinit;
00046   vnl_vector_fixed<double,4> ABC = pmatrix.get_row(2);
00047 
00048   // this currently sets the back clipping plane to pass through
00049   //   point [1 0 -0.5] for no real reason... just that it seems
00050   //   to work for all my vrml models.  Geoff.
00051   double d1=
00052     (ABC(0)-pmatrix(2,0))* 1 +
00053     (ABC(1)-pmatrix(2,1))* 0 +
00054     (ABC(2)-pmatrix(2,2))* -0.5 + pmatrix(2,3);
00055 
00056   ABC(3)= d1;
00057 
00058   P.set_row( 2, ABC);
00059 
00060   return P;
00061 }