OpenWalnut
1.2.5
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WPICKINFO_H 00026 #define WPICKINFO_H 00027 00028 #include <string> 00029 #include <utility> 00030 00031 #include "../common/math/linearAlgebra/WLinearAlgebra.h" 00032 #include "../common/WDefines.h" 00033 #include "WExportWGE.h" 00034 00035 00036 /** 00037 * Encapsulates info for pick action. 00038 */ 00039 class WGE_EXPORT WPickInfo 00040 { 00041 public: 00042 /** 00043 * Different types of modifier keys. 00044 */ 00045 enum modifierKey 00046 { 00047 NONE, 00048 SHIFT, 00049 STRG, 00050 ALT, 00051 WIN 00052 }; 00053 00054 /** 00055 * Different types of mouse buttons. 00056 */ 00057 typedef enum 00058 { 00059 NOMOUSE, 00060 MOUSE_LEFT, 00061 MOUSE_RIGHT, 00062 MOUSE_MIDDLE, 00063 MOUSE4, 00064 MOUSE5 00065 } 00066 WMouseButton; 00067 00068 /** 00069 * Creates an object with the needed information. 00070 * \param name name of picked object 00071 * \param viewerName name of the viewer 00072 * \param pickPosition position where object was hit 00073 * \param pixelCoords pixel coordinates of the mouse 00074 * \param modKey relevant modifier key pressed during the pick 00075 * \param mButton mouse button that initiated the pick 00076 * \param pickNormal normal at position where object was hit. (0,0,0) means not set. 00077 */ 00078 inline WPickInfo( std::string name, 00079 std::string viewerName, 00080 WPosition pickPosition, 00081 std::pair< float, float > pixelCoords, 00082 modifierKey modKey, 00083 WMouseButton mButton = WPickInfo::MOUSE_LEFT, 00084 WVector3d pickNormal = WVector3d() ); 00085 00086 /** 00087 * Creates an object with the empty name, zero position and no modkey. 00088 */ 00089 inline WPickInfo(); 00090 00091 /** 00092 * Get the modifier key associated with the pick 00093 * 00094 * \return the mod key 00095 */ 00096 inline modifierKey getModifierKey() const; 00097 00098 /** 00099 * Get the mouse button associated with the pick 00100 * 00101 * \return the mouse button 00102 */ 00103 inline WMouseButton getMouseButton() const; 00104 00105 /** 00106 * Set the modifier key associated with the pick 00107 * \param modKey new modifier key 00108 */ 00109 inline void setModifierKey( const modifierKey& modKey ); 00110 00111 /** 00112 * Set the modifier key associated with the pick 00113 * \param mButton new mouse button 00114 */ 00115 inline void setMouseButton( const WMouseButton& mButton ); 00116 00117 00118 /** 00119 * Get name of picked object. 00120 * 00121 * \return object name 00122 */ 00123 inline std::string getName() const; 00124 00125 /** 00126 * Get name of the viewer. 00127 * 00128 * \return viewer name 00129 */ 00130 inline std::string getViewerName() const; 00131 00132 /** 00133 * Get position where object was hit. 00134 * 00135 * \return the pick position 00136 */ 00137 inline WPosition getPickPosition() const; 00138 00139 /** 00140 * Get normal at position where object was hit. 00141 * 00142 * \return pick normal 00143 */ 00144 inline WVector3d getPickNormal() const; 00145 00146 /** 00147 * Returns the picked pixel coordinates in screen-space. 00148 * 00149 * \return the coordinates 00150 */ 00151 inline WVector2d getPickPixel() const; 00152 00153 /** 00154 * Tests two pick infos for equality 00155 * \param rhs right hand side of comparison 00156 * 00157 * \return true if equal 00158 */ 00159 inline bool operator==( WPickInfo rhs ) const; 00160 00161 /** 00162 * Tests two pick infos for inequality 00163 * 00164 * \param rhs right hand side of comparison 00165 * 00166 * \return true if not equal 00167 */ 00168 inline bool operator!=( WPickInfo rhs ) const; 00169 00170 protected: 00171 private: 00172 00173 std::string m_name; //!< name of picked object. 00174 std::string m_viewerName; //!< name of the viewer 00175 WPosition m_pickPosition; //!< position where object was hit. 00176 std::pair< float, float > m_pixelCoords; //!< Pixel coordinates of the mouse. 00177 modifierKey m_modKey; //!< modifier key associated with the pick 00178 WMouseButton m_mouseButton; //!< which mouse button was used for the pick 00179 WVector3d m_pickNormal; //!< normal at position where object was hit. 00180 }; 00181 00182 WPickInfo::WPickInfo( std::string name, 00183 std::string viewerName, 00184 WPosition pickPosition, 00185 std::pair< float, float > pixelCoords, 00186 modifierKey modKey, 00187 WMouseButton mButton, 00188 WVector3d pickNormal ) : 00189 m_name( name ), 00190 m_viewerName( viewerName ), 00191 m_pickPosition( pickPosition ), 00192 m_pixelCoords( pixelCoords ), 00193 m_modKey( modKey ), 00194 m_mouseButton( mButton ), 00195 m_pickNormal( pickNormal ) 00196 { 00197 } 00198 00199 WPickInfo::WPickInfo() : 00200 m_name( "" ), 00201 m_viewerName( "" ), 00202 m_pickPosition( WPosition() ), 00203 m_pixelCoords( std::make_pair( 0.0, 0.0 ) ), 00204 m_modKey( WPickInfo::NONE ), 00205 m_mouseButton( WPickInfo::MOUSE_LEFT ) 00206 { 00207 } 00208 00209 WPickInfo::modifierKey WPickInfo::getModifierKey() const 00210 { 00211 return m_modKey; 00212 } 00213 00214 void WPickInfo::setModifierKey( const modifierKey& modKey ) 00215 { 00216 m_modKey = modKey; 00217 } 00218 00219 WPickInfo::WMouseButton WPickInfo::getMouseButton() const 00220 { 00221 return m_mouseButton; 00222 } 00223 00224 void WPickInfo::setMouseButton( const WMouseButton& mButton ) 00225 { 00226 m_mouseButton = mButton; 00227 } 00228 00229 std::string WPickInfo::getName() const 00230 { 00231 return m_name; 00232 } 00233 00234 std::string WPickInfo::getViewerName() const 00235 { 00236 return m_viewerName; 00237 } 00238 00239 WPosition WPickInfo::getPickPosition() const 00240 { 00241 return m_pickPosition; 00242 } 00243 00244 WVector3d WPickInfo::getPickNormal() const 00245 { 00246 return m_pickNormal; 00247 } 00248 00249 inline bool WPickInfo::operator==( WPickInfo rhs ) const 00250 { 00251 return ( this->m_name == rhs.m_name 00252 && this->m_pickPosition == rhs.m_pickPosition 00253 && this->m_modKey == rhs.m_modKey ); 00254 } 00255 00256 inline bool WPickInfo::operator!=( WPickInfo rhs ) const 00257 { 00258 return !( *this == rhs ); 00259 } 00260 00261 inline WVector2d WPickInfo::getPickPixel() const 00262 { 00263 WVector2d v; 00264 v[0] = m_pixelCoords.first; 00265 v[1] = m_pixelCoords.second; 00266 return v; 00267 } 00268 00269 #endif // WPICKINFO_H