Restored trackball functionality. Not very much tested, and code will need some
cleanup.
This commit is contained in:
parent
16b3a3e11a
commit
7006d170be
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.25 2008/02/22 18:57:46 benedetti
|
||||||
|
first attempt to correct after quaternion ToMatrix() inversion (does not work yet)
|
||||||
|
|
||||||
Revision 1.24 2007/12/21 12:29:34 tarini
|
Revision 1.24 2007/12/21 12:29:34 tarini
|
||||||
*** empty log message ***
|
*** empty log message ***
|
||||||
|
|
||||||
|
@ -195,9 +198,10 @@ void Trackball::Scale(const float s)
|
||||||
|
|
||||||
void Trackball::Translate(Point3f tr)
|
void Trackball::Translate(Point3f tr)
|
||||||
{
|
{
|
||||||
Matrix44f m;
|
// Matrix44f m;
|
||||||
track.rot.ToMatrix(m);
|
// track.rot.ToMatrix(m);
|
||||||
track.tra = last_track.tra + m*tr/track.sca;
|
// track.tra = last_track.tra + m*tr/track.sca;
|
||||||
|
track.tra = last_track.tra + tr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.26 2008/02/15 20:56:41 benedetti
|
||||||
|
removed some variable initialization related warning, added snap to CylinderMode
|
||||||
|
|
||||||
Revision 1.25 2007/10/24 10:39:07 ponchio
|
Revision 1.25 2007/10/24 10:39:07 ponchio
|
||||||
#include <gl/glew.h> -> #include <GL/glew.h>
|
#include <gl/glew.h> -> #include <GL/glew.h>
|
||||||
|
|
||||||
|
@ -167,11 +170,12 @@ void SphereMode::Apply (Trackball * tb, Point3f new_point)
|
||||||
Point3f hitOld = HitSphere (tb, tb->last_point);
|
Point3f hitOld = HitSphere (tb, tb->last_point);
|
||||||
Point3f hitNew = HitSphere (tb, new_point);
|
Point3f hitNew = HitSphere (tb, new_point);
|
||||||
tb->Hits.push_back (hitNew);
|
tb->Hits.push_back (hitNew);
|
||||||
Point3f center = tb->center;
|
Point3f center = tb->center + tb->track.tra;
|
||||||
Point3f axis = (hitNew - center) ^ (hitOld - center);
|
Point3f axis = (hitNew - center) ^ (hitOld - center);
|
||||||
// Figure out how much to rotate around that axis.
|
// Figure out how much to rotate around that axis.
|
||||||
float phi = Distance (hitNew, hitOld) / tb->radius;
|
float phi = Distance (hitNew, hitOld) / tb->radius;
|
||||||
tb->track.rot = tb->last_track.rot * Quaternionf (phi, axis);
|
// tb->track.rot = tb->last_track.rot * Quaternionf (-phi, axis);
|
||||||
|
tb->track.rot = Quaternionf (-phi, axis) * tb->last_track.rot;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SphereMode::Draw(Trackball * tb){
|
void SphereMode::Draw(Trackball * tb){
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
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
|
Revision 1.8 2008/02/15 20:54:45 benedetti
|
||||||
removed some variable initialization related warning
|
removed some variable initialization related warning
|
||||||
|
|
||||||
|
@ -62,6 +65,8 @@ Utility functions for the trackmodes, first version
|
||||||
#include <wrap/gl/math.h>
|
#include <wrap/gl/math.h>
|
||||||
#include <wrap/gl/space.h>
|
#include <wrap/gl/space.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
namespace vcg {
|
namespace vcg {
|
||||||
|
|
||||||
|
@ -216,17 +221,20 @@ eq cono y=x+sqrt(2);
|
||||||
*/
|
*/
|
||||||
Point3f HitSphere (Trackball * tb, const Point3f & p)
|
Point3f HitSphere (Trackball * tb, const Point3f & p)
|
||||||
{
|
{
|
||||||
// const float Thr = tb->radius/math::Sqrt(2.0f);
|
Point3f center = tb->center + tb->track.tra;
|
||||||
Line3fN vn = tb->camera.ViewLineFromModel (tb->center);
|
Line3fN ln = tb->camera.ViewLineFromWindow (Point3f (p[0], p[1], 0));
|
||||||
Line3fN ln = tb->camera.ViewLineFromWindow (Point3f (p[0], p[1], 0));
|
Plane3f vp = GetViewPlane (tb->camera, center);
|
||||||
Point3f viewpoint = tb->camera.ViewPoint ();
|
Point3f hitPlane(0,0,0), //intersection view plane with point touched
|
||||||
Plane3f vp = GetViewPlane (tb->camera, tb->center);
|
hitSphere(0,0,0),
|
||||||
Point3f hit(0,0,0), hitPlane(0,0,0), hitSphere(0,0,0), hitSphere1(0,0,0), hitSphere2(0,0,0), hitHyper(0,0,0);
|
hitSphere1(0,0,0),
|
||||||
|
hitSphere2(0,0,0),
|
||||||
|
hitHyper(0,0,0);
|
||||||
IntersectionLinePlane < float >(vp, ln, hitPlane);
|
IntersectionLinePlane < float >(vp, ln, hitPlane);
|
||||||
|
|
||||||
Sphere3f sphere (tb->center, tb->radius);
|
Sphere3f sphere (center, tb->radius);//trackball sphere
|
||||||
bool resSp = IntersectionLineSphere < float >(sphere, ln, hitSphere1, hitSphere2);
|
bool resSp = IntersectionLineSphere < float >(sphere, ln, hitSphere1, hitSphere2);
|
||||||
|
|
||||||
|
Point3f viewpoint = tb->camera.ViewPoint ();
|
||||||
if (resSp == true) {
|
if (resSp == true) {
|
||||||
if (Distance (viewpoint, hitSphere1) < Distance (viewpoint, hitSphere2))
|
if (Distance (viewpoint, hitSphere1) < Distance (viewpoint, hitSphere2))
|
||||||
hitSphere = hitSphere1;
|
hitSphere = hitSphere1;
|
||||||
|
@ -234,14 +242,14 @@ Point3f HitSphere (Trackball * tb, const Point3f & p)
|
||||||
hitSphere = hitSphere2;
|
hitSphere = hitSphere2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*float dl= */ Distance (ln, tb->center);
|
/*float dl= */ Distance (ln, center);
|
||||||
bool resHp = HitHyper (tb->center, tb->radius, viewpoint, vp, hitPlane, hitHyper);
|
bool resHp = HitHyper (center, tb->radius, viewpoint, vp, hitPlane, hitHyper);
|
||||||
|
|
||||||
// four cases
|
// four cases
|
||||||
|
|
||||||
// 1) Degenerate line tangent to both sphere and hyperboloid!
|
// 1) Degenerate line tangent to both sphere and hyperboloid!
|
||||||
if ((!resSp && !resHp)) {
|
if ((!resSp && !resHp)) {
|
||||||
hit = ClosestPoint (ln, tb->center);
|
Point3f hit = ClosestPoint (ln, center);
|
||||||
//printf("closest point to line %f\n",Distance(hit,tb->center));
|
//printf("closest point to line %f\n",Distance(hit,tb->center));
|
||||||
return hit;
|
return hit;
|
||||||
}
|
}
|
||||||
|
@ -251,7 +259,7 @@ Point3f HitSphere (Trackball * tb, const Point3f & p)
|
||||||
return hitHyper; // 3) line cross only the hyperboloid
|
return hitHyper; // 3) line cross only the hyperboloid
|
||||||
|
|
||||||
// 4) line cross both sphere and hyperboloid: choose according angle.
|
// 4) line cross both sphere and hyperboloid: choose according angle.
|
||||||
float angleDeg = math::ToDeg (Angle ((viewpoint - tb->center), (hitSphere - tb->center)));
|
float angleDeg = math::ToDeg (Angle ((viewpoint - center), (hitSphere - center)));
|
||||||
|
|
||||||
//printf("Angle %f (%5.2f %5.2f %5.2f) (%5.2f %5.2f %5.2f)\n",angleDeg,hitSphere[0],hitSphere[1],hitSphere[2],hitHyper[0],hitHyper[1],hitHyper[2]);
|
//printf("Angle %f (%5.2f %5.2f %5.2f) (%5.2f %5.2f %5.2f)\n",angleDeg,hitSphere[0],hitSphere[1],hitSphere[2],hitHyper[0],hitHyper[1],hitHyper[2]);
|
||||||
if (angleDeg < 45)
|
if (angleDeg < 45)
|
||||||
|
@ -667,12 +675,7 @@ void DrawSphereIcon (Trackball * tb,bool active)
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPushMatrix ();
|
glPushMatrix ();
|
||||||
glTranslate (tb->center);
|
glTranslate (tb->center);
|
||||||
glMultMatrix (tb->track.InverseMatrix ());
|
|
||||||
glScale (tb->radius);
|
glScale (tb->radius);
|
||||||
Matrix44f r;
|
|
||||||
tb->track.rot.ToMatrix (r);
|
|
||||||
|
|
||||||
glMultMatrix (Inverse(r));
|
|
||||||
|
|
||||||
float amb[4] = { .3f, .3f, .3f, 1.0f };
|
float amb[4] = { .3f, .3f, .3f, 1.0f };
|
||||||
float col[4] = { .5f, .5f, .8f, 1.0f };
|
float col[4] = { .5f, .5f, .8f, 1.0f };
|
||||||
|
|
Loading…
Reference in New Issue