2004-03-25 15:55:25 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* VCGLib o o *
|
|
|
|
* Visual and Computer Graphics Library o o *
|
|
|
|
* _ O _ *
|
|
|
|
* Copyright(C) 2004 \/)\/ *
|
|
|
|
* Visual Computing Lab /\/| *
|
|
|
|
* ISTI - Italian National Research Council | *
|
|
|
|
* \ *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
2008-10-29 01:05:44 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
2004-03-25 15:55:25 +01:00
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
|
|
|
* for more details. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
|
|
History
|
|
|
|
|
|
|
|
$Log: not supported by cvs2svn $
|
2008-02-24 19:05:08 +01:00
|
|
|
Revision 1.26 2008/02/24 14:37:00 ponchio
|
|
|
|
Restored trackball functionality. Not very much tested, and code will need some
|
|
|
|
cleanup.
|
|
|
|
|
2008-02-24 15:37:00 +01:00
|
|
|
Revision 1.25 2008/02/22 18:57:46 benedetti
|
|
|
|
first attempt to correct after quaternion ToMatrix() inversion (does not work yet)
|
|
|
|
|
2008-02-22 19:57:47 +01:00
|
|
|
Revision 1.24 2007/12/21 12:29:34 tarini
|
|
|
|
*** empty log message ***
|
|
|
|
|
2007-12-21 13:29:34 +01:00
|
|
|
Revision 1.23 2007/10/12 14:02:39 corsini
|
|
|
|
solve memory leak in dtor
|
|
|
|
|
2007-10-12 16:02:39 +02:00
|
|
|
Revision 1.22 2007/07/09 22:47:18 benedetti
|
|
|
|
Removed using namespace std and modified accordingly.
|
|
|
|
|
2007-07-10 00:47:18 +02:00
|
|
|
Revision 1.21 2007/06/20 12:59:43 corsini
|
|
|
|
adjust wheel back-compatibility
|
|
|
|
|
2007-06-20 14:59:43 +02:00
|
|
|
Revision 1.20 2007/06/13 17:15:08 benedetti
|
|
|
|
Added one-level undo system and sticky trackmodes.
|
|
|
|
|
2007-06-13 19:15:09 +02:00
|
|
|
Revision 1.19 2007/05/15 15:00:27 benedetti
|
|
|
|
Moved the drawing code to trackmodes, some other minor changes
|
|
|
|
|
2007-05-15 17:00:47 +02:00
|
|
|
Revision 1.18 2007/02/26 01:30:02 cignoni
|
|
|
|
Added reflection Name
|
|
|
|
|
2007-02-26 02:30:02 +01:00
|
|
|
Revision 1.17 2007/01/15 15:04:15 tarini
|
|
|
|
added "ToAscii" and "SetFromAscii" methods to load/store current trackball status from/to ascii strings
|
|
|
|
(intended uses: clipboard operations and comments inside png snapshots!)
|
|
|
|
|
2007-01-15 16:04:15 +01:00
|
|
|
Revision 1.16 2006/07/26 13:54:45 cignoni
|
|
|
|
Reversed the direction of wheel scaling and added middle mouse panning
|
|
|
|
|
2006-07-26 15:54:45 +02:00
|
|
|
Revision 1.15 2006/02/13 13:15:52 cignoni
|
|
|
|
Added Scale and Translate methods.
|
|
|
|
Added many drawing hints and raised the default num. of steps when drawing circles.
|
|
|
|
Added MouseDown without coords (for remembering changes of keys modifiers)
|
|
|
|
Added ZMode to the default modes under Alt+left
|
|
|
|
Added DrawPostApply (to be completed)
|
|
|
|
|
2006-02-13 14:15:52 +01:00
|
|
|
Revision 1.14 2005/10/17 01:29:46 cignoni
|
|
|
|
Main restructuring. Removed the Draw function and slightly changed the meaning of the trackball itself.
|
|
|
|
See the notes at the beginning of trackball.h
|
|
|
|
|
2005-10-17 03:29:46 +02:00
|
|
|
Revision 1.13 2005/04/17 17:48:24 ganovelli
|
|
|
|
modes deallocation commented (quick and dirty solution..to debug)
|
|
|
|
|
2005-04-17 19:48:24 +02:00
|
|
|
Revision 1.12 2004/12/17 10:28:10 ricciodimare
|
|
|
|
*** empty log message ***
|
|
|
|
|
2004-12-17 11:28:10 +01:00
|
|
|
Revision 1.11 2004/09/28 15:30:12 ponchio
|
|
|
|
Added a 'else'.
|
|
|
|
|
2004-09-28 17:30:12 +02:00
|
|
|
Revision 1.10 2004/09/09 14:38:52 ponchio
|
|
|
|
#include <gl... -> #include <GL...
|
|
|
|
|
2004-09-09 16:38:52 +02:00
|
|
|
Revision 1.9 2004/07/11 22:06:55 cignoni
|
|
|
|
Added scaling by wheel
|
|
|
|
|
2004-07-12 00:06:56 +02:00
|
|
|
Revision 1.8 2004/06/09 14:01:13 cignoni
|
|
|
|
Heavily restructured. To be completed only rotation works...
|
|
|
|
|
2004-06-09 16:01:13 +02:00
|
|
|
Revision 1.7 2004/05/14 03:15:09 ponchio
|
|
|
|
Redesigned partial version.
|
|
|
|
|
2004-05-14 05:15:09 +02:00
|
|
|
Revision 1.6 2004/05/12 20:55:18 ponchio
|
|
|
|
*** empty log message ***
|
|
|
|
|
2004-05-12 22:55:18 +02:00
|
|
|
Revision 1.5 2004/05/07 12:46:08 cignoni
|
|
|
|
Restructured and adapted in a better way to opengl
|
|
|
|
|
2004-05-07 14:46:08 +02:00
|
|
|
Revision 1.4 2004/04/07 10:54:10 cignoni
|
|
|
|
Commented out unused parameter names and other minor warning related issues
|
|
|
|
|
2004-04-07 12:54:11 +02:00
|
|
|
Revision 1.3 2004/03/31 15:08:03 ponchio
|
|
|
|
Fixed current_action initialization.
|
|
|
|
|
2004-03-31 17:08:03 +02:00
|
|
|
Revision 1.2 2004/03/25 14:55:25 ponchio
|
|
|
|
Adding copyright.
|
|
|
|
|
2004-03-25 15:55:25 +01:00
|
|
|
|
|
|
|
****************************************************************************/
|
2005-10-17 03:29:46 +02:00
|
|
|
|
2004-09-09 16:38:52 +02:00
|
|
|
#include <GL/glew.h>
|
2004-03-25 15:50:08 +01:00
|
|
|
#include "trackball.h"
|
2008-11-13 10:33:43 +01:00
|
|
|
#include<set>
|
2004-05-07 14:46:08 +02:00
|
|
|
|
2004-03-31 17:08:03 +02:00
|
|
|
#include <wrap/gl/math.h>
|
2004-05-07 14:46:08 +02:00
|
|
|
#include <wrap/gl/space.h>
|
2004-03-25 15:50:08 +01:00
|
|
|
|
2007-05-15 17:00:47 +02:00
|
|
|
using namespace vcg;
|
2004-03-25 15:50:08 +01:00
|
|
|
|
|
|
|
Transform::Transform() {
|
|
|
|
track.SetIdentity();
|
2004-05-07 14:46:08 +02:00
|
|
|
radius=1.0f;
|
|
|
|
center=Point3f(0,0,0);
|
2004-03-25 15:50:08 +01:00
|
|
|
}
|
|
|
|
|
2007-05-15 17:00:47 +02:00
|
|
|
Trackball::Trackball(): current_button(0), current_mode(NULL), inactive_mode(NULL),
|
2008-11-28 15:55:45 +01:00
|
|
|
dragging(false), last_time(0), spinnable(true), spinning(false),
|
|
|
|
history_size(10), fixedTimestepMode(false) {
|
2007-05-15 17:00:47 +02:00
|
|
|
setDefaultMapping ();
|
2004-03-25 15:50:08 +01:00
|
|
|
}
|
|
|
|
|
2008-10-29 01:05:44 +01:00
|
|
|
Trackball::~Trackball()
|
2007-10-12 16:02:39 +02:00
|
|
|
{
|
2008-11-13 10:33:43 +01:00
|
|
|
// Note: people ofter maps different keys to the same modes.
|
|
|
|
// so we should avoid double deletion of these double referenced modes.
|
|
|
|
std::set<TrackMode *> goodModes;
|
2007-10-12 16:02:39 +02:00
|
|
|
std::map<int, TrackMode *>::iterator it;
|
|
|
|
for(it = modes.begin(); it != modes.end(); it++)
|
2008-11-13 10:33:43 +01:00
|
|
|
if ((*it).second) goodModes.insert( (*it).second);
|
|
|
|
|
|
|
|
std::set<TrackMode *>::iterator its;
|
|
|
|
for(its = goodModes.begin(); its != goodModes.end(); its++)
|
|
|
|
delete *its;
|
2009-01-23 14:58:20 +01:00
|
|
|
delete inactive_mode;
|
2004-05-14 05:15:09 +02:00
|
|
|
}
|
|
|
|
|
2007-05-15 17:00:47 +02:00
|
|
|
|
|
|
|
void Trackball::setDefaultMapping () {
|
2008-11-12 17:33:40 +01:00
|
|
|
idle_and_keys_mode = NULL;
|
|
|
|
|
2007-05-15 17:00:47 +02:00
|
|
|
inactive_mode = new InactiveMode ();
|
|
|
|
modes.clear ();
|
|
|
|
modes[0] = NULL;
|
2008-11-12 17:33:40 +01:00
|
|
|
|
|
|
|
modes[BUTTON_MIDDLE | KEY_ALT] =
|
2007-05-15 17:00:47 +02:00
|
|
|
modes[BUTTON_LEFT] = new SphereMode ();
|
2008-11-12 17:33:40 +01:00
|
|
|
|
2007-05-15 17:00:47 +02:00
|
|
|
modes[BUTTON_LEFT | KEY_CTRL] = new PanMode ();
|
2008-11-12 17:33:40 +01:00
|
|
|
|
2007-05-15 17:00:47 +02:00
|
|
|
modes[BUTTON_MIDDLE] = new PanMode ();
|
2008-11-12 17:33:40 +01:00
|
|
|
|
|
|
|
modes[WHEEL] =
|
2007-05-15 17:00:47 +02:00
|
|
|
modes[BUTTON_LEFT | KEY_SHIFT] = new ScaleMode ();
|
2008-11-12 17:33:40 +01:00
|
|
|
|
2007-05-15 17:00:47 +02:00
|
|
|
modes[BUTTON_LEFT | KEY_ALT] = new ZMode ();
|
2008-11-12 17:33:40 +01:00
|
|
|
|
2007-05-15 17:00:47 +02:00
|
|
|
}
|
|
|
|
|
2004-03-25 15:50:08 +01:00
|
|
|
void Trackball::SetIdentity() {
|
2004-05-07 14:46:08 +02:00
|
|
|
track.SetIdentity();
|
2004-03-25 15:50:08 +01:00
|
|
|
Reset();
|
|
|
|
}
|
2004-05-07 14:46:08 +02:00
|
|
|
void Trackball::SetPosition(const Point3f &c, int /* millisec */) {
|
|
|
|
center = c;
|
2004-03-25 15:50:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Trackball::GetView() {
|
|
|
|
camera.GetView();
|
|
|
|
}
|
2004-05-14 05:15:09 +02:00
|
|
|
|
2007-05-15 17:00:47 +02:00
|
|
|
// the drawing code has been moved to the trackmodes
|
2008-10-29 01:05:44 +01:00
|
|
|
void Trackball::DrawPostApply() {
|
2007-05-15 17:00:47 +02:00
|
|
|
if(current_mode !=NULL){
|
|
|
|
current_mode->Draw(this);
|
|
|
|
}else{
|
2008-11-12 17:33:40 +01:00
|
|
|
if (inactive_mode != NULL) inactive_mode->Draw(this);
|
|
|
|
}
|
2007-05-15 17:00:47 +02:00
|
|
|
}
|
2006-02-13 14:15:52 +01:00
|
|
|
|
2007-05-15 17:00:47 +02:00
|
|
|
void Trackball::Apply () {
|
2008-10-30 12:31:28 +01:00
|
|
|
glTranslate (center);
|
2008-02-24 19:05:08 +01:00
|
|
|
glMultMatrix (track.Matrix());
|
2007-05-15 17:00:47 +02:00
|
|
|
glTranslate (-center);
|
2006-02-13 14:15:52 +01:00
|
|
|
}
|
|
|
|
|
2008-10-29 01:05:44 +01:00
|
|
|
void Trackball::Apply(bool ToDraw) {
|
2007-05-15 17:00:47 +02:00
|
|
|
Apply();
|
|
|
|
if(ToDraw){
|
|
|
|
DrawPostApply();
|
2005-10-17 03:29:46 +02:00
|
|
|
}
|
2004-06-09 16:01:13 +02:00
|
|
|
}
|
|
|
|
|
2007-05-15 17:00:47 +02:00
|
|
|
|
2008-10-29 01:05:44 +01:00
|
|
|
void Trackball::ApplyInverse() {
|
2004-06-09 16:01:13 +02:00
|
|
|
glTranslate(center);
|
|
|
|
glMultMatrix(track.InverseMatrix());
|
|
|
|
glTranslate(-center);
|
2004-05-07 14:46:08 +02:00
|
|
|
}
|
|
|
|
|
2009-03-31 11:03:18 +02:00
|
|
|
// 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());
|
|
|
|
}
|
|
|
|
|
2006-02-13 14:15:52 +01:00
|
|
|
void Trackball::Scale(const float s)
|
|
|
|
{
|
|
|
|
track.sca*=s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Trackball::Translate(Point3f tr)
|
|
|
|
{
|
2008-02-24 19:05:08 +01:00
|
|
|
Quaternionf irot = track.rot;
|
|
|
|
irot.Invert();
|
|
|
|
track.tra = last_track.tra + irot.Rotate(tr)/track.sca;
|
2006-02-13 14:15:52 +01:00
|
|
|
}
|
|
|
|
|
2004-05-07 14:46:08 +02:00
|
|
|
/***************************************************************/
|
2007-05-15 17:00:47 +02:00
|
|
|
// DrawCircle () e DrawPlane() have been moved to trackutils.h
|
|
|
|
// the drawing code has been moved to the trackmodes
|
|
|
|
/*
|
2004-05-14 05:15:09 +02:00
|
|
|
void Trackball::DrawCircle() {
|
2004-07-12 00:06:56 +02:00
|
|
|
int nside=DH.CircleStep;
|
2004-05-14 05:15:09 +02:00
|
|
|
const double pi2=3.14159265*2.0;
|
2006-02-13 14:15:52 +01:00
|
|
|
glBegin(GL_LINE_LOOP);
|
|
|
|
for(double i=0;i<nside;i++){
|
2004-05-14 05:15:09 +02:00
|
|
|
glNormal3d(cos(i*pi2/nside), sin(i*pi2/nside), 0.0);
|
|
|
|
glVertex3d(cos(i*pi2/nside), sin(i*pi2/nside), 0.0);
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
DrawPlaneHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Trackball::DrawPlane() {
|
|
|
|
const int nl=10;
|
|
|
|
float w=5.0f/3.0f;
|
|
|
|
float u;
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glNormal3f(0.0,0.0,1.0);
|
|
|
|
for( u=-w; u<=w+0.01f; u+=2*w/nl){
|
|
|
|
glVertex3f(-w, +u, 0);
|
|
|
|
glVertex3f(+w, +u, 0);
|
|
|
|
glVertex3f(+u, -w, 0);
|
|
|
|
glVertex3f(+u, +w, 0);
|
|
|
|
}
|
|
|
|
glEnd();
|
2004-05-07 14:46:08 +02:00
|
|
|
}
|
2007-05-15 17:00:47 +02:00
|
|
|
*/
|
2004-05-07 14:46:08 +02:00
|
|
|
|
2007-01-15 16:04:15 +01:00
|
|
|
void Trackball::ToAscii(char* result){
|
|
|
|
float * f = (float*) &track;
|
2009-03-31 11:03:18 +02:00
|
|
|
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] );
|
2007-01-15 16:04:15 +01:00
|
|
|
}
|
|
|
|
|
2007-12-21 13:29:34 +01:00
|
|
|
bool Trackball::SetFromAscii(const char * st){
|
2007-01-15 16:04:15 +01:00
|
|
|
float * f = (float*) &track;
|
2009-03-31 11:03:18 +02:00
|
|
|
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 );
|
2007-01-15 16:04:15 +01:00
|
|
|
|
2009-03-31 11:03:18 +02:00
|
|
|
return (res==8);
|
2007-01-15 16:04:15 +01:00
|
|
|
}
|
|
|
|
|
2007-05-15 17:00:47 +02:00
|
|
|
// DrawPlaneHandle() e DrawIcon() have been moved to trackutils.h
|
|
|
|
// the drawing code has been moved to the trackmodes
|
|
|
|
/*
|
2004-05-14 05:15:09 +02:00
|
|
|
void Trackball::DrawPlaneHandle() {
|
|
|
|
float r=1.0;
|
|
|
|
float dr=r/10.0f;
|
|
|
|
glBegin(GL_LINE_STRIP);
|
|
|
|
glVertex3f(+r+dr, +r, 0.0);
|
|
|
|
glVertex3f(+r , +r+dr,0.0);
|
|
|
|
glVertex3f(+r-dr, +r, 0.0);
|
|
|
|
glVertex3f(+r , +r-dr,0.0);
|
|
|
|
glVertex3f(+r+dr, +r, 0.0);
|
|
|
|
glEnd();
|
|
|
|
glBegin(GL_LINE_STRIP);
|
|
|
|
glVertex3f(-r+dr, -r, 0.0);
|
|
|
|
glVertex3f(-r , -r+dr,0.0);
|
|
|
|
glVertex3f(-r-dr, -r, 0.0);
|
|
|
|
glVertex3f(-r , -r-dr,0.0);
|
|
|
|
glVertex3f(-r+dr, -r, 0.0);
|
|
|
|
glEnd();
|
2004-03-25 15:50:08 +01:00
|
|
|
}
|
|
|
|
|
2005-10-17 03:29:46 +02:00
|
|
|
void Trackball::DrawIcon() {
|
2004-03-25 15:50:08 +01:00
|
|
|
glPushMatrix();
|
2008-10-29 01:05:44 +01:00
|
|
|
|
2005-10-17 03:29:46 +02:00
|
|
|
glScale(radius);
|
2004-05-07 14:46:08 +02:00
|
|
|
/// Here start the real drawing stuff
|
2004-05-14 05:15:09 +02:00
|
|
|
float amb[4] ={.3f,.3f,.3f,1.0f};
|
|
|
|
float col[4] ={.5f,.5f,.8f,1.0f};
|
2004-07-12 00:06:56 +02:00
|
|
|
//float col2[4]={.9f,.9f,1.0f,1.0f};
|
2004-05-14 05:15:09 +02:00
|
|
|
glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_CURRENT_BIT | GL_LIGHTING_BIT);
|
2006-02-13 14:15:52 +01:00
|
|
|
|
2008-10-29 01:05:44 +01:00
|
|
|
|
2006-02-13 14:15:52 +01:00
|
|
|
if(current_mode == NULL ) glLineWidth(DH.LineWidthStill);
|
|
|
|
else glLineWidth(DH.LineWidthMoving);
|
2008-10-29 01:05:44 +01:00
|
|
|
|
2004-05-14 05:15:09 +02:00
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
glEnable(GL_LIGHT0);
|
|
|
|
glEnable(GL_LINE_SMOOTH);
|
|
|
|
glEnable(GL_BLEND);
|
2006-02-13 14:15:52 +01:00
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glColor(DH.color);
|
2008-10-29 01:05:44 +01:00
|
|
|
|
2004-05-14 05:15:09 +02:00
|
|
|
glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,amb);
|
|
|
|
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,col);
|
|
|
|
glPushMatrix();
|
2004-06-09 16:01:13 +02:00
|
|
|
DrawCircle();
|
|
|
|
glPushMatrix();
|
2008-10-29 01:05:44 +01:00
|
|
|
|
2004-06-09 16:01:13 +02:00
|
|
|
glRotatef(90,1,0,0);
|
|
|
|
DrawCircle();
|
|
|
|
glRotatef(90,0,1,0);
|
|
|
|
DrawCircle();
|
2008-10-29 01:05:44 +01:00
|
|
|
|
2004-06-09 16:01:13 +02:00
|
|
|
glPopMatrix();
|
2004-05-14 05:15:09 +02:00
|
|
|
glPopMatrix();
|
2008-10-29 01:05:44 +01:00
|
|
|
|
2006-02-13 14:15:52 +01:00
|
|
|
//glColor4f(1.0,.8f,.8f,1.0f);
|
2004-05-14 05:15:09 +02:00
|
|
|
|
|
|
|
glPopAttrib();
|
2004-05-07 14:46:08 +02:00
|
|
|
|
2004-03-25 15:50:08 +01:00
|
|
|
glPopMatrix();
|
|
|
|
}
|
2007-05-15 17:00:47 +02:00
|
|
|
*/
|
2004-03-25 15:50:08 +01:00
|
|
|
|
|
|
|
void Trackball::Reset() {
|
|
|
|
track.SetIdentity();
|
2007-06-13 19:15:09 +02:00
|
|
|
undo_track = track;
|
2007-07-10 00:47:18 +02:00
|
|
|
std::map<int, TrackMode *>::iterator i;
|
2007-05-15 17:00:47 +02:00
|
|
|
for(i = modes.begin(); i != modes.end(); i++){
|
|
|
|
TrackMode * mode=(*i).second;
|
|
|
|
if(mode!=NULL)
|
|
|
|
mode->Reset();
|
|
|
|
}
|
2008-11-12 17:33:40 +01:00
|
|
|
if (inactive_mode != NULL) inactive_mode->Reset();
|
2007-05-15 17:00:47 +02:00
|
|
|
}
|
2004-03-25 15:50:08 +01:00
|
|
|
|
|
|
|
//interface
|
2006-02-13 14:15:52 +01:00
|
|
|
void Trackball::MouseDown(int button) {
|
2007-06-13 19:15:09 +02:00
|
|
|
undo_track = track;
|
2008-10-29 01:05:44 +01:00
|
|
|
current_button |= button;
|
2006-02-13 14:15:52 +01:00
|
|
|
SetCurrentAction();
|
|
|
|
Hits.clear();
|
|
|
|
}
|
2004-06-09 16:01:13 +02:00
|
|
|
void Trackball::MouseDown(int x, int y, int button) {
|
2007-06-13 19:15:09 +02:00
|
|
|
undo_track = track;
|
2008-10-29 01:05:44 +01:00
|
|
|
current_button |= button;
|
2004-03-25 15:50:08 +01:00
|
|
|
SetCurrentAction();
|
2004-05-14 05:15:09 +02:00
|
|
|
last_point = Point3f((float)x, (float)y, 0);
|
2004-06-09 16:01:13 +02:00
|
|
|
Hits.clear();
|
2004-03-25 15:50:08 +01:00
|
|
|
}
|
|
|
|
|
2008-10-29 01:05:44 +01:00
|
|
|
void Trackball::MouseMove(int x, int y) {
|
|
|
|
if(current_mode == NULL) return;
|
2004-05-14 05:15:09 +02:00
|
|
|
if(last_point[2] == -1) { //changed mode in the middle of moving
|
|
|
|
last_point = Point3f((float)x, (float)y, 0);
|
2004-03-25 15:50:08 +01:00
|
|
|
return;
|
|
|
|
}
|
2007-06-13 19:15:09 +02:00
|
|
|
undo_track = track;
|
2004-05-14 05:15:09 +02:00
|
|
|
current_mode->Apply(this, Point3f(float(x), float(y), 0));
|
2008-10-29 01:05:44 +01:00
|
|
|
}
|
2004-03-25 15:50:08 +01:00
|
|
|
|
2008-11-12 17:33:40 +01:00
|
|
|
bool Trackball::IsAnimating(unsigned int msec){
|
|
|
|
bool res;
|
|
|
|
if(idle_and_keys_mode == NULL) res=false; else res=idle_and_keys_mode->IsAnimating(this);
|
|
|
|
|
|
|
|
if (!fixedTimestepMode) {
|
|
|
|
if (msec==0) msec = clock()*1000/CLOCKS_PER_SEC;
|
|
|
|
if (!res) {
|
|
|
|
last_time = msec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Trackball::Sync(unsigned int msec) {
|
|
|
|
if (!fixedTimestepMode) Animate(msec);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Trackball::Animate(unsigned int msec){
|
|
|
|
unsigned int delta;
|
|
|
|
if (fixedTimestepMode) delta=msec;
|
|
|
|
else {
|
|
|
|
if (msec==0) msec = clock()*1000/CLOCKS_PER_SEC;
|
|
|
|
delta = msec -last_time;
|
|
|
|
last_time = msec;
|
|
|
|
}
|
|
|
|
if(idle_and_keys_mode == NULL) return;
|
|
|
|
idle_and_keys_mode->Animate(delta,this);
|
|
|
|
}
|
|
|
|
|
2008-10-29 01:05:44 +01:00
|
|
|
void Trackball::MouseUp(int /* x */, int /* y */, int button) {
|
2007-06-13 19:15:09 +02:00
|
|
|
undo_track = track;
|
2008-11-12 17:33:40 +01:00
|
|
|
ButtonUp(vcg::Trackball::Button(button));
|
|
|
|
//current_button &= (~button);
|
|
|
|
//SetCurrentAction();
|
2008-10-29 01:05:44 +01:00
|
|
|
}
|
2007-05-15 17:00:47 +02:00
|
|
|
|
|
|
|
// it assumes that a notch of 1.0 is a single step of the wheel
|
2008-10-29 01:05:44 +01:00
|
|
|
void Trackball::MouseWheel(float notch)
|
2007-06-20 14:59:43 +02:00
|
|
|
{
|
2007-06-13 19:15:09 +02:00
|
|
|
undo_track = track;
|
2007-06-20 14:59:43 +02:00
|
|
|
int buttons = current_button;
|
|
|
|
current_button = WHEEL | (buttons&(KEY_SHIFT|KEY_CTRL|KEY_ALT));
|
|
|
|
SetCurrentAction();
|
|
|
|
if (current_mode == NULL)
|
2004-07-12 00:06:56 +02:00
|
|
|
{
|
2008-11-12 17:33:40 +01:00
|
|
|
//ScaleMode scalemode;
|
|
|
|
//scalemode.Apply (this, notch);
|
2008-10-29 01:05:44 +01:00
|
|
|
}
|
2007-06-20 14:59:43 +02:00
|
|
|
else
|
|
|
|
{
|
2007-05-15 17:00:47 +02:00
|
|
|
current_mode->Apply(this, notch);
|
|
|
|
}
|
2007-06-20 14:59:43 +02:00
|
|
|
current_button = buttons;
|
|
|
|
SetCurrentAction();
|
2007-05-15 17:00:47 +02:00
|
|
|
}
|
|
|
|
|
2007-06-20 14:59:43 +02:00
|
|
|
void Trackball::MouseWheel(float notch, int button)
|
2007-05-15 17:00:47 +02:00
|
|
|
{
|
2007-06-13 19:15:09 +02:00
|
|
|
undo_track = track;
|
2007-05-15 17:00:47 +02:00
|
|
|
current_button |= button;
|
2007-06-20 14:59:43 +02:00
|
|
|
SetCurrentAction();
|
2007-05-15 17:00:47 +02:00
|
|
|
if (current_mode == NULL) {
|
|
|
|
ScaleMode scalemode;
|
|
|
|
scalemode.Apply (this, notch);
|
|
|
|
} else {
|
|
|
|
current_mode->Apply (this, notch);
|
|
|
|
}
|
|
|
|
current_button &= (~button);
|
|
|
|
SetCurrentAction ();
|
2004-03-25 15:50:08 +01:00
|
|
|
}
|
|
|
|
|
2008-11-12 17:33:40 +01:00
|
|
|
void Trackball::ButtonDown(Trackball::Button button, unsigned int msec) {
|
|
|
|
Sync(msec);
|
2007-06-13 19:15:09 +02:00
|
|
|
bool old_sticky=false, new_sticky=false;
|
|
|
|
assert (modes.count (0));
|
2008-11-12 17:33:40 +01:00
|
|
|
|
|
|
|
Button b=Button(current_button & MODIFIER_MASK);
|
|
|
|
if ( ( modes.count (b) ) && ( modes[b] != NULL ) ) old_sticky = modes[b]->isSticky();
|
|
|
|
|
2008-10-29 01:05:44 +01:00
|
|
|
current_button |= button;
|
2008-11-12 17:33:40 +01:00
|
|
|
b=Button(current_button & MODIFIER_MASK);
|
|
|
|
if ( ( modes.count (b) ) && ( modes[b] != NULL ) ) new_sticky = modes[b]->isSticky();
|
|
|
|
|
|
|
|
if ( !old_sticky && !new_sticky) SetCurrentAction();
|
|
|
|
|
2004-03-25 15:50:08 +01:00
|
|
|
}
|
|
|
|
|
2008-10-29 01:05:44 +01:00
|
|
|
void Trackball::ButtonUp(Trackball::Button button) {
|
2007-06-13 19:15:09 +02:00
|
|
|
bool old_sticky=false, new_sticky=false;
|
2008-11-12 17:33:40 +01:00
|
|
|
assert (modes.count (0));
|
|
|
|
|
|
|
|
Button b=Button(current_button & MODIFIER_MASK);
|
|
|
|
if ( ( modes.count (b) ) && ( modes[b] != NULL ) ) old_sticky = modes[b]->isSticky();
|
|
|
|
|
2008-10-29 01:05:44 +01:00
|
|
|
current_button &= (~button);
|
2008-11-12 17:33:40 +01:00
|
|
|
b=Button(current_button & MODIFIER_MASK);
|
|
|
|
if ( ( modes.count (b) ) && ( modes[b] != NULL ) ) new_sticky = modes[b]->isSticky();
|
|
|
|
|
|
|
|
if ( !old_sticky && !new_sticky) SetCurrentAction();
|
2004-03-25 15:50:08 +01:00
|
|
|
}
|
|
|
|
|
2007-06-13 19:15:09 +02:00
|
|
|
void Trackball::Undo(){
|
|
|
|
track = undo_track;
|
|
|
|
if(current_mode != NULL)
|
|
|
|
current_mode->Undo();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-25 15:50:08 +01:00
|
|
|
//spinning interface
|
2004-04-07 12:54:11 +02:00
|
|
|
void Trackball::SetSpinnable(bool /* on*/ ){}
|
2004-03-25 15:50:08 +01:00
|
|
|
bool Trackball::IsSpinnable() {
|
|
|
|
return spinnable;
|
2008-10-29 01:05:44 +01:00
|
|
|
}
|
2004-04-07 12:54:11 +02:00
|
|
|
void Trackball::SetSpinning(Quaternionf &/* spin*/){}
|
2004-03-25 15:50:08 +01:00
|
|
|
void Trackball::StopSpinning(){}
|
|
|
|
bool Trackball::IsSpinning() {
|
|
|
|
return spinning;
|
2008-10-29 01:05:44 +01:00
|
|
|
}
|
2004-03-25 15:50:08 +01:00
|
|
|
|
2007-05-15 17:00:47 +02:00
|
|
|
//navigation interface:
|
2004-03-25 15:50:08 +01:00
|
|
|
void Trackball::Back(){}
|
|
|
|
void Trackball::Forward(){}
|
|
|
|
void Trackball::Home(){}
|
2007-05-15 17:00:47 +02:00
|
|
|
void Trackball::HistorySize(int /* length */){}
|
2004-03-25 15:50:08 +01:00
|
|
|
|
2007-05-15 17:00:47 +02:00
|
|
|
void Trackball::SetCurrentAction ()
|
|
|
|
{
|
2004-03-25 15:50:08 +01:00
|
|
|
//I use strict matching.
|
2007-05-15 17:00:47 +02:00
|
|
|
assert (modes.count (0));
|
2008-11-12 17:33:40 +01:00
|
|
|
if (!modes.count (current_button & MODIFIER_MASK)) {
|
2004-05-14 05:15:09 +02:00
|
|
|
current_mode = NULL;
|
2007-05-15 17:00:47 +02:00
|
|
|
} else {
|
2008-11-12 17:33:40 +01:00
|
|
|
current_mode = modes[current_button & MODIFIER_MASK];
|
2007-05-15 17:00:47 +02:00
|
|
|
if(current_mode != NULL)
|
|
|
|
current_mode->SetAction();
|
|
|
|
}
|
|
|
|
last_point = Point3f (0, 0, -1);
|
2004-03-25 15:50:08 +01:00
|
|
|
last_track = track;
|
|
|
|
}
|
|
|
|
|
2004-05-07 14:46:08 +02:00
|
|
|
////return center of trackball in Window coordinates.
|
2008-10-29 01:05:44 +01:00
|
|
|
//Point3f Trackball::ScreenOrigin() {
|
|
|
|
// return camera.Project(ModelOrigin());
|
2004-05-07 14:46:08 +02:00
|
|
|
//}
|
|
|
|
|
2004-03-25 15:50:08 +01:00
|
|
|
|
|
|
|
//return center of trackball in Model coordinates
|
2004-05-14 05:15:09 +02:00
|
|
|
//Point3f Trackball::ModelOrigin() {
|
2008-10-29 01:05:44 +01:00
|
|
|
// return center;
|
2004-05-14 05:15:09 +02:00
|
|
|
//}
|
2004-03-25 15:50:08 +01:00
|
|
|
|
2004-05-07 14:46:08 +02:00
|
|
|
//Matrix44f Trackball::ScreenToModel() {
|
|
|
|
// return camera.inverse;
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//Similarityf Trackball::ModelToLocal() {
|
|
|
|
// Similarityf m = local * last_track;
|
|
|
|
// return m;
|
|
|
|
//}
|
2004-03-25 15:50:08 +01:00
|
|
|
|