Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

sglUnScale.hpp

00001 /*****************************************************************************
00002  * SGL: A Scene Graph Library
00003  *
00004  * Copyright (C) 1997-2001  Scott McMillan   All Rights Reserved.
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the Free
00018  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  *****************************************************************************
00020  *     File: sglUnScale.hpp
00021  *   Author: Tom Stimson
00022  *  Created: 1 October 2000
00023  *  Summary: Dynamically scales to maintain a constant visible size.
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    // See sglNode::intersect(f) for details.
00080    virtual sglBound::IntersectResultEnum intersect(
00081       sglIntersectf &isector) const;
00082 
00083    // See sglNode::intersect(d) for details.
00084    virtual sglBound::IntersectResultEnum intersect(
00085       sglIntersectd &isector) const;
00086 
00087    // See sglNode::pick(f) for details.
00088    virtual void pick(sglPickf &pick_state, unsigned int cull_flags) const;
00089 
00090    // See sglNode::pick(d) for details.
00091    virtual void pick(sglPickd &pick_state, unsigned int cull_flags) const;
00092 
00093    // See sglNode::clone() for details.
00094    virtual sglNode *clone(unsigned int mode) const;
00095 
00096    // See sglObject::printInfo() for details.
00097    virtual void printInfo(ostream &ostrm, const char *indent_string) const;
00098 
00099 protected:
00100    // See sglNode::cull(f) for details
00101    virtual void cull(sglCull<float> &trav_state,
00102                      unsigned int cull_flags) const;
00103 
00104    // See sglNode::cull(d) for details
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 &);              // not implemented
00112    sglUnScale &operator=(const sglUnScale &);   // not implemented
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                 // HACK precompute this in sglProbeTemplate.
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                 // HACK precompute this in sglProbeTemplate.
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

Generated at Mon Jul 1 18:00:06 2002 for SGL by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001