Arc Look At Camera
Arc ball based camera
arc-look-at/ArcLookAt.hpp
00001 /*
00002    For more information, please see: http://software.sci.utah.edu
00003 
00004    The MIT License
00005 
00006    Copyright (c) 2013 Scientific Computing and Imaging Institute,
00007    University of Utah.
00008 
00009 
00010    Permission is hereby granted, free of charge, to any person obtaining a
00011    copy of this software and associated documentation files (the "Software"),
00012    to deal in the Software without restriction, including without limitation
00013    the rights to use, copy, modify, merge, publish, distribute, sublicense,
00014    and/or sell copies of the Software, and to permit persons to whom the
00015    Software is furnished to do so, subject to the following conditions:
00016 
00017    The above copyright notice and this permission notice shall be included
00018    in all copies or substantial portions of the Software.
00019 
00020    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00021    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00022    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00023    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00024    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00025    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00026    DEALINGS IN THE SOFTWARE.
00027 */
00028 
00031 
00032 #ifndef IAUNS_ARC_LOOK_AT_H
00033 #define IAUNS_ARC_LOOK_AT_H
00034 
00035 #include <stdint.h>
00036 #include <memory>
00037 
00038 #include <glm/glm.hpp>
00039 #include <glm/gtc/type_ptr.hpp>
00040 #include <glm/gtc/matrix_inverse.hpp>
00041 #include <glm/gtc/matrix_transform.hpp>
00042 
00043 #include <glm-aabb/AABB.hpp>
00044 
00045 // Forward declaration of ArcBall in its CPM namespace.
00046 namespace CPM_ARC_BALL_NS {
00047   class ArcBall;
00048 }
00049 
00050 namespace CPM_ARC_LOOK_AT_NS {
00051 
00057 class ArcLookAt
00058 {
00059 public:
00060   ArcLookAt();
00061   virtual ~ArcLookAt();
00062   
00067   void doReferenceDown(const glm::vec2& ssPos);
00068 
00072   void doPan(const glm::vec2& ssPos);
00073 
00075   void doRotation(const glm::vec2& ssPos);
00076 
00079   void doZoom(glm::float_t camZoom);
00080 
00083   void doZoom(const glm::vec2& ssPos);
00084 
00090   void autoview(const CPM_GLM_AABB_NS::AABB& aabb, float fov);
00091 
00093   glm::float_t getCamDistance() const   {return mCamDistance;}
00094 
00096   glm::vec3 getLookAt() const   {return mCamLookAt;}
00097 
00100   glm::mat4 getWorldViewTransform() const;
00101 
00102 private:
00103   std::unique_ptr<CPM_ARC_BALL_NS::ArcBall>  mArcBall;
00104 
00105   glm::vec3                 mCamLookAt;     
00106   glm::float_t              mCamDistance;   
00107 
00108   // The following are reference variables set when doReferenceDown is called.
00109   glm::vec2                 mReferenceScreenPos;
00110   glm::vec3                 mReferenceLookAt;
00111   glm::mat4                 mReferenceTransform;
00112   glm::float_t              mReferenceCamDistance;
00113 };
00114 
00115 } // namespace CPM_ARC_LOOK_AT_NS 
00116 
00117 #endif