PixelLightAPI  .
Picking.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Picking.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_PICKING_H__
00024 #define __PLENGINE_PICKING_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLRenderer/Renderer/Types.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         *  @param[in]  nCull
00099         *    Cull mode (see "PLRenderer::Cull")
00100         *
00101         *  @return
00102         *    'true' if anything has been picked, else 'false'
00103         */
00104         PL_API bool PerformPicking(PickingResult &cPickingResult, PLScene::SceneContainer &cContainer, const PLMath::Vector3 &vLineStartPos, const PLMath::Vector3 &vLineEndPos, PLRenderer::Cull::Enum nCull = PLRenderer::Cull::CCW);
00105 
00106         /**
00107         *  @brief
00108         *    Performs picking using the mesh of the given scene node by using the given line start and end positions
00109         *
00110         *  @param[out] cPickingResult
00111         *    Receives the picking result if all went fine
00112         *  @param[in]  cSceneNode
00113         *    Scene node we're performing the mesh picking in
00114         *  @param[in]  vLineStartPos
00115         *    Picking line start position within the given scene node
00116         *  @param[in]  vLineEndPos
00117         *    Picking line end position within the given scene node
00118         *  @param[in]  plstGeometries
00119         *    List of mesh geometry indices to use, if a null pointer all mesh geometries are used
00120         *  @param[in]  nCull
00121         *    Cull mode (see "PLRenderer::Cull")
00122         *
00123         *  @return
00124         *    'true' if anything has been picked, else 'false'
00125         */
00126         PL_API bool PerformPicking(PickingResult &cPickingResult, PLScene::SceneNode &cSceneNode, const PLMath::Vector3 &vLineStartPos, const PLMath::Vector3 &vLineEndPos,
00127                                    PLCore::Array<PLCore::uint32> *plstGeometries = nullptr, PLRenderer::Cull::Enum nCull = PLRenderer::Cull::CCW);
00128 
00129 
00130     //[-------------------------------------------------------]
00131     //[ Private functions                                     ]
00132     //[-------------------------------------------------------]
00133     private:
00134         /**
00135         *  @brief
00136         *    Called when a scene node was found
00137         *
00138         *  @param[in] cQuery
00139         *    Query found the scene node
00140         *  @param[in] cSceneNode
00141         *    Found scene node
00142         */
00143         void OnSceneNode(PLScene::SceneQuery &cQuery, PLScene::SceneNode &cSceneNode);
00144 
00145         /**
00146         *  @brief
00147         *    Perform mesh intersection
00148         *
00149         *  @param[in]  cSceneNode
00150         *    Scene node we're performing the mesh picking in
00151         *  @param[in]  vLineStartPos
00152         *    Picking line start position within the given scene node
00153         *  @param[in]  vLineEndPos
00154         *    Picking line end position within the given scene node
00155         *  @param[in]  plstGeometries
00156         *    List of mesh geometry indices to use, if a null pointer all mesh geometries are used
00157         *  @param[in]  nCull
00158         *    Cull mode (see "PLRenderer::Cull")
00159         */
00160         void MeshIntersection(PLScene::SceneNode &cSceneNode, const PLMath::Vector3 &vLineStartPos, const PLMath::Vector3 &vLineEndPos,
00161                               PLCore::Array<PLCore::uint32> *plstGeometries = nullptr, PLRenderer::Cull::Enum nCull = PLRenderer::Cull::CCW);
00162 
00163 
00164     //[-------------------------------------------------------]
00165     //[ Protected virtual Picking functions                   ]
00166     //[-------------------------------------------------------]
00167     protected:
00168         /**
00169         *  @brief
00170         *    Function that is called when a picking candidate has been found ("picking filter function")
00171         *
00172         *  @param[in] cSceneNode
00173         *    Scene node candidate
00174         *
00175         *  @return
00176         *    'true' to take this candidate into account, else 'false' to throw it away (no further processing of the scene node)
00177         *
00178         *  @note
00179         *    - The default implementation is empty
00180         */
00181         PL_API virtual bool OnPickingCandidate(PLScene::SceneNode &cSceneNode);
00182 
00183 
00184     //[-------------------------------------------------------]
00185     //[ Private event handlers                                ]
00186     //[-------------------------------------------------------]
00187     private:
00188         PLCore::EventHandler<PLScene::SceneQuery &, PLScene::SceneNode &> EventHandlerSceneNode;
00189 
00190 
00191     //[-------------------------------------------------------]
00192     //[ Private data                                          ]
00193     //[-------------------------------------------------------]
00194     private:
00195         PickingResult *m_pPickingResult;    /**< Current picking result, always valid! (used inside 'OnSceneNode()') */
00196 
00197 
00198 };
00199 
00200 
00201 //[-------------------------------------------------------]
00202 //[ Namespace                                             ]
00203 //[-------------------------------------------------------]
00204 } // PLEngine
00205 
00206 
00207 #endif // __PLENGINE_PICKING_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:58
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported