My Project
BufferPicking.h
1 #pragma once
2 #include "math/ParaRect.h"
3 #include "AssetEntity.h"
4 #include "IObjectScriptingInterface.h"
5 
6 namespace ParaEngine
7 {
8  class CRenderTarget;
9 
16  struct CBufferPicking : public AssetEntity
17  {
18  public:
19  explicit CBufferPicking(const AssetKey& key);
20  virtual ~CBufferPicking();
21 
22  ATTRIBUTE_DEFINE_CLASS(CBufferPicking);
23 
25  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
26 
28  virtual IAttributeFields* GetChildAttributeObject(const std::string& sName);
30  virtual int GetChildAttributeObjectCount(int nColumnIndex = 0);
32  virtual int GetChildAttributeColumnCount();
33  virtual IAttributeFields* GetChildAttributeObject(int nRowIndex, int nColumnIndex = 0);
34 
35  ATTRIBUTE_METHOD1(CBufferPicking, GetPickingCount_s, int*) { *p1 = cls->GetPickingCount(); return S_OK; }
36  ATTRIBUTE_METHOD1(CBufferPicking, GetPickingID_s, DWORD*) { *p1 = cls->GetPickingID(-1); return S_OK; }
37  ATTRIBUTE_METHOD1(CBufferPicking, FetchPickingResult_s, void**) { cls->FetchPickingResult((DWORD **)p1); return S_OK; }
38  ATTRIBUTE_METHOD(CBufferPicking, ClearPickingResult_s) { cls->ClearPickingResult(); return S_OK; }
39  ATTRIBUTE_METHOD(CBufferPicking, CheckDoPick_s) { cls->CheckDoPick(); return S_OK; }
40 
41  ATTRIBUTE_METHOD1(CBufferPicking, GetPickLeftTop_s, Vector2*) { *p1 = cls->GetPickLeftTop(); return S_OK; }
42  ATTRIBUTE_METHOD1(CBufferPicking, SetPickLeftTop_s, Vector2) { cls->SetPickLeftTop(p1); return S_OK; }
43 
44  ATTRIBUTE_METHOD1(CBufferPicking, GetPickWidthHeight_s, Vector2*) { *p1 = cls->GetPickWidthHeight(); return S_OK; }
45  ATTRIBUTE_METHOD1(CBufferPicking, SetPickWidthHeight_s, Vector2) { cls->SetPickWidthHeight(p1); return S_OK; }
46 
47  ATTRIBUTE_METHOD1(CBufferPicking, IsResultDirty_s, bool*) { *p1 = cls->IsResultDirty(); return S_OK; }
48  ATTRIBUTE_METHOD1(CBufferPicking, SetResultDirty_s, bool) { cls->SetResultDirty(p1); return S_OK; }
49 
50  ATTRIBUTE_METHOD1(CBufferPicking, GetPickIndex_s, int*) { *p1 = cls->GetPickIndex(); return S_OK; }
51  ATTRIBUTE_METHOD1(CBufferPicking, SetPickIndex_s, int) { cls->SetPickIndex(p1); return S_OK; }
52 
53  ATTRIBUTE_METHOD1(CBufferPicking, GetViewport_s, int*) { *p1 = cls->GetViewport(); return S_OK; }
54  ATTRIBUTE_METHOD1(CBufferPicking, SetViewport_s, int) { cls->SetViewport(p1); return S_OK; }
55 
56  public:
57  virtual HRESULT InitDeviceObjects();
58  virtual HRESULT DeleteDeviceObjects();
59 
65  DWORD Pick(int nX, int nY, int nViewportId = -1);
66 
72  int Pick(const QRect& region, int nViewportId = -1);
73 
75  const vector<DWORD>& GetPickingResult() { return m_pickingResult; };
76 
78  int GetPickingCount();
79 
83  DWORD GetPickingID(int nIndex = 0);
84 
86  void FetchPickingResult(DWORD ** ppResult);
87 
89  void ClearPickingResult();
90 
91  void SetPickLeftTop(const Vector2& vPos);
92  const Vector2& GetPickLeftTop();
93  void SetPickWidthHeight(const Vector2& vPos);
94  const Vector2& GetPickWidthHeight();
95 
96  int GetPickIndex() const;
97  void SetPickIndex(int val);
98 
99  bool IsResultDirty() const;
100  void SetResultDirty(bool bDirty=true);
101 
102  /* in which viewport to pick. default to -1, which is the default one. */
103  int GetViewport() const;
104  /* in which viewport to pick. default to -1, which is the default one. */
105  void SetViewport(int val);
106 
111  void CheckDoPick(bool bForceUpdate = false);
112  protected:
113  bool BeginBuffer();
114 
115  void DrawObjects();
116 
117  void EndBuffer();
119  virtual CRenderTarget* CreateGetRenderTarget(bool bCreateIfNotExist = true);
120 
121  private:
122  vector <DWORD> m_pickingResult;
123  QRect m_pickRect;
124  bool m_bResultDirty;
125 
126  int m_currentPickIndex;
127 
128  Vector2 m_cache_left_top;
129  Vector2 m_cache_width_height;
130  int m_nViewport;
131 
133  WeakPtr m_renderTarget;
134  };
135 
143  class BufferPickingManager : public AssetManager <CBufferPicking>
144  {
145  public:
147  static BufferPickingManager& GetInstance();
148  public:
150  void SetResultDirty();
151  };
152 }
153 
154 
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
all picking buffers There is a default one called BufferPickingManager::GetInstance().GetEntity("backbuffer"); which is the current backbuffer Some predefined picking object can be retrieved via NPL script using
Definition: BufferPicking.h:143
virtual IAttributeFields * GetChildAttributeObject(const std::string &sName)
get attribute by child object.
Definition: BufferPicking.cpp:204
DWORD GetPickingID(int nIndex=0)
get the picked item id of the given picking item.
Definition: BufferPicking.cpp:48
picking from frame buffer (back buffer) When there is picking query, it will render scene again (if o...
Definition: BufferPicking.h:16
a render target scene object.
Definition: RenderTarget.h:16
different physics engine has different winding order.
Definition: EventBinding.h:32
void ClearPickingResult()
clear last picking result
Definition: BufferPicking.cpp:30
void CheckDoPick(bool bForceUpdate=false)
do picking using current picking rectangle.
Definition: BufferPicking.cpp:124
void FetchPickingResult(DWORD **ppResult)
Definition: BufferPicking.cpp:56
when concerting QRect with QRectF and RECT, we ensure that their left, top and width, height are the same.
Definition: ParaRect.h:16
virtual int GetChildAttributeObjectCount(int nColumnIndex=0)
get the number of child objects (row count) in the given column.
Definition: BufferPicking.cpp:213
AssetManager manages a set of asset entities of a certain type.
Definition: AssetManager.h:13
Standard 2-dimensional vector.
Definition: ParaVector2.h:16
const vector< DWORD > & GetPickingResult()
return an array of unique picking id in the last pick call.
Definition: BufferPicking.h:75
A common interface for all classes implementing IAttributeFields By implementing this class&#39;s virtual...
Definition: IAttributeFields.h:59
DWORD Pick(int nX, int nY, int nViewportId=-1)
pick by a point in the viewport.
Definition: BufferPicking.cpp:140
std::string AssetKey
the unique key object for asset entity.
Definition: AssetEntity.h:13
virtual int InstallFields(CAttributeClass *pClass, bool bOverride)
this class should be implemented if one wants to add new attribute.
Definition: BufferPicking.cpp:393
virtual int GetChildAttributeColumnCount()
we support multi-dimensional child object.
Definition: BufferPicking.cpp:218
Base class for managed asset entity in ParaEngine.
Definition: AssetEntity.h:25
virtual CRenderTarget * CreateGetRenderTarget(bool bCreateIfNotExist=true)
a render target will be created with the same name as this object.
Definition: BufferPicking.cpp:237
int GetPickingCount()
return the number of objects picked.
Definition: BufferPicking.cpp:65