1 | #pragma once
|
---|
2 | #include "Node.h"
|
---|
3 | #include "NxPhysics.h"
|
---|
4 | #include "Quad.h"
|
---|
5 | #include <boost/shared_ptr.hpp>
|
---|
6 | #include <algorithm>
|
---|
7 | #include "Renderer.h"
|
---|
8 | #include "ResourceManager.h"
|
---|
9 | #include "RenderTarget.h"
|
---|
10 | #include "Camera.h"
|
---|
11 | #include "SimpleMeshRenderer.h"
|
---|
12 | #include "TerrainRenderer.h"
|
---|
13 | #include "SkyBoxRenderer.h"
|
---|
14 | #include "HUDRenderer.h"
|
---|
15 | #include "OceanRenderer.h"
|
---|
16 | #include "ParticleRenderer.h"
|
---|
17 | #include "PhysXDebugRenderer.h"
|
---|
18 | #include "Trigger.h"
|
---|
19 | #include "RaytraceRenderer.h"
|
---|
20 | #include "RenderPass.h"
|
---|
21 | #include "ParticleGroup.h"
|
---|
22 | #include "SharedResource.h"
|
---|
23 | #include "SharedResourceTexture.h"
|
---|
24 |
|
---|
25 | class Plane;
|
---|
26 | class GameManager;
|
---|
27 | class Object3d;
|
---|
28 | class soundNode;
|
---|
29 | class ResourceManager;
|
---|
30 | class Box;
|
---|
31 |
|
---|
32 | #define NOFADE 0
|
---|
33 | #define FADEOUT 1
|
---|
34 | #define FADEIN 2
|
---|
35 |
|
---|
36 | #define QUADLEVEL 5
|
---|
37 |
|
---|
38 | #define SPTR boost::shared_ptr
|
---|
39 | #define WPTR boost::weak_ptr
|
---|
40 |
|
---|
41 | class Scene
|
---|
42 | {
|
---|
43 | public:
|
---|
44 |
|
---|
45 | friend class Node;
|
---|
46 | friend class RenderPass;
|
---|
47 |
|
---|
48 | Scene(void);
|
---|
49 | ~Scene(void);
|
---|
50 |
|
---|
51 | virtual void initScene(GameManager &_manager);
|
---|
52 |
|
---|
53 | Node* getRoot();
|
---|
54 |
|
---|
55 | void setVisible(bool _visible);
|
---|
56 | bool isVisible();
|
---|
57 | void fadeIn(float _duration);
|
---|
58 | void fadeOut(float _duration);
|
---|
59 | void setSceneAlpha(float _alpha);
|
---|
60 |
|
---|
61 | void setKeyPressed(UINT key, bool bKeyPressed);
|
---|
62 | void setMouseStatus(bool bLeftButtonDown, bool bRightButtonDown,bool bMiddleButtonDown,
|
---|
63 | bool bSideButton1Down, bool bSideButton2Down, int nMouseWheelDelta,
|
---|
64 | int xPos, int yPos);
|
---|
65 | int* getMousePos();
|
---|
66 | virtual void OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext );
|
---|
67 |
|
---|
68 | void setWidth(float _w);
|
---|
69 | void setHeight(float _h);
|
---|
70 | void setDepth(float _d);
|
---|
71 | float getWidth();
|
---|
72 | float getHeight();
|
---|
73 | float getDepth();
|
---|
74 | virtual void clearScene();
|
---|
75 |
|
---|
76 | Camera * getActiveCamera();
|
---|
77 |
|
---|
78 | virtual void renderScene(float fElapsedTime);
|
---|
79 |
|
---|
80 | struct renderSortFunction {
|
---|
81 | bool operator()(Renderer* &r1, Renderer* &r2) {
|
---|
82 | return r1->isLowerThan(r2);
|
---|
83 | }
|
---|
84 | };
|
---|
85 |
|
---|
86 | struct triggerSortFunction {
|
---|
87 | bool operator()(SPTR<Trigger> &t1, SPTR<Trigger> &t2) {
|
---|
88 | return t1->getTime() < t2->getTime();
|
---|
89 | }
|
---|
90 | };
|
---|
91 |
|
---|
92 | RenderPass* getActiveRenderPass();
|
---|
93 |
|
---|
94 | //Physic Stuff
|
---|
95 | NxVec3 pDefaultGravity;
|
---|
96 | NxSceneDesc* getPhysicSceneDescriptor();
|
---|
97 | float getDeltaTime();
|
---|
98 | IDirect3DDevice9 * device;
|
---|
99 |
|
---|
100 | //Factory Stuff
|
---|
101 | static const int NODE_OBJECT3D = 1;
|
---|
102 | static const int NODE_CAMERA = 2;
|
---|
103 | static const int NODE_SOUND = 4;
|
---|
104 | static const int NODE_BOX = 8;
|
---|
105 | static const int NODE_PARTICLEGROUP = 16;
|
---|
106 | static const int NODE_PARTICLEEMITTER = 32;
|
---|
107 | static const int NODE_SPRITE = 64;
|
---|
108 |
|
---|
109 | virtual Node* createNode(int type);
|
---|
110 | virtual Node* createNode(int type, Node &father);
|
---|
111 | virtual Node* createNode(int type, bool addDefaultRenderer);
|
---|
112 | virtual Node* createNode(int type, Node &father, bool addDefaultRenderer);
|
---|
113 | virtual Node* createNode(int type, Node &father, bool addDefaultRenderer, bool isReference);
|
---|
114 | virtual Node* createReferenceNode(int type, bool addDefaultRenderer);
|
---|
115 | void connectNodeAndRenderer(Node &node, SPTR<Renderer> &renderer);
|
---|
116 | GameManager *manager;
|
---|
117 |
|
---|
118 | //Shared Resource
|
---|
119 | std::vector<SPTR<SharedResource> > sharedResourceVector;
|
---|
120 | static const int SR_TEXTURE_VIEWDEPTH = 1; //DepthTexture Resource
|
---|
121 | static const int SR_TEXTURE_DISTORTION = 2; //DistortionMap Resource
|
---|
122 | virtual SharedResource* createSharedResource(int id);
|
---|
123 | SharedResource* getSharedResource(int id);
|
---|
124 |
|
---|
125 | //Physic Stuff
|
---|
126 | NxScene* pScene;
|
---|
127 | bool usePhysXDebugger;
|
---|
128 | void setContactReport(NxUserContactReport *_contactReport);
|
---|
129 | void setTriggerReport(NxUserTriggerReport *_triggerReport);
|
---|
130 | void setNotifyReport(NxUserNotify* _notifyReport);
|
---|
131 |
|
---|
132 | //Device Stuff
|
---|
133 | virtual void OnLostDevice( void* pUserContext );
|
---|
134 | virtual void OnDestroyDevice( void* pUserContext );
|
---|
135 | virtual HRESULT OnResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext );
|
---|
136 |
|
---|
137 | //Trigger Stuff
|
---|
138 | static const int TRIGGER_UNSETSTANDBY = 0;
|
---|
139 | static const int TRIGGER_KILLNODE = 1;
|
---|
140 | static const int TRIGGER_SETDETAIL = 2;
|
---|
141 | void setTrigger(int type, float time);
|
---|
142 | void setTrigger(int type, Node *node, float time);
|
---|
143 | void setTrigger(int type, Node *node, Node* secondNode, float time);
|
---|
144 | void setTrigger(int type, Node *node, Node* secondNode, Vector normal, float time);
|
---|
145 | float getSceneLiveTime();
|
---|
146 |
|
---|
147 | //Effect Stuff
|
---|
148 | Vector getSunDirection();
|
---|
149 | void setSunDirection(Vector &v);
|
---|
150 |
|
---|
151 | D3DXMATRIX getWorldMatrix();
|
---|
152 | D3DXMATRIX getViewMatrix();
|
---|
153 | D3DXMATRIX getProjectionMatrix();
|
---|
154 | D3DXMATRIX getIdentityMatrix();
|
---|
155 |
|
---|
156 | void renderNodes();
|
---|
157 | Renderer* specialRenderer;
|
---|
158 |
|
---|
159 | void deleteNode(Node* node);
|
---|
160 |
|
---|
161 | SPTR<Node> getSmartPointer(Node *node);
|
---|
162 | Object3d *sObj;
|
---|
163 | RenderPass *activeRenderPass;
|
---|
164 |
|
---|
165 | // light:
|
---|
166 | void setLight(Vector direction);
|
---|
167 |
|
---|
168 | //Particle Stuff
|
---|
169 | std::list<SPTR<Node> >* getParticleList();
|
---|
170 | ParticleGroup* getParticleGroup(int id);
|
---|
171 | void addToParticleList(Node *node);
|
---|
172 |
|
---|
173 |
|
---|
174 | ParticleGroup* defaultParticleGroup;
|
---|
175 | std::vector<SPTR<Renderer> > rendererList; //List of all renderer in scene
|
---|
176 |
|
---|
177 | void deleteRendererInList(Renderer* renderer);
|
---|
178 | bool drawBBoxes;
|
---|
179 |
|
---|
180 | void renderFinalImage(ID3DXEffect* fadeEffect);
|
---|
181 | int getActivePassId();
|
---|
182 | //Pass stuff
|
---|
183 | static const int PASS_NORMAL = 0;
|
---|
184 | static const int PASS_RAYTRACE = 1;
|
---|
185 | static const int PASS_DEPTH = 2;
|
---|
186 | void setActiveRenderPass(RenderPass &_activePass);
|
---|
187 |
|
---|
188 | LPD3DXMESH getQuadMesh();
|
---|
189 | bool useDepthImposter;
|
---|
190 | bool useRaytracer;
|
---|
191 |
|
---|
192 | FSOUND_STREAM *bgMusicStream;
|
---|
193 | int bgSoundChannel;
|
---|
194 | float bgSoundVolume;
|
---|
195 | bool soundStopped;
|
---|
196 | void setBackgroundSound(std::string filename);
|
---|
197 | void setBackgroundSoundVolume(float vol);
|
---|
198 | void playBackgroundSound();
|
---|
199 | virtual void updateSoundNodeVolume();
|
---|
200 | virtual void setBackgroundSoundMute(bool _playMusic);
|
---|
201 | bool getBackgroundSoundMute();
|
---|
202 |
|
---|
203 | protected:
|
---|
204 | //Scene Management Stuff
|
---|
205 | bool visible;
|
---|
206 | float fadeDuration;
|
---|
207 | float fadeTimer;
|
---|
208 | int fadeState;
|
---|
209 | float sceneAlpha;
|
---|
210 | bool muteMusic;
|
---|
211 | Box* boundingBox;
|
---|
212 |
|
---|
213 | //Keyboard & Mouse Stuff
|
---|
214 | bool keyDown[256];
|
---|
215 | static const int MOUSE_LEFT = 0;
|
---|
216 | static const int MOUSE_RIGHT = 1;
|
---|
217 | static const int MOUSE_MIDDLE = 2;
|
---|
218 | static const int MOUSE_SIDE1 = 3;
|
---|
219 | static const int MOUSE_SIDE2 = 4;
|
---|
220 | bool mouseButton[5];
|
---|
221 | int mousePos[2];
|
---|
222 | int mouseWheel;
|
---|
223 |
|
---|
224 | float width;
|
---|
225 | float height;
|
---|
226 | float depth;
|
---|
227 |
|
---|
228 | //RenderChain Stuff
|
---|
229 | std::list<void (Scene::*)(void)> renderChain;
|
---|
230 | bool firstFrame;
|
---|
231 |
|
---|
232 | void takeTime();
|
---|
233 | void fetchPhysicResults();
|
---|
234 | void doFade();
|
---|
235 | void updateTrigger();
|
---|
236 | void updateNodes();
|
---|
237 | void calculateTransformations();
|
---|
238 | void doFrustumCulling();
|
---|
239 | void doViewingTransformation();
|
---|
240 | virtual void cleanUpScene();
|
---|
241 | void startPhysic();
|
---|
242 | void startRenderPasses();
|
---|
243 |
|
---|
244 | //Clear operations
|
---|
245 | void clearRenderTargetAndZBuffer();
|
---|
246 | void clearSharedResources();
|
---|
247 |
|
---|
248 | //Physic Stuff
|
---|
249 | NxSceneDesc sceneDesc;
|
---|
250 | NxReal myTimeStep;
|
---|
251 | PhysXDebugRenderer physxRenderer;
|
---|
252 |
|
---|
253 | float dt;
|
---|
254 | LARGE_INTEGER frequency;
|
---|
255 | LARGE_INTEGER lastFrame;
|
---|
256 | LARGE_INTEGER currentFrame;
|
---|
257 |
|
---|
258 | bool initPhysic();
|
---|
259 |
|
---|
260 | //Culling Stuff
|
---|
261 | Quad fcQuad;
|
---|
262 | void buildQuadTree();
|
---|
263 | bool enableFrustumCulling;
|
---|
264 | bool quadTreeBuilt;
|
---|
265 |
|
---|
266 | //Scene Objects Stuff
|
---|
267 | Node root;
|
---|
268 | D3DXMATRIX worldMatrix;
|
---|
269 | D3DXMATRIX identMatrix;
|
---|
270 | std::list<SPTR<Node> > visibleNodeList;
|
---|
271 | std::vector<RaytraceRenderer *> raytraceRendererList;
|
---|
272 | std::vector<ParticleRenderer *> heatHazeParticleRendererList;
|
---|
273 | std::list<SPTR<Node> > zombieNodeList;
|
---|
274 | Camera *activeCamera;
|
---|
275 | Camera *defaultCamera;
|
---|
276 |
|
---|
277 | std::list<SPTR<Node> > nodeList; //List of all nodes in scene
|
---|
278 |
|
---|
279 | std::vector<SPTR<Node> > refObject3dList; //List of all object3d s in scene
|
---|
280 | std::vector<SPTR<Node> > refCameraList; //List of all cameras
|
---|
281 | std::vector<SPTR<Node> > refSoundList; //List of soundNodes
|
---|
282 |
|
---|
283 | std::list<SPTR<Node> > particleList; //List of all Particles in Scene
|
---|
284 | std::list<SPTR<Node> > soundNodeList; //List of all SoundNodes in Scene
|
---|
285 | void deleteNodeInList(Node* node, std::list<SPTR<Node> > &list);
|
---|
286 |
|
---|
287 | //Sun Stuff
|
---|
288 | Vector sunDirection;
|
---|
289 | D3DLIGHT9 d3dLight;
|
---|
290 |
|
---|
291 | //TriggerStuff
|
---|
292 | float sceneLifeTime;
|
---|
293 | std::vector<SPTR<Trigger> > triggerList;
|
---|
294 | virtual void executeTrigger(SPTR<Trigger> trigger);
|
---|
295 |
|
---|
296 | //Physic Stuff
|
---|
297 | NxUserContactReport *contactReport;
|
---|
298 | NxUserTriggerReport *triggerReport;
|
---|
299 | NxUserNotify *notifyReport;
|
---|
300 |
|
---|
301 | //ParticleSystem Stuff
|
---|
302 | int particleGroupCounter;
|
---|
303 | std::vector<SPTR<Node> > particleGroupVector;
|
---|
304 |
|
---|
305 | //Fading & Postprocessing Stuff
|
---|
306 | IDirect3DTexture9* finalImage;
|
---|
307 | IDirect3DSurface9* finalImageSurface;
|
---|
308 | D3DSURFACE_DESC finalImageDesc;
|
---|
309 | D3DXMATRIX spriteMatrix;
|
---|
310 | LPD3DXMESH quadMesh;
|
---|
311 | bool meshCreated;
|
---|
312 | void createQuadMesh();
|
---|
313 |
|
---|
314 | struct Vertex
|
---|
315 | {
|
---|
316 | Vertex(float _x, float _y, float _z, float _u, float _v)
|
---|
317 | {
|
---|
318 | x = _x;
|
---|
319 | y = _y;
|
---|
320 | z = _z;
|
---|
321 | u = _u;
|
---|
322 | v = _v;
|
---|
323 | }
|
---|
324 |
|
---|
325 | Vertex(Vector vec, float _u, float _v)
|
---|
326 | {
|
---|
327 | x = vec.x;
|
---|
328 | y = vec.y;
|
---|
329 | z = vec.z;
|
---|
330 | u = _u;
|
---|
331 | v = _v;
|
---|
332 | }
|
---|
333 |
|
---|
334 | float x, y, z, u, v;
|
---|
335 | };
|
---|
336 |
|
---|
337 | const static DWORD FVF_Flags = D3DFVF_XYZ | D3DFVF_TEX1;
|
---|
338 |
|
---|
339 | RenderPass defaultRenderPass;
|
---|
340 | RenderPass depthRenderPass;
|
---|
341 | RenderPass raytraceRenderPass;
|
---|
342 | SharedResourceTexture* depthTextureResource;
|
---|
343 | LPDIRECT3DSURFACE9 depthSurface;
|
---|
344 | bool needDepthPass;
|
---|
345 | bool needRaytracePass;
|
---|
346 | bool needDistortionPass;
|
---|
347 | IDirect3DTexture9* distortionMap1;
|
---|
348 | IDirect3DTexture9* distortionMap2;
|
---|
349 | IDirect3DTexture9* preDistortionFinal;
|
---|
350 | IDirect3DSurface9* preDistortionFinalSurface;
|
---|
351 | IDirect3DTexture9* screenDistortionMap;
|
---|
352 | IDirect3DSurface9* screenDistortionMapSurface;
|
---|
353 | };
|
---|