TDPoint.h

00001 #ifndef TDPOINT_H
00002 #define TDPOINT_H
00003 /*
00004  _______ _____  _____      _       _   
00005 |__   __|  __ \|  __ \    (_)     | |  
00006    | |  | |  | | |__) |__  _ _ __ | |_ 
00007    | |  | |  | |  ___/ _ \| | '_ \| __|
00008    | |  | |__| | |  | (_) | | | | | |_ 
00009    |_|  |_____/|_|   \___/|_|_| |_|\__|
00010 */
00011 #include "QGLViewer/vec.h"
00012 #include "SelectableThing.h"
00013 #include <QGLViewer/qglviewer.h>
00014 #include <qobject.h>
00015 
00016 using namespace std;
00017 using namespace qglviewer;
00019 class TDPoint : public SelectableThing
00020 {
00025 public :
00028         bool IsAPoint(){return true;};
00031         bool IsAPatch(){return false;};
00034         TDPoint* GetPoint(){return this;};
00037         BaryPatch* GetPatch(){return NULL;};
00039         TDPoint(int ThingName, SelectableThing** Workspace): SelectableThing(ThingName,Workspace)
00040         {
00041         };
00043         TDPoint(int ThingName, SelectableThing** Workspace, Vec Position): SelectableThing(ThingName,Workspace)
00044         {
00045                 _ThingGlobalFrame.setPosition(Position);
00046         };
00053         void draw(ManipulatedFrame* MF)
00054         {
00055                 if(_IsSelected)
00056                         // I am moving with the selection
00057                         // my position relatively to the selection remains constant
00058                         // my position in the world is changing
00059                 {
00060                         glColor3f(_Color[0], _Color[1], _Color[2]);
00061                         // Local -> Global
00062                         _ThingGlobalFrame.setPosition(MF->inverseCoordinatesOf(_ThingLocalFrame.position()));
00063                 }
00064                 else 
00065                         // I am not moving with the selection
00066                         // my position relatively to the selection is changing
00067                         // my position in the world remains constant
00068                 {
00069                         glColor3f(_Color[0]/2., _Color[1]/2., _Color[2]/2.);
00070                         // Global -> Local
00071                         _ThingLocalFrame.setPosition(MF->coordinatesOf(_ThingGlobalFrame.position()));
00072                 }
00073                 glPushName(_ThingName);
00074                 glPushMatrix();
00075                 glMultMatrixd(_ThingGlobalFrame.matrix());
00076                 glutSolidSphere(0.005,6,6);
00077                 glPopMatrix();
00078                 glPopName();
00079         }
00081         void UpdateNameTag()
00082         {
00083                 _NameTag = "Point " + QString::number(WhatsMyNumber());
00084         };
00086         int WhatsMyNumber()
00087         {
00088                 int CountWorkspacePoints = 0;
00089                 for(int i=0;i<_ThingName;i++)
00090                 {
00091                         if ((_Workspace[i])&&(_Workspace[i]->IsAPoint()))
00092                                 CountWorkspacePoints++;
00093                 }
00094                 return CountWorkspacePoints;
00095         };
00098         int Clear()
00099         {
00100                 // delete patches using me
00101                 // replaced by implementation 1 level up in JViewer
00102         };
00104         void SnapToGrid(float GridSpace, ManipulatedFrame* MF)
00105         {
00106                 // move global coords, update local
00107                 Vec Pos = _ThingGlobalFrame.position();
00108                 _ThingGlobalFrame.setPosition(Round(Pos[0]/GridSpace)*GridSpace,Round(Pos[1]/GridSpace)*GridSpace,Round(Pos[2]/GridSpace)*GridSpace);
00109                 _ThingLocalFrame.setPosition(MF->coordinatesOf(_ThingGlobalFrame.position()));
00110         }
00111 };
00112 #endif

Generated on Thu Sep 28 09:43:42 2006 by  doxygen 1.4.7