diff --git a/vcg/math/shot.h b/vcg/math/shot.h index 1c9e20b7..3726dc74 100644 --- a/vcg/math/shot.h +++ b/vcg/math/shot.h @@ -93,6 +93,28 @@ creation ****************************************************************************/ +/** class Shot +The shot is made of two things: +* the Instrinsics paramaters, which are stored as a Camera type (check vcg/math/camera) and that +determines how a point in the frame of the camera is projected in the 2D projection plane + +* the Extrinsics parameters, which are stored in the class Shot (che the type ReferenceFrame) +and that tell viewpoint and view direction. + +The Extrinsics parameters are kept as a rotation matrix "rot" and a translation vector "tra" +NOTE: the translation matrix "tra" corresponds to -viewpoint while the rotation matrix +"rot" corresponds to the axis of the reference frame by row, i.e. +rot[0][0|1|2] == X axis +rot[1][0|1|2] == Y axis +rot[2][0|1|2] == Z axis + +It follows that the matrix made with the upper left 3x3 equal to rot and the 4th colum equal to tra +and (0,0,0,1) in the bottom row transform a point from world coordiantes to the reference frame +of the shot. + + + + **/ #ifndef __VCGLIB_SHOT #define __VCGLIB_SHOT @@ -177,14 +199,25 @@ public: // accessors public: - /* returns a matrix which contains the reference frame of the shot - On the first three rows the axes (x,y,z) and on the 4th colum the viewpoint */ - Matrix44 GetExtrinsics() const { + /* Returns the matrix M such that + 3dpoint_in_world_coordinates = M * 3dpoint_in_local_coordinates + */ + Matrix44 GetExtrinsicsToWorldMatrix() const { Matrix44 rotM ; Extrinsics.rot.ToMatrix(rotM); + Transpose(rotM); return Matrix44().SetTranslate(Extrinsics.tra) * rotM; } + /* Returns the matrix M such that + 3dpoint_in_local_coordinates = M * 3dpoint_in_world_coordinates + */ + Matrix44 GetWorldToExtrinsicsMatrix() const { + Matrix44 rotM ; + Extrinsics.rot.ToMatrix(rotM); + return rotM * Matrix44().SetTranslate(-Extrinsics.tra) ; + } + /* multiply the current reference frame for the matrix passed note: it is up to the caller to check the the matrix passed is a pure rototraslation */ @@ -215,7 +248,7 @@ const vcg::Point3 Shot::GetViewPoint() const template void Shot::SetViewPoint(const vcg::Point3 & viewpoint) { - Extrinsics.tra = viewpoint; + Extrinsics.SetTra( viewpoint ); } //--- @@ -270,7 +303,7 @@ vcg::Point3 Shot::ConvertWorldToCameraCoordinates(const vcg:: { Matrix44 rotM; Extrinsics.rot.ToMatrix(rotM); - vcg::Point3 cp = rotM * (p - Extrinsics.tra); + vcg::Point3 cp = rotM * (p - GetViewPoint() ); cp[2]=-cp[2]; // note: camera reference system is right handed return cp; } @@ -283,8 +316,8 @@ vcg::Point3 Shot::ConvertCameraToWorldCoordinates(const vcg:: vcg::Point3 cp = p; cp[2]=-cp[2]; // note: World reference system is left handed Extrinsics.rot.ToMatrix(rotM); - Invert(rotM); - cp = rotM * cp+Extrinsics.tra; + Transpose(rotM); + cp = rotM * cp+ GetViewPoint(); return cp; }