00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef CGenericObjectH
00024 #define CGenericObjectH
00025
00026 #include "math/CMaths.h"
00027 #include "graphics/CDraw3D.h"
00028 #include "graphics/CColor.h"
00029 #include "graphics/CMacrosGL.h"
00030 #include "graphics/CMaterial.h"
00031 #include "graphics/CTexture2D.h"
00032 #include "collisions/CCollisionBasics.h"
00033 #include "forces/CInteractionBasics.h"
00034 #include "effects/CGenericEffect.h"
00035 #include "extras/CGenericType.h"
00036
00037 #include <typeinfo>
00038 #include <vector>
00039 #include <list>
00040
00041 using std::vector;
00042
00043 class cTriangle;
00044 class cGenericCollision;
00045 class cGenericPointForceAlgo;
00046 class cMesh;
00047
00048
00049
00051 typedef enum {
00052 CHAI_RENDER_MODE_RENDER_ALL = 0,
00053 CHAI_RENDER_MODE_NON_TRANSPARENT_ONLY,
00054 CHAI_RENDER_MODE_TRANSPARENT_BACK_ONLY,
00055 CHAI_RENDER_MODE_TRANSPARENT_FRONT_ONLY
00056 } chai_render_modes;
00057
00058
00059
00067
00068
00069
00092
00093 class cGenericObject : public cGenericType
00094 {
00095
00096 public:
00097
00098
00099
00100
00101
00103 cGenericObject();
00104
00106 virtual ~cGenericObject();
00107
00108
00109
00110
00111
00112
00114 void setPos(const cVector3d& a_pos)
00115 {
00116 m_localPos = a_pos;
00117 }
00118
00120 void setPos(const double a_x, const double a_y, const double a_z)
00121 {
00122 m_localPos.set(a_x, a_y, a_z);
00123 }
00124
00126 inline cVector3d getPos() const { return (m_localPos); }
00127
00129 inline cVector3d getGlobalPos() const { return (m_globalPos); }
00130
00132 inline void setRot(const cMatrix3d& a_rot)
00133 {
00134 m_localRot = a_rot;
00135 }
00136
00138 inline cMatrix3d getRot() const { return (m_localRot); }
00139
00141 inline cMatrix3d getGlobalRot() const { return (m_globalRot); }
00142
00144 void translate(const cVector3d& a_translation);
00145
00147 void translate(const double a_x, const double a_y, const double a_z);
00148
00150 void rotate(const cMatrix3d& a_rotation);
00151
00153 void rotate(const cVector3d& a_axis, const double a_angle);
00154
00155
00156
00157
00158
00159
00161 void computeGlobalPositions(const bool a_frameOnly = true,
00162 const cVector3d& a_globalPos = cVector3d(0.0, 0.0, 0.0),
00163 const cMatrix3d& a_globalRot = cIdentity3d());
00164
00166 void computeGlobalCurrentObjectOnly(const bool a_frameOnly = true);
00167
00169 void computeGlobalPositionsAndMotion(const bool a_frameOnly = true,
00170 const cVector3d& a_globalPos = cVector3d(0.0, 0.0, 0.0),
00171 const cMatrix3d& a_globalRot = cIdentity3d());
00172
00173
00174
00175
00176
00177
00178
00179 cVector3d computeInteractions(const cVector3d& a_toolPos,
00180 const cVector3d& a_toolVel,
00181 const unsigned int a_IDN,
00182 cInteractionRecorder& a_interactions,
00183 cInteractionSettings& a_interactionSettings);
00184
00186 cVector3d m_interactionProjectedPoint;
00187
00189 bool m_interactionInside;
00190
00192 vector<cGenericEffect*> m_effects;
00193
00195 void addEffect(cGenericEffect* a_newEffect);
00196
00197
00198
00199
00200
00202 void setStiffness(double a_stiffness, const bool a_affectChildren=0);
00203
00205 void setFriction(double a_staticFriction, double a_dynamicFriction, const bool a_affectChildren=0);
00206
00207
00208
00209
00210
00211
00213 cMaterial m_material;
00214
00216 cTexture2D* m_texture;
00217
00219 void setShowEnabled(const bool a_show, const bool a_affectChildren = false);
00220
00222 bool getShowEnabled() const { return (m_show); }
00223
00225 void setHapticEnabled(const bool a_hapticEnabled, const bool a_affectChildren = false);
00226
00228 bool getHapticEnabled() const { return (m_hapticEnabled); }
00229
00231 void setShowTree(const bool a_showTree, const bool a_affectChildren = false);
00232
00234 bool getShowTree() const { return (m_showTree); }
00235
00237 void setTreeColor(const cColorf& a_treeColor, const bool a_affectChildren = false);
00238
00240 cColorf getTreeColor() const { return (m_treeColor); }
00241
00243 void setShowFrame(const bool a_showFrame, const bool a_affectChildren = false);
00244
00246 bool getShowFrame(void) const { return (m_showFrame); }
00247
00249 void setShowBox(const bool iShowBox, const bool iAffectChildren = false);
00250
00252 bool getShowBox() const { return (m_showBox); }
00253
00255 void setBoxColor(const cColorf& a_boxColor, const bool a_affectChildren = false);
00256
00258 cColorf getBoxColor() const { return (m_boundaryBoxColor); }
00259
00261 void setShowCollisionTree(const bool a_showCollisionTree, const bool a_affectChildren = false);
00262
00264 bool getShowCollisionTree() { return (m_showCollisionTree); }
00265
00267 virtual void onDisplayReset(const bool a_affectChildren = true);
00268
00270 virtual void finalize(const bool a_affectChildren = true);
00271
00273 virtual void unfinalize(const bool a_affectChildren = true);
00274
00276 virtual void renderSceneGraph(const int a_renderMode=CHAI_RENDER_MODE_RENDER_ALL);
00277
00278
00279
00280
00281
00282
00284 void setMaterial(cMaterial& a_mat, const bool a_affectChildren=false, const bool a_applyPhysicalParmetersOnly=false);
00285
00287 virtual void setTransparencyLevel(const float a_level,
00288 const bool a_applyToTextures=false,
00289 const bool a_affectChildren=true);
00290
00292 void setTransparencyRenderMode(const bool a_useMultipassTransparency, const bool a_affectChildren=true);
00293
00295 bool getMultipassTransparencyEnabled() const { return m_useMultipassTransparency; }
00296
00298 void setUseTransparency(const bool a_useTransparency, const bool a_affectChildren=true);
00299
00301 bool getUseTransparency() const { return m_useTransparency; }
00302
00304 void setWireMode(const bool a_showWireMode, const bool a_affectChildren=true);
00305
00307 bool getWireMode() const { return m_triangleMode == GL_LINE; }
00308
00310 void setUseCulling(const bool a_useCulling, const bool a_affectChildren=true);
00311
00313 bool getUseCulling() const { return m_cullingEnabled; }
00314
00316 void setUseVertexColors(const bool a_useColors, const bool a_affectChildren=true);
00317
00319 bool getUseVertexColors() const { return m_useVertexColors; }
00320
00322 void setUseMaterial(const bool a_useMaterial, const bool a_affectChildren=true);
00323
00325 bool getUseMaterial() const { return m_useMaterialProperty; }
00326
00328 void setUseTexture(const bool a_useTexture, const bool a_affectChildren=true);
00329
00331 bool getUseTexture() const { return m_useTextureMapping; }
00332
00334 void setTexture(cTexture2D* a_texture, const bool a_affectChildren=0);
00335
00337 cTexture2D* getTexture() const { return(m_texture); }
00338
00339
00340
00341
00342
00343
00345 cVector3d getBoundaryMin() const { return (m_boundaryBoxMin); }
00346
00348 cVector3d getBoundaryMax() const { return (m_boundaryBoxMax); }
00349
00351 cVector3d getBoundaryCenter() const { return (m_boundaryBoxMax+m_boundaryBoxMin)/2.0; }
00352
00354 void computeBoundaryBox(const bool a_includeChildren=true);
00355
00356
00357
00358
00359
00360
00362 bool setFrameSize(const double a_size=1.0, const double a_thickness=1.0, const bool a_affectChildren = false);
00363
00365 double getFrameSize() const { return (m_frameSize); }
00366
00367
00368
00369
00370
00371
00373 void setCollisionDetector(cGenericCollision* a_collisionDetector)
00374 { m_collisionDetector = a_collisionDetector; }
00375
00377 inline cGenericCollision* getCollisionDetector() const { return (m_collisionDetector); }
00378
00380 void setCollisionDetectorProperties(unsigned int a_displayDepth, cColorf& a_color, const bool a_affectChildren = false);
00381
00383 void deleteCollisionDetector(const bool a_affectChildren = false);
00384
00386 bool computeCollisionDetection(cVector3d& a_segmentPointA,
00387 cVector3d& a_segmentPointB,
00388 cCollisionRecorder& a_recorder,
00389 cCollisionSettings& a_settings);
00390
00392 virtual void adjustCollisionSegment(cVector3d& a_segmentPointA,
00393 cVector3d& a_segmentPointAadjusted);
00394
00395
00396
00397
00398
00399
00401 void setParent(cGenericObject* a_parent) { m_parent = a_parent; }
00402
00404 cGenericObject* getParent() const { return (m_parent); }
00405
00407 inline cGenericObject* getChild(const unsigned int a_index) const { return (m_children[a_index]); }
00408
00410 void addChild(cGenericObject* a_object);
00411
00413 bool removeChild(cGenericObject* a_object);
00414
00416 bool containsChild(cGenericObject* a_object, bool a_includeChildren=false);
00417
00419 bool deleteChild(cGenericObject *a_object);
00420
00422 void clearAllChildren();
00423
00425 void deleteAllChildren();
00426
00428 inline unsigned int getNumChildren() { return ((unsigned int)m_children.size()); }
00429
00431 unsigned int getNumDescendants(bool a_includeCurrentObject=false);
00432
00434 void enumerateChildren(std::list<cGenericObject*>& a_childList, bool a_includeCurrentObject=true);
00435
00437 inline bool removeFromGraph()
00438 {
00439 if (m_parent) return m_parent->removeChild(this);
00440 else return false;
00441 }
00442
00444 void setAsGhost(bool a_ghostStatus);
00445
00447 bool getAsGhost() { return (m_ghostStatus); }
00448
00449
00450
00451
00452
00453
00455 void setExternalParent(cGenericType* a_externalParent, const bool a_affectChildren = false);
00456
00458 inline cGenericType* getExternalParent() { return (m_externalParent); }
00459
00461 void setSuperParent(cGenericObject* a_superParent, const bool a_affectChildren = false);
00462
00464 inline cGenericObject* getSuperParent() { return (m_superParent); }
00465
00466
00467
00468
00469
00470
00472 void scale(const double& a_scaleFactor, const bool a_includeChildren = true);
00473
00475 void scale(const cVector3d& a_scaleFactors, const bool a_includeChildren = true);
00476
00477
00478
00479
00480
00481
00483 int m_tag;
00484
00486 virtual void setTag(const int a_tag, const bool a_affectChildren=0);
00487
00489 void* m_userData;
00490
00492 virtual void setUserData(void* a_data, const bool a_affectChildren=0);
00493
00495 char m_objectName[CHAI_SIZE_NAME];
00496
00498 virtual void setName(const char* a_name, const bool a_affectChildren=0);
00499
00500
00501 protected:
00502
00503
00504
00505
00506
00508 cGenericObject* m_parent;
00509
00511 vector<cGenericObject*> m_children;
00512
00514 bool m_ghostStatus;
00515
00516
00517
00518
00519
00520
00528 cGenericType* m_externalParent;
00529
00535 cGenericObject* m_superParent;
00536
00537
00538
00539
00540
00541
00543 cVector3d m_localPos;
00544
00546 cVector3d m_globalPos;
00547
00549 cMatrix3d m_localRot;
00550
00552 cMatrix3d m_globalRot;
00553
00555 cVector3d m_prevLocalPos;
00556
00558 cMatrix3d m_prevLocalRot;
00559
00560
00561
00562
00563
00564
00566 cVector3d m_prevGlobalPos;
00567
00569 cMatrix3d m_prevGlobalRot;
00570
00571
00572
00573
00574
00575
00577 cVector3d m_boundaryBoxMin;
00578
00580 cVector3d m_boundaryBoxMax;
00581
00582
00583
00584
00585
00586
00588 double m_frameSize;
00589
00591 double m_frameThicknessScale;
00592
00593
00594
00595
00596
00597
00599 bool m_show;
00600
00602 bool m_hapticEnabled;
00603
00605 bool m_showFrame;
00606
00608 bool m_showBox;
00609
00611 bool m_showTree;
00612
00614 bool m_showCollisionTree;
00615
00617 cColorf m_treeColor;
00618
00620 cColorf m_boundaryBoxColor;
00621
00623 bool m_useTextureMapping;
00624
00626 bool m_useMaterialProperty;
00627
00629 bool m_useVertexColors;
00630
00632 int m_triangleMode;
00633
00640 bool m_useTransparency;
00641
00650 bool m_useMultipassTransparency;
00651
00662 bool m_cullingEnabled;
00663
00664
00665
00666
00667
00668
00670 cGenericCollision* m_collisionDetector;
00671
00672
00673
00674
00675
00676
00678 virtual void render(const int a_renderMode=CHAI_RENDER_MODE_RENDER_ALL);
00679
00681 virtual void updateGlobalPositions(const bool a_frameOnly) {};
00682
00684 virtual void updateBoundaryBox() {};
00685
00687 virtual void scaleObject(const cVector3d& a_scaleFactors) {};
00688
00690 virtual void computeLocalInteraction(const cVector3d& a_toolPos,
00691 const cVector3d& a_toolVel,
00692 const unsigned int a_IDN);
00693
00695 virtual cVector3d computeOtherInteractions(const cVector3d& a_toolPos,
00696 const cVector3d& a_toolVel,
00697 const unsigned int a_IDN,
00698 cInteractionRecorder& a_interactions,
00699 cInteractionSettings& a_interactionSettings) { return cVector3d(0,0,0); }
00700
00702 virtual bool computeOtherCollisionDetection(cVector3d& a_segmentPointA,
00703 cVector3d& a_segmentPointB,
00704 cCollisionRecorder& a_recorder,
00705 cCollisionSettings& a_settings) {return(false);}
00706
00707
00708
00709
00710
00711
00713 cMatrixGL m_frameGL;
00714 };
00715
00716
00717
00718 #endif
00719
00720