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