![]() |
rtVTK
0.6.0
|
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_Trackball_h 00038 #define Core_uiCore_Trackball_h 00039 00040 #include <Core/uiCore/Camera.h> 00041 #include <Core/uiCore/Mouse.h> 00042 namespace uiCore 00043 { 00048 class Trackball 00049 { 00050 public: 00051 Trackball(const Camera& cam_ = Camera(), float radius_ = 0.8f) : 00052 cam(cam_), 00053 radius(radius_) 00054 { 00055 // no-op 00056 } 00057 00058 void mouseClick(Mouse::Button, uint, uint); 00059 void mouseRelease(Mouse::Button, uint, uint); 00060 void mouseMove(uint, uint, uint, uint, 00061 float = 1.f, float = 1.f, float = 1.f); 00062 00063 Camera& getCam() { return cam; } 00064 const Camera& getCam() const { return cam; } 00065 00066 Point getEye() const { return cam.getEye(); } 00067 Point getLook() const { return cam.getLook(); } 00068 Vector getUp() const { return cam.getUp(); } 00069 float getFOV() const { return cam.getFOV(); } 00070 float getNear() const { return cam.getNear(); } 00071 float getFar() const { return cam.getFar(); } 00072 CameraMode getMode() const { return cam.getMode(); } 00073 00074 void setLookMode(CameraMode& mode) { cam.setLookMode(mode); } 00075 void setFOV(float fov) { cam.setFOV(fov); } 00076 00077 void reset() { cam.reset(); } 00078 00079 private: 00086 struct xyPair 00087 { 00088 xyPair(const Mouse::xyCoord& xy) : x(xy.x), y(xy.y) {} 00089 xyPair(float x_, float y_ ) : x(x_), y(y_) {} 00090 xyPair(float n ) : x(n), y(n) {} 00091 xyPair( ) : x(0), y(0) {} 00092 00093 friend xyPair operator+(const xyPair& lhs, const xyPair& rhs) 00094 { return xyPair(lhs.x+rhs.x, lhs.y+rhs.y); } 00095 00096 friend xyPair operator-(const xyPair& lhs, const xyPair& rhs) 00097 { return xyPair(lhs.x-rhs.x, lhs.y-rhs.y); } 00098 00099 friend xyPair operator*(const xyPair& lhs, const xyPair& rhs) 00100 { return xyPair(lhs.x*rhs.x, lhs.y*rhs.y); } 00101 00102 friend xyPair operator/(const xyPair& lhs, const xyPair& rhs) 00103 { return xyPair(lhs.x/rhs.x, lhs.y/rhs.y); } 00104 00105 friend float Dot(const xyPair& lhs, const xyPair& rhs) 00106 { return lhs.x*rhs.x + lhs.y*rhs.y; } 00107 00108 float x, y; 00109 }; // struct xyPair 00110 00111 Camera cam; 00112 Mouse mouse; 00113 float radius; 00114 }; // class Trackball 00115 00116 } // namespace uiCore 00117 00118 #endif // Core_uiCore_Trackball_h