Added Matrix)() and InverseMatrix() methods, which respectively return the direct and inverse matrices that describe how the trackball similarity is applied with respect to the trackball center.

Corrected ToAscii() and SetFromAscii() methods, which should work with 8 values instead of 9 (well, in effect they are implemantation dependent methods, so...).
This commit is contained in:
Paolo Cignoni 2009-03-31 09:03:18 +00:00
parent 3447c82e88
commit a353708f16
2 changed files with 24 additions and 6 deletions

View File

@ -208,6 +208,20 @@ void Trackball::ApplyInverse() {
glTranslate(-center); glTranslate(-center);
} }
// T(c) S R T(t) T(-c) => S R T(S^(-1) R^(-1)(c) + t - c)
Matrix44f Trackball::Matrix() const{
Matrix44f r; track.rot.ToMatrix(r);
Matrix44f sr = Matrix44f().SetScale(track.sca, track.sca, track.sca) * r;
Matrix44f s_inv = Matrix44f().SetScale(1/track.sca, 1/track.sca, 1/track.sca);
Matrix44f t = Matrix44f().SetTranslate(s_inv*Transposed(r)*center + track.tra - center);
return Matrix44f(sr*t);
}
Matrix44f Trackball::InverseMatrix() const{
return Inverse(Matrix());
}
void Trackball::Scale(const float s) void Trackball::Scale(const float s)
{ {
track.sca*=s; track.sca*=s;
@ -254,17 +268,16 @@ void Trackball::DrawPlane() {
void Trackball::ToAscii(char* result){ void Trackball::ToAscii(char* result){
float * f = (float*) &track; float * f = (float*) &track;
sprintf(result, "trackball(%f,%f,%f,%f,%f,%f,%f,%f,%f)", sprintf(result, "trackball(%f,%f,%f,%f,%f,%f,%f,%f)",
f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8] ); f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7] );
} }
bool Trackball::SetFromAscii(const char * st){ bool Trackball::SetFromAscii(const char * st){
float * f = (float*) &track; float * f = (float*) &track;
int res= sscanf(st, "trackball(%f,%f,%f,%f,%f,%f,%f,%f,%f)", int res= sscanf(st, "trackball(%f,%f,%f,%f,%f,%f,%f,%f)",
f+0,f+1,f+2,f+3,f+4,f+5,f+6,f+7,f+8 ); f+0,f+1,f+2,f+3,f+4,f+5,f+6,f+7 );
return (res==9);
return (res==8);
} }
// DrawPlaneHandle() e DrawIcon() have been moved to trackutils.h // DrawPlaneHandle() e DrawIcon() have been moved to trackutils.h

View File

@ -275,6 +275,11 @@ public:
void ApplyInverse(); void ApplyInverse();
// DrawIcon() has been moved to trackutils.h // DrawIcon() has been moved to trackutils.h
//void DrawIcon(); //void DrawIcon();
// T(c) S R T(t) T(-c) => S R T(S^(-1) R^(-1)(c) + t - c)
Matrix44f Matrix() const;
Matrix44f InverseMatrix() const;
/*! /*!
@brief Reset the transformation and every mapped manipulator. @brief Reset the transformation and every mapped manipulator.
*/ */