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 #ifndef __SGL_UNSCALE_HPP
00027 #define __SGL_UNSCALE_HPP
00028
00029 #include <sgl.h>
00030 #include <sglGroup.hpp>
00031
00057 class SGL_DLL_API sglUnScale : public sglGroup
00058 {
00059 public:
00064 sglUnScale(bool fixedPixelScale = false);
00065
00067 virtual ~sglUnScale();
00068
00072 void setFixedPixelScale(bool on) { m_pixel_scale = on; }
00073
00077 bool getFixedPixelScale() const { return m_pixel_scale; }
00078
00079
00080 virtual sglBound::IntersectResultEnum intersect(
00081 sglIntersectf &isector) const;
00082
00083
00084 virtual sglBound::IntersectResultEnum intersect(
00085 sglIntersectd &isector) const;
00086
00087
00088 virtual void pick(sglPickf &pick_state, unsigned int cull_flags) const;
00089
00090
00091 virtual void pick(sglPickd &pick_state, unsigned int cull_flags) const;
00092
00093
00094 virtual sglNode *clone(unsigned int mode) const;
00095
00096
00097 virtual void printInfo(ostream &ostrm, const char *indent_string) const;
00098
00099 protected:
00100
00101 virtual void cull(sglCull<float> &trav_state,
00102 unsigned int cull_flags) const;
00103
00104
00105 virtual void cull(sglCull<double> &trav_state,
00106 unsigned int cull_flags) const;
00107
00108 void copyTo(sglUnScale *dst, unsigned int mode) const;
00109
00110 private:
00111 sglUnScale(const sglUnScale &);
00112 sglUnScale &operator=(const sglUnScale &);
00113
00114 template <class T>
00115 T computeScale(sglProbeTemplate<T> &probe) const
00116 {
00117 T scale = 1.0f;
00118
00119 if (probe.getOrigViewFrustum().getOrthoFlag())
00120 {
00121
00122 scale =
00123 probe.getOrigViewFrustum().getPlane(
00124 sglFrustum<T>::eUP).getDistance() +
00125 probe.getOrigViewFrustum().getPlane(
00126 sglFrustum<T>::eDOWN).getDistance();
00127 }
00128 else
00129 {
00130 scale = -(probe.getModelViewMatrix())[3][2] *
00131 tan((probe.getOrigViewFrustum().getFOVY())*0.5) * 2.0;
00132 }
00133
00134 if (m_pixel_scale)
00135 {
00136 unsigned int viewport_x, viewport_y;
00137 probe.getViewportSize(viewport_x, viewport_y);
00138 scale /= (T)viewport_y;
00139 }
00140
00141 return scale;
00142 }
00143
00144 template <class T>
00145 T computeScale(sglCull<T> &trav_state) const
00146 {
00147 T scale = 1.0f;
00148
00149 if (trav_state.getOrigFrustum().getOrthoFlag())
00150 {
00151
00152 scale =
00153 trav_state.getOrigFrustum().getPlane(
00154 sglFrustum<T>::eUP).getDistance() +
00155 trav_state.getOrigFrustum().getPlane(
00156 sglFrustum<T>::eDOWN).getDistance();
00157 }
00158 else
00159 {
00160 scale = -(trav_state.getModelViewMatrix())[3][2] *
00161 tan((trav_state.getOrigFrustum().getFOVY())*0.5) * 2.0;
00162 }
00163
00164 if (m_pixel_scale)
00165 {
00166 unsigned int viewport_x, viewport_y;
00167 trav_state.getViewportSize(viewport_x, viewport_y);
00168 scale /= (T)viewport_y;
00169 }
00170
00171 return scale;
00172 }
00173
00174 private:
00175 bool m_pixel_scale;
00176 };
00177
00178 #endif