Transformable.h

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @class  Transformable
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Fall 2008
00006    
00007    @brief
00008       Represents a Shape which is defined in its own local "object space" and
00009    knows how to transform itself into the global "world space"
00010    <!-------------------------------------------------------------------->**/
00011 
00012 #ifndef TRANSFORMABLE_H_
00013 #define TRANSFORMABLE_H_
00014 
00015 #include <shapes/Shape.h>
00016 #include <common/math/algebra.h>
00017 
00018 class Transformable : public Shape {
00019    public:
00020       ///@name Constructors
00021       //@{-----------------------------------------------------------------
00022       
00023       inline Transformable(const Matrix4x4 &transToWorld, 
00024                            const Matrix4x4 &transToWorldInv, 
00025                            Material *material = NULL)
00026          : Shape(material), 
00027            m_transToWorld(transToWorld), 
00028            m_transToWorldInv(transToWorldInv)
00029       { }
00030       
00031       inline Transformable(const Matrix4x4 &transToWorld, 
00032                            Material *material = NULL)
00033          : Shape(material), 
00034            m_transToWorld(transToWorld), 
00035            m_transToWorldInv(transToWorld.getInverse())
00036       { }
00037       
00038       inline Transformable(Material *material = NULL)
00039          : Shape(material), 
00040            m_transToWorld(Matrix4x4::identity()), 
00041            m_transToWorldInv(Matrix4x4::identity())
00042       { }
00043       
00044       virtual ~Transformable()
00045       { }
00046       
00047       
00048       //@}-----------------------------------------------------------------
00049       ///@name Initialization
00050       //@{-----------------------------------------------------------------
00051       
00052       /**
00053        * @brief
00054        *    Initializes this Transformable's world-space AABB, assuming a 
00055        * derived class has already filled in m_objSpaceAABB
00056        */
00057       virtual void init();
00058       
00059       
00060       //@}-----------------------------------------------------------------
00061       ///@name Main usage interface
00062       //@{-----------------------------------------------------------------
00063       
00064       /**
00065        * Display a crude OpenGL preview of this shape
00066        * 
00067        * @note
00068        *    Default implementation sets the ModelView matrix appropriately
00069        * with respect to this Transformable's transformation
00070        */
00071       virtual void preview();
00072       
00073        
00074       //@}-----------------------------------------------------------------
00075       ///@name Sampling functionality
00076       //@{-----------------------------------------------------------------
00077       
00078       /**
00079        * @note implementation returns the origin of this shape in world space 
00080        *    because not all shapes support this functionality
00081        */
00082       virtual Point3 getPosition(const UV &uv);
00083       
00084       
00085       //@}-----------------------------------------------------------------
00086       ///@name Accessors / Mutators
00087       //@{-----------------------------------------------------------------
00088       
00089       inline const Matrix4x4 &getTransToWorld() const {
00090          return m_transToWorld;
00091       }
00092       
00093       inline void setTransToWorld(const Matrix4x4 &transToWorld) {
00094          m_transToWorld = transToWorld;
00095          m_transToWorldInv = transToWorld.getInverse();
00096       }
00097       
00098       inline const Matrix4x4 &getTransToWorldInv() const {
00099          return m_transToWorldInv;
00100       }
00101       
00102       inline void setTransToWorldInv(const Matrix4x4 &transToWorldInv) {
00103          m_transToWorldInv = transToWorldInv;
00104       }
00105       
00106       inline const AABB &getObjSpaceAABB() const {
00107          return m_objSpaceAABB;
00108       }
00109       
00110       /**
00111        * @returns true iff this Shape subclasses Transformable
00112        */
00113       virtual bool isTransformable() const {
00114          return true;
00115       }
00116       
00117       
00118       //@}-----------------------------------------------------------------
00119       
00120    protected:
00121       void _transformRayWorldToObj(const Ray &ray, Point3 &p, 
00122                                    Vector3 &d) const;
00123       
00124       void _transformPoint3WorldToObj(const Point3 &pWorld, 
00125                                       Point3 &pObj) const;
00126       
00127       void _transformVector3WorldToObj(const Vector3 &vWorld, 
00128                                        Vector3 &vObj) const;
00129       
00130       void _transformVector3ObjToWorld(const Vector3 &nObj, 
00131                                        Vector3 &nWorld) const;
00132       
00133    protected:
00134       Matrix4x4 m_transToWorld;
00135       Matrix4x4 m_transToWorldInv;
00136       
00137       AABB      m_objSpaceAABB;
00138 };
00139 
00140 /* Include inline implementations */
00141 #include <shapes/Transformable.inl>
00142 
00143 #endif // TRANSFORMABLE_H_
00144 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6