diff --git a/vcg/math/shot.h b/vcg/math/shot.h index c5e07dac..b7613cfc 100644 --- a/vcg/math/shot.h +++ b/vcg/math/shot.h @@ -23,6 +23,9 @@ /**************************************************************************** History $Log: not supported by cvs2svn $ +Revision 1.2 2004/10/05 19:04:25 ganovelli +version 5-10-2004 in progress + Revision 1.1 2004/09/15 22:58:05 ganovelli re-creation @@ -53,19 +56,35 @@ class Shot { public: typedef Camera CameraType; typedef S ScalarType; - + + enum { + NOTVALID_BIT = 0x1 + }; + char flags; + bool IsValid(){ return (flags& NOTVALID_BIT)==0;} + void SetValid(bool v){ if(!v) flags|=NOTVALID_BIT; else flags&=~NOTVALID_BIT;} + Camera & camera; // the camera that shot - vcg::Similarity similarity; // the position from where it did it + vcg::Similarity similarity; // the position from where it did it Shot( Camera & c):camera(c){} Camera & Camera(){return camera;}; /// take the i-th axis of the coordinate system of the camera - vcg::Point3const & Axis(const int & i)const { vcg::Matrix44 m; similarity.rot.ToMatrix(m); return m.Column3(i);} - + vcg::Point3 Axis(const int & i)const; + /// take the viewpoint - vcg::Point3const & ViewPoint(); + vcg::Point3 const &ViewPoint(); + + /// set the viewpoint + void SetViewPoint(const vcg::Point3 & viewpoint); + + /// look at + void LookAt(const vcg::Point3 & z_dir,const vcg::Point3 & up); + + /// look at + void LookTowards(const vcg::Point3 & z_dir,const vcg::Point3 & up); /// convert a 3d point in camera coordinates vcg::Point3 ConvertToCameraCoordinates(const vcg::Point3 & p) const; @@ -80,24 +99,49 @@ public: template vcg::Point3const & Shot::ViewPoint(){ - Matrix44 m = similarity.Matrix(); - return Point3(m[0][3],m[1][3],m[2][3]); + //Matrix44 m = similarity.Matrix(); + //return Point3(m[0][3],m[1][3],m[2][3]); + return -similarity.tra; +} + +template + vcg::Point3 Shot::Axis(const int & i) const { + vcg::Matrix44 m; + similarity.rot.ToMatrix(m); + vcg::Point3f aa = m.Row3(i); + return aa; + } + +template +void Shot::SetViewPoint(const vcg::Point3 & viewpoint){ + similarity.tra = -viewpoint; +} + +template +void Shot::LookAt(const vcg::Point3 & z_dir,const vcg::Point3 & up){ + LookTowards(z_dir-ViewPoint(),up); +} + +template +void Shot::LookTowards(const vcg::Point3 & z_dir,const vcg::Point3 & up){ + vcg::Point3 x_dir = up ^-z_dir ; + vcg::Point3 y_dir = -z_dir ^x_dir ; + + Matrix44 m; + m.SetIdentity(); + *(vcg::Point3 *)&m[0][0] = x_dir/x_dir.SquaredNorm(); + *(vcg::Point3 *)&m[1][0] = y_dir/y_dir.SquaredNorm(); + *(vcg::Point3 *)&m[2][0] = -z_dir/z_dir.SquaredNorm(); + + similarity.rot.FromMatrix(m); } template vcg::Point3 Shot::ConvertToCameraCoordinates(const vcg::Point3 & p) const{ - ::QMessageBox mb; - char t[200]; - sprintf(t,"shot in %f %f %f",p[0],p[1],p[2]); - mb.setText(t); - mb.exec(); - - vcg::Point3 tmp = similarity.Matrix()*p; - - sprintf(t,"shot out %f %f %f",tmp[0],tmp[1],tmp[2]); - mb.setText(t); - mb.exec(); - return tmp; + vcg::Point3 cp = similarity.Matrix()*p; + // note: the camera reference system is right handed + cp[2]=-cp[2]; + return cp; } template @@ -107,7 +151,7 @@ vcg::Point2 Shot::Project(const vcg::Point3 & p) const{ template S Shot::Depth(const vcg::Point3 & p)const { - return (camera.Project(ConvertToCameraCoordinates(p))). + return ConvertToCameraCoordinates(p).Z(); } }