| 1 | /* |
|---|
| 2 | ================================================================================= |
|---|
| 3 | This file is part of Cafu, the open-source game engine and graphics engine |
|---|
| 4 | for multiplayer, cross-platform, real-time 3D action. |
|---|
| 5 | Copyright (C) 2002-2012 Carsten Fuchs Software. |
|---|
| 6 | |
|---|
| 7 | Cafu is free software: you can redistribute it and/or modify it under the terms |
|---|
| 8 | of the GNU General Public License as published by the Free Software Foundation, |
|---|
| 9 | either version 3 of the License, or (at your option) any later version. |
|---|
| 10 | |
|---|
| 11 | Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
|---|
| 12 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|---|
| 13 | PURPOSE. See the GNU General Public License for more details. |
|---|
| 14 | |
|---|
| 15 | You should have received a copy of the GNU General Public License |
|---|
| 16 | along with Cafu. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | |
|---|
| 18 | For support and more information about Cafu, visit us at <http://www.cafu.de>. |
|---|
| 19 | ================================================================================= |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | #ifndef CAFU_CHILDFRAME_VIEW_WIN_3D_HPP_INCLUDED |
|---|
| 23 | #define CAFU_CHILDFRAME_VIEW_WIN_3D_HPP_INCLUDED |
|---|
| 24 | |
|---|
| 25 | #include "AxesInfo.hpp" |
|---|
| 26 | #include "ChildFrameViewWin.hpp" |
|---|
| 27 | #include "Generic3DWindow.hpp" |
|---|
| 28 | #include "Renderer3D.hpp" |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | class MapElementT; |
|---|
| 32 | class ToolCameraT; |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | class ViewWindow3DT : public Generic3DWindowT, public ViewWindowT |
|---|
| 36 | { |
|---|
| 37 | public: |
|---|
| 38 | |
|---|
| 39 | /// This struct describes a hit (an intersection of a map element with a view ray through a given pixel) as returned by the GetElementsAt() method. |
|---|
| 40 | struct HitInfoT |
|---|
| 41 | { |
|---|
| 42 | MapElementT* Object; ///< Pointer to the intersected map element. |
|---|
| 43 | unsigned long FaceNr; ///< If Object is a map brush, this is the number of its face that was hit. |
|---|
| 44 | float Depth; ///< Depth value (distance from ray origin (on near clip plane) along the ray) of the hit object. |
|---|
| 45 | Vector3fT Pos; ///< The point in the world where the object was hit. |
|---|
| 46 | }; |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | /// The constructor. |
|---|
| 50 | ViewWindow3DT(wxWindow* Parent, ChildFrameT* ChildFrame, CameraT* InitialCamera, ViewTypeT InitialViewType); |
|---|
| 51 | |
|---|
| 52 | // Methods inherited from ObserverT. |
|---|
| 53 | // Note that the 3D view is updated on idle anyway, so no observer messages are implemented at this point. |
|---|
| 54 | // void NotifySubjectDies(SubjectT* dyingSubject); // Already implemented in base class ViewWindowT. |
|---|
| 55 | |
|---|
| 56 | // Methods inherited from ToolsObserverT. |
|---|
| 57 | void NotifySubjectChanged(ToolsSubjectT* Subject, ToolT* Tool, ToolsUpdatePriorityT Priority); |
|---|
| 58 | |
|---|
| 59 | // Inherited methods from the ViewWindowT base class. |
|---|
| 60 | wxWindow* GetWindow(); |
|---|
| 61 | ViewTypeT GetViewType() const { return m_ViewType; } |
|---|
| 62 | AxesInfoT GetAxesInfo() const { return Generic3DWindowT::GetAxesInfo(); } |
|---|
| 63 | |
|---|
| 64 | /// This method returns visible all map elements at a given pixel in the 3D view window. |
|---|
| 65 | /// @param Pixel The pixel in window coordinates for which the map elements are to be found. |
|---|
| 66 | /// @returns The array of visible map elements that intersect the ray from the camera position through the pixel. |
|---|
| 67 | /// The elements are returned in front-to-back order, i.e. the nearest object is at array index 0. |
|---|
| 68 | ArrayT<HitInfoT> GetElementsAt(const wxPoint& Pixel) const; |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | private: |
|---|
| 72 | |
|---|
| 73 | // Implement virtual methods of Generic3DViewT base class. |
|---|
| 74 | virtual Vector3fT GetRefPtWorld(const wxPoint& RefPtWin) const; |
|---|
| 75 | virtual void InfoCameraChanged(); |
|---|
| 76 | virtual void InfoRightMouseClick(wxMouseEvent& ME); |
|---|
| 77 | |
|---|
| 78 | ViewTypeT m_ViewType; ///< The type of this 3D view (wireframe, flat, materials, ...). |
|---|
| 79 | Renderer3DT m_Renderer; ///< Performs the 3D rendering in our window. |
|---|
| 80 | unsigned long m_TimeOfLastPaint; ///< The time at which the OnPaint() event handler was last called. |
|---|
| 81 | ToolCameraT* m_CameraTool; ///< The camera tool that manages all cameras. The camera of this 3D view is always among the cameras in the tool. |
|---|
| 82 | |
|---|
| 83 | // Event handlers. |
|---|
| 84 | void OnKeyDown (wxKeyEvent& KE); |
|---|
| 85 | void OnKeyUp (wxKeyEvent& KE); |
|---|
| 86 | void OnKeyChar (wxKeyEvent& KE); |
|---|
| 87 | void OnMouseLeftDown (wxMouseEvent& ME); ///< We also handle "double-click" events in this method (use ME.ButtonDClick() for distinction). |
|---|
| 88 | void OnMouseLeftUp (wxMouseEvent& ME); |
|---|
| 89 | void OnMouseMiddleDown(wxMouseEvent& ME); ///< We also handle "double-click" events in this method (use ME.ButtonDClick() for distinction). |
|---|
| 90 | void OnMouseMiddleUp (wxMouseEvent& ME); |
|---|
| 91 | void OnMouseWheel (wxMouseEvent& ME); |
|---|
| 92 | void OnMouseMove (wxMouseEvent& ME); |
|---|
| 93 | void OnContextMenu (wxContextMenuEvent& CE); |
|---|
| 94 | void OnPaint (wxPaintEvent& PE); |
|---|
| 95 | |
|---|
| 96 | DECLARE_EVENT_TABLE() |
|---|
| 97 | }; |
|---|
| 98 | |
|---|
| 99 | #endif |
|---|