Trackball Improvement. Now it works well also for ortho views

This commit is contained in:
Paolo Cignoni 2014-11-04 23:16:04 +00:00
parent 63046a8bab
commit 1ff3a301ec
3 changed files with 266 additions and 285 deletions

View File

@ -72,9 +72,13 @@ void SphereMode::Apply (Trackball * tb, Point3f new_point)
tb->Hits.push_back (hitNew);
Point3f center = tb->center;
Point3f axis = (hitNew - center) ^ (hitOld - center);
vcg::Normalize(axis);
// Figure out how much to rotate around that axis.
float phi = Distance (hitNew, hitOld) / tb->radius;
// tb->track.rot = tb->last_track.rot * Quaternionf (-phi, axis);
// float phi = Distance (hitNew, hitOld) / tb->radius;
// float phi = vcg::Angle(hitNew - center,hitOld - center)*(Distance(hitNew,center)/tb->radius);
float phi = max(vcg::Angle(hitNew - center,hitOld - center),(Distance(hitNew,hitOld)/tb->radius)) ;
tb->track.rot = Quaternionf (-phi, axis) * tb->last_track.rot;
}

View File

@ -20,51 +20,7 @@
* for more details. *
* *
****************************************************************************/
/****************************************************************************
History
$Log: not supported by cvs2svn $
Revision 1.13 2008/02/26 18:46:55 ponchio
Fixed bug in drawing position of the trackball when changin center.
Revision 1.12 2008/02/24 18:10:54 ponchio
Fixed scale behaviour.
Revision 1.11 2008/02/24 18:05:08 ponchio
Should work as before. I didn't test cylinder and other exotic modes.
Revision 1.10 2008/02/24 14:37:00 ponchio
Restored trackball functionality. Not very much tested, and code will need some
cleanup.
Revision 1.9 2008/02/22 18:57:47 benedetti
first attempt to correct after quaternion ToMatrix() inversion (does not work yet)
Revision 1.8 2008/02/15 20:54:45 benedetti
removed some variable initialization related warning
Revision 1.7 2007/10/22 14:39:54 cignoni
corrected bug into the drawsphere (thanks to nico and guido!)
Revision 1.6 2007/08/17 09:19:40 cignoni
glEnable (GL_LINE_SMOOTH) should go before changing the linewidth.
Revision 1.5 2007/07/14 12:44:40 benedetti
Minor edits in Doxygen documentation.
Revision 1.4 2007/07/09 22:41:22 benedetti
Added Doxygen documentation, removed using namespace std, some other minor changes.
Revision 1.3 2007/06/12 08:58:08 benedetti
Minor fix in DrawUglyCylinderMode()
Revision 1.2 2007/05/28 08:10:47 fiorin
Removed type cast warnings
Revision 1.1 2007/05/15 14:57:34 benedetti
Utility functions for the trackmodes, first version
****************************************************************************/
#ifndef TRACKUTILS_H
#define TRACKUTILS_H

View File

@ -108,6 +108,7 @@ Note: mainly it is used only by the TrackBall.
template <class T> class View {
public:
View();
void GetView();
void SetView(const float *_proj, const float *_modelview, const int *_viewport);
Point3<T> Project(const Point3<T> &p) const;
@ -134,13 +135,21 @@ public:
Matrix44<T> matrix;
Matrix44<T> inverse;
int viewport[4];
bool isOrtho;
};
template <class T> View<T>::View() {
isOrtho=false;
}
template <class T> void View<T>::GetView() {
glGetv(GL_PROJECTION_MATRIX,proj);
glGetv(GL_MODELVIEW_MATRIX,model);
glGetIntegerv(GL_VIEWPORT, (GLint*)viewport);
if(proj[3][3]==0) isOrtho = false;
else isOrtho = true;
matrix = proj*model;
inverse = vcg::Inverse(matrix);
}
@ -161,6 +170,7 @@ template <class T> void View<T>::SetView(const float *_proj,
}
template <class T> Point3<T> View<T>::ViewPoint() const {
if(isOrtho) return vcg::Inverse(model)* Point3<T>(0, 0, 3);
return vcg::Inverse(model)* Point3<T>(0, 0, 0);
}
// Note that p it is assumed to be in model coordinate.
@ -179,22 +189,33 @@ template <class T> Plane3<T> View<T>::ViewPlaneFromModel(const Point3<T> &p)
// Note that p it is assumed to be in model coordinate.
template <class T> Line3<T> View<T>::ViewLineFromModel(const Point3<T> &p)
{
Point3<T> vp=ViewPoint();
Line3<T> line;
Point3<T> vp=ViewPoint();
if(isOrtho){
line.SetOrigin(p);
line.SetDirection(- vp );
} else {
line.SetOrigin(vp);
line.SetDirection(p - vp);
}
return line;
}
// Note that p it is assumed to be in window coordinate.
template <class T> Line3<T> View<T>::ViewLineFromWindow(const Point3<T> &p)
{
Line3<T> ln; // plane perpedicular to view direction and passing through manip center
Line3<T> line; // plane perpedicular to view direction and passing through manip center
Point3<T> vp=ViewPoint();
Point3<T> pp=UnProject(p);
ln.SetOrigin(vp);
ln.SetDirection(pp-vp);
return ln;
if(isOrtho){
line.SetOrigin(pp);
line.SetDirection(- vp );
} else {
line.SetOrigin(vp);
line.SetDirection(pp-vp);
}
return line;
}
template <class T> Point3<T> View<T>::Project(const Point3<T> &p) const {