Moved the dreawing code to trackmodes, some other minor changes
This commit is contained in:
parent
db4c4f0944
commit
0fd4e977e5
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.18 2007/02/26 01:30:02 cignoni
|
||||||
|
Added reflection Name
|
||||||
|
|
||||||
Revision 1.17 2007/01/15 15:04:15 tarini
|
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
|
added "ToAscii" and "SetFromAscii" methods to load/store current trackball status from/to ascii strings
|
||||||
(intended uses: clipboard operations and comments inside png snapshots!)
|
(intended uses: clipboard operations and comments inside png snapshots!)
|
||||||
|
@ -86,9 +89,8 @@ Adding copyright.
|
||||||
|
|
||||||
#include <wrap/gl/math.h>
|
#include <wrap/gl/math.h>
|
||||||
#include <wrap/gl/space.h>
|
#include <wrap/gl/space.h>
|
||||||
using namespace vcg;
|
|
||||||
|
|
||||||
#include <iostream> //debug!
|
using namespace vcg;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Transform::Transform() {
|
Transform::Transform() {
|
||||||
|
@ -97,26 +99,32 @@ Transform::Transform() {
|
||||||
center=Point3f(0,0,0);
|
center=Point3f(0,0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Trackball::Trackball(): current_button(0), current_mode(NULL),
|
Trackball::Trackball(): current_button(0), current_mode(NULL), inactive_mode(NULL),
|
||||||
dragging(false), spinnable(true), spinning(false),
|
dragging(false), spinnable(true), spinning(false),
|
||||||
history_size(10) {
|
history_size(10){
|
||||||
//here we add mode
|
setDefaultMapping ();
|
||||||
modes[0] = NULL;
|
|
||||||
modes[BUTTON_LEFT] = new SphereMode();
|
|
||||||
modes[BUTTON_LEFT | KEY_CTRL] = new PlaneMode(Plane3f(0, Point3f(1, 0, 0)));
|
|
||||||
modes[BUTTON_MIDDLE] = new PlaneMode(Plane3f(0, Point3f(1, 0, 0)));
|
|
||||||
modes[BUTTON_LEFT | KEY_SHIFT] = new ScaleMode();
|
|
||||||
modes[BUTTON_LEFT | KEY_ALT ] = new ZMode();
|
|
||||||
modes[WHEEL] = new ScaleMode();
|
|
||||||
SetCurrentAction();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Trackball::~Trackball() {
|
Trackball::~Trackball() {
|
||||||
map<int, TrackMode *>::iterator i;
|
//map<int, TrackMode *>::iterator i;
|
||||||
//for(i = modes.begin(); i != modes.end(); i++)
|
//for(i = modes.begin(); i != modes.end(); i++)
|
||||||
// delete (*i).second;
|
// delete (*i).second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Trackball::setDefaultMapping () {
|
||||||
|
inactive_mode = new InactiveMode ();
|
||||||
|
modes.clear ();
|
||||||
|
modes[0] = NULL;
|
||||||
|
modes[BUTTON_LEFT] = new SphereMode ();
|
||||||
|
modes[BUTTON_LEFT | KEY_CTRL] = new PanMode ();
|
||||||
|
modes[BUTTON_MIDDLE] = new PanMode ();
|
||||||
|
modes[BUTTON_LEFT | KEY_SHIFT] = new ScaleMode ();
|
||||||
|
modes[BUTTON_LEFT | KEY_ALT] = new ZMode ();
|
||||||
|
modes[WHEEL] = new ScaleMode ();
|
||||||
|
SetCurrentAction ();
|
||||||
|
}
|
||||||
|
|
||||||
void Trackball::SetIdentity() {
|
void Trackball::SetIdentity() {
|
||||||
track.SetIdentity();
|
track.SetIdentity();
|
||||||
Reset();
|
Reset();
|
||||||
|
@ -129,41 +137,30 @@ void Trackball::GetView() {
|
||||||
camera.GetView();
|
camera.GetView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the drawing code has been moved to the trackmodes
|
||||||
void Trackball::DrawPostApply() {
|
void Trackball::DrawPostApply() {
|
||||||
glPushMatrix();
|
if(current_mode !=NULL){
|
||||||
|
current_mode->Draw(this);
|
||||||
|
}else{
|
||||||
|
assert(inactive_mode != NULL);
|
||||||
|
inactive_mode->Draw(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
glTranslate(center);
|
void Trackball::Apply () {
|
||||||
glMultMatrix(track.InverseMatrix());
|
glTranslate (center);
|
||||||
Matrix44f r;
|
glMultMatrix (track.Matrix ());
|
||||||
track.rot.ToMatrix(r);
|
glTranslate (-center);
|
||||||
glMultMatrix(r);
|
|
||||||
DrawIcon();
|
|
||||||
|
|
||||||
glTranslate(-center);
|
|
||||||
glMultMatrix(track.Matrix());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Trackball::Apply(bool ToDraw) {
|
void Trackball::Apply(bool ToDraw) {
|
||||||
glTranslate(center);
|
Apply();
|
||||||
if(ToDraw)
|
if(ToDraw){
|
||||||
{
|
DrawPostApply();
|
||||||
if(DH.DrawTrack) {
|
|
||||||
glBegin(GL_LINE_STRIP);
|
|
||||||
for(vector<Point3f>::iterator vi=Hits.begin();vi!=Hits.end();++vi)
|
|
||||||
glVertex(*vi);
|
|
||||||
glEnd();
|
|
||||||
}
|
}
|
||||||
glPushMatrix();
|
|
||||||
Matrix44f r;
|
|
||||||
track.rot.ToMatrix(r);
|
|
||||||
glMultMatrix(r);
|
|
||||||
DrawIcon();
|
|
||||||
glPopMatrix();
|
|
||||||
}
|
|
||||||
glMultMatrix(track.Matrix());
|
|
||||||
glTranslate(-center);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Trackball::ApplyInverse() {
|
void Trackball::ApplyInverse() {
|
||||||
glTranslate(center);
|
glTranslate(center);
|
||||||
glMultMatrix(track.InverseMatrix());
|
glMultMatrix(track.InverseMatrix());
|
||||||
|
@ -183,7 +180,9 @@ void Trackball::Translate(Point3f tr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
|
// DrawCircle () e DrawPlane() have been moved to trackutils.h
|
||||||
|
// the drawing code has been moved to the trackmodes
|
||||||
|
/*
|
||||||
void Trackball::DrawCircle() {
|
void Trackball::DrawCircle() {
|
||||||
int nside=DH.CircleStep;
|
int nside=DH.CircleStep;
|
||||||
const double pi2=3.14159265*2.0;
|
const double pi2=3.14159265*2.0;
|
||||||
|
@ -210,6 +209,7 @@ void Trackball::DrawPlane() {
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void Trackball::ToAscii(char* result){
|
void Trackball::ToAscii(char* result){
|
||||||
float * f = (float*) &track;
|
float * f = (float*) &track;
|
||||||
|
@ -226,6 +226,9 @@ bool Trackball::SetFromAscii(char * st){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DrawPlaneHandle() e DrawIcon() have been moved to trackutils.h
|
||||||
|
// the drawing code has been moved to the trackmodes
|
||||||
|
/*
|
||||||
void Trackball::DrawPlaneHandle() {
|
void Trackball::DrawPlaneHandle() {
|
||||||
float r=1.0;
|
float r=1.0;
|
||||||
float dr=r/10.0f;
|
float dr=r/10.0f;
|
||||||
|
@ -286,10 +289,19 @@ void Trackball::DrawIcon() {
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void Trackball::Reset() {
|
void Trackball::Reset() {
|
||||||
track.SetIdentity();
|
track.SetIdentity();
|
||||||
}
|
map<int, TrackMode *>::iterator i;
|
||||||
|
for(i = modes.begin(); i != modes.end(); i++){
|
||||||
|
TrackMode * mode=(*i).second;
|
||||||
|
if(mode!=NULL)
|
||||||
|
mode->Reset();
|
||||||
|
}
|
||||||
|
assert(inactive_mode != NULL);
|
||||||
|
inactive_mode->Reset();
|
||||||
|
}
|
||||||
|
|
||||||
//interface
|
//interface
|
||||||
void Trackball::MouseDown(int button) {
|
void Trackball::MouseDown(int button) {
|
||||||
|
@ -317,14 +329,32 @@ void Trackball::MouseUp(int /* x */, int /* y */, int button) {
|
||||||
current_button &= (~button);
|
current_button &= (~button);
|
||||||
SetCurrentAction();
|
SetCurrentAction();
|
||||||
}
|
}
|
||||||
// it assumes that a notch of 1.0 is a single step of the wheel
|
|
||||||
|
// it assumes that a notch of 1.0 is a single step of the wheel
|
||||||
void Trackball::MouseWheel(float notch ) {
|
void Trackball::MouseWheel(float notch ) {
|
||||||
if(current_mode == NULL)
|
if(current_mode == NULL)
|
||||||
{
|
{
|
||||||
SphereMode tm;
|
//SphereMode tm;
|
||||||
tm.TrackMode::Apply(this, notch);
|
//tm.TrackMode::Apply(this, notch);
|
||||||
} else
|
ScaleMode scalemode;
|
||||||
|
scalemode.Apply (this, notch);
|
||||||
|
} else{
|
||||||
current_mode->Apply(this, notch);
|
current_mode->Apply(this, notch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Trackball::MouseWheel (float notch, int button)
|
||||||
|
{
|
||||||
|
current_button |= button;
|
||||||
|
SetCurrentAction ();
|
||||||
|
if (current_mode == NULL) {
|
||||||
|
ScaleMode scalemode;
|
||||||
|
scalemode.Apply (this, notch);
|
||||||
|
} else {
|
||||||
|
current_mode->Apply (this, notch);
|
||||||
|
}
|
||||||
|
current_button &= (~button);
|
||||||
|
SetCurrentAction ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Trackball::ButtonDown(Trackball::Button button) {
|
void Trackball::ButtonDown(Trackball::Button button) {
|
||||||
|
@ -337,8 +367,6 @@ void Trackball::ButtonUp(Trackball::Button button) {
|
||||||
SetCurrentAction();
|
SetCurrentAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//spinning interface
|
//spinning interface
|
||||||
void Trackball::SetSpinnable(bool /* on*/ ){}
|
void Trackball::SetSpinnable(bool /* on*/ ){}
|
||||||
bool Trackball::IsSpinnable() {
|
bool Trackball::IsSpinnable() {
|
||||||
|
@ -350,23 +378,25 @@ bool Trackball::IsSpinning() {
|
||||||
return spinning;
|
return spinning;
|
||||||
}
|
}
|
||||||
|
|
||||||
//interfaccia navigation:
|
//navigation interface:
|
||||||
void Trackball::Back(){}
|
void Trackball::Back(){}
|
||||||
void Trackball::Forward(){}
|
void Trackball::Forward(){}
|
||||||
void Trackball::Home(){}
|
void Trackball::Home(){}
|
||||||
void Trackball::HistorySize(int /* lenght */){}
|
void Trackball::HistorySize(int /* length */){}
|
||||||
|
|
||||||
void Trackball::SetCurrentAction() {
|
void Trackball::SetCurrentAction ()
|
||||||
|
{
|
||||||
//I use strict matching.
|
//I use strict matching.
|
||||||
assert(modes.count(0));
|
assert (modes.count (0));
|
||||||
if(!modes.count(current_button))
|
if (!modes.count (current_button)) {
|
||||||
current_mode = NULL;
|
current_mode = NULL;
|
||||||
else
|
} else {
|
||||||
current_mode = modes[current_button];
|
current_mode = modes[current_button];
|
||||||
|
if(current_mode != NULL)
|
||||||
last_point = Point3f(0, 0, -1);
|
current_mode->SetAction();
|
||||||
|
}
|
||||||
|
last_point = Point3f (0, 0, -1);
|
||||||
last_track = track;
|
last_track = track;
|
||||||
// last_view = view;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////return center of trackball in Window coordinates.
|
////return center of trackball in Window coordinates.
|
||||||
|
@ -389,4 +419,3 @@ void Trackball::SetCurrentAction() {
|
||||||
// return m;
|
// return m;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.13 2007/02/26 01:30:02 cignoni
|
||||||
|
Added reflection Name
|
||||||
|
|
||||||
Revision 1.12 2007/01/15 15:04:15 tarini
|
Revision 1.12 2007/01/15 15:04:15 tarini
|
||||||
added "ToAscii" and "SetFromAscii" methods to load/store current trackball status from/to ascii strings
|
added "ToAscii" and "SetFromAscii" methods to load/store current trackball status from/to ascii strings
|
||||||
(intended uses: clipboard operations and comments inside png snapshots!)
|
(intended uses: clipboard operations and comments inside png snapshots!)
|
||||||
|
@ -134,9 +137,9 @@ namespace vcg {
|
||||||
Transform();
|
Transform();
|
||||||
Similarityf track;
|
Similarityf track;
|
||||||
|
|
||||||
/// la posizione della track nello spazio di modello. il defgault e' 000
|
/// track position in model space. default is 0,0,0
|
||||||
Point3f center;
|
Point3f center;
|
||||||
/// size of the widget in spazio di modello.
|
/// size of the widget in model space.
|
||||||
float radius;
|
float radius;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -145,27 +148,10 @@ namespace vcg {
|
||||||
class TrackMode;
|
class TrackMode;
|
||||||
class Trackball: public Transform {
|
class Trackball: public Transform {
|
||||||
public:
|
public:
|
||||||
class DrawingHint
|
// the drawing code has been moved to the trackmodes
|
||||||
{
|
// class DrawingHint {
|
||||||
public:
|
|
||||||
DrawingHint() {
|
|
||||||
CircleStep=64;
|
|
||||||
HideStill=false;
|
|
||||||
DrawTrack=false;
|
|
||||||
LineWidthStill=0.5f;
|
|
||||||
LineWidthMoving=1.5f;
|
|
||||||
color=Color4b::LightBlue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CircleStep;
|
// DrawingHint DH;
|
||||||
bool HideStill,DrawTrack;
|
|
||||||
Color4b color;
|
|
||||||
float LineWidthStill;
|
|
||||||
float LineWidthMoving;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
DrawingHint DH;
|
|
||||||
|
|
||||||
|
|
||||||
enum Button { BUTTON_NONE = 0x0000,
|
enum Button { BUTTON_NONE = 0x0000,
|
||||||
|
@ -183,23 +169,26 @@ namespace vcg {
|
||||||
void SetIdentity();
|
void SetIdentity();
|
||||||
void SetPosition(const Point3f &c, int millisec = 0);
|
void SetPosition(const Point3f &c, int millisec = 0);
|
||||||
void SetScale(const float s) {radius=s;};
|
void SetScale(const float s) {radius=s;};
|
||||||
void SetTransform(const Transform &transform, int miilisec = 0);
|
void SetTransform(const Transform &transform, int millisec = 0);
|
||||||
void Translate(Point3f tr);
|
void Translate(Point3f tr);
|
||||||
void Scale(const float f);
|
void Scale(const float f);
|
||||||
|
|
||||||
|
|
||||||
//operating
|
//operating
|
||||||
void GetView();
|
void GetView();
|
||||||
void Apply(bool Draw=true);
|
void Apply(bool Draw);
|
||||||
|
void Apply ();
|
||||||
void DrawPostApply();
|
void DrawPostApply();
|
||||||
void ApplyInverse();
|
void ApplyInverse();
|
||||||
void DrawIcon();
|
// DrawIcon() has been moved to trackutils.h
|
||||||
|
//void DrawIcon();
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
// Internal Drawing stuff
|
// DrawCircle (), DrawPlane(), DrawPlaneHandle() has been moved to trackutils.h
|
||||||
void DrawCircle ();
|
// the drawing code has been moved to the trackmodes
|
||||||
void DrawPlane();
|
// void DrawCircle ();
|
||||||
void DrawPlaneHandle();
|
// void DrawPlane();
|
||||||
|
// void DrawPlaneHandle();
|
||||||
|
|
||||||
//interface
|
//interface
|
||||||
void MouseDown(/*Button*/ int button);
|
void MouseDown(/*Button*/ int button);
|
||||||
|
@ -207,6 +196,7 @@ namespace vcg {
|
||||||
void MouseMove(int x, int y);
|
void MouseMove(int x, int y);
|
||||||
void MouseUp(int x, int y, /*Button */ int button);
|
void MouseUp(int x, int y, /*Button */ int button);
|
||||||
void MouseWheel(float notch); // it assumes that a notch of 1.0 is a single step of the wheel
|
void MouseWheel(float notch); // it assumes that a notch of 1.0 is a single step of the wheel
|
||||||
|
void MouseWheel (float notch, /*Button */ int button);
|
||||||
void ButtonUp(Button button);
|
void ButtonUp(Button button);
|
||||||
void ButtonDown(Button button);
|
void ButtonDown(Button button);
|
||||||
|
|
||||||
|
@ -254,6 +244,14 @@ namespace vcg {
|
||||||
int current_button;
|
int current_button;
|
||||||
TrackMode *current_mode;
|
TrackMode *current_mode;
|
||||||
|
|
||||||
|
// inactive_mode is used to draw the inactive trackball
|
||||||
|
// can be assigned, for example, to draw an area or a path
|
||||||
|
// even when the user is not interacting with it
|
||||||
|
TrackMode *inactive_mode;
|
||||||
|
|
||||||
|
// reset modes to default mapping.
|
||||||
|
void setDefaultMapping ();
|
||||||
|
|
||||||
std::map<int, TrackMode *> modes;
|
std::map<int, TrackMode *> modes;
|
||||||
|
|
||||||
Similarityf last_track;
|
Similarityf last_track;
|
||||||
|
|
Loading…
Reference in New Issue