diff --git a/vcg/math/shot.h b/vcg/math/shot.h index 7a063c5f..61b7b7ad 100644 --- a/vcg/math/shot.h +++ b/vcg/math/shot.h @@ -23,6 +23,9 @@ /**************************************************************************** History $Log: not supported by cvs2svn $ +Revision 1.5 2004/10/22 14:29:40 ponchio +#include <...Point --> #include <...point + Revision 1.4 2004/10/07 14:41:31 fasano Little fix on ViewPoint() method @@ -47,11 +50,8 @@ creation #ifndef __VCGLIB_SHOT #define __VCGLIB_SHOT -// #include -// #include -// #include -#include -#include +#include +#include #include #include @@ -71,9 +71,9 @@ public: 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){} + Shot( Camera & c):camera(c){similarity.SetIdentity();} Camera & Camera(){return camera;}; @@ -81,7 +81,7 @@ public: vcg::Point3 Axis(const int & i)const; /// take the viewpoint - const vcg::Point3 ViewPoint(); + const vcg::Point3 ViewPoint()const; /// set the viewpoint void SetViewPoint(const vcg::Point3 & viewpoint); @@ -89,7 +89,11 @@ public: /// look at void LookAt(const vcg::Point3 & z_dir,const vcg::Point3 & up); - /// look at + /// look at (same as opengl) + void LookAt(const S & eye_x,const S & eye_y,const S & eye_z,const S & at_x,const S & at_y,const S & at_z, + const S & up_x,const S & up_y,const S & up_z); + + /// look towards void LookTowards(const vcg::Point3 & z_dir,const vcg::Point3 & up); /// convert a 3d point in camera coordinates @@ -101,10 +105,11 @@ public: /// take the distance from the point p and the plane parallel to the camera plane and passing through the view /// point. The would be z depth S Depth(const vcg::Point3 & p)const; + }; // end class definition template -const vcg::Point3 Shot::ViewPoint(){ +const vcg::Point3 Shot::ViewPoint() const { //Matrix44 m = similarity.Matrix(); //return Point3(m[0][3],m[1][3],m[2][3]); return -similarity.tra; @@ -128,6 +133,14 @@ void Shot::LookAt(const vcg::Point3 & z_dir,const vcg::Point3 & up){ LookTowards(z_dir-ViewPoint(),up); } +template +void Shot::LookAt(const S & eye_x,const S & eye_y,const S & eye_z,const S & at_x,const S & at_y,const S & at_z, + const S & up_x,const S & up_y,const S & up_z){ + SetViewPoint(Point3(eye_x,eye_y,eye_z)); + LookAt(Point3(at_x,at_y,at_z),Point3(up_x,up_y,up_z)); + } + + template void Shot::LookTowards(const vcg::Point3 & z_dir,const vcg::Point3 & up){ vcg::Point3 x_dir = up ^-z_dir ; @@ -135,9 +148,9 @@ void Shot::LookTowards(const vcg::Point3 & z_dir,const vcg::Point3 & up 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(); + *(vcg::Point3 *)&m[0][0] = x_dir/x_dir.Norm(); + *(vcg::Point3 *)&m[1][0] = y_dir/y_dir.Norm(); + *(vcg::Point3 *)&m[2][0] = -z_dir/z_dir.Norm(); similarity.rot.FromMatrix(m); }