Visualization Library v1.0.3A lightweight C++ OpenGL middleware for 2D/3D graphics |
[Download] [Tutorials] [All Classes] [Grouped Classes] |
00001 /**************************************************************************************/ 00002 /* */ 00003 /* Visualization Library */ 00004 /* http://visualizationlibrary.org */ 00005 /* */ 00006 /* Copyright (c) 2005-2010, Michele Bosi */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without modification, */ 00010 /* are permitted provided that the following conditions are met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, this */ 00013 /* list of conditions and the following disclaimer. */ 00014 /* */ 00015 /* - Redistributions in binary form must reproduce the above copyright notice, this */ 00016 /* list of conditions and the following disclaimer in the documentation and/or */ 00017 /* other materials provided with the distribution. */ 00018 /* */ 00019 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */ 00020 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 00021 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ 00022 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */ 00023 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ 00024 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 00025 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ 00026 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ 00027 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 00028 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 00029 /* */ 00030 /**************************************************************************************/ 00031 00032 #ifndef TrackballManipulator_INCLUDE_ONCE 00033 #define TrackballManipulator_INCLUDE_ONCE 00034 00035 #include <vlGraphics/UIEventListener.hpp> 00036 #include <vlGraphics/Camera.hpp> 00037 #include <vlCore/Vector3.hpp> 00038 00039 namespace vl 00040 { 00041 class Transform; 00042 class Rendering; 00043 class SceneManager; 00044 class ActorCollection; 00045 00046 //------------------------------------------------------------------------------ 00047 // TrackballManipulator 00048 //------------------------------------------------------------------------------ 00061 class VLGRAPHICS_EXPORT TrackballManipulator: public UIEventListener 00062 { 00063 VL_INSTRUMENT_CLASS(vl::TrackballManipulator, UIEventListener) 00064 00065 public: 00066 typedef enum { NoMode, RotationMode, TranslationMode, ZoomMode } ETrackballMode; 00067 00068 public: 00070 TrackballManipulator(): mMode(NoMode), 00071 mRotationButton(LeftButton), mTranslationButton(MiddleButton), mZoomButton(RightButton), 00072 mRotationSpeed(1.0f), mTranslationSpeed(1.0f), mZoomSpeed(1.0f) 00073 { 00074 VL_DEBUG_SET_OBJECT_NAME() 00075 } 00076 00077 // --- UIEventListener --- 00078 00079 virtual void mouseDownEvent(EMouseButton, int x, int y); 00080 00081 virtual void mouseUpEvent(EMouseButton, int x, int y); 00082 00083 virtual void mouseMoveEvent(int x, int y); 00084 00085 virtual void enableEvent(bool enabled); 00086 00087 virtual void initEvent() {} 00088 00089 virtual void destroyEvent() {} 00090 00091 virtual void updateEvent() {} 00092 00093 virtual void addedListenerEvent(OpenGLContext*) {} 00094 00095 virtual void removedListenerEvent(OpenGLContext*) {} 00096 00097 virtual void mouseWheelEvent(int) {} 00098 00099 virtual void keyPressEvent(unsigned short, EKey) {} 00100 00101 virtual void keyReleaseEvent(unsigned short, EKey) {} 00102 00103 virtual void resizeEvent(int, int) {} 00104 00105 virtual void fileDroppedEvent(const std::vector<String>&) {} 00106 00107 virtual void visibilityEvent(bool) {} 00108 00109 // --- user methods --- 00110 00112 void setCamera(Camera* camera) { mCamera = camera; } 00113 00115 Camera* camera() { return mCamera.get(); } 00116 00118 void setPivot(vec3 pivot) { mPivot = pivot; } 00119 00121 vec3 pivot() const { return mPivot; } 00122 00124 void setTransform(Transform* tr) { mTransform = tr; } 00125 00127 Transform* transform() { return mTransform.get(); } 00128 00130 int rotationButton() const { return mRotationButton; } 00131 00133 void setRotationButton(int mouse_button) { mRotationButton = mouse_button; } 00134 00136 int zoomButton() const { return mZoomButton; } 00137 00139 void setZoomButton(int mouse_button) { mZoomButton = mouse_button; } 00140 00142 int translationButton() const { return mTranslationButton; } 00143 00145 void setTranslationButton(int mouse_button) { mTranslationButton = mouse_button; } 00146 00148 float rotationSpeed() const { return mRotationSpeed; } 00149 00151 void setRotationSpeed(float speed) { mRotationSpeed = speed; } 00152 00154 float zoomSpeed() const { return mZoomSpeed; } 00155 00157 void setZoomSpeed(float speed) { mZoomSpeed = speed; } 00158 00160 float translationSpeed() const { return mTranslationSpeed; } 00161 00163 void setTranslationSpeed(float speed) { mTranslationSpeed = speed; } 00164 00166 void adjustView(const AABB& aabb, const vec3& dir, const vec3& up, real bias=1.0f); 00167 00169 void adjustView(ActorCollection& actors, const vec3& dir, const vec3& up, real bias=1.0f); 00170 00172 void adjustView(SceneManager* scene, const vec3& dir, const vec3& up, real bias=1.0f); 00173 00175 void adjustView(Rendering* rendering, const vec3& dir, const vec3& up, real bias=1.0f); 00176 00177 // --- Advanced methods --- 00178 00179 mat4 trackballRotation(int x, int y); 00180 00181 vec3 computeVector(int x, int y); 00182 00184 ETrackballMode mode() const { return mMode; } 00185 00186 protected: 00187 ref<Camera> mCamera; 00188 ivec2 mMouseStart; 00189 mat4 mStartMatrix; 00190 vec3 mPivot; 00191 vec3 mStartCameraPos; 00192 vec3 mStartPivot; 00193 ref<Transform> mTransform; 00194 ETrackballMode mMode; 00195 int mRotationButton; 00196 int mTranslationButton; 00197 int mZoomButton; 00198 float mRotationSpeed; 00199 float mTranslationSpeed; 00200 float mZoomSpeed; 00201 }; 00202 } 00203 00204 #endif