My Project
MiniSceneGraph.h
1 #pragma once
2 #include "RenderTarget.h"
3 #include "SceneState.h"
4 #include "IScene.h"
5 #include "SunLight.h"
6 #include <map>
7 
8 namespace ParaEngine
9 {
10  // forward declare
11  class CCanvasCamera;
12  class CBaseCamera;
13  struct TextureEntity;
14  class CShapeRay;
15  class IBatchedElementDraw;
16  class CBatchedElementDraw;
17 
19  typedef bool (*OBJECT_FILTER_CALLBACK)(CBaseObject* obj);
20 
29  class CMiniSceneGraph : public CRenderTarget, public IScene
30  {
31  public:
33  CMiniSceneGraph(void);
34  virtual ~CMiniSceneGraph(void);
35  virtual CBaseObject::_SceneObjectType GetType(){return CBaseObject::MiniSceneGraph;};
36 
38  // implementation of IAttributeFields
40  virtual int GetAttributeClassID(){return ATTRIBUTE_CLASSID_MiniSceneGraph;}
42  virtual const char* GetAttributeClassName(){static const char name[] = "CMiniSceneGraph"; return name;}
44  virtual const char* GetAttributeClassDescription(){static const char desc[] = ""; return desc;}
46  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
47 
48  ATTRIBUTE_METHOD1(CMiniSceneGraph, IsLightEnabled_s, bool*) {*p1 = cls->IsLightEnabled(); return S_OK;}
49  ATTRIBUTE_METHOD1(CMiniSceneGraph, EnableLight_s, bool) {cls->EnableLight(p1); return S_OK;}
50 
51  ATTRIBUTE_METHOD1(CMiniSceneGraph, GetBackGroundColor_s, Vector3*) { *p1 = cls->GetBackGroundColor().ToVector3(); return S_OK; }
52  ATTRIBUTE_METHOD1(CMiniSceneGraph, SetBackGroundColor_s, Vector3) { LinearColor c(p1.x, p1.y, p1.z, 1); cls->SetBackGroundColor(c); return S_OK; }
53 
54  ATTRIBUTE_METHOD1(CMiniSceneGraph, IsSunLightEnabled_s, bool*) {*p1 = cls->IsSunLightEnabled(); return S_OK;}
55  ATTRIBUTE_METHOD1(CMiniSceneGraph, EnableSunLight_s, bool) {cls->EnableSunLight(p1); return S_OK;}
56 
57  ATTRIBUTE_METHOD1(CMiniSceneGraph, IsFogEnabled_s, bool*) {*p1 = cls->IsFogEnabled(); return S_OK;}
58  ATTRIBUTE_METHOD1(CMiniSceneGraph, EnableFog_s, bool) {cls->EnableFog(p1); return S_OK;}
59 
60  ATTRIBUTE_METHOD1(CMiniSceneGraph, GetFogColor_s, Vector3*) {*p1 = cls->GetFogColorFactor().ToVector3(); return S_OK;}
61  ATTRIBUTE_METHOD1(CMiniSceneGraph, SetFogColor_s, Vector3) {LinearColor c(p1.x, p1.y,p1.z,1); cls->SetFogColorFactor(c); return S_OK;}
62 
63  ATTRIBUTE_METHOD1(CMiniSceneGraph, GetFogStart_s, float*) {*p1 = cls->GetFogStart(); return S_OK;}
64  ATTRIBUTE_METHOD1(CMiniSceneGraph, SetFogStart_s, float) {cls->SetFogStart(p1); return S_OK;}
65 
66  ATTRIBUTE_METHOD1(CMiniSceneGraph, GetFogEnd_s, float*) {*p1 = cls->GetFogEnd(); return S_OK;}
67  ATTRIBUTE_METHOD1(CMiniSceneGraph, SetFogEnd_s, float) {cls->SetFogEnd(p1); return S_OK;}
68 
69  ATTRIBUTE_METHOD1(CMiniSceneGraph, GetFogDensity_s, float*) {*p1 = cls->GetFogDensity(); return S_OK;}
70  ATTRIBUTE_METHOD1(CMiniSceneGraph, SetFogDensity_s, float) {cls->SetFogDensity(p1); return S_OK;}
71 
72  ATTRIBUTE_METHOD1(CMiniSceneGraph, IsRenderSky_s, bool*) {*p1 = cls->IsRenderSky(); return S_OK;}
73  ATTRIBUTE_METHOD1(CMiniSceneGraph, EnableSkyRendering_s, bool) {cls->EnableSkyRendering(p1); return S_OK;}
74 
75  ATTRIBUTE_METHOD1(CMiniSceneGraph, IsHeadOnDisplayShown_s, bool*) {*p1 = cls->IsHeadOnDisplayShown(); return S_OK;}
76  ATTRIBUTE_METHOD1(CMiniSceneGraph, ShowHeadOnDisplay_s, bool) {cls->ShowHeadOnDisplay(p1); return S_OK;}
77 
78  ATTRIBUTE_METHOD1(CMiniSceneGraph, IsUsePointTexture_s, bool*) { *p1 = cls->IsUsePointTexture(); return S_OK; }
79  ATTRIBUTE_METHOD1(CMiniSceneGraph, SetUsePointTexture_s, bool) { cls->SetUsePointTexture(p1); return S_OK; }
80 
81  ATTRIBUTE_METHOD1(CMiniSceneGraph, GetMaxHeadOnDisplayDistance_s, float*) {*p1 = cls->GetMaxHeadOnDisplayDistance(); return S_OK;}
82  ATTRIBUTE_METHOD1(CMiniSceneGraph, SetMaxHeadOnDisplayDistance_s, float) {cls->SetMaxHeadOnDisplayDistance(p1); return S_OK;}
83 
84  ATTRIBUTE_METHOD1(CMiniSceneGraph, GetRenderPipelineOrder_s, int*) {*p1 = cls->GetRenderPipelineOrder(); return S_OK;}
85  ATTRIBUTE_METHOD1(CMiniSceneGraph, SetRenderPipelineOrder_s, int) {cls->SetRenderPipelineOrder(p1); return S_OK;}
86 
87 
89  bool IsRenderSky(){ return m_bRenderSky; }
90  void EnableSkyRendering(bool bEnable){m_bRenderSky = bEnable;};
91 
93  void SetFogColorFactor(const LinearColor& fogColorFactor){m_FogColorFactor = fogColorFactor;};
94  const LinearColor& GetFogColorFactor(){return m_FogColorFactor;};
95  void SetFogColor(const LinearColor& fogColor);
96  LinearColor GetFogColor();
97  void SetFogStart(float fFogStart);
98  float GetFogStart();
99  void SetFogEnd(float fFogEnd);
100  float GetFogEnd();
101  void SetFogDensity(float fFogDensity);
102  float GetFogDensity();
103  void EnableFog(bool bEnableFog);
104  bool IsFogEnabled();
105 
107  bool IsLightEnabled();
109  void EnableLight(bool bEnable);
110 
112  bool IsSunLightEnabled();
114  void EnableSunLight(bool bEnable);
115 
123  bool CreateSkyBox(const string& strObjectName, AssetEntity& MeshAsset, float fScaleX, float fScaleY,float fScaleZ, float fHeightOffset);
126  bool DeleteSkyBox(const string& strObjectName);
127 
130  public:
136  void SetActor(CBaseObject * pActor);
137 
139  CBaseObject * GetActor();
140 
142  virtual void Cleanup();
143 
148  virtual void DestroyChildren();
149 
152 
155 
160  void CameraZoom(float fAmount);
161 
166  void CameraZoomSphere(const CShapeSphere& sphere);
167 
171  void CameraSetLookAtPos(float x, float y, float z);
172  void CameraGetLookAtPos(float* x, float* y, float* z);
173 
180  void CameraSetEyePosByAngle(float fRotY, float fLiftupAngle, float fCameraObjectDist);
181  void CameraGetEyePosByAngle(float* fRotY, float* fLiftupAngle, float* fCameraObjectDist);
182  void CameraSetEyePos(double x, double y, double z);
183  void CameraGetEyePos(double* x, double* y, double* z);
184 
191  void CameraRotate(float dx, float dy, float dz);
192 
198  void CameraPan(float dx, float dy);
199 
202  int PrepareRender(CBaseCamera* pCamera, SceneState* pSceneState);
203 
209  virtual bool PrepareRenderObject(CBaseObject* pObj, CBaseCamera* pCamera, SceneState& sceneState);
210 
217  int RenderSelection(DWORD dwSelection=0xffffffff, double dTimeDelta=0);
218 
220  int RenderHeadOnDisplay();
221 
225  void Draw(float fDeltaTime);
226 
230  void SetMaskTexture(TextureEntity* pTexture);
231 
232 
234  const char* GetName();
235 
237  void SetName(const char* sName);
238 
240  void EnableCamera(bool bEnable);
241 
248  bool IsCameraEnabled();
249 
252  bool IsNeedUpdate();
253 
259  CBaseObject* GetObject(const char* name, bool bRecursive = false);
260 
262  CBaseObject* GetObject(float x, float y, float z, float fEpsilon = 0.01f);
263 
266  int RemoveObject(const char* name, bool bRecursive = false);
267 
268 
271  int RemoveObject(CBaseObject* pObj);
272 
277  int DestroyObject(const char* name, bool bRecursive = false);
278 
284  int DestroyObject(CBaseObject* pObj);
285 
286 
288  void Reset();
289 
290  virtual void AddChild(CBaseObject * pObject);
291 
294  SceneState* GetSceneState(){return &m_sceneState;};
295 
297  bool PickObject(const CShapeRay& ray, CBaseObject** pTouchedObject, float fMaxDistance=0, OBJECT_FILTER_CALLBACK pFnctFilter=NULL);
298  bool PickObject(int nScreenX, int nScreenY, CBaseObject** pTouchedObject, float fMaxDistance=0, OBJECT_FILTER_CALLBACK pFnctFilter=NULL);
299 
301  void ShowHeadOnDisplay(bool bShow){m_bShowHeadOnDisplay = bShow;};
302 
304  bool IsHeadOnDisplayShown(){return m_bShowHeadOnDisplay;};
305 
307  void SetMaxHeadOnDisplayDistance(float fDist){m_fMaxHeadOnDisplayDistance = fDist;};
308 
310  float GetMaxHeadOnDisplayDistance(){return m_fMaxHeadOnDisplayDistance;};
311 
312  bool IsUsePointTexture() const;
313  void SetUsePointTexture(bool val);
314 
330 
331 
334 
336  //
337  // following functions are just for post processing effects that are called per render frame move.
338  //
340 
341 
343  bool SetEffect(CEffectFile* pEffect);
344 
350  void SetRenderPipelineOrder(int nOrder);
351 
358 
359  void SetBackGroundColor(const LinearColor& bgColor);
360 
362  private:
363  typedef std::map<std::string, CBaseObject*> ObjectNameMap_Type;
364  ObjectNameMap_Type m_name_map;
365 
367  CCanvasCamera* m_pCamera;
368 
370  bool m_bUseLocalCamera;
371 
373  bool m_bUsePointTexture;
374 
375  bool m_bEnabled;
376 
378  asset_ptr<TextureEntity> m_pMask;
379 
381  CBaseObject * m_pActor;
382 
385  SceneState m_sceneState;
386 
387  Vector3 m_vRenderOrigin;
388 
390  bool m_bShowHeadOnDisplay;
391 
393  float m_fMaxHeadOnDisplayDistance;
394 
396  unordered_ref_array<CSkyMesh*> m_skymeshes;
398  bool m_bRenderSky;
399 
400  // render fog
401  bool m_bRenderFog;
403  DWORD m_dwFogColor;
404  LinearColor m_FogColorFactor;
405  FLOAT m_fFogStart;
406  FLOAT m_fFogEnd;
407  FLOAT m_fFogDensity;
408 
410  bool m_bEnableLighting;
411 
413  bool m_bEnableSunLight;
414 
416  CSunLight m_SunLight;
417 
423  int m_nRenderPipelineOrder;
424 
426  CBatchedElementDraw* m_pBatchedElementDraw;
427  private:
428  void Draw_Internal(float fDeltaTime);
429 
430  };
431 
432 }
Which DXT Compression to Use? Obviously, there are some trade-offs between the different formats whic...
Definition: TextureEntity.h:29
Used for viewing objects on 3D canvas.
Definition: CanvasCamera.h:9
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
virtual const char * GetAttributeClassName()
a static string, describing the attribute class object&#39;s name
Definition: MiniSceneGraph.h:42
int GetRenderPipelineOrder()
default to PIPELINE_3D_SCENE.
Definition: MiniSceneGraph.cpp:1337
It&#39;s used as parameter to Draw method of each scene object.
Definition: SceneState.h:284
bool SetEffect(CEffectFile *pEffect)
set the current effect
int PrepareRender(CBaseCamera *pCamera, SceneState *pSceneState)
this function is called at the beginning of each frame to build the scene state from the specified ca...
Definition: MiniSceneGraph.cpp:831
Basic scene interface: implemented by the CSceneObject and CMiniScenegraph class. ...
Definition: IScene.h:12
CSkyMesh * GetCurrentSky()
return NULL if no sky defined.
Definition: MiniSceneGraph.cpp:1434
a render target scene object.
Definition: RenderTarget.h:16
Mini scene graph does not use a spatial partitions for its stored objects, instead it just implement ...
Definition: MiniSceneGraph.h:29
different physics engine has different winding order.
Definition: EventBinding.h:32
void CameraSetLookAtPos(float x, float y, float z)
set the camera look at position
Definition: MiniSceneGraph.cpp:709
CCanvasCamera * GetCamera()
get the camera object.
Definition: MiniSceneGraph.cpp:96
CSunLight & GetSunLight()
get sun light object
Definition: MiniSceneGraph.cpp:1483
virtual int InstallFields(CAttributeClass *pClass, bool bOverride)
this class should be implemented if one wants to add new attribute.
Definition: MiniSceneGraph.cpp:1498
void CameraSetEyePosByAngle(float fRotY, float fLiftupAngle, float fCameraObjectDist)
set the camera eye position
Definition: MiniSceneGraph.cpp:723
void SetRenderPipelineOrder(int nOrder)
default to PIPELINE_3D_SCENE.
Definition: MiniSceneGraph.cpp:1332
Modeling the global sun and its directional light, including sun position, direction, color, time of day, etc.
Definition: SunLight.h:26
void SetBackGroundColor(const LinearColor &bgColor)
set the color of the scene ground when it is not enabled.When scene is enabled, the background color ...
Definition: MiniSceneGraph.cpp:1357
the sky object in the scene.
Definition: SkyMesh.h:13
bool IsRenderSky()
whether rendering the sky
Definition: MiniSceneGraph.h:89
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
void ShowHeadOnDisplay(bool bShow)
show or hide all scene&#39;s objects&#39; head on display
Definition: MiniSceneGraph.h:301
Definition: BaseCamera.h:70
IBatchedElementDraw * GetBatchedElementDrawer()
get debug draw
Definition: MiniSceneGraph.cpp:1342
const char * GetName()
get name
Definition: MiniSceneGraph.cpp:350
float GetMaxHeadOnDisplayDistance()
whether all scene&#39;s objects&#39; head on display
Definition: MiniSceneGraph.h:310
bool CreateSkyBox(const string &strObjectName, AssetEntity &MeshAsset, float fScaleX, float fScaleY, float fScaleZ, float fHeightOffset)
create a sky box and add it to the current list, and select it as the current skybox.
Definition: MiniSceneGraph.cpp:1441
IParaDebugDraw draw interface draws line based primitives for debugging purposes. ...
Definition: IBatchedElementDraw.h:12
int DestroyObject(const char *name, bool bRecursive=false)
destroy all objects with the given name.
Definition: MiniSceneGraph.cpp:178
bool IsNeedUpdate()
even when active rendering is on, the mini scene graph will not update itself, if need update is fals...
Definition: MiniSceneGraph.cpp:1367
void CameraRotate(float dx, float dy, float dz)
rotate the camera round the object on canvas
Definition: MiniSceneGraph.cpp:699
int RenderSelection(DWORD dwSelection=0xffffffff, double dTimeDelta=0)
render objects in the post rendering list.
Definition: MiniSceneGraph.cpp:895
void Reset()
clear the entire scene graph
Definition: MiniSceneGraph.cpp:302
weak reference ptr use in a class like this: weak_ptr<CRefCounted> p; e.g.
Definition: PERef.h:105
void Draw(float fDeltaTime)
draw the content of the scene graph to the current render target.
Definition: MiniSceneGraph.cpp:618
Definition: ShapeSphere.h:6
void CameraZoomSphere(const CShapeSphere &sphere)
reset the camera parameters to view the entire sphere at best (default) distance
Definition: MiniSceneGraph.cpp:694
SceneState * GetSceneState()
get the scene state information.
Definition: MiniSceneGraph.h:294
void CameraZoom(float fAmount)
Zoom the camera.
Definition: MiniSceneGraph.cpp:689
CBaseCamera * GetCurrentCamera()
get the current camera
Definition: MiniSceneGraph.h:154
bool IsHeadOnDisplayShown()
whether all scene&#39;s objects&#39; head on display
Definition: MiniSceneGraph.h:304
bool IsLightEnabled()
get light enable state
Definition: MiniSceneGraph.cpp:1376
CBaseObject * GetObject(const char *name, bool bRecursive=false)
get object by name, if there are multiple objects with the same name, the last added one is inserted...
Definition: MiniSceneGraph.cpp:143
Vector3 GetRenderOrigin()
get the render origin in the rendering coordinate system.rendering coordinate system is a 3D coordina...
Definition: MiniSceneGraph.cpp:1127
void SetActor(CBaseObject *pActor)
set the actor: The camera always focuses on actor, so this actor can be used to control the current c...
Definition: MiniSceneGraph.cpp:340
Definition: effect_file.h:323
bool(* OBJECT_FILTER_CALLBACK)(CBaseObject *obj)
call back function type for ray picking.
Definition: MiniSceneGraph.h:19
void SetMaskTexture(TextureEntity *pTexture)
this is an optional 2D mask, which is drawn over the entire canvas after scene is rendered in to it...
Definition: MiniSceneGraph.cpp:103
virtual void Cleanup()
clean up all resource objects
Definition: MiniSceneGraph.cpp:82
void EnableLight(bool bEnable)
whether use light
Definition: MiniSceneGraph.cpp:1381
int RemoveObject(const char *name, bool bRecursive=false)
remove an object from this scene graph but do not destroy it.
Definition: MiniSceneGraph.cpp:226
void SetName(const char *sName)
set the object name.
Definition: MiniSceneGraph.cpp:355
bool PickObject(const CShapeRay &ray, CBaseObject **pTouchedObject, float fMaxDistance=0, OBJECT_FILTER_CALLBACK pFnctFilter=NULL)
Definition: MiniSceneGraph.cpp:1163
bool DeleteSkyBox(const string &strObjectName)
delete a name sky box.
Definition: MiniSceneGraph.cpp:1474
void EnableSunLight(bool bEnable)
whether use light
Definition: MiniSceneGraph.cpp:1493
int RenderHeadOnDisplay()
render the head on display, return the number of objects rendered
Definition: MiniSceneGraph.cpp:587
LinearColor GetBackGroundColor()
Get the color of the scene ground when it is not enabled.When scene is enabled, the background color ...
Definition: MiniSceneGraph.cpp:1362
bool IsSunLightEnabled()
get light enable state
Definition: MiniSceneGraph.cpp:1489
virtual bool PrepareRenderObject(CBaseObject *pObj, CBaseCamera *pCamera, SceneState &sceneState)
decide whether pObj is visible by the pCamera, if so, it will add it to the proper render queue in sc...
Definition: MiniSceneGraph.cpp:748
void CameraPan(float dx, float dy)
pan the camera
Definition: MiniSceneGraph.cpp:704
void SetFogColorFactor(const LinearColor &fogColorFactor)
fog parameters
Definition: MiniSceneGraph.h:93
Defines the base class of all scene elements:CBaseObject for Parallel World Engine.
Definition: BaseObject.h:230
A ray is a half-line P(t) = mOrig + mDir * t, with 0 <= t <= +infinity.
Definition: ShapeRay.h:11
void SetMaxHeadOnDisplayDistance(float fDist)
show or hide all scene&#39;s objects&#39; head on display
Definition: MiniSceneGraph.h:307
virtual void DestroyChildren()
Completely destroy child nodes from memory recursively.
Definition: MiniSceneGraph.cpp:683
A linear, 32-bit/component floating point RGBA color.
Definition: ParaColor.h:12
for drawing special element object(like particles, lines, etc) in the scene.
Definition: BatchedElementDraw.h:15
virtual int GetAttributeClassID()
attribute class ID should be identical, unless one knows how overriding rules work.
Definition: MiniSceneGraph.h:40
CBaseObject * GetActor()
get the current actor
Definition: MiniSceneGraph.cpp:345
Base class for managed asset entity in ParaEngine.
Definition: AssetEntity.h:25
bool IsCameraEnabled()
whether camera is enabled.
Definition: MiniSceneGraph.cpp:138
virtual void AddChild(CBaseObject *pObject)
add another object as the child of this object
Definition: MiniSceneGraph.cpp:311
void EnableCamera(bool bEnable)
enable or disable a given camera
Definition: MiniSceneGraph.cpp:111
CMiniSceneGraph(void)
Definition: MiniSceneGraph.cpp:44
virtual const char * GetAttributeClassDescription()
a static string, describing the attribute class object
Definition: MiniSceneGraph.h:44