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