PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: MousePicking.h * 00003 * 00004 * Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLENGINE_MOUSEPICKING_H__ 00024 #define __PLENGINE_MOUSEPICKING_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLEngine/Picking/Picking.h" 00032 00033 00034 //[-------------------------------------------------------] 00035 //[ Forward declarations ] 00036 //[-------------------------------------------------------] 00037 namespace PLCore { 00038 class Frontend; 00039 } 00040 namespace PLMath { 00041 class Vector2i; 00042 } 00043 namespace PLScene { 00044 class SNCamera; 00045 } 00046 00047 00048 //[-------------------------------------------------------] 00049 //[ Namespace ] 00050 //[-------------------------------------------------------] 00051 namespace PLEngine { 00052 00053 00054 //[-------------------------------------------------------] 00055 //[ Classes ] 00056 //[-------------------------------------------------------] 00057 /** 00058 * @brief 00059 * Class offering scene picking functionality by using the mouse 00060 */ 00061 class MousePicking : public Picking { 00062 00063 00064 //[-------------------------------------------------------] 00065 //[ Public functions ] 00066 //[-------------------------------------------------------] 00067 public: 00068 /** 00069 * @brief 00070 * Constructor 00071 * 00072 * @param[in] cFrontend 00073 * Frontend instance used to determine the mouse position 00074 * @param[in] pCamera 00075 * Camera to perform the picking with, if a null pointer no picking is possible 00076 */ 00077 PL_API MousePicking(PLCore::Frontend &cFrontend, PLScene::SNCamera *pCamera = nullptr); 00078 00079 /** 00080 * @brief 00081 * Destructor 00082 */ 00083 PL_API virtual ~MousePicking(); 00084 00085 /** 00086 * @brief 00087 * Returns the frontend instance used to determine the mouse position 00088 * 00089 * @return 00090 * The frontend instance used to determine the mouse position 00091 */ 00092 PL_API PLCore::Frontend &GetFrontend() const; 00093 00094 /** 00095 * @brief 00096 * Returns the camera to perform the picking with 00097 * 00098 * @return 00099 * The camera to perform the picking with, if a null pointer no picking is possible 00100 */ 00101 PL_API PLScene::SNCamera *GetCamera() const; 00102 00103 /** 00104 * @brief 00105 * Sets the camera to perform the picking with 00106 * 00107 * @param[in] pCamera 00108 * The camera to perform the picking with, if a null pointer no picking is possible 00109 */ 00110 PL_API void SetCamera(PLScene::SNCamera *pCamera); 00111 00112 /** 00113 * @brief 00114 * Performs picking by using the current camera and current mouse position within the widget 00115 * 00116 * @param[out] cPickingResult 00117 * Receives the picking result if all went fine 00118 * @param[in] fMaxDistance 00119 * Maximum picking distance, if negative there's no maximum picking distance (in the same scene container the camera is in) 00120 * @param[in] nCull 00121 * Cull mode (see "PLRenderer::Cull") 00122 * 00123 * @return 00124 * 'true' if anything has been picked, else 'false' 00125 * 00126 * @note 00127 * - For performance reasons we recommend to always set a maximum picking distance 00128 * - The function will only work if a widget and camera is set ('SetWidget()' and 'GetCamera()') 00129 */ 00130 PL_API bool PerformMousePicking(PickingResult &cPickingResult, float fMaxDistance = -1.0f, PLRenderer::Cull::Enum nCull = PLRenderer::Cull::CCW); 00131 00132 /** 00133 * @brief 00134 * Performs picking by using the current camera and the given mouse position 00135 * 00136 * @param[out] cPickingResult 00137 * Receives the picking result if all went fine 00138 * @param[in] vMousePos 00139 * Position of the mouse inside the widget the picking takes place 00140 * @param[in] fMaxDistance 00141 * Maximum picking distance, if negative there's no maximum picking distance (in the same scene container the camera is in) 00142 * @param[in] nCull 00143 * Cull mode (see "PLRenderer::Cull") 00144 * 00145 * @return 00146 * 'true' if anything has been picked, else 'false' 00147 * 00148 * @note 00149 * - For performance reasons we recommend to always set a maximum picking distance 00150 * - The function will only work if a widget and camera is set ('SetWidget()' and 'GetCamera()') 00151 */ 00152 PL_API bool PerformMousePicking(PickingResult &cPickingResult, const PLMath::Vector2i &vMousePos, float fMaxDistance = -1.0f, PLRenderer::Cull::Enum nCull = PLRenderer::Cull::CCW); 00153 00154 00155 //[-------------------------------------------------------] 00156 //[ Private functions ] 00157 //[-------------------------------------------------------] 00158 private: 00159 /** 00160 * @brief 00161 * Called when a camera was destroyed 00162 */ 00163 void OnCameraDestroy(); 00164 00165 00166 //[-------------------------------------------------------] 00167 //[ Private event handlers ] 00168 //[-------------------------------------------------------] 00169 private: 00170 PLCore::EventHandler<> EventHandlerCameraDestroy; 00171 00172 00173 //[-------------------------------------------------------] 00174 //[ Private data ] 00175 //[-------------------------------------------------------] 00176 private: 00177 PLCore::Frontend *m_pFrontend; /**< Frontend instance used to determine the mouse position, always valid! */ 00178 PLScene::SNCamera *m_pCamera; /**< Camera to perform the picking with, can be a null pointer */ 00179 00180 00181 }; 00182 00183 00184 //[-------------------------------------------------------] 00185 //[ Namespace ] 00186 //[-------------------------------------------------------] 00187 } // PLEngine 00188 00189 00190 #endif // __PLENGINE_MOUSEPICKING_H__
|