00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef S5_OBJECT_H_INCLUDED_
00019 #define S5_OBJECT_H_INCLUDED_
00020
00021 #include <Inventor/nodes/SoSwitch.h>
00022 #include <Inventor/nodes/SoMatrixTransform.h>
00023 #include <Inventor/fields/SoSFFloat.h>
00024 #include <Inventor/SbTime.h>
00025
00026 class S5camera;
00027
00028
00029
00030
00031 inline SbVec3f matrixGetTranslation(const SbMatrix m) { return SbVec3f(m[3][0], m[3][1], m[3][2]); }
00032 inline void matrixGetTranslation(const SbMatrix m, float &x, float &y, float &z) { x=m[3][0]; y=m[3][1]; z=m[3][2]; }
00033 inline void matrixSetTranslation(SbMatrix &m, const SbVec3f vec) { m[3][0]=vec[0]; m[3][1]=vec[1]; m[3][2]=vec[2]; }
00034 inline void matrixSetTranslation(SbMatrix &m, const float x, const float y, const float z) { m[3][0]=x; m[3][1]=y; m[3][2]=z; }
00035
00036 inline SbVec3f matrixGetVecAhead(const SbMatrix m) { return SbVec3f(-m[2][0], -m[2][1], -m[2][2]); }
00037 inline void matrixSetVecAhead(SbMatrix &m, const SbVec3f vec) { m[2][0]=-vec[0]; m[2][1]=-vec[1]; m[2][2]=-vec[2]; }
00038
00039 inline SbVec3f matrixGetVecRight(const SbMatrix m) { return SbVec3f(m[0][0], m[0][1], m[0][2]); }
00040 inline void matrixSetVecRight(SbMatrix &m, const SbVec3f vec) { m[0][0]=vec[0]; m[0][1]=vec[1]; m[0][2]=vec[2]; }
00041
00042 inline SbVec3f matrixGetVecUp(const SbMatrix m) { return SbVec3f(m[1][0], m[1][1], m[1][2]); }
00043 inline void matrixSetVecUp(SbMatrix &m, const SbVec3f vec) { m[1][0]=vec[0]; m[1][1]=vec[1]; m[1][2]=vec[2]; }
00044
00045
00046
00047 class S5object : public SoSwitch
00048 {
00049
00050 SO_NODE_HEADER(S5object);
00051
00052 public:
00053
00054 SoSFFloat collisionRadius;
00055
00056
00057 void getMatrix(SbMatrix &m) const { matrixTransform->matrix.getValue().getValue(m); };
00058 const SbMatrix& getMatrix() const { return matrixTransform->matrix.getValue(); };
00059 void setMatrix(const SbMatrix m) { matrixTransform->matrix.setValue(m); };
00060
00061
00062 SbVec3f getTranslation() const { return matrixGetTranslation(getMatrix()); };
00063 SbVec3f getDirectionAhead() const { return matrixGetVecAhead(getMatrix()); };
00064 SbVec3f getDirectionRight() const { return matrixGetVecRight(getMatrix()); };
00065 SbVec3f getDirectionUp() const { return matrixGetVecUp(getMatrix()); };
00066
00067
00068 void rotate(const float heading, const float pitch, const float roll = 0.f);
00069
00070
00071 void setTranslation(SbVec3f vec) { SbMatrix m(getMatrix()); matrixSetTranslation(m, vec); setMatrix(m); };
00072 void setTranslation(float x, float y, float z) { SbMatrix m(getMatrix()); matrixSetTranslation(m, x,y,z); setMatrix(m); };
00073
00074
00075 SoNode* getGraph() { return graph; };
00076 void setGraph(SoNode *g);
00077
00078 SbBool getVisibility() { return visible; };
00079 void setVisibility(SbBool newVisibility);
00080
00081
00082
00083 SbMatrix getTransformation();
00084 SbVec3f getPosition() { return matrixGetTranslation(getTransformation()); };
00085
00086 void attachCamera(S5camera *newCamera);
00087 void detachCamera() { attachCamera(NULL); }
00088 S5camera* getCamera() { return camera; };
00089
00090
00091 static void performTimeTick(SbTime dt);
00092
00093 virtual void timeTick(SbTime dt) {};
00094
00095 S5object();
00096
00097 public:
00098
00099 S5object* getNext() { return next; };
00100 S5object* getPrev() { return prev; };
00101 static S5object* getFirst() { return first; };
00102 static S5object* getLast() { return last; };
00103
00104 private:
00105
00106 void insertToList();
00107 void removeFromList();
00108
00109 S5object *next;
00110 S5object *prev;
00111 static S5object *first;
00112 static S5object *last;
00113
00114 SoINTERNAL public:
00115
00116 SbBool getVisibilityForCameras() { return visibleForCameras; };
00117 void setVisibilityForCameras(SbBool newVisibility);
00118
00119 static void initClass();
00120
00121 protected:
00122
00123 virtual SbBool readInstance(SoInput * in, unsigned short flags);
00124
00125 virtual ~S5object();
00126
00127 void doShow();
00128 void doHide();
00129
00130 SoSeparator *separator;
00131 SoMatrixTransform *matrixTransform;
00132 SoNode *graph;
00133
00134 SbBool visible;
00135 SbBool visibleForCameras;
00136
00137 friend S5camera;
00138 S5camera *camera;
00139
00140 };
00141
00142
00143 #endif