Cafu Engine
ChildFrameViewWin3D.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_CHILDFRAME_VIEW_WIN_3D_HPP_INCLUDED
8 #define CAFU_CHILDFRAME_VIEW_WIN_3D_HPP_INCLUDED
9 
10 #include "ChildFrameViewWin.hpp"
11 #include "Renderer3D.hpp"
12 
13 #include "../AxesInfo.hpp"
14 #include "../Generic3DWindow.hpp"
15 
16 
17 class MapElementT;
18 class ToolCameraT;
19 
20 
22 {
23  public:
24 
25  /// 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.
26  struct HitInfoT
27  {
28  MapElementT* Object; ///< Pointer to the intersected map element.
29  unsigned long FaceNr; ///< If Object is a map brush, this is the number of its face that was hit.
30  float Depth; ///< Depth value (distance from ray origin (on near clip plane) along the ray) of the hit object.
31  Vector3fT Pos; ///< The point in the world where the object was hit.
32  };
33 
34 
35  /// The constructor.
36  ViewWindow3DT(wxWindow* Parent, ChildFrameT* ChildFrame, CameraT* InitialCamera, ViewTypeT InitialViewType);
37 
38  // Methods inherited from ObserverT.
39  // Note that the 3D view is updated on idle anyway, so no observer messages are implemented at this point.
40  // void NotifySubjectDies(SubjectT* dyingSubject); // Already implemented in base class ViewWindowT.
41 
42  // Methods inherited from ToolsObserverT.
43  void NotifySubjectChanged(ToolsSubjectT* Subject, ToolT* Tool, ToolsUpdatePriorityT Priority);
44 
45  // Inherited methods from the ViewWindowT base class.
46  wxWindow* GetWindow();
47  ViewTypeT GetViewType() const { return m_ViewType; }
49 
50  /// This method returns visible all map elements at a given pixel in the 3D view window.
51  /// @param Pixel The pixel in window coordinates for which the map elements are to be found.
52  /// @returns The array of visible map elements that intersect the ray from the camera position through the pixel.
53  /// The elements are returned in front-to-back order, i.e. the nearest object is at array index 0.
54  ArrayT<HitInfoT> GetElementsAt(const wxPoint& Pixel) const;
55 
56 
57  private:
58 
59  // Implement virtual methods of Generic3DViewT base class.
60  virtual Vector3fT GetRefPtWorld(const wxPoint& RefPtWin) const;
61  virtual void InfoCameraChanged();
62  virtual void InfoRightMouseClick(wxMouseEvent& ME);
63 
64  ViewTypeT m_ViewType; ///< The type of this 3D view (wireframe, flat, materials, ...).
65  Renderer3DT m_Renderer; ///< Performs the 3D rendering in our window.
66  unsigned long m_TimeOfLastPaint; ///< The time at which the OnPaint() event handler was last called.
67  ToolCameraT* m_CameraTool; ///< The camera tool that manages all cameras. The camera of this 3D view is always among the cameras in the tool.
68 
69  // Event handlers.
70  void OnKeyDown (wxKeyEvent& KE);
71  void OnKeyUp (wxKeyEvent& KE);
72  void OnKeyChar (wxKeyEvent& KE);
73  void OnMouseLeftDown (wxMouseEvent& ME); ///< We also handle "double-click" events in this method (use ME.ButtonDClick() for distinction).
74  void OnMouseLeftUp (wxMouseEvent& ME);
75  void OnMouseMiddleDown(wxMouseEvent& ME); ///< We also handle "double-click" events in this method (use ME.ButtonDClick() for distinction).
76  void OnMouseMiddleUp (wxMouseEvent& ME);
77  void OnMouseWheel (wxMouseEvent& ME);
78  void OnMouseMove (wxMouseEvent& ME);
79  void OnContextMenu (wxContextMenuEvent& CE);
80  void OnPaint (wxPaintEvent& PE);
81 
82  DECLARE_EVENT_TABLE()
83 };
84 
85 #endif
This class provides auxiliary means for rendering a 3D view.
Definition: Renderer3D.hpp:30
unsigned long FaceNr
If Object is a map brush, this is the number of its face that was hit.
Definition: ChildFrameViewWin3D.hpp:29
ArrayT< HitInfoT > GetElementsAt(const wxPoint &Pixel) const
This method returns visible all map elements at a given pixel in the 3D view window.
Definition: ChildFrameViewWin3D.cpp:111
ToolsUpdatePriorityT
An enumeration that determines the urgency with which observers should update themselves when their s...
Definition: ObserverPatternTools.hpp:21
This class implements a camera.
Definition: Camera.hpp:17
ViewTypeT GetViewType() const
Returns the view type of this view window.
Definition: ChildFrameViewWin3D.hpp:47
wxWindow * GetWindow()
This function is not const because we can mutate this(!) object via the returned pointer.
Definition: ChildFrameViewWin3D.cpp:99
This class represents a child frame.
Definition: ChildFrame.hpp:55
ViewWindow3DT(wxWindow *Parent, ChildFrameT *ChildFrame, CameraT *InitialCamera, ViewTypeT InitialViewType)
The constructor.
Definition: ChildFrameViewWin3D.cpp:56
Definition: ToolCamera.hpp:20
AxesInfoT GetAxesInfo() const
This method returns the axes info for this window. In the case of a 3D window, it computes the 2D axe...
Definition: ChildFrameViewWin3D.hpp:48
MapElementT * Object
Pointer to the intersected map element.
Definition: ChildFrameViewWin3D.hpp:28
This class represents a (superclass of a) 2D or 3D map view window.
Definition: ChildFrameViewWin.hpp:21
AxesInfoT GetAxesInfo() const
Returns the set of axes that the camera orientation is currently the closest to.
Definition: Generic3DWindow.cpp:134
void NotifySubjectChanged(ToolsSubjectT *Subject, ToolT *Tool, ToolsUpdatePriorityT Priority)
Notifies the observer that the current subject has been changed.
Definition: ChildFrameViewWin3D.cpp:73
This class describes how the three world-space axes are mapped to the two screen- or window-space axe...
Definition: AxesInfo.hpp:15
This class implements a generic 3D window.
Definition: Generic3DWindow.hpp:20
Definition: ChildFrameViewWin3D.hpp:21
Vector3fT Pos
The point in the world where the object was hit.
Definition: ChildFrameViewWin3D.hpp:31
float Depth
Depth value (distance from ray origin (on near clip plane) along the ray) of the hit object...
Definition: ChildFrameViewWin3D.hpp:30
This struct describes a hit (an intersection of a map element with a view ray through a given pixel) ...
Definition: ChildFrameViewWin3D.hpp:26
This is the base class for all tools in the map editor.
Definition: Tool.hpp:34
Definition: Renderer.hpp:16
This is the base class for all elements ("objects") that can exist in a map.
Definition: MapElement.hpp:57
Definition: ObserverPatternTools.hpp:49