PixelLightAPI  .
Picking.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Picking.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_PICKING_H__
00024 #define __PLENGINE_PICKING_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLCore/Base/Event/EventHandler.h>
00032 #include "PLEngine/PLEngine.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Forward declarations                                  ]
00037 //[-------------------------------------------------------]
00038 namespace PLCore {
00039     template <class ValueType> class Array;
00040 }
00041 namespace PLMath {
00042     class Vector3;
00043 }
00044 namespace PLScene {
00045     class SceneNode;
00046     class SceneQuery;
00047     class SceneContainer;
00048 }
00049 namespace PLEngine {
00050     class PickingResult;
00051 }
00052 
00053 
00054 //[-------------------------------------------------------]
00055 //[ Namespace                                             ]
00056 //[-------------------------------------------------------]
00057 namespace PLEngine {
00058 
00059 
00060 //[-------------------------------------------------------]
00061 //[ Classes                                               ]
00062 //[-------------------------------------------------------]
00063 /**
00064 *  @brief
00065 *    Class offering scene picking (some also call it 'trace line') functionality
00066 */
00067 class Picking {
00068 
00069 
00070     //[-------------------------------------------------------]
00071     //[ Public functions                                      ]
00072     //[-------------------------------------------------------]
00073     public:
00074         /**
00075         *  @brief
00076         *    Constructor
00077         */
00078         PL_API Picking();
00079 
00080         /**
00081         *  @brief
00082         *    Destructor
00083         */
00084         PL_API virtual ~Picking();
00085 
00086         /**
00087         *  @brief
00088         *    Performs picking by using the given line start and end positions
00089         *
00090         *  @param[out] cPickingResult
00091         *    Receives the picking result if all went fine
00092         *  @param[in]  cContainer
00093         *    Scene container we're performing the picking in
00094         *  @param[in]  vLineStartPos
00095         *    Picking line start position within the given scene container
00096         *  @param[in]  vLineEndPos
00097         *    Picking line end position within the given scene container
00098         *
00099         *  @return
00100         *    'true' if anything has been picked, else 'false'
00101         */
00102         PL_API bool PerformPicking(PickingResult &cPickingResult, PLScene::SceneContainer &cContainer, const PLMath::Vector3 &vLineStartPos, const PLMath::Vector3 &vLineEndPos);
00103 
00104         /**
00105         *  @brief
00106         *    Performs picking using the mesh of the given scene node by using the given line start and end positions
00107         *
00108         *  @param[out] cPickingResult
00109         *    Receives the picking result if all went fine
00110         *  @param[in]  cSceneNode
00111         *    Scene node we're performing the mesh picking in
00112         *  @param[in]  vLineStartPos
00113         *    Picking line start position within the given scene node
00114         *  @param[in]  vLineEndPos
00115         *    Picking line end position within the given scene node
00116         *  @param[in]  plstGeometries
00117         *    List of mesh geometry indices to use, if a null pointer all mesh geometries are used
00118         *
00119         *  @return
00120         *    'true' if anything has been picked, else 'false'
00121         */
00122         PL_API bool PerformPicking(PickingResult &cPickingResult, PLScene::SceneNode &cSceneNode, const PLMath::Vector3 &vLineStartPos, const PLMath::Vector3 &vLineEndPos,
00123                                    PLCore::Array<PLCore::uint32> *plstGeometries = nullptr);
00124 
00125 
00126     //[-------------------------------------------------------]
00127     //[ Private functions                                     ]
00128     //[-------------------------------------------------------]
00129     private:
00130         /**
00131         *  @brief
00132         *    Called when a scene node was found
00133         *
00134         *  @param[in] cQuery
00135         *    Query found the scene node
00136         *  @param[in] cSceneNode
00137         *    Found scene node
00138         */
00139         void OnSceneNode(PLScene::SceneQuery &cQuery, PLScene::SceneNode &cSceneNode);
00140 
00141         /**
00142         *  @brief
00143         *    Perform mesh intersection
00144         *
00145         *  @param[in]  cSceneNode
00146         *    Scene node we're performing the mesh picking in
00147         *  @param[in]  vLineStartPos
00148         *    Picking line start position within the given scene node
00149         *  @param[in]  vLineEndPos
00150         *    Picking line end position within the given scene node
00151         *  @param[in]  plstGeometries
00152         *    List of mesh geometry indices to use, if a null pointer all mesh geometries are used
00153         */
00154         void MeshIntersection(PLScene::SceneNode &cSceneNode, const PLMath::Vector3 &vLineStartPos, const PLMath::Vector3 &vLineEndPos,
00155                               PLCore::Array<PLCore::uint32> *plstGeometries = nullptr);
00156 
00157 
00158     //[-------------------------------------------------------]
00159     //[ Protected virtual Picking functions                   ]
00160     //[-------------------------------------------------------]
00161     protected:
00162         /**
00163         *  @brief
00164         *    Function that is called when a picking candidate has been found ("picking filter function")
00165         *
00166         *  @param[in] cSceneNode
00167         *    Scene node candidate
00168         *
00169         *  @return
00170         *    'true' to take this candidate into account, else 'false' to throw it away (no further processing of the scene node)
00171         *
00172         *  @note
00173         *    - The default implementation is empty
00174         */
00175         PL_API virtual bool OnPickingCandidate(PLScene::SceneNode &cSceneNode);
00176 
00177 
00178     //[-------------------------------------------------------]
00179     //[ Private event handlers                                ]
00180     //[-------------------------------------------------------]
00181     private:
00182         PLCore::EventHandler<PLScene::SceneQuery &, PLScene::SceneNode &> EventHandlerSceneNode;
00183 
00184 
00185     //[-------------------------------------------------------]
00186     //[ Private data                                          ]
00187     //[-------------------------------------------------------]
00188     private:
00189         PickingResult *m_pPickingResult;    /**< Current picking result, always valid! (used inside 'OnSceneNode()') */
00190 
00191 
00192 };
00193 
00194 
00195 //[-------------------------------------------------------]
00196 //[ Namespace                                             ]
00197 //[-------------------------------------------------------]
00198 } // PLEngine
00199 
00200 
00201 #endif // __PLENGINE_PICKING_H__


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