[1378] | 1 | #include "dxstdafx.h"
|
---|
| 2 | #include ".\scene.h"
|
---|
| 3 | #include "GameManager.h"
|
---|
| 4 | #include "Object3d.h"
|
---|
| 5 | #include "Box.h"
|
---|
| 6 | #include "Sprite.h"
|
---|
| 7 | #include "ParticleGroup.h"
|
---|
| 8 | #include "ParticleEmitter.h"
|
---|
| 9 | #include "SoundNode.h"
|
---|
| 10 | #include "SharedResourceTexture.h"
|
---|
| 11 | #include "fmod.h"
|
---|
| 12 |
|
---|
| 13 | Scene::Scene(void)
|
---|
| 14 | {
|
---|
| 15 | this->sceneAlpha = 1;
|
---|
| 16 | this->root.setScene(*this);
|
---|
| 17 | this->sceneLifeTime = 0;
|
---|
| 18 | this->usePhysXDebugger = true;
|
---|
| 19 |
|
---|
| 20 | //Fade Stuff
|
---|
| 21 | this->visible = true;
|
---|
| 22 | this->fadeState = NOFADE;
|
---|
| 23 |
|
---|
| 24 | //Gravity
|
---|
| 25 | this->pDefaultGravity.x = 0;
|
---|
| 26 | this->pDefaultGravity.y = -9.8f;
|
---|
| 27 | this->pDefaultGravity.z = 0;
|
---|
| 28 |
|
---|
| 29 | //Frustum Stuff
|
---|
| 30 | this->enableFrustumCulling = true;
|
---|
| 31 | this->drawBBoxes = true;
|
---|
| 32 | this->boundingBox = NULL;
|
---|
| 33 | this->quadTreeBuilt = false;
|
---|
| 34 |
|
---|
| 35 | //RenderChain Timing usw
|
---|
| 36 | QueryPerformanceFrequency(&this->frequency);
|
---|
| 37 | this->firstFrame = true;
|
---|
| 38 |
|
---|
| 39 | //PhysicStuff
|
---|
| 40 | this->pScene = NULL;
|
---|
| 41 | D3DXMatrixIdentity(&this->worldMatrix);
|
---|
| 42 | D3DXMatrixIdentity(&this->identMatrix);
|
---|
| 43 |
|
---|
| 44 | this->root.myScene = this;
|
---|
| 45 | this->contactReport = NULL;
|
---|
| 46 | this->triggerReport = NULL;
|
---|
| 47 | this->notifyReport = NULL;
|
---|
| 48 |
|
---|
| 49 | //Get the Device
|
---|
| 50 | this->device = DXUTGetD3DDevice();
|
---|
| 51 | this->physxRenderer.setDevice(*this->device);
|
---|
| 52 |
|
---|
| 53 | //Sun Stuff
|
---|
| 54 | this->sunDirection.setXYZ(-1.0f, -2.0f, 1.0f);
|
---|
| 55 | this->specialRenderer = NULL;
|
---|
| 56 |
|
---|
| 57 | //DefaultRenderPass konfigurieren
|
---|
| 58 | this->activeRenderPass = NULL;
|
---|
| 59 |
|
---|
| 60 | //Particle Group Stuff
|
---|
| 61 | this->particleGroupCounter = 0;
|
---|
| 62 |
|
---|
| 63 | this->finalImage = NULL;
|
---|
| 64 | this->preDistortionFinal = NULL;
|
---|
| 65 | this->distortionMap1 = NULL;
|
---|
| 66 | this->distortionMap2 = NULL;
|
---|
| 67 | this->screenDistortionMap = NULL;
|
---|
| 68 | this->quadMesh = NULL;
|
---|
| 69 | this->meshCreated = false;
|
---|
| 70 | this->depthTextureResource = NULL;
|
---|
| 71 | this->useDepthImposter = true;
|
---|
| 72 | this->useRaytracer = true;
|
---|
| 73 |
|
---|
| 74 | this->muteMusic = false;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | Scene::~Scene(void)
|
---|
| 78 | {
|
---|
| 79 | SAFE_RELEASE(this->finalImage);
|
---|
| 80 | SAFE_RELEASE(this->finalImageSurface);
|
---|
| 81 | SAFE_RELEASE(this->quadMesh);
|
---|
| 82 | SAFE_RELEASE(this->depthSurface);
|
---|
| 83 | SAFE_RELEASE(this->preDistortionFinal);
|
---|
| 84 | SAFE_RELEASE(this->preDistortionFinalSurface);
|
---|
| 85 | SAFE_RELEASE(this->screenDistortionMapSurface);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | void Scene::initScene(GameManager &_manager)
|
---|
| 89 | {
|
---|
| 90 | HRESULT hr;
|
---|
| 91 |
|
---|
| 92 | this->manager = &_manager;
|
---|
| 93 |
|
---|
| 94 | //Textur für endgültiges Bild erzeugen
|
---|
| 95 | if(!this->finalImage) {
|
---|
| 96 | //Create Texture
|
---|
| 97 | V( DXUTGetD3DDevice()->CreateTexture(this->manager->screenWidth, this->manager->screenHeight, 1, D3DUSAGE_RENDERTARGET,
|
---|
[1396] | 98 | //V( DXUTGetD3DDevice()->CreateTexture(this->manager->screenWidth, this->manager->screenHeight+1, 1, D3DUSAGE_RENDERTARGET,
|
---|
[1378] | 99 | D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &this->finalImage, NULL ) );
|
---|
| 100 |
|
---|
| 101 | //Get Surface for RenderTarget
|
---|
| 102 | this->finalImage->GetSurfaceLevel(0, &this->finalImageSurface);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | this->sceneLifeTime = 0;
|
---|
| 106 | this->firstFrame = true;
|
---|
| 107 |
|
---|
| 108 | this->defaultParticleGroup = (ParticleGroup*) this->createNode(Scene::NODE_PARTICLEGROUP, false);
|
---|
| 109 | this->initPhysic();
|
---|
| 110 | this->boundingBox = (Box*) this->createNode(Scene::NODE_BOX);
|
---|
| 111 | this->boundingBox->setVisible(false);
|
---|
| 112 | this->boundingBox->setStandBy(true);
|
---|
| 113 |
|
---|
| 114 | //Camera Stuff
|
---|
| 115 | this->defaultCamera = (Camera *) this->createNode(this->NODE_CAMERA);
|
---|
| 116 | this->activeCamera = this->defaultCamera;
|
---|
| 117 |
|
---|
| 118 | //Default RenderPass
|
---|
| 119 | this->defaultRenderPass.setSafeAndRestoreRenderTarget(false);
|
---|
| 120 | this->defaultRenderPass.setScene(*this);
|
---|
| 121 | this->defaultRenderPass.setRenderPassId(Scene::PASS_NORMAL);
|
---|
| 122 | this->defaultRenderPass.setRenderTarget(this->finalImageSurface);
|
---|
| 123 | this->defaultRenderPass.execute(RenderPass::CMD_CLEARRENDERTARGETANDZBUFFER);
|
---|
| 124 | this->defaultRenderPass.execute(RenderPass::CMD_RENDERNODES);
|
---|
| 125 |
|
---|
| 126 | //Depth RenderPass
|
---|
| 127 | this->depthTextureResource = (SharedResourceTexture*) this->getSharedResource(Scene::SR_TEXTURE_VIEWDEPTH);
|
---|
| 128 | if(!this->depthTextureResource) {
|
---|
| 129 | if(this->depthSurface){
|
---|
| 130 | SAFE_RELEASE (this->depthSurface);
|
---|
| 131 | }
|
---|
| 132 | this->depthTextureResource = (SharedResourceTexture*) this->createSharedResource(Scene::SR_TEXTURE_VIEWDEPTH);
|
---|
| 133 | this->depthTextureResource->getTexture()->GetSurfaceLevel(0, &this->depthSurface);
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | //Load DistortionMaps
|
---|
| 137 | if(!this->distortionMap1)
|
---|
| 138 | this->distortionMap1 = this->manager->resManager.loadTexture("./media/textures/heatnoise.tga");
|
---|
| 139 | if(!this->distortionMap2)
|
---|
| 140 | this->distortionMap2 = this->manager->resManager.loadTexture("./media/textures/heatnoise2.tga");
|
---|
| 141 | if(!this->screenDistortionMap) {
|
---|
| 142 | SharedResourceTexture* distMap = (SharedResourceTexture*) this->createSharedResource(Scene::SR_TEXTURE_DISTORTION);
|
---|
| 143 | this->screenDistortionMap = distMap->getTexture();
|
---|
| 144 | this->screenDistortionMap->GetSurfaceLevel(0, &this->screenDistortionMapSurface);
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | if(!this->preDistortionFinal) {
|
---|
| 148 | //Create Texture
|
---|
| 149 | V( DXUTGetD3DDevice()->CreateTexture(this->manager->screenWidth, this->manager->screenHeight, 1, D3DUSAGE_RENDERTARGET,
|
---|
| 150 | D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &this->preDistortionFinal, NULL ) );
|
---|
| 151 |
|
---|
| 152 | //Get Surface for RenderTarget
|
---|
| 153 | this->preDistortionFinal->GetSurfaceLevel(0, &this->preDistortionFinalSurface);
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | this->depthRenderPass.setSafeAndRestoreRenderTarget(false);
|
---|
| 157 | this->depthRenderPass.setScene(*this);
|
---|
| 158 | this->depthRenderPass.setRenderPassId(Scene::PASS_DEPTH);
|
---|
| 159 | this->depthRenderPass.setRenderTarget(this->depthSurface);
|
---|
| 160 | this->depthRenderPass.execute(RenderPass::CMD_CLEARRENDERTARGETANDZBUFFER);
|
---|
| 161 | this->depthRenderPass.execute(RenderPass::CMD_RENDERNODES);
|
---|
| 162 | this->depthRenderPass.useThisRendererList(this->defaultRenderPass.usedRendererList);
|
---|
| 163 |
|
---|
| 164 | //Raytrace RenderPass
|
---|
| 165 | this->raytraceRenderPass.setSafeAndRestoreRenderTarget(false);
|
---|
| 166 | this->raytraceRenderPass.setScene(*this);
|
---|
| 167 | this->raytraceRenderPass.setRenderPassId(Scene::PASS_RAYTRACE);
|
---|
| 168 | this->raytraceRenderPass.execute(RenderPass::CMD_CLEARRENDERTARGETANDZBUFFER);
|
---|
| 169 | this->raytraceRenderPass.execute(RenderPass::CMD_DOFRUSTUMCULLING);
|
---|
| 170 | this->raytraceRenderPass.execute(RenderPass::CMD_RENDERNODES);
|
---|
| 171 |
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | float Scene::getSceneLiveTime()
|
---|
| 175 | {
|
---|
| 176 | return this->sceneLifeTime;
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | void Scene::setVisible(bool _visible)
|
---|
| 180 | {
|
---|
| 181 | this->visible = _visible;
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | bool Scene::isVisible()
|
---|
| 185 | {
|
---|
| 186 | return this->visible;
|
---|
| 187 | }
|
---|
| 188 | void Scene::fadeIn(float _duration)
|
---|
| 189 | {
|
---|
| 190 | this->fadeDuration = _duration;
|
---|
| 191 | this->fadeTimer = 0;
|
---|
| 192 | this->fadeState = FADEIN;
|
---|
| 193 | this->setVisible(true);
|
---|
| 194 | }
|
---|
| 195 | void Scene::fadeOut(float _duration)
|
---|
| 196 | {
|
---|
| 197 | this->fadeDuration = _duration;
|
---|
| 198 | this->fadeTimer = 0;
|
---|
| 199 | this->fadeState = FADEOUT;
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | void Scene::setSceneAlpha(float _alpha)
|
---|
| 203 | {
|
---|
| 204 | if(_alpha>1) _alpha = 1;
|
---|
| 205 | if(_alpha<0) _alpha = 0;
|
---|
| 206 | this->sceneAlpha = _alpha;
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | Node* Scene::getRoot()
|
---|
| 210 | {
|
---|
| 211 | return &this->root;
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | void Scene::clearScene() {
|
---|
| 215 | this->root.removeAllChildren();
|
---|
| 216 | this->cleanUpScene();
|
---|
| 217 |
|
---|
| 218 | this->nodeList.clear();
|
---|
| 219 | this->particleList.clear();
|
---|
| 220 | this->rendererList.clear();
|
---|
| 221 | this->refObject3dList.clear();
|
---|
| 222 | this->refCameraList.clear();
|
---|
| 223 | this->refSoundList.clear();
|
---|
| 224 | this->triggerList.clear();
|
---|
| 225 | this->particleGroupVector.clear();
|
---|
| 226 | this->clearSharedResources();
|
---|
| 227 | this->sharedResourceVector.clear();
|
---|
| 228 | this->visibleNodeList.clear();
|
---|
| 229 | this->soundNodeList.clear();
|
---|
| 230 | //this->usedRendererList.clear();
|
---|
| 231 | this->zombieNodeList.clear();
|
---|
| 232 |
|
---|
| 233 | if(this->manager && this->manager->pPhysicsSDK) {
|
---|
| 234 | this->manager->pPhysicsSDK->releaseScene(*this->pScene);
|
---|
| 235 | this->pScene = NULL;
|
---|
| 236 | }
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | void Scene::setWidth(float _w)
|
---|
| 240 | {
|
---|
| 241 | this->width = _w;
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | void Scene::setHeight(float _h)
|
---|
| 245 | {
|
---|
| 246 | this->height = _h;
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | void Scene::setDepth(float _d)
|
---|
| 250 | {
|
---|
| 251 | this->depth = _d;
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | float Scene::getWidth()
|
---|
| 255 | {
|
---|
| 256 | return this->width;
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | float Scene::getHeight()
|
---|
| 260 | {
|
---|
| 261 | return this->height;
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | float Scene::getDepth()
|
---|
| 265 | {
|
---|
| 266 | return this->depth;
|
---|
| 267 | }
|
---|
| 268 |
|
---|
[1400] | 269 | float Scene::viewPortRatio()
|
---|
| 270 | {
|
---|
| 271 | //return float(this->width) / this->height;
|
---|
| 272 | return float(this->manager->screenWidth)/this->manager->screenHeight;
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 |
|
---|
[1378] | 276 | Camera* Scene::getActiveCamera()
|
---|
| 277 | {
|
---|
| 278 | return this->activeCamera;
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 | NxSceneDesc* Scene::getPhysicSceneDescriptor()
|
---|
| 282 | {
|
---|
| 283 | return &this->sceneDesc;
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 | bool Scene::initPhysic()
|
---|
| 287 | {
|
---|
| 288 | // Create the scene
|
---|
| 289 | this->manager->pPhysicsSDK->setParameter(NX_SKIN_WIDTH, (NxReal)0.01);
|
---|
| 290 | if(this->usePhysXDebugger) {
|
---|
| 291 | this->manager->pPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 5.0f);
|
---|
| 292 | this->manager->pPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1);
|
---|
| 293 | this->manager->pPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1);
|
---|
| 294 | this->manager->pPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_LOCAL_AXES, 1.0f);
|
---|
| 295 | this->manager->pPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_WORLD_AXES, 1);
|
---|
| 296 | this->manager->pPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_ERROR, 1);
|
---|
| 297 | this->manager->pPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_LIMITS, 1);
|
---|
| 298 | this->manager->pPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_FORCE, 1);
|
---|
| 299 | }
|
---|
| 300 | this->sceneDesc.gravity = pDefaultGravity;
|
---|
| 301 | this->sceneDesc.collisionDetection = true;
|
---|
| 302 | if(this->pScene!=NULL) {
|
---|
| 303 | this->manager->pPhysicsSDK->releaseScene(*this->pScene);
|
---|
| 304 | }
|
---|
| 305 | this->pScene = this->manager->pPhysicsSDK->createScene(this->sceneDesc);
|
---|
| 306 | if(this->contactReport) this->pScene->setUserContactReport(this->contactReport);
|
---|
| 307 | if(this->triggerReport) this->pScene->setUserTriggerReport(this->triggerReport);
|
---|
| 308 | if(this->notifyReport) this->pScene->setUserNotify(this->notifyReport);
|
---|
| 309 | this->pScene->setTiming(1.0f/60.0f, 8, NX_TIMESTEP_FIXED);
|
---|
| 310 |
|
---|
| 311 | // Create the default material
|
---|
| 312 | NxMaterial* defaultMaterial = this->pScene->getMaterialFromIndex(0);
|
---|
| 313 | defaultMaterial->setRestitution(0.5);
|
---|
| 314 | defaultMaterial->setStaticFriction(0.5);
|
---|
| 315 | defaultMaterial->setDynamicFriction(0.5);
|
---|
| 316 |
|
---|
| 317 | return true;
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 | float Scene::getDeltaTime()
|
---|
| 321 | {
|
---|
| 322 | return this->dt;
|
---|
| 323 | }
|
---|
| 324 |
|
---|
| 325 | void Scene::buildQuadTree()
|
---|
| 326 | {
|
---|
| 327 | this->fcQuad.setDimension(this->getWidth(), this->getWidth());
|
---|
| 328 | this->fcQuad.setPosition(this->getWidth()/2, this->getWidth()/2);
|
---|
| 329 | this->fcQuad.buildQuadTree(QUADLEVEL);
|
---|
| 330 | this->quadTreeBuilt = true;
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 | RenderPass* Scene::getActiveRenderPass()
|
---|
| 334 | {
|
---|
| 335 | return this->activeRenderPass;
|
---|
| 336 | }
|
---|
| 337 |
|
---|
| 338 | void Scene::renderScene(float fElapsedTime)
|
---|
| 339 | {
|
---|
| 340 | if(this->isVisible()) {
|
---|
| 341 | if(this->device==0) {
|
---|
| 342 | this->device = DXUTGetD3DDevice();
|
---|
| 343 | this->physxRenderer.setDevice(*this->device);
|
---|
| 344 | }
|
---|
| 345 | this->device->SetRenderTarget(0, this->finalImageSurface);
|
---|
| 346 |
|
---|
| 347 | this->takeTime();
|
---|
| 348 | //ClearScreen
|
---|
| 349 | //this->clearRenderTargetAndZBuffer();
|
---|
| 350 | //Clear SharedResources
|
---|
| 351 | this->clearSharedResources();
|
---|
| 352 | //Fetch Physic Results
|
---|
| 353 | this->fetchPhysicResults();
|
---|
| 354 | //Fading Stuff
|
---|
| 355 | this->doFade();
|
---|
| 356 | //Trigger updates
|
---|
| 357 | this->updateTrigger();
|
---|
| 358 | //Update Nodes
|
---|
| 359 | this->updateNodes();
|
---|
| 360 | //Calculate Transformations
|
---|
| 361 | this->calculateTransformations();
|
---|
| 362 |
|
---|
| 363 | //startRenderPasses
|
---|
| 364 | this->startRenderPasses();
|
---|
| 365 |
|
---|
| 366 | //Cleanup Memory
|
---|
| 367 | this->cleanUpScene();
|
---|
| 368 | //Start Physic
|
---|
| 369 | this->startPhysic();
|
---|
| 370 |
|
---|
| 371 | this->firstFrame = false;
|
---|
| 372 | }
|
---|
| 373 | }
|
---|
| 374 |
|
---|
| 375 | void Scene::takeTime()
|
---|
| 376 | {
|
---|
| 377 | //Take time
|
---|
| 378 | if(this->firstFrame) {
|
---|
| 379 | QueryPerformanceCounter(&this->currentFrame);
|
---|
| 380 | this->lastFrame = this->currentFrame;
|
---|
| 381 | return;
|
---|
| 382 | } else {
|
---|
| 383 | this->lastFrame = this->currentFrame;
|
---|
| 384 | QueryPerformanceCounter(&this->currentFrame);
|
---|
| 385 | }
|
---|
| 386 | double tempdt;
|
---|
| 387 | tempdt = (double)(this->currentFrame.QuadPart-this->lastFrame.QuadPart)/(double)this->frequency.QuadPart;
|
---|
| 388 | this->dt = (float) tempdt;
|
---|
| 389 | this->dt = min(0.033f, this->dt);
|
---|
| 390 | }
|
---|
| 391 |
|
---|
| 392 | void Scene::fetchPhysicResults()
|
---|
| 393 | {
|
---|
| 394 | if(!this->firstFrame) {
|
---|
| 395 | this->pScene->fetchResults(NX_RIGID_BODY_FINISHED, true);
|
---|
| 396 | }
|
---|
| 397 | }
|
---|
| 398 |
|
---|
| 399 | void Scene::doFade()
|
---|
| 400 | {
|
---|
| 401 | switch(this->fadeState)
|
---|
| 402 | {
|
---|
| 403 | case FADEOUT:
|
---|
| 404 | this->fadeTimer+=this->dt;
|
---|
| 405 | this->sceneAlpha -= this->dt/this->fadeDuration;
|
---|
| 406 | if(this->sceneAlpha<=0) {
|
---|
| 407 | this->setVisible(false);
|
---|
| 408 | this->fadeState = NOFADE;
|
---|
| 409 | this->sceneAlpha = 0;
|
---|
| 410 | }
|
---|
| 411 | this->updateSoundNodeVolume();
|
---|
| 412 | break;
|
---|
| 413 | case FADEIN:
|
---|
| 414 | if(!this->visible)
|
---|
| 415 | this->setVisible(true);
|
---|
| 416 | this->fadeTimer+=this->dt;
|
---|
| 417 | this->sceneAlpha+=this->dt/this->fadeDuration;
|
---|
| 418 | if(this->sceneAlpha>=1) {
|
---|
| 419 | this->fadeState = NOFADE;
|
---|
| 420 | this->sceneAlpha = 1;
|
---|
| 421 | }
|
---|
| 422 | this->updateSoundNodeVolume();
|
---|
| 423 | break;
|
---|
| 424 | default:
|
---|
| 425 | break;
|
---|
| 426 | }
|
---|
| 427 | }
|
---|
| 428 |
|
---|
| 429 | void Scene::updateTrigger()
|
---|
| 430 | {
|
---|
| 431 | this->sceneLifeTime+=this->getDeltaTime();
|
---|
| 432 | std::vector<SPTR<Trigger> >::iterator it;
|
---|
| 433 | for(it=this->triggerList.begin();it!=this->triggerList.end();it++) {
|
---|
| 434 | if(this->sceneLifeTime>(*it)->getTime()) {
|
---|
| 435 | this->executeTrigger(*it);
|
---|
| 436 | this->triggerList.erase(it);
|
---|
| 437 | it--;
|
---|
| 438 | } else {
|
---|
| 439 | return;
|
---|
| 440 | }
|
---|
| 441 | }
|
---|
| 442 |
|
---|
| 443 | for(UINT i=0;i<this->triggerList.size();i++) {
|
---|
| 444 | if(this->sceneLifeTime>this->triggerList.at(i)->getTime()) {
|
---|
| 445 | this->executeTrigger(this->triggerList.at(i));
|
---|
| 446 | i--;
|
---|
| 447 | } else {
|
---|
| 448 | return;
|
---|
| 449 | }
|
---|
| 450 | }
|
---|
| 451 | }
|
---|
| 452 |
|
---|
| 453 | void Scene::updateNodes()
|
---|
| 454 | {
|
---|
| 455 | this->root.update(this->dt);
|
---|
| 456 | }
|
---|
| 457 |
|
---|
| 458 |
|
---|
| 459 | void Scene::calculateTransformations()
|
---|
| 460 | {
|
---|
| 461 | //Object transformation
|
---|
| 462 | this->root.calcWorldMatrix(this->worldMatrix);
|
---|
| 463 | this->root.updateBBox();
|
---|
| 464 | }
|
---|
| 465 |
|
---|
| 466 |
|
---|
| 467 |
|
---|
| 468 | void Scene::doFrustumCulling()
|
---|
| 469 | {
|
---|
[1400] | 470 | Camera cam(this->viewPortRatio());
|
---|
[1378] | 471 | cam.setViewMatrix(*this->activeRenderPass->getViewMatrix());
|
---|
| 472 | cam.setProjectionMatrix(*this->activeRenderPass->getProjectionMatrix());
|
---|
| 473 |
|
---|
| 474 | std::vector<Renderer *>* usedRendererList;
|
---|
| 475 | usedRendererList = this->activeRenderPass->usedRendererList;
|
---|
| 476 |
|
---|
| 477 | std::list<SPTR<Node> >::iterator nodeIt;
|
---|
| 478 | Node* node;
|
---|
| 479 |
|
---|
| 480 | if(!this->quadTreeBuilt)
|
---|
| 481 | this->buildQuadTree();
|
---|
| 482 | usedRendererList->clear();
|
---|
| 483 |
|
---|
| 484 | Renderer *renderer;
|
---|
| 485 |
|
---|
| 486 | if(this->enableFrustumCulling) {
|
---|
| 487 | Plane view[4];
|
---|
| 488 |
|
---|
| 489 | view[0] = cam.getNearPlane();
|
---|
| 490 | view[1] = cam.getFarPlane();
|
---|
| 491 | view[2] = cam.getLeftPlane();
|
---|
| 492 | view[3] = cam.getRightPlane();
|
---|
| 493 | this->fcQuad.clipQuadAgainstCamera(&view[0]);
|
---|
| 494 |
|
---|
| 495 | for(nodeIt = this->nodeList.begin(); nodeIt!=this->nodeList.end();nodeIt++) {
|
---|
| 496 | node = (*nodeIt).get();
|
---|
| 497 | if(!node->onStandBy() && node->visible && node->hasRenderer() && node->testAgainstFrustum && this->fcQuad.nodeInside(node)) {
|
---|
| 498 | renderer = node->getRenderer().get();
|
---|
| 499 | if(this->activeRenderPass == &this->defaultRenderPass) {
|
---|
| 500 | if(renderer->isA(Renderer::RENDERER_PARTICLE)) {
|
---|
| 501 | this->needDepthPass |= renderer->needsExtraPass();
|
---|
| 502 | if(((ParticleRenderer*) renderer)->needHeatHazePass()) {
|
---|
| 503 | this->needDistortionPass = true;
|
---|
| 504 | this->heatHazeParticleRendererList.push_back((ParticleRenderer*) renderer);
|
---|
| 505 | }
|
---|
| 506 | } else if(renderer->isA(Renderer::RENDERER_RAYTRACE)) {
|
---|
| 507 | this->needRaytracePass = true;
|
---|
| 508 | this->raytraceRendererList.push_back((RaytraceRenderer*) renderer);
|
---|
| 509 | }
|
---|
| 510 | }
|
---|
| 511 | usedRendererList->push_back(renderer);
|
---|
| 512 | } else if(!node->onStandBy() && node->visible && node->hasRenderer() && !node->testAgainstFrustum) {
|
---|
| 513 | renderer = node->getRenderer().get();
|
---|
| 514 | if(this->activeRenderPass == &this->defaultRenderPass) {
|
---|
| 515 | if(renderer->isA(Renderer::RENDERER_PARTICLE)) {
|
---|
| 516 | this->needDepthPass |= renderer->needsExtraPass();
|
---|
| 517 | if(((ParticleRenderer*) renderer)->needHeatHazePass()) {
|
---|
| 518 | this->needDistortionPass = true;
|
---|
| 519 | this->heatHazeParticleRendererList.push_back((ParticleRenderer*) renderer);
|
---|
| 520 | }
|
---|
| 521 | } else if(renderer->isA(Renderer::RENDERER_RAYTRACE)) {
|
---|
| 522 | this->needRaytracePass = true;
|
---|
| 523 | this->raytraceRendererList.push_back((RaytraceRenderer*) renderer);
|
---|
| 524 | }
|
---|
| 525 | }
|
---|
| 526 | usedRendererList->push_back(renderer);
|
---|
| 527 | }
|
---|
| 528 | }
|
---|
| 529 | } else {
|
---|
| 530 | for(nodeIt = this->nodeList.begin(); nodeIt!=this->nodeList.end();nodeIt++) {
|
---|
| 531 | node = (*nodeIt).get();
|
---|
| 532 | if(!node->onStandBy() && node->visible && node->hasRenderer()) {
|
---|
| 533 | renderer = node->getRenderer().get();
|
---|
| 534 | if(this->activeRenderPass == &this->defaultRenderPass) {
|
---|
| 535 | if(renderer->isA(Renderer::RENDERER_PARTICLE)) {
|
---|
| 536 | this->needDepthPass |= renderer->needsExtraPass();
|
---|
| 537 | if(((ParticleRenderer*) renderer)->needHeatHazePass()) {
|
---|
| 538 | this->needDistortionPass = true;
|
---|
| 539 | this->heatHazeParticleRendererList.push_back((ParticleRenderer*) renderer);
|
---|
| 540 | }
|
---|
| 541 | } else if(renderer->isA(Renderer::RENDERER_RAYTRACE)) {
|
---|
| 542 | this->needRaytracePass = true;
|
---|
| 543 | this->raytraceRendererList.push_back((RaytraceRenderer*) renderer);
|
---|
| 544 | }
|
---|
| 545 | }
|
---|
| 546 | usedRendererList->push_back(renderer);
|
---|
| 547 | }
|
---|
| 548 | }
|
---|
| 549 | }
|
---|
| 550 | }
|
---|
| 551 |
|
---|
| 552 | void Scene::doViewingTransformation()
|
---|
| 553 | {
|
---|
| 554 | this->device->SetTransform(D3DTS_VIEW, this->activeCamera->getViewMatrix() );
|
---|
| 555 | }
|
---|
| 556 |
|
---|
| 557 |
|
---|
| 558 | void Scene::renderNodes()
|
---|
| 559 | {
|
---|
| 560 | std::vector<Renderer *>* usedRendererList;
|
---|
| 561 | usedRendererList = this->activeRenderPass->usedRendererList;
|
---|
| 562 |
|
---|
| 563 | //Sorts the rendering processes by its priority!
|
---|
| 564 | std::sort(usedRendererList->begin(), usedRendererList->end(), renderSortFunction());
|
---|
| 565 |
|
---|
| 566 | std::vector<Renderer *>::iterator it;
|
---|
| 567 | for(it=usedRendererList->begin();it!=usedRendererList->end();it++) {
|
---|
| 568 | if((*it) == 0) {
|
---|
| 569 | this->manager->printToConsole("Renderer in usedRenderList is NULL!!!!");
|
---|
| 570 | }
|
---|
| 571 | if((*it)->nodeAdded) {
|
---|
| 572 | SPTR<Node> n = (*it)->myNode.lock();
|
---|
| 573 | if(!n->onStandBy() && n->visible) {
|
---|
| 574 | this->worldMatrix = *n->getWorldMatrix();
|
---|
| 575 | (*it)->render();
|
---|
| 576 | }
|
---|
| 577 | }
|
---|
| 578 | }
|
---|
| 579 | if(this->usePhysXDebugger && this->activeRenderPass==&this->defaultRenderPass) {
|
---|
| 580 | D3DXMATRIX worldMat;
|
---|
| 581 | D3DXMatrixIdentity(&worldMat);
|
---|
| 582 | this->device->SetTransform( D3DTS_WORLD, &worldMat);
|
---|
| 583 | this->device->SetTransform( D3DTS_PROJECTION, this->activeCamera->getProjectionMatrix());
|
---|
| 584 | this->device->SetTransform( D3DTS_VIEW, this->activeCamera->getViewMatrix());
|
---|
| 585 | const NxDebugRenderable *dbgRenderable = pScene->getDebugRenderable();
|
---|
| 586 | this->physxRenderer.render(*dbgRenderable);
|
---|
| 587 | this->device->SetTransform( D3DTS_PROJECTION, &worldMat);
|
---|
| 588 | this->device->SetTransform( D3DTS_VIEW, &worldMat);
|
---|
| 589 | }
|
---|
| 590 | /*D3DXMatrixIdentity(&this->worldMatrix);
|
---|
| 591 | if(this->drawBBoxes && this->boundingBox!=NULL) {
|
---|
| 592 | for(it=this->usedRendererList.begin();it!=this->usedRendererList.end();it++) {
|
---|
| 593 | SPTR<Node> n = (*it)->myNode.lock();
|
---|
| 594 | D3DXMATRIX tMat;
|
---|
| 595 | Vector dim = *n->getAbsMaxBBox() - *n->getAbsMinBBox();
|
---|
| 596 | Vector absPos;
|
---|
| 597 | absPos = *n->getAbsMinBBox()+dim/2;
|
---|
| 598 | D3DXMatrixTranslation(&tMat, absPos.x, absPos.y, absPos.z);
|
---|
| 599 | this->device->SetTransform( D3DTS_WORLD, &tMat);
|
---|
| 600 |
|
---|
| 601 | this->boundingBox->setDimension(dim.x, dim.y, dim.z);
|
---|
| 602 | this->boundingBox->getRenderer()->render();
|
---|
| 603 | }
|
---|
| 604 | }*/
|
---|
| 605 | }
|
---|
| 606 |
|
---|
| 607 | void Scene::cleanUpScene()
|
---|
| 608 | {
|
---|
| 609 | std::list<SPTR<Node> >::iterator it;
|
---|
| 610 | std::list<SPTR<Node> >::iterator nit;
|
---|
| 611 | std::vector<SPTR<Renderer> >::iterator rit;
|
---|
| 612 | Node* node;
|
---|
| 613 | for(it=this->zombieNodeList.begin();it!=this->zombieNodeList.end();it++) {
|
---|
| 614 | node = (*it).get();
|
---|
| 615 | node->getFather()->removeChild(*it);
|
---|
| 616 |
|
---|
| 617 | //Delete Renderer
|
---|
| 618 | if(node->hasRenderer())
|
---|
| 619 | {
|
---|
| 620 | Renderer *r = node->getRenderer().get();
|
---|
| 621 | for(rit=this->rendererList.begin();rit!=this->rendererList.end();rit++) {
|
---|
| 622 | if((*rit).get() == r)
|
---|
| 623 | {
|
---|
| 624 | this->rendererList.erase(rit);
|
---|
| 625 | break;
|
---|
| 626 | }
|
---|
| 627 | }
|
---|
| 628 | }
|
---|
| 629 |
|
---|
| 630 | //Delete Physic Actor
|
---|
| 631 | if(node->getActor()!=NULL)
|
---|
| 632 | {
|
---|
| 633 | this->pScene->releaseActor(*node->getActor());
|
---|
| 634 | }
|
---|
| 635 |
|
---|
| 636 | //Delete from NodeList
|
---|
| 637 | this->deleteNodeInList(node, this->nodeList);
|
---|
| 638 | this->deleteNodeInList(node, this->particleList);
|
---|
| 639 | this->deleteNodeInList(node, this->soundNodeList);
|
---|
| 640 | }
|
---|
| 641 | this->zombieNodeList.clear();
|
---|
| 642 | }
|
---|
| 643 |
|
---|
| 644 | void Scene::deleteNodeInList(Node* node, std::list<SPTR<Node> > &list) {
|
---|
| 645 | std::list<SPTR<Node> >::iterator it;
|
---|
| 646 | for(it=list.begin();it!=list.end();it++) {
|
---|
| 647 | if((*it).get() == node)
|
---|
| 648 | {
|
---|
| 649 | list.erase(it);
|
---|
| 650 | break;
|
---|
| 651 | }
|
---|
| 652 | }
|
---|
| 653 | }
|
---|
| 654 |
|
---|
| 655 | void Scene::deleteRendererInList(Renderer* renderer) {
|
---|
| 656 | // remove particle renderer
|
---|
| 657 | std::vector<SPTR<Renderer> >::iterator it;
|
---|
| 658 | for(it=rendererList.begin();it!=rendererList.end();it++) {
|
---|
| 659 | if((*it).get() == renderer) {
|
---|
| 660 | rendererList.erase(it);
|
---|
| 661 | break;
|
---|
| 662 | }
|
---|
| 663 | }
|
---|
| 664 | }
|
---|
| 665 |
|
---|
| 666 | void Scene::startPhysic()
|
---|
| 667 | {
|
---|
| 668 | this->pScene->simulate(this->dt);
|
---|
| 669 | this->pScene->flushStream();
|
---|
| 670 | }
|
---|
| 671 |
|
---|
| 672 | void Scene::clearRenderTargetAndZBuffer()
|
---|
| 673 | {
|
---|
| 674 | DXUTGetD3DDevice()->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(255, 0, 0, 0), 1.0f, 0);
|
---|
| 675 | }
|
---|
| 676 |
|
---|
| 677 | //Clear SharedResources
|
---|
| 678 | void Scene::clearSharedResources()
|
---|
| 679 | {
|
---|
| 680 | for(UINT i=0;i<this->sharedResourceVector.size();i++) {
|
---|
| 681 | this->sharedResourceVector.at(i)->setResourceAvailable(false);
|
---|
| 682 | }
|
---|
| 683 | }
|
---|
| 684 |
|
---|
| 685 | void Scene::setKeyPressed(UINT key, bool bKeyPressed)
|
---|
| 686 | {
|
---|
| 687 | this->keyDown[key] = bKeyPressed;
|
---|
| 688 | }
|
---|
| 689 |
|
---|
| 690 | void Scene::setMouseStatus(bool bLeftButtonDown, bool bRightButtonDown,bool bMiddleButtonDown,
|
---|
| 691 | bool bSideButton1Down, bool bSideButton2Down, int nMouseWheelDelta,
|
---|
| 692 | int xPos, int yPos)
|
---|
| 693 | {
|
---|
| 694 | this->mouseButton[MOUSE_LEFT] = bLeftButtonDown;
|
---|
| 695 | this->mouseButton[MOUSE_RIGHT] = bRightButtonDown;
|
---|
| 696 | this->mouseButton[MOUSE_MIDDLE] = bMiddleButtonDown;
|
---|
| 697 | this->mouseButton[MOUSE_SIDE1] = bSideButton1Down;
|
---|
| 698 | this->mouseButton[MOUSE_SIDE2] = bSideButton2Down;
|
---|
| 699 | this->mousePos[0] = xPos;
|
---|
| 700 | this->mousePos[1] = yPos;
|
---|
| 701 | this->mouseWheel = nMouseWheelDelta;
|
---|
| 702 | }
|
---|
| 703 |
|
---|
| 704 | Node* Scene::createNode(int type)
|
---|
| 705 | {
|
---|
| 706 | return this->createNode(type, this->root, true, false);
|
---|
| 707 | }
|
---|
| 708 |
|
---|
| 709 | Node* Scene::createNode(int type, Node &father)
|
---|
| 710 | {
|
---|
| 711 | return this->createNode(type, father, true, false);
|
---|
| 712 | }
|
---|
| 713 |
|
---|
| 714 | Node* Scene::createNode(int type, bool addDefaultRenderer)
|
---|
| 715 | {
|
---|
| 716 | return this->createNode(type, this->root, addDefaultRenderer, false);
|
---|
| 717 | }
|
---|
| 718 |
|
---|
| 719 | Node* Scene::createNode(int type, Node &father, bool addDefaultRenderer) {
|
---|
| 720 | return this->createNode(type, father, addDefaultRenderer, false);
|
---|
| 721 | }
|
---|
| 722 |
|
---|
| 723 | Node* Scene::createReferenceNode(int type, bool addDefaultRenderer)
|
---|
| 724 | {
|
---|
| 725 | Node* n=0;
|
---|
| 726 | Node* newNode = this->createNode(type, *n, addDefaultRenderer, true);
|
---|
| 727 | newNode->setStandBy(true);
|
---|
| 728 | return newNode;
|
---|
| 729 | }
|
---|
| 730 |
|
---|
| 731 | Node* Scene::createNode(int type, Node &father, bool addDefaultRenderer, bool isReference)
|
---|
| 732 | {
|
---|
| 733 | switch(type)
|
---|
| 734 | {
|
---|
| 735 | case NODE_OBJECT3D:
|
---|
| 736 | {
|
---|
| 737 | SPTR<Node> node(new Object3d);
|
---|
| 738 | node->setScene(*this);
|
---|
| 739 | if(!isReference) {
|
---|
| 740 | father.addChild(node);
|
---|
| 741 | this->nodeList.push_back(node);
|
---|
| 742 | } else {
|
---|
| 743 | this->refObject3dList.push_back(node);
|
---|
| 744 | }
|
---|
| 745 | if(addDefaultRenderer) {
|
---|
| 746 | SPTR<Renderer> renderer(new SimpleMeshRenderer);
|
---|
| 747 | renderer->setScene(*this);
|
---|
| 748 | WPTR<Node> wn(node);
|
---|
| 749 | renderer->setNode(wn);
|
---|
| 750 | node->setRenderer(renderer);
|
---|
| 751 | renderer->init();
|
---|
| 752 | this->rendererList.push_back(renderer);
|
---|
| 753 | }
|
---|
| 754 | return node.get();
|
---|
| 755 | }
|
---|
| 756 | break;
|
---|
| 757 | case NODE_CAMERA:
|
---|
| 758 | {
|
---|
[1400] | 759 | //SPTR<Node> node(new Camera);
|
---|
| 760 | SPTR<Node> node(new Camera(this->viewPortRatio())); // MG
|
---|
[1378] | 761 | if(!isReference) {
|
---|
| 762 | father.addChild(node);
|
---|
| 763 | this->nodeList.push_back(node);
|
---|
| 764 | } else {
|
---|
| 765 | this->refCameraList.push_back(node);
|
---|
| 766 | }
|
---|
| 767 | node->setScene(*this);
|
---|
| 768 |
|
---|
| 769 | return node.get();
|
---|
| 770 | }
|
---|
| 771 | break;
|
---|
| 772 | case NODE_SOUND:
|
---|
| 773 | {
|
---|
| 774 | SPTR<Node> node(new SoundNode);
|
---|
| 775 | if(!isReference) {
|
---|
| 776 | father.addChild(node);
|
---|
| 777 | this->nodeList.push_back(node);
|
---|
| 778 | this->soundNodeList.push_back(node);
|
---|
| 779 | } else {
|
---|
| 780 | this->refSoundList.push_back(node);
|
---|
| 781 | }
|
---|
| 782 | node->setScene(*this);
|
---|
| 783 |
|
---|
| 784 | return node.get();
|
---|
| 785 | }
|
---|
| 786 | case NODE_BOX:
|
---|
| 787 | {
|
---|
| 788 | SPTR<Node> node(new Box);
|
---|
| 789 | node->setScene(*this);
|
---|
| 790 | if(!isReference) {
|
---|
| 791 | father.addChild(node);
|
---|
| 792 | this->nodeList.push_back(node);
|
---|
| 793 | }
|
---|
| 794 | if(addDefaultRenderer) {
|
---|
| 795 | SPTR<Renderer> renderer(new SimpleMeshRenderer);
|
---|
| 796 | renderer->setScene(*this);
|
---|
| 797 | WPTR<Node> wn(node);
|
---|
| 798 | renderer->setNode(wn);
|
---|
| 799 | node->setRenderer(renderer);
|
---|
| 800 | renderer->init();
|
---|
| 801 | this->rendererList.push_back(renderer);
|
---|
| 802 | }
|
---|
| 803 | return node.get();
|
---|
| 804 | }
|
---|
| 805 | break;
|
---|
| 806 | case NODE_SPRITE:
|
---|
| 807 | {
|
---|
| 808 | SPTR<Node> node(new Sprite);
|
---|
| 809 | node->setScene(*this);
|
---|
| 810 | if(!isReference) {
|
---|
| 811 | father.addChild(node);
|
---|
| 812 | this->nodeList.push_back(node);
|
---|
| 813 | } else {
|
---|
| 814 | this->refObject3dList.push_back(node);
|
---|
| 815 | }
|
---|
| 816 | if(addDefaultRenderer) {
|
---|
| 817 | SPTR<Renderer> renderer(new ParticleRenderer);
|
---|
| 818 | renderer->setScene(*this);
|
---|
| 819 | WPTR<Node> wn(node);
|
---|
| 820 | renderer->setNode(wn);
|
---|
| 821 | ((ParticleRenderer*) renderer.get())->setRenderSingleParticle(true);
|
---|
| 822 | node->setRenderer(renderer);
|
---|
| 823 | renderer->init();
|
---|
| 824 | this->rendererList.push_back(renderer);
|
---|
| 825 | }
|
---|
| 826 | return node.get();
|
---|
| 827 | }
|
---|
| 828 | break;
|
---|
| 829 | case NODE_PARTICLEGROUP:
|
---|
| 830 | {
|
---|
| 831 | SPTR<Node> node(new ParticleGroup);
|
---|
| 832 | node->setScene(*this);
|
---|
| 833 | if(!isReference) {
|
---|
| 834 | if(&father != this->getRoot()) {
|
---|
| 835 | this->manager->printToConsole("ERROR: Call of createNode for ParticleGroup only allows rootNode as father!!");
|
---|
| 836 | }
|
---|
| 837 | father.addChild(node);
|
---|
| 838 | this->nodeList.push_back(node);
|
---|
| 839 | }
|
---|
| 840 | if(addDefaultRenderer) {
|
---|
| 841 | //TODO add ParticleRenderer
|
---|
| 842 | SPTR<Renderer> renderer(new ParticleRenderer);
|
---|
| 843 | renderer->setScene(*this);
|
---|
| 844 | WPTR<Node> wn(node);
|
---|
| 845 | renderer->setNode(wn);
|
---|
| 846 | node->setRenderer(renderer);
|
---|
| 847 | renderer->init();
|
---|
| 848 | this->rendererList.push_back(renderer);
|
---|
| 849 | }
|
---|
| 850 | ((ParticleGroup*) node.get())->setParticleGroup(this->particleGroupCounter);
|
---|
| 851 | this->particleGroupVector.push_back(node);
|
---|
| 852 | this->particleGroupCounter++;
|
---|
| 853 | return node.get();
|
---|
| 854 | }
|
---|
| 855 | break;
|
---|
| 856 | case NODE_PARTICLEEMITTER:
|
---|
| 857 | {
|
---|
| 858 | SPTR<Node> node(new ParticleEmitter);
|
---|
| 859 | node->setScene(*this);
|
---|
| 860 | if(!isReference) {
|
---|
| 861 | father.addChild(node);
|
---|
| 862 | this->nodeList.push_back(node);
|
---|
| 863 | }
|
---|
| 864 | return node.get();
|
---|
| 865 | }
|
---|
| 866 | break;
|
---|
| 867 | }
|
---|
| 868 | return 0;
|
---|
| 869 | }
|
---|
| 870 |
|
---|
| 871 | void Scene::connectNodeAndRenderer(Node &node, SPTR<Renderer> &renderer)
|
---|
| 872 | {
|
---|
| 873 | std::list<SPTR<Node> >::iterator it;
|
---|
| 874 | SPTR<Node> sN;
|
---|
| 875 | for(it = this->nodeList.begin(); it!=this->nodeList.end();it++) {
|
---|
| 876 | if((*it).get() == &node) {
|
---|
| 877 | WPTR<Node> wn(*it);
|
---|
| 878 | renderer->setScene(*this);
|
---|
| 879 | renderer->setNode(wn);
|
---|
| 880 | (*it)->setRenderer(renderer);
|
---|
| 881 | renderer->init();
|
---|
| 882 | this->rendererList.push_back(renderer);
|
---|
| 883 | break;
|
---|
| 884 | }
|
---|
| 885 | }
|
---|
| 886 | }
|
---|
| 887 |
|
---|
| 888 | void Scene::OnLostDevice( void* pUserContext )
|
---|
| 889 | {
|
---|
| 890 | SAFE_RELEASE(this->finalImage);
|
---|
| 891 | SAFE_RELEASE(this->finalImageSurface);
|
---|
| 892 | SAFE_RELEASE(this->quadMesh);
|
---|
| 893 | SAFE_RELEASE(this->depthSurface);
|
---|
| 894 | SAFE_RELEASE(this->preDistortionFinal);
|
---|
| 895 | SAFE_RELEASE(this->preDistortionFinalSurface);
|
---|
| 896 | SAFE_RELEASE(this->screenDistortionMapSurface);
|
---|
| 897 | this->finalImage = NULL;
|
---|
| 898 | this->finalImageSurface = NULL;
|
---|
| 899 | this->meshCreated = false;
|
---|
| 900 | this->quadMesh = NULL;
|
---|
| 901 | this->preDistortionFinal = NULL;
|
---|
| 902 | this->preDistortionFinalSurface = NULL;
|
---|
| 903 | this->screenDistortionMapSurface = NULL;
|
---|
| 904 |
|
---|
| 905 | std::list<SPTR<Node> >::iterator nit;
|
---|
| 906 | for(nit=this->nodeList.begin();nit!=this->nodeList.end();nit++) {
|
---|
| 907 | (*nit)->OnLostDevice(pUserContext);
|
---|
| 908 | }
|
---|
| 909 |
|
---|
| 910 | for(UINT i=0;i<this->sharedResourceVector.size();i++) {
|
---|
| 911 | this->sharedResourceVector.at(i)->OnLostDevice();
|
---|
| 912 | }
|
---|
| 913 |
|
---|
| 914 | std::vector<SPTR<Renderer> >::iterator it;
|
---|
| 915 | for(it=this->rendererList.begin();it!=this->rendererList.end();it++) {
|
---|
| 916 | (*it)->OnLostDevice(pUserContext);
|
---|
| 917 | }
|
---|
| 918 | }
|
---|
| 919 |
|
---|
| 920 | void Scene::OnDestroyDevice( void* pUserContext )
|
---|
| 921 | {
|
---|
| 922 | std::list<SPTR<Node> >::iterator nit;
|
---|
| 923 | for(nit=this->nodeList.begin();nit!=this->nodeList.end();nit++) {
|
---|
| 924 | (*nit)->OnDestroyDevice(pUserContext);
|
---|
| 925 | }
|
---|
| 926 |
|
---|
| 927 | std::vector<SPTR<Renderer> >::iterator it;
|
---|
| 928 | for(it=this->rendererList.begin();it!=this->rendererList.end();it++) {
|
---|
| 929 | (*it)->OnDestroyDevice(pUserContext);
|
---|
| 930 | }
|
---|
| 931 |
|
---|
| 932 | this->depthTextureResource = NULL;
|
---|
| 933 | this->sharedResourceVector.clear();
|
---|
| 934 | this->distortionMap1 = NULL;
|
---|
| 935 | this->distortionMap2 = NULL;
|
---|
| 936 | this->screenDistortionMap = NULL;
|
---|
| 937 | this->preDistortionFinal = NULL;
|
---|
| 938 | }
|
---|
| 939 |
|
---|
| 940 | HRESULT Scene::OnResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
|
---|
| 941 | {
|
---|
| 942 | HRESULT hr;
|
---|
| 943 |
|
---|
| 944 | //Restore that stuff
|
---|
| 945 | this->device = pd3dDevice;
|
---|
| 946 |
|
---|
| 947 | SAFE_RELEASE(this->quadMesh);
|
---|
| 948 | SAFE_RELEASE(this->depthSurface);
|
---|
| 949 | SAFE_RELEASE(this->preDistortionFinal);
|
---|
| 950 | SAFE_RELEASE(this->preDistortionFinalSurface);
|
---|
| 951 | SAFE_RELEASE(this->screenDistortionMapSurface);
|
---|
| 952 |
|
---|
| 953 |
|
---|
| 954 | //Textur für endgültiges Bild erzeugen
|
---|
| 955 | if(!this->finalImage) {
|
---|
| 956 | //Create Texture
|
---|
| 957 | V( DXUTGetD3DDevice()->CreateTexture(this->manager->screenWidth, this->manager->screenHeight, 1, D3DUSAGE_RENDERTARGET,
|
---|
| 958 | D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &this->finalImage, NULL ) );
|
---|
| 959 |
|
---|
| 960 | //Get Surface for RenderTarget
|
---|
| 961 | this->finalImage->GetSurfaceLevel(0, &this->finalImageSurface);
|
---|
| 962 | }
|
---|
| 963 |
|
---|
| 964 | //Depth RenderPass
|
---|
| 965 | this->depthTextureResource = (SharedResourceTexture*) this->getSharedResource(Scene::SR_TEXTURE_VIEWDEPTH);
|
---|
| 966 | if(!this->depthTextureResource) {
|
---|
| 967 | this->depthTextureResource = (SharedResourceTexture*) this->createSharedResource(Scene::SR_TEXTURE_VIEWDEPTH);
|
---|
| 968 | }
|
---|
| 969 | this->depthTextureResource->getTexture()->GetSurfaceLevel(0, &this->depthSurface);
|
---|
| 970 |
|
---|
| 971 | //Load DistortionMaps
|
---|
| 972 | if(!this->distortionMap1)
|
---|
| 973 | this->distortionMap1 = this->manager->resManager.loadTexture("./media/textures/heatnoise.tga");
|
---|
| 974 | if(!this->distortionMap2)
|
---|
| 975 | this->distortionMap2 = this->manager->resManager.loadTexture("./media/textures/heatnoise2.tga");
|
---|
| 976 | if(!this->screenDistortionMap) {
|
---|
| 977 | SharedResourceTexture* distMap = (SharedResourceTexture*) this->createSharedResource(Scene::SR_TEXTURE_DISTORTION);
|
---|
| 978 | this->screenDistortionMap = distMap->getTexture();
|
---|
| 979 | this->screenDistortionMap->GetSurfaceLevel(0, &this->screenDistortionMapSurface);
|
---|
| 980 | }
|
---|
| 981 |
|
---|
| 982 | if(!this->preDistortionFinal) {
|
---|
| 983 | //Create Texture
|
---|
| 984 | V( DXUTGetD3DDevice()->CreateTexture(this->manager->screenWidth, this->manager->screenHeight, 1, D3DUSAGE_RENDERTARGET,
|
---|
| 985 | D3DFMT_A16B16G16R16F, D3DPOOL_DEFAULT, &this->preDistortionFinal, NULL ) );
|
---|
| 986 |
|
---|
| 987 | //Get Surface for RenderTarget
|
---|
| 988 | this->preDistortionFinal->GetSurfaceLevel(0, &this->preDistortionFinalSurface);
|
---|
| 989 | }
|
---|
| 990 |
|
---|
| 991 | this->defaultRenderPass.setRenderTarget(this->finalImageSurface);
|
---|
| 992 | this->depthRenderPass.setRenderTarget(this->depthSurface);
|
---|
| 993 |
|
---|
| 994 | std::list<SPTR<Node> >::iterator nit;
|
---|
| 995 | for(nit=this->nodeList.begin();nit!=this->nodeList.end();nit++) {
|
---|
| 996 | (*nit)->OnResetDevice(pd3dDevice, pBackBufferSurfaceDesc, pUserContext);
|
---|
| 997 | }
|
---|
| 998 |
|
---|
| 999 | std::vector<SPTR<Renderer> >::iterator it;
|
---|
| 1000 | for(it=this->rendererList.begin();it!=this->rendererList.end();it++) {
|
---|
| 1001 | (*it)->OnResetDevice(pd3dDevice, pBackBufferSurfaceDesc, pUserContext);
|
---|
| 1002 | }
|
---|
| 1003 | return S_OK;
|
---|
| 1004 | }
|
---|
| 1005 |
|
---|
| 1006 | Vector Scene::getSunDirection()
|
---|
| 1007 | {
|
---|
| 1008 | return this->sunDirection;
|
---|
| 1009 | }
|
---|
| 1010 |
|
---|
| 1011 | void Scene::setSunDirection(Vector &v)
|
---|
| 1012 | {
|
---|
| 1013 | this->sunDirection.x = v.x;
|
---|
| 1014 | this->sunDirection.y = v.y;
|
---|
| 1015 | this->sunDirection.z = v.z;
|
---|
| 1016 | this->sunDirection.normalize();
|
---|
| 1017 | }
|
---|
| 1018 |
|
---|
| 1019 | D3DXMATRIX Scene::getIdentityMatrix()
|
---|
| 1020 | {
|
---|
| 1021 | return this->identMatrix;
|
---|
| 1022 | }
|
---|
| 1023 |
|
---|
| 1024 | D3DXMATRIX Scene::getWorldMatrix()
|
---|
| 1025 | {
|
---|
| 1026 | return this->worldMatrix;
|
---|
| 1027 | }
|
---|
| 1028 |
|
---|
| 1029 | D3DXMATRIX Scene::getViewMatrix()
|
---|
| 1030 | {
|
---|
| 1031 | return *this->activeRenderPass->getViewMatrix();
|
---|
| 1032 | }
|
---|
| 1033 |
|
---|
| 1034 | D3DXMATRIX Scene::getProjectionMatrix()
|
---|
| 1035 | {
|
---|
| 1036 | return *this->activeRenderPass->getProjectionMatrix();
|
---|
| 1037 | }
|
---|
| 1038 |
|
---|
| 1039 | void Scene::setTrigger(int type, float time)
|
---|
| 1040 | {
|
---|
| 1041 | SPTR<Trigger> t(new Trigger(type, time));
|
---|
| 1042 | this->triggerList.push_back(t);
|
---|
| 1043 | std::sort(this->triggerList.begin(), this->triggerList.end(), triggerSortFunction());
|
---|
| 1044 | }
|
---|
| 1045 |
|
---|
| 1046 | void Scene::setTrigger(int type, Node *node, float time)
|
---|
| 1047 | {
|
---|
| 1048 | SPTR<Node> sN = this->getSmartPointer(node);
|
---|
| 1049 |
|
---|
| 1050 | SPTR<Trigger> t(new Trigger(type, sN, time));
|
---|
| 1051 | this->triggerList.push_back(t);
|
---|
| 1052 | std::sort(this->triggerList.begin(), this->triggerList.end(), triggerSortFunction());
|
---|
| 1053 | }
|
---|
| 1054 |
|
---|
| 1055 | void Scene::setTrigger(int type, Node *node, Node* secondNode, float time)
|
---|
| 1056 | {
|
---|
| 1057 | SPTR<Node> sN = this->getSmartPointer(node);
|
---|
| 1058 | SPTR<Node> secondSN = this->getSmartPointer(secondNode);
|
---|
| 1059 |
|
---|
| 1060 | SPTR<Trigger> t(new Trigger(type, sN, secondSN, time));
|
---|
| 1061 | this->triggerList.push_back(t);
|
---|
| 1062 | std::sort(this->triggerList.begin(), this->triggerList.end(), triggerSortFunction());
|
---|
| 1063 | }
|
---|
| 1064 |
|
---|
| 1065 | void Scene::setTrigger(int type, Node *node, Node* secondNode, Vector normal, float time)
|
---|
| 1066 | {
|
---|
| 1067 | SPTR<Node> sN = this->getSmartPointer(node);
|
---|
| 1068 | SPTR<Node> secondSN = this->getSmartPointer(secondNode);
|
---|
| 1069 |
|
---|
| 1070 | SPTR<Trigger> t(new Trigger(type, sN, secondSN, normal, time));
|
---|
| 1071 | this->triggerList.push_back(t);
|
---|
| 1072 | std::sort(this->triggerList.begin(), this->triggerList.end(), triggerSortFunction());
|
---|
| 1073 | }
|
---|
| 1074 |
|
---|
| 1075 | SPTR<Node> Scene::getSmartPointer(Node *node)
|
---|
| 1076 | {
|
---|
| 1077 | std::list<SPTR<Node> >::iterator it;
|
---|
| 1078 | for(it = this->nodeList.begin(); it!=this->nodeList.end();it++) {
|
---|
| 1079 | if((*it).get() == node) {
|
---|
| 1080 | break;
|
---|
| 1081 | }
|
---|
| 1082 | }
|
---|
| 1083 | if(it==this->nodeList.end()) {
|
---|
| 1084 | this->manager->printToConsole("NODE NOT FOUND IN LIST!!!");
|
---|
| 1085 | }
|
---|
| 1086 | return (*it);
|
---|
| 1087 | }
|
---|
| 1088 |
|
---|
| 1089 | void Scene::executeTrigger(SPTR<Trigger> trigger)
|
---|
| 1090 | {
|
---|
| 1091 | Trigger *t = trigger.get();
|
---|
| 1092 | switch(t->getType())
|
---|
| 1093 | {
|
---|
| 1094 | case this->TRIGGER_UNSETSTANDBY:
|
---|
| 1095 | if(!t->getNode()->isA(Scene::NODE_SOUND)) {
|
---|
| 1096 | t->getNode()->setStandBy(false);
|
---|
| 1097 | } else {
|
---|
| 1098 | t->getNode()->setStandBy(false);
|
---|
| 1099 | ((SoundNode*) t->getNode().get())->play();
|
---|
| 1100 | }
|
---|
| 1101 | break;
|
---|
| 1102 | case this->TRIGGER_KILLNODE:
|
---|
| 1103 | t->getNode()->killMe();
|
---|
| 1104 | break;
|
---|
| 1105 | case this->TRIGGER_SETDETAIL:
|
---|
| 1106 | break;
|
---|
| 1107 | }
|
---|
| 1108 | }
|
---|
| 1109 |
|
---|
| 1110 | void Scene::deleteNode(Node* node)
|
---|
| 1111 | {
|
---|
| 1112 | std::list<SPTR<Node> >::iterator it;
|
---|
| 1113 | for(it=this->zombieNodeList.begin();it!=this->zombieNodeList.end();it++) {
|
---|
| 1114 | if((*it).get() == node) {
|
---|
| 1115 | return;
|
---|
| 1116 | }
|
---|
| 1117 | }
|
---|
| 1118 | SPTR<Node> sn = this->getSmartPointer(node);
|
---|
| 1119 | this->zombieNodeList.push_back(sn);
|
---|
| 1120 | }
|
---|
| 1121 |
|
---|
| 1122 | void Scene::setContactReport(NxUserContactReport *_contactReport)
|
---|
| 1123 | {
|
---|
| 1124 | this->contactReport = _contactReport;
|
---|
| 1125 | ((UserContactReport*) this->contactReport)->setScene(this);
|
---|
| 1126 | }
|
---|
| 1127 |
|
---|
| 1128 | void Scene::setTriggerReport(NxUserTriggerReport *_triggerReport)
|
---|
| 1129 | {
|
---|
| 1130 | this->triggerReport = _triggerReport;
|
---|
| 1131 | ((UserTriggerReport*) this->triggerReport)->setScene(this);
|
---|
| 1132 | }
|
---|
| 1133 |
|
---|
| 1134 | void Scene::setNotifyReport(NxUserNotify* _notifyReport)
|
---|
| 1135 | {
|
---|
| 1136 | this->notifyReport = _notifyReport;
|
---|
| 1137 | ((UserNotify*) this->notifyReport)->setScene(this);
|
---|
| 1138 | }
|
---|
| 1139 |
|
---|
| 1140 | void Scene::setLight(Vector direction) {
|
---|
| 1141 | //set ambient light:
|
---|
| 1142 | DXUTGetD3DDevice()->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_XRGB(120,120,120) );
|
---|
| 1143 |
|
---|
| 1144 | // Fill in a light structure defining our light
|
---|
| 1145 | D3DLIGHT9 light;
|
---|
| 1146 | ZeroMemory( &light, sizeof(D3DLIGHT9) );
|
---|
| 1147 | light.Type = D3DLIGHT_DIRECTIONAL;
|
---|
| 1148 | light.Diffuse.r = 1.0f;
|
---|
| 1149 | light.Diffuse.g = 1.0f;
|
---|
| 1150 | light.Diffuse.b = 1.0f;
|
---|
| 1151 | light.Diffuse.a = 1.0f;
|
---|
| 1152 | light.Range = 1000.0f;
|
---|
| 1153 |
|
---|
| 1154 | // Create a direction for our light - it must be normalized
|
---|
| 1155 | D3DXVECTOR3 vecDir;
|
---|
| 1156 | vecDir = D3DXVECTOR3(direction.x,direction.y,direction.z);
|
---|
| 1157 | D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir );
|
---|
| 1158 |
|
---|
| 1159 | // Tell the device about the light and turn it on
|
---|
| 1160 | DXUTGetD3DDevice()->SetLight( 0, &light );
|
---|
| 1161 | DXUTGetD3DDevice()->LightEnable( 0, TRUE );
|
---|
| 1162 | }
|
---|
| 1163 |
|
---|
| 1164 | std::list<SPTR<Node> >* Scene::getParticleList()
|
---|
| 1165 | {
|
---|
| 1166 | return &this->particleList;
|
---|
| 1167 | }
|
---|
| 1168 |
|
---|
| 1169 | void Scene::addToParticleList(Node *node)
|
---|
| 1170 | {
|
---|
| 1171 | SPTR<Node> sn = this->getSmartPointer(node);
|
---|
| 1172 | this->particleList.push_back(sn);
|
---|
| 1173 | }
|
---|
| 1174 |
|
---|
| 1175 | ParticleGroup* Scene::getParticleGroup(int id)
|
---|
| 1176 | {
|
---|
| 1177 | ParticleGroup* pg;
|
---|
| 1178 | for(UINT i=0;i<this->particleGroupVector.size();i++) {
|
---|
| 1179 | pg = (ParticleGroup*) this->particleGroupVector.at(i).get();
|
---|
| 1180 | if(pg->getParticleGroup()==id) {
|
---|
| 1181 | return pg;
|
---|
| 1182 | }
|
---|
| 1183 | }
|
---|
| 1184 | return NULL;
|
---|
| 1185 | }
|
---|
| 1186 |
|
---|
| 1187 | SharedResource* Scene::createSharedResource(int id)
|
---|
| 1188 | {
|
---|
| 1189 | switch(id) {
|
---|
| 1190 | case this->SR_TEXTURE_VIEWDEPTH:
|
---|
| 1191 | {
|
---|
| 1192 | SPTR<SharedResource> srt(new SharedResourceTexture);
|
---|
| 1193 | SharedResourceTexture* t = (SharedResourceTexture*) srt.get();
|
---|
| 1194 | t->setResourceIdentifier(id);
|
---|
| 1195 | t->createTexture(this->manager->screenWidth, this->manager->screenHeight, D3DFMT_A16B16G16R16F, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT);
|
---|
| 1196 | this->sharedResourceVector.push_back(srt);
|
---|
| 1197 | return t;
|
---|
| 1198 | }
|
---|
| 1199 | break;
|
---|
| 1200 | case this->SR_TEXTURE_DISTORTION:
|
---|
| 1201 | {
|
---|
| 1202 | SPTR<SharedResource> srt(new SharedResourceTexture);
|
---|
| 1203 | SharedResourceTexture* t = (SharedResourceTexture*) srt.get();
|
---|
| 1204 | t->setResourceIdentifier(id);
|
---|
| 1205 | t->createTexture(this->manager->screenWidth, this->manager->screenHeight, D3DFMT_A16B16G16R16F, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT);
|
---|
| 1206 | this->sharedResourceVector.push_back(srt);
|
---|
| 1207 | return t;
|
---|
| 1208 | }
|
---|
| 1209 | break;
|
---|
| 1210 | }
|
---|
| 1211 | return NULL;
|
---|
| 1212 | }
|
---|
| 1213 |
|
---|
| 1214 | SharedResource* Scene::getSharedResource(int id)
|
---|
| 1215 | {
|
---|
| 1216 | for(UINT i=0;i<this->sharedResourceVector.size();i++) {
|
---|
| 1217 | if(this->sharedResourceVector.at(i)->getResourceIdentifier()==id) {
|
---|
| 1218 | SharedResource* sr = this->sharedResourceVector.at(i).get();
|
---|
| 1219 | return sr;
|
---|
| 1220 | }
|
---|
| 1221 | }
|
---|
| 1222 | return NULL;
|
---|
| 1223 | }
|
---|
| 1224 |
|
---|
| 1225 | int* Scene::getMousePos() {
|
---|
| 1226 | return this->mousePos;
|
---|
| 1227 | }
|
---|
| 1228 |
|
---|
| 1229 | void Scene::OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext )
|
---|
| 1230 | {
|
---|
| 1231 | }
|
---|
| 1232 |
|
---|
| 1233 | void Scene::createQuadMesh()
|
---|
| 1234 | {
|
---|
| 1235 | HRESULT hr;
|
---|
| 1236 | //Create a quad for rendering to screen
|
---|
| 1237 | if(SUCCEEDED( D3DXCreateMeshFVF(2, 4, D3DXMESH_MANAGED, this->FVF_Flags, this->device, &this->quadMesh)) ) {
|
---|
| 1238 | //lock vertex buffer
|
---|
| 1239 | Vector ecken[4];
|
---|
| 1240 | Vertex* pVertices;
|
---|
| 1241 | V( this->quadMesh->LockVertexBuffer( 0, (void**)&pVertices ) );
|
---|
| 1242 |
|
---|
| 1243 | ecken[0] = Vector(-1.0f, 1.0f, 0.0f);
|
---|
| 1244 | ecken[1] = Vector(-1.0f, -1.0f, 0.0f);
|
---|
| 1245 | ecken[2] = Vector(1.0f, -1.0f, 0.0f);
|
---|
| 1246 | ecken[3] = Vector(1.0f, 1.0f, 0.0f);
|
---|
| 1247 |
|
---|
| 1248 | pVertices[0] = Vertex(ecken[0], 0.0f, 0.0f);
|
---|
| 1249 | pVertices[1] = Vertex(ecken[1], 0.0f, 1.0f);
|
---|
| 1250 | pVertices[2] = Vertex(ecken[2], 1.0f, 1.0f);
|
---|
| 1251 | pVertices[3] = Vertex(ecken[3], 1.0f, 0.0f);
|
---|
| 1252 |
|
---|
| 1253 | //unlock vertex buffer
|
---|
| 1254 | V( this->quadMesh->UnlockVertexBuffer() );
|
---|
| 1255 |
|
---|
| 1256 | // fill the indices:
|
---|
| 1257 | WORD* pIndices = NULL;
|
---|
| 1258 | this->quadMesh->LockIndexBuffer( 0, (void**)&pIndices );
|
---|
| 1259 |
|
---|
| 1260 | pIndices[0] = (WORD) 0; pIndices[1] = (WORD) 2; pIndices[2] = (WORD) 1;
|
---|
| 1261 | pIndices[3] = (WORD) 0; pIndices[4] = (WORD) 3; pIndices[5] = (WORD) 2;
|
---|
| 1262 |
|
---|
| 1263 | this->quadMesh->UnlockIndexBuffer();
|
---|
| 1264 | this->meshCreated=true;
|
---|
| 1265 | } else {
|
---|
| 1266 | this->manager->printToConsole("ERROR creating mesh!");
|
---|
| 1267 | }
|
---|
| 1268 |
|
---|
| 1269 | }
|
---|
| 1270 |
|
---|
| 1271 | void Scene::renderFinalImage(ID3DXEffect* fadeEffect)
|
---|
| 1272 | {
|
---|
| 1273 | HRESULT hr = 0;
|
---|
| 1274 |
|
---|
| 1275 |
|
---|
| 1276 | if(!this->meshCreated) {
|
---|
| 1277 | this->createQuadMesh();
|
---|
| 1278 | }
|
---|
| 1279 |
|
---|
| 1280 | UINT cPass;
|
---|
| 1281 | V( fadeEffect->SetFloat("alpha", this->sceneAlpha) );
|
---|
| 1282 | V( fadeEffect->SetTexture("sceneRendering", this->finalImage) );
|
---|
| 1283 | V( fadeEffect->CommitChanges() );
|
---|
| 1284 | V( fadeEffect->SetTechnique("fade") );
|
---|
| 1285 | V( fadeEffect->Begin( &cPass, 0 ) );
|
---|
| 1286 | V( fadeEffect->BeginPass( 0 ) );
|
---|
| 1287 | V( this->device->BeginScene() );
|
---|
| 1288 | V( this->device->SetTexture(0, this->finalImage) );
|
---|
| 1289 | V( this->quadMesh->DrawSubset(0) );
|
---|
| 1290 | V( this->device->SetTexture(0, 0) );
|
---|
| 1291 | V( this->device->EndScene() );
|
---|
| 1292 | V( fadeEffect->EndPass() );
|
---|
| 1293 | V( fadeEffect->End() );
|
---|
| 1294 | }
|
---|
| 1295 |
|
---|
| 1296 | int Scene::getActivePassId() {
|
---|
| 1297 | if(this->activeRenderPass==NULL) {
|
---|
| 1298 | return this->PASS_NORMAL;
|
---|
| 1299 | } else {
|
---|
| 1300 | return this->activeRenderPass->getRenderPassId();
|
---|
| 1301 | }
|
---|
| 1302 | }
|
---|
| 1303 |
|
---|
| 1304 | void Scene::setActiveRenderPass(RenderPass &_activePass)
|
---|
| 1305 | {
|
---|
| 1306 | this->activeRenderPass = &_activePass;
|
---|
| 1307 | this->activeRenderPass->calculateMatrices();
|
---|
| 1308 | }
|
---|
| 1309 |
|
---|
| 1310 | void Scene::startRenderPasses()
|
---|
| 1311 | {
|
---|
| 1312 | //char temp[100];
|
---|
| 1313 | HRESULT hr;
|
---|
| 1314 | bool tempDistortionPass = false;
|
---|
| 1315 |
|
---|
| 1316 | //Reset values
|
---|
| 1317 | this->needDepthPass = false;
|
---|
| 1318 | this->needRaytracePass = false;
|
---|
| 1319 | this->needDistortionPass = false;
|
---|
| 1320 | this->heatHazeParticleRendererList.clear();
|
---|
| 1321 |
|
---|
| 1322 | //DefaultRenderPass aktivieren
|
---|
| 1323 | this->defaultRenderPass.setViewMatrix(*this->activeCamera->getViewMatrix());
|
---|
| 1324 | this->defaultRenderPass.setProjectionMatrix(*this->activeCamera->getProjectionMatrix());
|
---|
| 1325 | this->setActiveRenderPass(this->defaultRenderPass);
|
---|
| 1326 | //Gegen Frustum Cullen
|
---|
| 1327 | this->doFrustumCulling();
|
---|
| 1328 |
|
---|
| 1329 | //Ueberprufen ob heatHaze benötigt wird, defaultRenderPass...renderTarget umstellen!
|
---|
| 1330 | if(this->needDistortionPass) {
|
---|
| 1331 | tempDistortionPass = true;
|
---|
| 1332 | this->defaultRenderPass.setRenderTarget(this->preDistortionFinalSurface);
|
---|
| 1333 | }
|
---|
| 1334 |
|
---|
| 1335 | //Ueberpruefen welche Passes gerendert werden
|
---|
| 1336 | if(this->needDepthPass && this->useDepthImposter) {
|
---|
| 1337 | //this->depthRenderPass.setRenderTarget(this->finalImageSurface);
|
---|
| 1338 | //this->manager->printToConsole("DepthPass Needed");
|
---|
| 1339 | this->depthRenderPass.setViewMatrix(*this->activeCamera->getViewMatrix());
|
---|
| 1340 | this->depthRenderPass.setProjectionMatrix(*this->activeCamera->getProjectionMatrix());
|
---|
| 1341 | this->setActiveRenderPass(this->depthRenderPass);
|
---|
| 1342 | this->activeRenderPass->executePass();
|
---|
| 1343 | this->depthTextureResource->setResourceAvailable(true);
|
---|
| 1344 | }
|
---|
| 1345 |
|
---|
| 1346 | if(this->needRaytracePass) {
|
---|
| 1347 | //Nächster Raytracerenderer finden
|
---|
| 1348 | Vector objPos;
|
---|
| 1349 | Vector camPos;
|
---|
| 1350 | Vector dist;
|
---|
| 1351 | float minDistance=9999999;
|
---|
| 1352 | float distance=0;
|
---|
| 1353 | RaytraceRenderer* nearestRenderer = NULL;
|
---|
| 1354 | camPos = this->activeCamera->getAbsolutePosition();
|
---|
| 1355 |
|
---|
| 1356 | for(UINT i=0;i<this->raytraceRendererList.size();i++) {
|
---|
| 1357 | objPos = this->raytraceRendererList.at(i)->myNode.lock().get()->getAbsolutePosition();
|
---|
| 1358 | distance = (camPos-objPos).length();
|
---|
| 1359 | if(minDistance>distance) {
|
---|
| 1360 | minDistance = distance;
|
---|
| 1361 | nearestRenderer = this->raytraceRendererList.at(i);
|
---|
| 1362 | }
|
---|
| 1363 | }
|
---|
| 1364 |
|
---|
| 1365 | //RaytracePass aktivieren
|
---|
| 1366 | bool oldFrustum = this->enableFrustumCulling;
|
---|
| 1367 | this->raytraceRenderPass.setProjectionMatrix(*nearestRenderer->getCubeMapProjectionMatrix());
|
---|
| 1368 | for(int i=0;i<6;i++) {
|
---|
| 1369 | this->raytraceRenderPass.setViewMatrix(nearestRenderer->getCubeMapView(i));
|
---|
| 1370 | this->raytraceRenderPass.setRenderTarget(nearestRenderer->getCubeMapSurface(i));
|
---|
| 1371 | this->setActiveRenderPass(this->raytraceRenderPass);
|
---|
| 1372 | if(i==2)
|
---|
| 1373 | this->enableFrustumCulling = false ;
|
---|
| 1374 | this->activeRenderPass->executePass();
|
---|
| 1375 | if(i==2)
|
---|
| 1376 | this->enableFrustumCulling = oldFrustum;
|
---|
| 1377 | SAFE_RELEASE(this->raytraceRenderPass.renderTarget);
|
---|
| 1378 |
|
---|
| 1379 | //BlurThatStuff
|
---|
| 1380 | //nearestRenderer->blurDepthPass(i);
|
---|
| 1381 | }
|
---|
| 1382 | RaytraceRenderer* tempRenderer;
|
---|
| 1383 | for(UINT i=0;i<this->raytraceRendererList.size();i++) {
|
---|
| 1384 | tempRenderer = this->raytraceRendererList.at(i);
|
---|
| 1385 | if(tempRenderer!=nearestRenderer && tempRenderer->needsUpdate()) {
|
---|
| 1386 | //this->manager->printToConsole("UPDATING OTHER RAYTRACER!");
|
---|
| 1387 | this->raytraceRenderPass.setProjectionMatrix(*tempRenderer->getCubeMapProjectionMatrix());
|
---|
| 1388 | for(int i=0;i<6;i++) {
|
---|
| 1389 | this->raytraceRenderPass.setViewMatrix(tempRenderer->getCubeMapView(i));
|
---|
| 1390 | this->raytraceRenderPass.setRenderTarget(tempRenderer->getCubeMapSurface(i));
|
---|
| 1391 | this->setActiveRenderPass(this->raytraceRenderPass);
|
---|
| 1392 | if(i==2)
|
---|
| 1393 | this->enableFrustumCulling = false ;
|
---|
| 1394 | this->activeRenderPass->executePass();
|
---|
| 1395 | if(i==2)
|
---|
| 1396 | this->enableFrustumCulling = oldFrustum;
|
---|
| 1397 | SAFE_RELEASE(this->raytraceRenderPass.renderTarget);
|
---|
| 1398 | }
|
---|
| 1399 | }
|
---|
| 1400 | }
|
---|
| 1401 |
|
---|
| 1402 | //Cullen, Nodes rendern...gegen die 6 flächen....
|
---|
| 1403 | //Clear Raytracerlist
|
---|
| 1404 | this->raytraceRendererList.clear();
|
---|
| 1405 | }
|
---|
| 1406 |
|
---|
| 1407 | FSOUND_Update(); //Update sount because of jittering
|
---|
| 1408 |
|
---|
| 1409 | //DefaultRenderPass aktivieren
|
---|
| 1410 | this->setActiveRenderPass(this->defaultRenderPass);
|
---|
| 1411 | this->activeRenderPass->executePass();
|
---|
| 1412 |
|
---|
| 1413 | //if(this->needDistortionPass) {
|
---|
| 1414 | if(tempDistortionPass) {
|
---|
| 1415 | //Distortion
|
---|
| 1416 | if(!this->meshCreated) {
|
---|
| 1417 | this->createQuadMesh();
|
---|
| 1418 | }
|
---|
| 1419 |
|
---|
| 1420 | ID3DXEffect* particleEffect;
|
---|
| 1421 | particleEffect = this->manager->getEffect(GameManager::EFFECT_DEPTHIMP);
|
---|
| 1422 |
|
---|
| 1423 | //Distortion Map rendern
|
---|
| 1424 | this->device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
|
---|
| 1425 | this->device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
|
---|
| 1426 | this->device->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW);
|
---|
| 1427 | this->device->SetRenderState( D3DRS_LIGHTING, FALSE );
|
---|
| 1428 | this->device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
|
---|
| 1429 | this->device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
|
---|
| 1430 | this->device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
|
---|
| 1431 | this->device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
---|
| 1432 | this->device->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
|
---|
| 1433 | this->device->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
|
---|
| 1434 | this->device->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
|
---|
| 1435 |
|
---|
| 1436 | this->device->SetRenderTarget(0, this->screenDistortionMapSurface);
|
---|
| 1437 | this->device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 128, 128, 128), 1.0f, 0);
|
---|
| 1438 |
|
---|
| 1439 | V( particleEffect->SetTexture("distortionMap1", this->distortionMap1) );
|
---|
| 1440 | V( particleEffect->SetTexture("distortionMap2", this->distortionMap2) );
|
---|
| 1441 | V( particleEffect->SetTexture("screenDistortionMap", this->screenDistortionMap) );
|
---|
| 1442 | V( particleEffect->CommitChanges() );
|
---|
| 1443 |
|
---|
| 1444 | for(UINT i=0;i<this->heatHazeParticleRendererList.size();i++) {
|
---|
| 1445 | this->heatHazeParticleRendererList.at(i)->renderHeatHaze();
|
---|
| 1446 | }
|
---|
| 1447 |
|
---|
| 1448 | this->device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
|
---|
| 1449 |
|
---|
| 1450 | //Bild auf finalRenderPass rendern
|
---|
| 1451 | this->device->SetRenderTarget(0, this->finalImageSurface);
|
---|
| 1452 | this->device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
|
---|
| 1453 |
|
---|
| 1454 |
|
---|
| 1455 | //Bild in finalImageSurface kopieren
|
---|
| 1456 | UINT cPass;
|
---|
| 1457 | V( particleEffect->SetTexture("preDistortion", this->preDistortionFinal) );
|
---|
| 1458 | V( particleEffect->CommitChanges() );
|
---|
| 1459 | V( particleEffect->SetTechnique("HeatHazeCopy") );
|
---|
| 1460 | V( particleEffect->Begin( &cPass, 0 ) );
|
---|
| 1461 | V( particleEffect->BeginPass( 0 ) );
|
---|
| 1462 | V( this->device->BeginScene() );
|
---|
| 1463 | V( this->quadMesh->DrawSubset(0) );
|
---|
| 1464 | V( this->device->SetTexture(0, 0) );
|
---|
| 1465 | V( this->device->EndScene() );
|
---|
| 1466 | V( particleEffect->EndPass() );
|
---|
| 1467 | V( particleEffect->End() );
|
---|
| 1468 |
|
---|
| 1469 | this->device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
|
---|
| 1470 | this->device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
|
---|
| 1471 |
|
---|
| 1472 | //Reset default RenderTarget
|
---|
| 1473 | this->defaultRenderPass.setRenderTarget(this->finalImageSurface);
|
---|
| 1474 | }
|
---|
| 1475 | }
|
---|
| 1476 |
|
---|
| 1477 | void Scene::updateSoundNodeVolume()
|
---|
| 1478 | {
|
---|
| 1479 | std::list<SPTR<Node> >::iterator it;
|
---|
| 1480 | for(it = this->soundNodeList.begin();it!=this->soundNodeList.end();it++) {
|
---|
| 1481 | ((SoundNode*) it->get())->setSceneAlpha(this->sceneAlpha);
|
---|
| 1482 | }
|
---|
| 1483 | if(this->bgSoundChannel!=-1 && !this->muteMusic) {
|
---|
| 1484 | FSOUND_SetVolume(this->bgSoundChannel, (int)(255*this->bgSoundVolume*this->sceneAlpha));
|
---|
| 1485 | }
|
---|
| 1486 | }
|
---|
| 1487 |
|
---|
| 1488 | LPD3DXMESH Scene::getQuadMesh()
|
---|
| 1489 | {
|
---|
| 1490 | if(!this->meshCreated) {
|
---|
| 1491 | this->createQuadMesh();
|
---|
| 1492 | }
|
---|
| 1493 | return this->quadMesh;
|
---|
| 1494 | }
|
---|
| 1495 |
|
---|
| 1496 | void Scene::setBackgroundSoundMute(bool _muteMusic)
|
---|
| 1497 | {
|
---|
| 1498 | this->muteMusic = _muteMusic;
|
---|
| 1499 | if(!this->muteMusic) {
|
---|
| 1500 | if(this->bgSoundChannel!=-1) {
|
---|
| 1501 | FSOUND_SetVolume(this->bgSoundChannel, (int)(255*this->bgSoundVolume*this->sceneAlpha));
|
---|
| 1502 | }
|
---|
| 1503 | } else {
|
---|
| 1504 | if(this->bgSoundChannel!=-1) {
|
---|
| 1505 | FSOUND_SetVolume(this->bgSoundChannel, 0);
|
---|
| 1506 | }
|
---|
| 1507 | }
|
---|
| 1508 | }
|
---|
| 1509 |
|
---|
| 1510 | bool Scene::getBackgroundSoundMute() {
|
---|
| 1511 | return this->muteMusic;
|
---|
| 1512 | }
|
---|
| 1513 |
|
---|
| 1514 | void Scene::setBackgroundSound(std::string filename) {
|
---|
| 1515 | this->bgMusicStream = FSOUND_Stream_Open(filename.c_str(), FSOUND_LOOP_NORMAL, 0, 0);
|
---|
| 1516 | }
|
---|
| 1517 |
|
---|
| 1518 | void Scene::setBackgroundSoundVolume(float vol) {
|
---|
| 1519 | this->bgSoundVolume = vol;
|
---|
| 1520 | if(this->bgSoundChannel!=-1) {
|
---|
| 1521 | if(!this->muteMusic) {
|
---|
| 1522 | FSOUND_SetVolume(this->bgSoundChannel, (int)(255*this->bgSoundVolume));
|
---|
| 1523 | } else {
|
---|
| 1524 | FSOUND_SetVolume(this->bgSoundChannel, 0);
|
---|
| 1525 | }
|
---|
| 1526 | }
|
---|
| 1527 | }
|
---|
| 1528 |
|
---|
| 1529 | void Scene::playBackgroundSound() {
|
---|
| 1530 | if(this->bgMusicStream!=NULL) {
|
---|
| 1531 | this->bgSoundChannel = FSOUND_Stream_Play(FSOUND_FREE, this->bgMusicStream);
|
---|
| 1532 | if(!this->muteMusic) {
|
---|
| 1533 | FSOUND_SetVolume(this->bgSoundChannel, (int)(255*this->bgSoundVolume));
|
---|
| 1534 | } else {
|
---|
| 1535 | FSOUND_SetVolume(this->bgSoundChannel, 0);
|
---|
| 1536 | }
|
---|
| 1537 | }
|
---|
| 1538 | } |
---|