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)
This commit is contained in:
parent
07613df38d
commit
95153f03dc
|
@ -24,6 +24,10 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
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
|
||||
|
||||
Revision 1.13 2005/04/17 17:48:24 ganovelli
|
||||
modes deallocation commented (quick and dirty solution..to debug)
|
||||
|
||||
|
@ -87,6 +91,7 @@ Trackball::Trackball(): current_button(0), current_mode(NULL),
|
|||
modes[BUTTON_LEFT] = new SphereMode();
|
||||
modes[BUTTON_LEFT | KEY_CTRL] = 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();
|
||||
}
|
||||
|
@ -109,10 +114,30 @@ void Trackball::GetView() {
|
|||
camera.GetView();
|
||||
}
|
||||
|
||||
void Trackball::DrawPostApply() {
|
||||
glPushMatrix();
|
||||
|
||||
glTranslate(center);
|
||||
glMultMatrix(track.InverseMatrix());
|
||||
Matrix44f r;
|
||||
track.rot.ToMatrix(r);
|
||||
glMultMatrix(r);
|
||||
DrawIcon();
|
||||
|
||||
glTranslate(-center);
|
||||
glMultMatrix(track.Matrix());
|
||||
}
|
||||
|
||||
void Trackball::Apply(bool ToDraw) {
|
||||
glTranslate(center);
|
||||
if(ToDraw)
|
||||
{
|
||||
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);
|
||||
|
@ -130,13 +155,25 @@ void Trackball::ApplyInverse() {
|
|||
glTranslate(-center);
|
||||
}
|
||||
|
||||
void Trackball::Scale(const float s)
|
||||
{
|
||||
track.sca*=s;
|
||||
}
|
||||
|
||||
void Trackball::Translate(Point3f tr)
|
||||
{
|
||||
Matrix44f m;
|
||||
track.rot.ToMatrix(m);
|
||||
track.tra = last_track.tra + Inverse(m)*tr/track.sca;;
|
||||
}
|
||||
|
||||
/***************************************************************/
|
||||
|
||||
void Trackball::DrawCircle() {
|
||||
int nside=DH.CircleStep;
|
||||
const double pi2=3.14159265*2.0;
|
||||
glBegin(GL_LINE_STRIP);
|
||||
for(double i=0;i<=nside;i++){
|
||||
glBegin(GL_LINE_LOOP);
|
||||
for(double i=0;i<nside;i++){
|
||||
glNormal3d(cos(i*pi2/nside), sin(i*pi2/nside), 0.0);
|
||||
glVertex3d(cos(i*pi2/nside), sin(i*pi2/nside), 0.0);
|
||||
}
|
||||
|
@ -180,19 +217,25 @@ void Trackball::DrawPlaneHandle() {
|
|||
|
||||
void Trackball::DrawIcon() {
|
||||
glPushMatrix();
|
||||
|
||||
|
||||
glScale(radius);
|
||||
/// Here start the real drawing stuff
|
||||
float amb[4] ={.3f,.3f,.3f,1.0f};
|
||||
float col[4] ={.5f,.5f,.8f,1.0f};
|
||||
//float col2[4]={.9f,.9f,1.0f,1.0f};
|
||||
glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_CURRENT_BIT | GL_LIGHTING_BIT);
|
||||
glLineWidth(2.0);
|
||||
|
||||
|
||||
if(current_mode == NULL ) glLineWidth(DH.LineWidthStill);
|
||||
else glLineWidth(DH.LineWidthMoving);
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glColor(DH.color);
|
||||
|
||||
glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,amb);
|
||||
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,col);
|
||||
glPushMatrix();
|
||||
|
@ -207,7 +250,7 @@ void Trackball::DrawIcon() {
|
|||
glPopMatrix();
|
||||
glPopMatrix();
|
||||
|
||||
glColor4f(1.0,.8f,.8f,1.0f);
|
||||
//glColor4f(1.0,.8f,.8f,1.0f);
|
||||
|
||||
glPopAttrib();
|
||||
|
||||
|
@ -219,6 +262,11 @@ void Trackball::Reset() {
|
|||
}
|
||||
|
||||
//interface
|
||||
void Trackball::MouseDown(int button) {
|
||||
current_button |= button;
|
||||
SetCurrentAction();
|
||||
Hits.clear();
|
||||
}
|
||||
void Trackball::MouseDown(int x, int y, int button) {
|
||||
current_button |= button;
|
||||
SetCurrentAction();
|
||||
|
|
|
@ -25,6 +25,10 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.9 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
|
||||
|
||||
Revision 1.8 2004/07/11 22:06:56 cignoni
|
||||
Added scaling by wheel
|
||||
|
||||
|
@ -59,7 +63,8 @@ Radius specify the radius of the interactive ball shaped icon to specify rotatio
|
|||
It is in absolute unit but it should be in screen related units like the previoous
|
||||
one it is not changed during interaction.
|
||||
|
||||
When you specify a traslation with the trackball the trackball center remain UNCHANGED.
|
||||
When you specify a traslation with the trackball the trackball center remain UNCHANGED,
|
||||
in other words it means that the object move out of the trackball icon.
|
||||
Similarly when you apply a scaling the size of the iconshaped ball do not change.
|
||||
|
||||
|
||||
|
@ -88,6 +93,8 @@ Perspective and gllookat are choosed to frame the origin centered 1-radius
|
|||
trackball.
|
||||
The final scale and translate are just to fit a generic mesh to the 1sized
|
||||
origin centered where the trackball stays box.
|
||||
The trackball works also on Orthographic projections
|
||||
BUT that are not centered around origin (just move it back along the Z)
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -95,6 +102,7 @@ origin centered where the trackball stays box.
|
|||
#define TRACKBALL_H
|
||||
|
||||
#include <vcg/math/similarity.h>
|
||||
#include <vcg/space/color4.h>
|
||||
#include <wrap/gui/view.h>
|
||||
#include <wrap/gui/trackmode.h>
|
||||
#include <list>
|
||||
|
@ -126,9 +134,20 @@ namespace vcg {
|
|||
class DrawingHint
|
||||
{
|
||||
public:
|
||||
DrawingHint() { CircleStep=32; }
|
||||
DrawingHint() {
|
||||
CircleStep=64;
|
||||
HideStill=false;
|
||||
DrawTrack=false;
|
||||
LineWidthStill=0.5f;
|
||||
LineWidthMoving=1.5f;
|
||||
color=Color4b::LightBlue;
|
||||
}
|
||||
|
||||
int CircleStep;
|
||||
bool HideStill,DrawTrack;
|
||||
Color4b color;
|
||||
float LineWidthStill;
|
||||
float LineWidthMoving;
|
||||
};
|
||||
|
||||
|
||||
|
@ -151,20 +170,25 @@ namespace vcg {
|
|||
void SetPosition(const Point3f &c, int millisec = 0);
|
||||
void SetScale(const float s) {radius=s;};
|
||||
void SetTransform(const Transform &transform, int miilisec = 0);
|
||||
void Translate(Point3f tr);
|
||||
void Scale(const float f);
|
||||
|
||||
|
||||
//operating
|
||||
void GetView();\
|
||||
void Apply(bool Draw=true);
|
||||
void DrawPostApply();
|
||||
void ApplyInverse();
|
||||
void DrawIcon();
|
||||
void Reset();
|
||||
|
||||
|
||||
// Internal Drawing stuff
|
||||
void DrawCircle ();
|
||||
void DrawPlane();
|
||||
void DrawPlaneHandle();
|
||||
|
||||
//interface
|
||||
void MouseDown(/*Button*/ int button);
|
||||
void MouseDown(int x, int y, /*Button*/ int button);
|
||||
void MouseMove(int x, int y);
|
||||
void MouseUp(int x, int y, /*Button */ int button);
|
||||
|
|
Loading…
Reference in New Issue