PixelLightAPI  .
MousePicking.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: MousePicking.h                                 *
00003  *
00004  *  Copyright (C) 2002-2011 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         *
00121         *  @return
00122         *    'true' if anything has been picked, else 'false'
00123         *
00124         *  @note
00125         *    - For performance reasons we recommend to always set a maximum picking distance
00126         *    - The function will only work if a widget and camera is set ('SetWidget()' and 'GetCamera()')
00127         */
00128         PL_API bool PerformMousePicking(PickingResult &cPickingResult, float fMaxDistance = -1.0f);
00129 
00130         /**
00131         *  @brief
00132         *    Performs picking by using the current camera and the given mouse position
00133         *
00134         *  @param[out] cPickingResult
00135         *    Receives the picking result if all went fine
00136         *  @param[in]  vMousePos
00137         *    Position of the mouse inside the widget the picking takes place
00138         *  @param[in]  fMaxDistance
00139         *    Maximum picking distance, if negative there's no maximum picking distance (in the same scene container the camera is in)
00140         *
00141         *  @return
00142         *    'true' if anything has been picked, else 'false'
00143         *
00144         *  @note
00145         *    - For performance reasons we recommend to always set a maximum picking distance
00146         *    - The function will only work if a widget and camera is set ('SetWidget()' and 'GetCamera()')
00147         */
00148         PL_API bool PerformMousePicking(PickingResult &cPickingResult, const PLMath::Vector2i &vMousePos, float fMaxDistance = -1.0f);
00149 
00150 
00151     //[-------------------------------------------------------]
00152     //[ Private functions                                     ]
00153     //[-------------------------------------------------------]
00154     private:
00155         /**
00156         *  @brief
00157         *    Called when a camera was destroyed
00158         */
00159         void OnCameraDestroy();
00160 
00161 
00162     //[-------------------------------------------------------]
00163     //[ Private event handlers                                ]
00164     //[-------------------------------------------------------]
00165     private:
00166         PLCore::EventHandler<> EventHandlerCameraDestroy;
00167 
00168 
00169     //[-------------------------------------------------------]
00170     //[ Private data                                          ]
00171     //[-------------------------------------------------------]
00172     private:
00173         PLCore::Frontend  *m_pFrontend; /**< Frontend instance used to determine the mouse position, always valid! */
00174         PLScene::SNCamera *m_pCamera;   /**< Camera to perform the picking with, can be a null pointer */
00175 
00176 
00177 };
00178 
00179 
00180 //[-------------------------------------------------------]
00181 //[ Namespace                                             ]
00182 //[-------------------------------------------------------]
00183 } // PLEngine
00184 
00185 
00186 #endif // __PLENGINE_MOUSEPICKING_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:50:58
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported