many user interface improvements, cleaned up a little
This commit is contained in:
parent
228db666c3
commit
b2d39163ac
|
|
@ -23,6 +23,9 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
History
|
History
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.4 2008/02/17 20:52:53 benedetti
|
||||||
|
some generalization made
|
||||||
|
|
||||||
Revision 1.3 2008/02/16 14:12:30 benedetti
|
Revision 1.3 2008/02/16 14:12:30 benedetti
|
||||||
first version
|
first version
|
||||||
|
|
||||||
|
|
@ -112,12 +115,13 @@ void CoordinateFrame::Render(QGLWidget* glw)
|
||||||
if(drawlabels){
|
if(drawlabels){
|
||||||
font.setBold(true);
|
font.setBold(true);
|
||||||
font.setPixelSize(12);
|
font.setPixelSize(12);
|
||||||
|
float dist=size+scalefactor*linewidth*1.5;
|
||||||
glColor(xcolor);
|
glColor(xcolor);
|
||||||
glw->renderText(size+scalefactor*linewidth*1.5,0,0,QString("X"),font);
|
glw->renderText(d,0,0,QString("X"),font);
|
||||||
glColor(ycolor);
|
glColor(ycolor);
|
||||||
glw->renderText(0,size+scalefactor*linewidth*1.5,0,QString("Y"),font);
|
glw->renderText(0,d,0,QString("Y"),font);
|
||||||
glColor(zcolor);
|
glColor(zcolor);
|
||||||
glw->renderText(0,0,size+scalefactor*linewidth*1.5,QString("Z"),font);
|
glw->renderText(0,0,d,QString("Z"),font);
|
||||||
}
|
}
|
||||||
if(drawvalues){
|
if(drawvalues){
|
||||||
font.setBold(false);
|
font.setBold(false);
|
||||||
|
|
@ -197,7 +201,8 @@ void MovableCoordinateFrame::Render(QGLWidget* gla)
|
||||||
glTranslate(position);
|
glTranslate(position);
|
||||||
Matrix44f mrot;
|
Matrix44f mrot;
|
||||||
rotation.ToMatrix(mrot);
|
rotation.ToMatrix(mrot);
|
||||||
glMultMatrix(mrot);
|
|
||||||
|
glMultMatrix(Inverse(mrot));
|
||||||
|
|
||||||
CoordinateFrame::Render(gla);
|
CoordinateFrame::Render(gla);
|
||||||
|
|
||||||
|
|
@ -215,7 +220,7 @@ void MovableCoordinateFrame::GetTransform(Matrix44f & transform)
|
||||||
Matrix44f rot;
|
Matrix44f rot;
|
||||||
rotation.ToMatrix(rot);
|
rotation.ToMatrix(rot);
|
||||||
|
|
||||||
transform = rot * transform ;
|
transform = Inverse(rot) * transform ;
|
||||||
|
|
||||||
// sposto in posizione
|
// sposto in posizione
|
||||||
Matrix44f pos;
|
Matrix44f pos;
|
||||||
|
|
@ -355,24 +360,15 @@ void MovableCoordinateFrame::RotateToAlign(const Point3f source, const Point3f d
|
||||||
|
|
||||||
ActiveCoordinateFrame::ActiveCoordinateFrame(float size)
|
ActiveCoordinateFrame::ActiveCoordinateFrame(float size)
|
||||||
:MovableCoordinateFrame(size),manipulator(NULL),drawmoves(true),
|
:MovableCoordinateFrame(size),manipulator(NULL),drawmoves(true),
|
||||||
drawrotations(true),
|
drawrotations(true),move_button(Trackball::BUTTON_RIGHT),
|
||||||
movx(Trackball::BUTTON_RIGHT ),
|
rotate_button(Trackball::BUTTON_LEFT),x_modifier(Trackball::BUTTON_NONE),
|
||||||
movy(Trackball::BUTTON_RIGHT | Trackball::KEY_CTRL),
|
y_modifier(Trackball::KEY_CTRL),z_modifier(Trackball::KEY_SHIFT),
|
||||||
movz(Trackball::BUTTON_RIGHT | Trackball::KEY_SHIFT),
|
movx(move_button | x_modifier),movy(move_button | y_modifier),
|
||||||
rotx(Trackball::BUTTON_LEFT),
|
movz(move_button | z_modifier),rotx(rotate_button | x_modifier),
|
||||||
roty(Trackball::BUTTON_LEFT | Trackball::KEY_CTRL),
|
roty(rotate_button | y_modifier),rotz(rotate_button | z_modifier),
|
||||||
rotz(Trackball::BUTTON_LEFT | Trackball::KEY_SHIFT),
|
|
||||||
x_axis(1,0,0),y_axis(0,1,0),z_axis(0,0,1),rot_snap_rad(0.0f),mov_snap(0.0f)
|
x_axis(1,0,0),y_axis(0,1,0),z_axis(0,0,1),rot_snap_rad(0.0f),mov_snap(0.0f)
|
||||||
{
|
{
|
||||||
manipulator=new Trackball();
|
manipulator=new Trackball();
|
||||||
std::map<int, TrackMode *>::iterator it;
|
|
||||||
for(it = manipulator->modes.begin(); it != manipulator->modes.end(); it++)
|
|
||||||
{
|
|
||||||
if ((*it).second)
|
|
||||||
delete (*it).second;
|
|
||||||
}
|
|
||||||
manipulator->modes.clear();
|
|
||||||
manipulator->modes[0] = NULL;
|
|
||||||
Update();
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -405,15 +401,7 @@ void ActiveCoordinateFrame::Render(QGLWidget* glw)
|
||||||
bool rotating=(current_mode==rotx)||(current_mode==roty)||(current_mode==rotz);
|
bool rotating=(current_mode==rotx)||(current_mode==roty)||(current_mode==rotz);
|
||||||
bool moving=(current_mode==movx)||(current_mode==movy)||(current_mode==movz);
|
bool moving=(current_mode==movx)||(current_mode==movy)||(current_mode==movz);
|
||||||
|
|
||||||
// non sto draggando o sto draggando quello che non devo disengnare
|
//devo disegnare qualcosa
|
||||||
if( (!rotating && !moving)||
|
|
||||||
(!((rotating && drawrotations)||(moving && drawmoves)))
|
|
||||||
){
|
|
||||||
glPopMatrix();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// sto draggando e devo disegnare qualcosa
|
|
||||||
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
@ -422,23 +410,30 @@ void ActiveCoordinateFrame::Render(QGLWidget* glw)
|
||||||
glEnable(GL_LINE_SMOOTH);
|
glEnable(GL_LINE_SMOOTH);
|
||||||
glEnable(GL_POINT_SMOOTH);
|
glEnable(GL_POINT_SMOOTH);
|
||||||
|
|
||||||
Color4b color;
|
QString message("sovrascrivimi");
|
||||||
QString message;
|
|
||||||
char axis_name;
|
char axis_name;
|
||||||
float verse;
|
float verse;
|
||||||
|
|
||||||
|
if(current_mode==x_modifier){
|
||||||
|
glColor(xcolor); message = QString("move or rotate on X axis");
|
||||||
|
} else if(current_mode==y_modifier){
|
||||||
|
glColor(ycolor); message = QString("move or rotate on Y axis");
|
||||||
|
} else if(current_mode==z_modifier){
|
||||||
|
glColor(zcolor); message = QString("move or rotate on Z axis");
|
||||||
|
} else
|
||||||
if(rotating && drawrotations){ // devo disegnare una rotazione
|
if(rotating && drawrotations){ // devo disegnare una rotazione
|
||||||
Point3f axis, arc_point;
|
Point3f axis, arc_point;
|
||||||
float angle;
|
float angle;
|
||||||
manipulator->track.rot.ToAxis(angle,axis);
|
manipulator->track.rot.ToAxis(angle,axis);
|
||||||
if(current_mode==rotx){
|
if(current_mode==rotx){
|
||||||
verse=((axis+x_axis).Norm()<1?-1:1);
|
verse=((axis+x_axis).Norm()<1?-1:1);
|
||||||
color=xcolor; axis_name='x'; arc_point=y_axis*(size*0.8);
|
glColor(xcolor); axis_name='x'; arc_point=y_axis*(size*0.8);
|
||||||
} else if(current_mode==roty) {
|
} else if(current_mode==roty) {
|
||||||
verse=((axis+y_axis).Norm()<1?-1:1);
|
verse=((axis+y_axis).Norm()<1?-1:1);
|
||||||
color=ycolor; axis_name='y'; arc_point=z_axis*(size*0.8);
|
glColor(ycolor); axis_name='y'; arc_point=z_axis*(size*0.8);
|
||||||
} else if(current_mode==rotz) {
|
} else if(current_mode==rotz) {
|
||||||
verse=((axis+z_axis).Norm()<1?-1:1);
|
verse=((axis+z_axis).Norm()<1?-1:1);
|
||||||
color=zcolor; axis_name='z'; arc_point=x_axis*(size*0.8);
|
glColor(zcolor); axis_name='z'; arc_point=x_axis*(size*0.8);
|
||||||
} else assert(0); // doveva essere una rotazione
|
} else assert(0); // doveva essere una rotazione
|
||||||
// normalizzo la rotazione a [-180,180]
|
// normalizzo la rotazione a [-180,180]
|
||||||
float sign = ((angle*verse)<0) ? -1 : 1;
|
float sign = ((angle*verse)<0) ? -1 : 1;
|
||||||
|
|
@ -450,7 +445,6 @@ void ActiveCoordinateFrame::Render(QGLWidget* glw)
|
||||||
.arg(axis_name);
|
.arg(axis_name);
|
||||||
Quaternionf arc_rot;
|
Quaternionf arc_rot;
|
||||||
arc_rot.FromAxis(angle/18.0,axis);
|
arc_rot.FromAxis(angle/18.0,axis);
|
||||||
glColor(color);
|
|
||||||
glBegin(GL_POLYGON);
|
glBegin(GL_POLYGON);
|
||||||
glVertex(position);
|
glVertex(position);
|
||||||
glVertex(position+arc_point);
|
glVertex(position+arc_point);
|
||||||
|
|
@ -464,13 +458,13 @@ void ActiveCoordinateFrame::Render(QGLWidget* glw)
|
||||||
ntra.Normalize();
|
ntra.Normalize();
|
||||||
if(current_mode==movx){
|
if(current_mode==movx){
|
||||||
verse=((ntra+x_axis).Norm()<1?-1:1);
|
verse=((ntra+x_axis).Norm()<1?-1:1);
|
||||||
color=xcolor; axis_name='x';
|
glColor(xcolor); axis_name='x';
|
||||||
}else if(current_mode==movy){
|
}else if(current_mode==movy){
|
||||||
verse=((ntra+y_axis).Norm()<1?-1:1);
|
verse=((ntra+y_axis).Norm()<1?-1:1);
|
||||||
color=ycolor; axis_name='y';
|
glColor(ycolor); axis_name='y';
|
||||||
}else if(current_mode==movz){
|
}else if(current_mode==movz){
|
||||||
verse=((ntra+z_axis).Norm()<1?-1:1);
|
verse=((ntra+z_axis).Norm()<1?-1:1);
|
||||||
color=zcolor; axis_name='z';
|
glColor(zcolor); axis_name='z';
|
||||||
}else assert(0); // doveva essere una traslazione
|
}else assert(0); // doveva essere una traslazione
|
||||||
message = QString("moved %1 units along %2")
|
message = QString("moved %1 units along %2")
|
||||||
.arg(verse*manipulator->track.tra.Norm(),5,'f',3)
|
.arg(verse*manipulator->track.tra.Norm(),5,'f',3)
|
||||||
|
|
@ -478,7 +472,6 @@ void ActiveCoordinateFrame::Render(QGLWidget* glw)
|
||||||
Point3f old_pos = position-manipulator->track.tra;
|
Point3f old_pos = position-manipulator->track.tra;
|
||||||
glLineWidth(2*linewidth);
|
glLineWidth(2*linewidth);
|
||||||
glPointSize(4*linewidth);
|
glPointSize(4*linewidth);
|
||||||
glColor(color);
|
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
glVertex(position);
|
glVertex(position);
|
||||||
glVertex(old_pos);
|
glVertex(old_pos);
|
||||||
|
|
@ -486,10 +479,15 @@ void ActiveCoordinateFrame::Render(QGLWidget* glw)
|
||||||
glBegin(GL_POINTS);
|
glBegin(GL_POINTS);
|
||||||
glVertex(old_pos);
|
glVertex(old_pos);
|
||||||
glEnd();
|
glEnd();
|
||||||
} else assert(0); // qualcosa lo dovevo disegnare
|
} else { // non dovevo disegnare nulla
|
||||||
|
glPopAttrib();
|
||||||
|
glPopMatrix();
|
||||||
|
return;
|
||||||
|
}
|
||||||
// disegno la stringa
|
// disegno la stringa
|
||||||
font.setBold(true);
|
font.setBold(true);
|
||||||
font.setPixelSize(12);
|
font.setPixelSize(12);
|
||||||
|
QPoint cursor=glw->mapFromGlobal(glw->cursor().pos());
|
||||||
glw->renderText(cursor.x()+16,cursor.y()+16,message,font);
|
glw->renderText(cursor.x()+16,cursor.y()+16,message,font);
|
||||||
|
|
||||||
glPopAttrib();
|
glPopAttrib();
|
||||||
|
|
@ -524,17 +522,15 @@ void ActiveCoordinateFrame::AlignWith(const Point3f primary,const Point3f second
|
||||||
manipulator->Reset();
|
manipulator->Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActiveCoordinateFrame::MouseDown(QPoint c,int x, int y, /*Button*/ int button)
|
void ActiveCoordinateFrame::MouseDown(int x, int y, /*Button*/ int button)
|
||||||
{
|
{
|
||||||
cursor=c;
|
|
||||||
Move(manipulator->track);
|
Move(manipulator->track);
|
||||||
manipulator->Reset();
|
manipulator->Reset();
|
||||||
manipulator->MouseDown(x,y,button);
|
manipulator->MouseDown(x,y,button);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActiveCoordinateFrame::MouseMove(QPoint c,int x, int y)
|
void ActiveCoordinateFrame::MouseMove(int x, int y)
|
||||||
{
|
{
|
||||||
cursor=c;
|
|
||||||
manipulator->MouseMove(x,y);
|
manipulator->MouseMove(x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -580,29 +576,19 @@ void ActiveCoordinateFrame::Update()
|
||||||
y_axis=r.Rotate(Point3f(0,1,0));
|
y_axis=r.Rotate(Point3f(0,1,0));
|
||||||
z_axis=r.Rotate(Point3f(0,0,1));
|
z_axis=r.Rotate(Point3f(0,0,1));
|
||||||
|
|
||||||
if(manipulator->modes[movx]!=NULL)
|
std::map<int, TrackMode *>::iterator it;
|
||||||
delete manipulator->modes[movx];
|
for(it = manipulator->modes.begin(); it != manipulator->modes.end(); it++)
|
||||||
|
{
|
||||||
|
if ((*it).second)
|
||||||
|
delete (*it).second;
|
||||||
|
}
|
||||||
|
manipulator->modes.clear();
|
||||||
|
manipulator->modes[0] = NULL;
|
||||||
manipulator->modes[movx] = new AxisMode(p,x_axis);
|
manipulator->modes[movx] = new AxisMode(p,x_axis);
|
||||||
|
|
||||||
if(manipulator->modes[movy]!=NULL)
|
|
||||||
delete manipulator->modes[movy];
|
|
||||||
manipulator->modes[movy] = new AxisMode(p,y_axis);
|
manipulator->modes[movy] = new AxisMode(p,y_axis);
|
||||||
|
|
||||||
if(manipulator->modes[movz]!=NULL)
|
|
||||||
delete manipulator->modes[movz];
|
|
||||||
manipulator->modes[movz] = new AxisMode(p,z_axis);
|
manipulator->modes[movz] = new AxisMode(p,z_axis);
|
||||||
|
|
||||||
if(manipulator->modes[rotx]!=NULL)
|
|
||||||
delete manipulator->modes[rotx];
|
|
||||||
manipulator->modes[rotx] = new CylinderMode(p,x_axis,rot_snap_rad);
|
manipulator->modes[rotx] = new CylinderMode(p,x_axis,rot_snap_rad);
|
||||||
|
|
||||||
if(manipulator->modes[roty]!=NULL)
|
|
||||||
delete manipulator->modes[roty];
|
|
||||||
manipulator->modes[roty] = new CylinderMode(p,y_axis,rot_snap_rad);
|
manipulator->modes[roty] = new CylinderMode(p,y_axis,rot_snap_rad);
|
||||||
|
|
||||||
if(manipulator->modes[rotz]!=NULL)
|
|
||||||
delete manipulator->modes[rotz];
|
|
||||||
manipulator->modes[rotz] = new CylinderMode(p,z_axis,rot_snap_rad);
|
manipulator->modes[rotz] = new CylinderMode(p,z_axis,rot_snap_rad);
|
||||||
|
|
||||||
manipulator->SetCurrentAction();
|
manipulator->SetCurrentAction();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,9 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
History
|
History
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.4 2008/02/17 20:52:53 benedetti
|
||||||
|
some generalization made
|
||||||
|
|
||||||
Revision 1.3 2008/02/16 14:12:30 benedetti
|
Revision 1.3 2008/02/16 14:12:30 benedetti
|
||||||
first version
|
first version
|
||||||
|
|
||||||
|
|
@ -103,8 +106,8 @@ public:
|
||||||
virtual void SetPosition(const Point3f);
|
virtual void SetPosition(const Point3f);
|
||||||
virtual void SetRotation(const Quaternionf);
|
virtual void SetRotation(const Quaternionf);
|
||||||
virtual void AlignWith(const Point3f, const Point3f,const char,const char);
|
virtual void AlignWith(const Point3f, const Point3f,const char,const char);
|
||||||
void MouseDown(QPoint,int, int, int);
|
void MouseDown(int, int, int);
|
||||||
void MouseMove(QPoint,int, int);
|
void MouseMove(int, int);
|
||||||
void MouseUp(int, int, int);
|
void MouseUp(int, int, int);
|
||||||
void ButtonUp(int);
|
void ButtonUp(int);
|
||||||
void ButtonDown(int);
|
void ButtonDown(int);
|
||||||
|
|
@ -115,10 +118,11 @@ public:
|
||||||
bool drawrotations;
|
bool drawrotations;
|
||||||
protected:
|
protected:
|
||||||
// data:
|
// data:
|
||||||
|
const int move_button,rotate_button;
|
||||||
|
const int x_modifier,y_modifier,z_modifier;
|
||||||
const int movx,movy,movz,rotx,roty,rotz;
|
const int movx,movy,movz,rotx,roty,rotz;
|
||||||
Point3f x_axis,y_axis,z_axis;
|
Point3f x_axis,y_axis,z_axis;
|
||||||
float rot_snap_rad,mov_snap;
|
float rot_snap_rad,mov_snap;
|
||||||
QPoint cursor;
|
|
||||||
|
|
||||||
// functions:
|
// functions:
|
||||||
virtual void Move(const Similarityf);
|
virtual void Move(const Similarityf);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue