rtVTK  0.6.0
Camera.h
00001 
00002 /******************************************************************************
00003  * Copyright (c) 2012, Grove City College
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are
00008  * met:
00009  * 
00010  *  * Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  *
00013  *  * Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in
00015  *    the documentation and/or other materials provided with the
00016  *    distribution.
00017  *
00018  *  * Neither the name of Grove City College nor the names of its
00019  *    contributors may be used to endorse or promote products derived
00020  *    from this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00025  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00026  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00027  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00028  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00029  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00030  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00031  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00032  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  */
00035 
00036 
00037 #ifndef Core_uiCore_Camera_h
00038 #define Core_uiCore_Camera_h
00039 
00040 #include <Math/Math.h>
00041 #include <Math/Quaternion.h>
00042 
00043 #ifdef WIN32
00044 #  undef near
00045 #  undef far
00046 #endif // WIN32
00047 
00048 namespace uiCore
00049 {
00050 
00052   // Using directives
00053 
00054   using MathF::Point;
00055   using MathF::Vector;
00056 
00057   using Math::Cross;
00058   using Math::Quaternion;
00059 
00060   // Eye == "Rotate about position".
00061   // LookAt == "Rotate about focal point".
00062   enum CameraMode { Eye, Lookat, numCameraModes };
00063 
00065   // Class definition
00070   class Camera
00071   {
00072   public:
00073     Camera(const Point&     = Point(0, 0, 5),
00074            const Point&     = Point(0, 0, 0),
00075            const Vector&    = Vector(0, 1, 0),
00076                  float      = 45.f,
00077                  float      = 0.1f,
00078                  float      = 100.f,
00079                  CameraMode = Lookat);
00080 
00081     ~Camera() { /* no-op */ }
00082 
00083     void reset();
00084 
00085     void moveCam(const Vector&);
00086     void rotateCam(const Vector&, float);
00087     void setLookMode(CameraMode);
00088 
00089     void setFOV(float fov_)   { fov = fov_;   }
00090     void setNear(float near_) { near = near_; }
00091     void setFar(float far_)   { far = far_;   }
00092 
00093     Point getEye() const
00094     {
00095       return (mode == Eye ? origin : origin - rotation.rotateV(move));
00096     }
00097 
00098     Point getLook() const
00099     {
00100       return (mode == Lookat ?
00101               origin + rotation.rotateV(refIn*move.length() - move) :
00102               origin + rotation.rotateV(move));
00103     }
00104 
00105     Point getRotPt() const
00106     {
00107       return (mode == Lookat ? origin : origin + rotation.rotateV(move));
00108     }
00109 
00110     Vector     getUp()    const { return rotation.rotateV(refUp); }
00111     float      getFOV()   const { return fov;                     }
00112     float      getNear()  const { return near;                    }
00113     float      getFar()   const { return far;                     }
00114     CameraMode getMode()  const { return mode;                    }
00115 
00116   private:
00121     Point  initPos;
00122     Point  initLook;
00123     Vector initUp;
00124     float  initFOV;
00126 
00127     float  fov;
00128     float  near;
00129     float  far;
00130 
00132     CameraMode mode;
00133 
00134     static const Vector refUp;
00135     static const Vector refIn;
00136     static const Vector refSide;
00137 
00143     Point      origin;
00144     Quaternion rotation;
00146 
00147     Vector move;
00148   }; // class Camera
00149 
00150 } // namespace uiCore
00151 
00152 #endif // Core_uiCore_Camera_h
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends