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_XT_COLLISION_VIEWER_
00026 #define _SO_XT_COLLISION_VIEWER_
00027
00028
00029
00030
00031 #include <Inventor/Win/SoWinBeginStrict.h>
00032
00033 #include <Inventor/actions/SoCallbackAction.h>
00034 #include <Inventor/misc/SoCallbackList.h>
00035 #include <Inventor/collision/SoIntersectionDetectionAction.h>
00036
00037
00038
00039 class SoWinCollisionViewer;
00040 class SoWinViewer;
00041 class SoIndexedLineSet;
00042 class SoVertexProperty;
00043 class SoCamera;
00044 class SoSceneManager;
00045
00046
00047
00048
00049
00050 typedef void SoWinCollisionViewerCB
00051 (void *userData, SoWinCollisionViewer *collisionViewer);
00052
00053
00054
00081 class SoWinCollisionViewer
00082 {
00083
00084 public :
00085
00089 SoWinCollisionViewer(SoWinViewer *viewer);
00093 ~SoWinCollisionViewer();
00094
00098 SoWinViewer *getViewer();
00099
00103 void setDistance(float distance);
00107 float getDistance() const;
00108
00113 void setNumSteps(int num_steps);
00117 int getNumSteps() const;
00118
00122 void setCollisionDetection(SbBool value = TRUE);
00126 SbBool getCollisionDetection() const;
00127
00136 void setZBufferOptimization(SbBool value = TRUE, SbBool useZBufferOnly = FALSE);
00140 SbBool getZBufferOptimistation() const;
00141
00147 void addCallback(SoWinCollisionViewerCB* f, void* ud = NULL);
00152 void removeCallback(SoWinCollisionViewerCB* f, void* ud = NULL);
00153
00154
00155 private :
00156
00157
00158 SoWinViewer* m_viewer;
00159 SbBool m_collision_detection;
00160 SbBool m_zbuffer_optimization;
00161 SbBool m_use_zbuffer_only;
00162 short m_num_steps;
00163 float m_distance;
00164 SoCallbackList m_cb_list;
00165
00166
00167 SoCamera* m_old_camera;
00168 short m_old_width;
00169 short m_old_height;
00170 short m_old_min_width_height;
00171 SbBool m_old_data_are_valid;
00172 SoCamera* m_new_camera;
00173 short m_new_width;
00174 short m_new_height;
00175 short m_new_min_width_height;
00176
00177
00178 SbBool m_slow_collision;
00179 SbMatrix m_old_matrix;
00180 SoIntersectionDetectionAction* m_slow_collision_detection_action;
00181 SoIndexedLineSet* m_indexed_line_set;
00182 SoVertexProperty* m_vertex_property;
00183 SbBool m_segment_line_is_inserted;
00184
00185
00186 void save();
00187 void restore();
00188 void updateInternalData();
00189 SbBool checkZBufferValue(int x, int y, float z);
00190 SbBool isThisMoveCorrect();
00191 SbBool toZBufferCoordinateSpace (float x, float y, float z,
00192 short &x_in_zbuffer,
00193 short &y_in_zbuffer,
00194 float &z_in_zbuffer);
00195 void addSegmentLineForSlowAlgorithm(float x1, float y1, float z1,
00196 float x2, float y2, float z2);
00197 void removeSegmentLineForSlowAlgorithm();
00198 float linearConvertion(float value,
00199 float min, float max, float newMin, float newMax);
00200 SoIntersectionDetectionAction::Resp onSlowCollision ();
00201 SbBool slowFilter (const SoPath* path1, const SoPath* path2);
00202 void onRender (void);
00203 SoCallbackAction::Response onFoundCamera (SoCallbackAction *action,
00204 const SoNode *node);
00205
00206
00207 static SoIntersectionDetectionAction::Resp
00208 onSlowCollisionCB(void *ud,
00209 const SoIntersectingPrimitive *,
00210 const SoIntersectingPrimitive *) {
00211 return ((SoWinCollisionViewer *) ud)->onSlowCollision ();
00212 }
00213
00214 static SbBool
00215 slowFilterCB(void *ud, const SoPath *p1, const SoPath *p2) {
00216 return ((SoWinCollisionViewer *)ud)->slowFilter (p1, p2);
00217 }
00218
00219 static void
00220 onRenderCB(void *ud, SoSceneManager *) {
00221 ((SoWinCollisionViewer *)ud)->onRender ();
00222 }
00223
00224 static SoCallbackAction::Response
00225 onFoundCameraCB(void *ud,
00226 SoCallbackAction *action,
00227 const SoNode *node) {
00228 return ((SoWinCollisionViewer*) ud)->onFoundCamera (action, node);
00229 }
00230
00231
00232 };
00233
00234 #include <Inventor/Win/SoWinEndStrict.h>
00235
00236 #endif//_SO_XT_COLLISION_VIEWER_
00237
00238