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