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 __SGL_PICK_HPP
00026 #define __SGL_PICK_HPP
00027
00028 #include <sgl.h>
00029 #include <sglProbe.hpp>
00030
00031 #include <vector>
00032
00033 class sglNode;
00034
00035
00036
00040 template <class T>
00041 class SGL_DLL_API sglPick : public sglProbeTemplate<T>
00042 {
00043 public:
00044 class SGL_DLL_API PickResult : public sglProbeTemplate<T>::ProbeResult
00045 {
00046 public:
00047 vector<sglNode*> m_path;
00048
00049 public:
00050 PickResult() : sglProbeTemplate<T>::ProbeResult() {}
00051 virtual ~PickResult() { reset(); }
00052
00053 virtual void reset()
00054 {
00055 m_path.clear();
00056 resetInternal();
00057 }
00058 };
00059
00060 public:
00062 sglPick(vector<PickResult*> *result_pool = NULL);
00063
00065 virtual ~sglPick();
00066
00073 void setPickFrustum(const sglMat4<T> &pick_matrix,
00074 const sglFrustum<T> &pick_frustum);
00075
00079 virtual void reset();
00080
00082 vector<sglNode*> &getPath() { return m_path; }
00083
00087 sglFrustum<T> &getOrigPickFrustum() { return m_orig_pick_frustum; }
00089 sglFrustum<T> &getPickFrustum() { return m_current_pick_frustum; }
00090
00098 void addHit(const sglGeode *geode, const sglDrawable *geometry);
00099
00102 const vector<PickResult*> &getResults() const { return m_results; }
00103
00104
00106
00107 void pushScale(S scale,
00108 S inv_scale,
00109 sglFrustum<T> &old_pick_frustum,
00110 sglMat4<T> &old_matrix,
00111 sglFrustum<T> &old_view_frustum)
00112 {
00113 if (m_mode & (eTRANSFORM|eUNSCALE_VIEW|eUNPROJECT_VIEW|
00114 eLOD_VIEW|eBILLBOARD_VIEW))
00115 {
00116
00117 old_matrix = m_modelview_matrix;
00118
00119
00120 m_modelview_matrix.scale(old_matrix, scale, scale, scale);
00121
00122
00123 if (m_mode & eUNPROJECT_VIEW)
00124 {
00125 old_view_frustum = m_current_view_frustum;
00126 m_current_view_frustum.scale(old_view_frustum, inv_scale);
00127 }
00128 }
00129
00130
00131
00132 old_pick_frustum = m_current_pick_frustum;
00133
00134
00135 m_current_pick_frustum.scale(old_pick_frustum, inv_scale);
00136 }
00137
00139 template <class S>
00140 void pushTranslate(S tx, S ty, S tz,
00141 sglFrustum<T> &old_pick_frustum,
00142 sglMat4<T> &old_matrix,
00143 sglFrustum<T> &old_view_frustum)
00144 {
00145 if (m_mode & (eTRANSFORM|eUNSCALE_VIEW|eUNPROJECT_VIEW|
00146 eLOD_VIEW|eBILLBOARD_VIEW))
00147 {
00148
00149 old_matrix = m_modelview_matrix;
00150
00151
00152 m_modelview_matrix.translate(old_matrix, tx, ty, tz);
00153
00154
00155 if (m_mode & eUNPROJECT_VIEW)
00156 {
00157 old_view_frustum = m_current_view_frustum;
00158 m_current_view_frustum.translate(old_view_frustum,
00159 -tx, -ty, -tz);
00160 }
00161 }
00162
00163
00164
00165 old_pick_frustum = m_current_pick_frustum;
00166
00167
00168 m_current_pick_frustum.translate(old_pick_frustum, -tx, -ty, -tz);
00169 }
00170
00171
00172
00173 template <class S>
00174 void pushTransform(const sglMat4<S> &xform,
00175 const sglMat4<S> &inv_xform,
00176 sglFrustum<T> &old_pick_frustum,
00177 sglMat4<T> &old_matrix,
00178 sglFrustum<T> &old_view_frustum)
00179 {
00180 if (m_mode & (eTRANSFORM|eUNSCALE_VIEW|eUNPROJECT_VIEW|
00181 eLOD_VIEW|eBILLBOARD_VIEW))
00182 {
00183
00184 old_matrix = m_modelview_matrix;
00185
00186
00187 m_modelview_matrix.mul(xform, old_matrix);
00188
00189
00190 if (m_mode & eUNPROJECT_VIEW)
00191 {
00192 old_view_frustum = m_current_view_frustum;
00193 m_current_view_frustum.mul(old_view_frustum, inv_xform);
00194 }
00195 }
00196
00197
00198
00199 old_pick_frustum = m_current_pick_frustum;
00200
00201
00202 m_current_pick_frustum.mul(old_pick_frustum, inv_xform);
00203 }
00204
00205
00206 void pop(sglFrustum<T> &old_pick_frustum,
00207 sglMat4<T> &old_matrix,
00208 sglFrustum<T> &old_view_frustum)
00209 {
00210 m_current_pick_frustum = old_pick_frustum;
00211
00212 if (m_mode & (eTRANSFORM|eUNSCALE_VIEW|eUNPROJECT_VIEW|
00213 eLOD_VIEW|eBILLBOARD_VIEW))
00214 {
00215 m_modelview_matrix = old_matrix;
00216
00217
00218 if (m_mode & eUNPROJECT_VIEW)
00219 {
00220 m_current_view_frustum = old_view_frustum;
00221 }
00222 }
00223 }
00224
00225 private:
00226 sglPick(const sglPick &);
00227 sglPick& operator=(const sglPick &);
00228
00229 protected:
00230 sglFrustum<T> m_orig_pick_frustum;
00231 sglFrustum<T> m_current_pick_frustum;
00232
00233 vector<PickResult*> m_results;
00234 vector<PickResult*> *m_result_pool;
00235
00236 vector<sglNode*> m_path;
00237 };
00238
00239
00240
00241
00242
00243 typedef sglPick<float> sglPickf;
00244 typedef sglPick<double> sglPickd;
00245
00246 #endif