diff --git a/vcg/math/shot.h b/vcg/math/shot.h index b8498281..e3c4428c 100644 --- a/vcg/math/shot.h +++ b/vcg/math/shot.h @@ -506,7 +506,7 @@ void Shot::ApplySimilarity(const Matrix44 & M) M2 = M2 * scalefactor; - Extrinsics.rot = rotM * M2.transpose(); + Extrinsics.rot = rotM * M2.transpose(); Extrinsics.rot.ElementAt(3,0) = 0; Extrinsics.rot.ElementAt(3,1) = 0; @@ -515,9 +515,38 @@ void Shot::ApplySimilarity(const Matrix44 & M) /// Given a similarity transformation such that p' = s R p + T modifies the reference frame accordingly. template -void Shot::ApplySimilarity(const Similarity & S) +void Shot::ApplySimilarity(const Similarity & Sm) { - //...TODO... + Matrix44 rotM; + Extrinsics.rot.ToMatrix(rotM); + + // similarity decomposition + vcg::Matrix44 R; + Sm.rot.ToMatrix(R); + vcg::Matrix44 T; + T.SetIdentity(); + T.ElementAt(0,3) = Sm.tra[0]; + T.ElementAt(1,3) = Sm.tra[1]; + T.ElementAt(2,3) = Sm.tra[2]; + vcg::Matrix44d S44; + S44.SetIdentity(); + S44 *= Sm.sca; + S44.ElementAt(3,3) = 1.0; + + vcg::Matrix44 M = T * R * S44; + + // roto-translate the viewpoint + Extrinsics.tra = M * Extrinsics.tra; + + vcg::Matrix44 M2 = M; + + M2 = M2 * (1.0 / Sm.sca); + + Extrinsics.rot = rotM * M2.transpose(); + + Extrinsics.rot.ElementAt(3,0) = 0; + Extrinsics.rot.ElementAt(3,1) = 0; + Extrinsics.rot.ElementAt(3,2) = 0; }