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
00026
00027
00028 #ifndef __SGL_UNSCALE_RANGE_HPP
00029 #define __SGL_UNSCALE_RANGE_HPP
00030
00031 #include <sgl.h>
00032 #include <sglGroup.hpp>
00033
00073 class SGL_DLL_API sglUnScaleRange : public sglGroup
00074 {
00075 public:
00077 sglUnScaleRange();
00078
00080 virtual ~sglUnScaleRange();
00081
00092 void setScaleParameters(float reference_size,
00093 unsigned int min_pixel_size,
00094 unsigned int max_pixel_size);
00095
00100 unsigned int getMinPixelSize() const { return m_min_pixel_size; }
00101
00106 unsigned int getMaxPixelSize() const { return m_max_pixel_size; }
00107
00111 float getReferenceSize() const { return m_reference_size; }
00112
00118 void setInverseMode(bool on) { m_inverse_mode = on; }
00119
00123 bool getInverseMode() const { return m_inverse_mode; }
00124
00125
00126 virtual sglBound::IntersectResultEnum intersect(
00127 sglIntersectf &isector) const;
00128
00129
00130 virtual sglBound::IntersectResultEnum intersect(
00131 sglIntersectd &isector) const;
00132
00133
00134 virtual void pick(sglPickf &pick_state, unsigned int cull_flags) const;
00135
00136
00137 virtual void pick(sglPickd &pick_state, unsigned int cull_flags) const;
00138
00139
00140 virtual sglNode *clone(unsigned int mode) const;
00141
00142
00143 virtual void printInfo(ostream &ostrm, const char *indent_string) const;
00144
00145 protected:
00146
00147 virtual void cull(sglCull<float> &trav_state,
00148 unsigned int cull_flags) const;
00149
00150
00151 virtual void cull(sglCull<double> &trav_state,
00152 unsigned int cull_flags) const;
00153
00154 void copyTo(sglUnScaleRange *dst, unsigned int mode) const;
00155
00156 private:
00157 sglUnScaleRange(const sglUnScaleRange &);
00158 sglUnScaleRange &operator=(const sglUnScaleRange &);
00159
00160 template <class T>
00161 T computeScale(sglProbeTemplate<T> &probe) const
00162 {
00163 T scale = (T)1;
00164
00165 if (probe.getOrigViewFrustum().getOrthoFlag())
00166 {
00167
00168 scale =
00169 probe.getOrigViewFrustum().getPlane(
00170 sglFrustum<T>::eUP).getDistance() +
00171 probe.getOrigViewFrustum().getPlane(
00172 sglFrustum<T>::eDOWN).getDistance();
00173 }
00174 else
00175 {
00176 scale = -(probe.getModelViewMatrix())[3][2] *
00177 tan((probe.getOrigViewFrustum().getFOVY())*0.5) * 2.0;
00178 }
00179
00180
00181
00182
00183 unsigned int viewport_x, viewport_y;
00184 probe.getViewportSize(viewport_x, viewport_y);
00185 T apparent_size = viewport_y*m_reference_size/scale;
00186
00187 if (apparent_size < m_min_pixel_size && m_min_pixel_size != 0)
00188 scale = (T)m_min_pixel_size/apparent_size;
00189 else if (apparent_size > m_max_pixel_size && m_max_pixel_size != 0)
00190 scale = (T)m_max_pixel_size/apparent_size;
00191 else
00192 scale = (T)1;
00193
00194 if (!m_inverse_mode)
00195 return scale;
00196 else
00197 return (T)1/scale;
00198 }
00199
00200 template <class T>
00201 T computeScale(sglCull<T> &trav_state) const
00202 {
00203 T scale = 1.0f;
00204
00205 if (trav_state.getOrigFrustum().getOrthoFlag())
00206 {
00207
00208 scale =
00209 trav_state.getOrigFrustum().getPlane(
00210 sglFrustum<T>::eUP).getDistance() +
00211 trav_state.getOrigFrustum().getPlane(
00212 sglFrustum<T>::eDOWN).getDistance();
00213 }
00214 else
00215 {
00216 scale = -(trav_state.getModelViewMatrix())[3][2] *
00217 tan((trav_state.getOrigFrustum().getFOVY())*0.5) * 2.0;
00218 }
00219
00220
00221
00222
00223 unsigned int viewport_x, viewport_y;
00224 trav_state.getViewportSize(viewport_x, viewport_y);
00225 T apparent_size = viewport_y*m_reference_size/scale;
00226
00227 if (apparent_size < m_min_pixel_size && m_min_pixel_size != 0)
00228 scale = (T)m_min_pixel_size/apparent_size;
00229 else if (apparent_size > m_max_pixel_size && m_max_pixel_size != 0)
00230 scale = (T)m_max_pixel_size/apparent_size;
00231 else
00232 scale = (T)1;
00233
00234 if (!m_inverse_mode)
00235 return scale;
00236 else
00237 return (T)1/scale;
00238 }
00239
00240 private:
00241 float m_reference_size;
00242 unsigned int m_min_pixel_size;
00243 unsigned int m_max_pixel_size;
00244 bool m_inverse_mode;
00245 };
00246
00247 #endif