00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _SO_QT_COLLISION_VIEWER_
00026 #define _SO_QT_COLLISION_VIEWER_
00027 #include <Inventor/Qt/OivQtCompat.h>
00028
00029
00030
00031
00032 #include <Inventor/actions/SoCallbackAction.h>
00033 #include <Inventor/misc/SoCallbackList.h>
00034 #include <Inventor/collision/SoIntersectionDetectionAction.h>
00035
00036
00037
00038 class SoQtCollisionViewer;
00039 class SoQtViewer;
00040 class SoIndexedLineSet;
00041 class SoVertexProperty;
00042 class SoCamera;
00043 class SoSceneManager;
00044
00045
00046
00047
00048 typedef void SoQtCollisionViewerCB
00049 (void *userData, SoQtCollisionViewer *collisionViewer);
00050
00051
00052
00079 class SoQtCollisionViewer
00080 {
00081
00082 public :
00083
00087 SoQtCollisionViewer(SoQtViewer *viewer);
00091 ~SoQtCollisionViewer();
00092
00096 SoQtViewer *getViewer();
00097
00101 void setDistance(float distance);
00105 float getDistance() const;
00106
00111 void setNumSteps(int num_steps);
00115 int getNumSteps() const;
00116
00120 void setCollisionDetection(SbBool value = TRUE);
00124 SbBool getCollisionDetection() const;
00125
00134 void setZBufferOptimization(SbBool value = TRUE, SbBool useZBufferOnly = FALSE);
00138 SbBool getZBufferOptimistation() const;
00139
00144 void addCallback(SoQtCollisionViewerCB* f, void* ud = NULL);
00148 void removeCallback(SoQtCollisionViewerCB* f, void* ud = NULL);
00149
00150
00151 private :
00152
00153
00154 SoQtViewer* m_viewer;
00155 SbBool m_collision_detection;
00156 SbBool m_zbuffer_optimization;
00157 SbBool m_use_zbuffer_only;
00158 short m_num_steps;
00159 float m_distance;
00160 SoCallbackList m_cb_list;
00161
00162
00163 SoCamera* m_old_camera;
00164 short m_old_width;
00165 short m_old_height;
00166 short m_old_min_width_height;
00167 SbBool m_old_data_are_valid;
00168 SoCamera* m_new_camera;
00169 short m_new_width;
00170 short m_new_height;
00171 short m_new_min_width_height;
00172
00173
00174 SbBool m_slow_collision;
00175 SbMatrix m_old_matrix;
00176 SoIntersectionDetectionAction* m_slow_collision_detection_action;
00177 SoIndexedLineSet* m_indexed_line_set;
00178 SoVertexProperty* m_vertex_property;
00179 SbBool m_segment_line_is_inserted;
00180
00181
00182 void save();
00183 void restore();
00184 void updateInternalData();
00185 SbBool checkZBufferValue(int x, int y, float z);
00186 SbBool isThisMoveCorrect();
00187 SbBool toZBufferCoordinateSpace (float x, float y, float z,
00188 short &x_in_zbuffer,
00189 short &y_in_zbuffer,
00190 float &z_in_zbuffer);
00191 void addSegmentLineForSlowAlgorithm(float x1, float y1, float z1,
00192 float x2, float y2, float z2);
00193 void removeSegmentLineForSlowAlgorithm();
00194 float linearConvertion(float value,
00195 float min, float max, float newMin, float newMax);
00196 SoIntersectionDetectionAction::Resp onSlowCollision ();
00197 SbBool slowFilter (const SoPath* path1, const SoPath* path2);
00198 void onRender (void);
00199 SoCallbackAction::Response onFoundCamera (SoCallbackAction *action,
00200 const SoNode *node);
00201
00202
00203 static SoIntersectionDetectionAction::Resp
00204 onSlowCollisionCB(void *ud,
00205 const SoIntersectingPrimitive *,
00206 const SoIntersectingPrimitive *) {
00207 return ((SoQtCollisionViewer *) ud)->onSlowCollision ();
00208 }
00209
00210 static SbBool
00211 slowFilterCB(void *ud, const SoPath *p1, const SoPath *p2) {
00212 return ((SoQtCollisionViewer *)ud)->slowFilter (p1, p2);
00213 }
00214
00215 static void
00216 onRenderCB(void *ud, SoSceneManager *) {
00217 ((SoQtCollisionViewer *)ud)->onRender ();
00218 }
00219
00220 static SoCallbackAction::Response
00221 onFoundCameraCB(void *ud,
00222 SoCallbackAction *action,
00223 const SoNode *node) {
00224 return ((SoQtCollisionViewer*) ud)->onFoundCamera (action, node);
00225 }
00226
00227
00228 };
00229
00230 #endif//_SO_QT_COLLISION_VIEWER_
00231
00232