From 3a6a28ff05a30d5eb629f0151096ecd7c8e8bdda Mon Sep 17 00:00:00 2001 From: Pawel Kolodziejski Date: Wed, 5 Jan 2005 22:13:56 +0000 Subject: [PATCH] corrected zbuffer data access, but screenblock not works for me (or rather never for me) --- bitmap.h | 1 + driver_gl.cpp | 4 ++-- engine.cpp | 10 ++++++---- scene.cpp | 16 ++++++++++++---- screen.cpp | 24 +++++++++--------------- screen.h | 1 - 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/bitmap.h b/bitmap.h index a62d37e3094..5ab9fd6c1a2 100644 --- a/bitmap.h +++ b/bitmap.h @@ -42,6 +42,7 @@ public: int y() const { return _y; } char *getData() { return _data[_currImage]; } + char *getZbufferData() { return _data[_currImage - 1]; } ~Bitmap(); diff --git a/driver_gl.cpp b/driver_gl.cpp index 392929511ed..9ccc91180b7 100644 --- a/driver_gl.cpp +++ b/driver_gl.cpp @@ -323,10 +323,10 @@ void Driver::updateMesh(const Model::Mesh *mesh) { if(winZ > bestDepth) bestDepth = winZ; - } - //screenBlocksAddRectangle(top, right, left, bottom, bestDepth); +// if (SCREENBLOCKS_GLOBAL) +// screenBlocksAddRectangle(top, right, left, bottom, bestDepth); } glDisable(GL_DEPTH_TEST); diff --git a/engine.cpp b/engine.cpp index 0a3b7a0fe59..8fbaf4a28ea 100644 --- a/engine.cpp +++ b/engine.cpp @@ -125,9 +125,6 @@ void Engine::mainLoop() { } } } else if (_mode == ENGINE_MODE_NORMAL) { - if (SCREENBLOCKS_GLOBAL) - screenBlocksReset(); - if (_currScene != NULL) { // Update actor costumes for (ActorListType::iterator i = _actors.begin(); i != _actors.end(); i++) { @@ -137,6 +134,9 @@ void Engine::mainLoop() { } } + if (SCREENBLOCKS_GLOBAL) + screenBlocksReset(); + g_driver->clearScreen(); if (SCREENBLOCKS_GLOBAL) @@ -176,7 +176,9 @@ void Engine::mainLoop() { if (_currScene != NULL && a->inSet(_currScene->name()) && a->visible()) a->draw(); } - //screenBlocksDrawDebug(); + + if (SCREENBLOCKS_GLOBAL) + screenBlocksDrawDebug(); } // Draw text diff --git a/scene.cpp b/scene.cpp index 7c5948fa516..391ec7e677d 100644 --- a/scene.cpp +++ b/scene.cpp @@ -172,7 +172,7 @@ void Scene::setSetup(int num) { return; if (_currSetup->_bkgndZBm) - screenBlocksInit(_currSetup->_bkgndZBm->getData() ); + screenBlocksInit(_currSetup->_bkgndZBm->getZbufferData()); else screenBlocksInitEmpty(); } @@ -229,7 +229,7 @@ ObjectState *Scene::findState(const char *filename) { void Scene::setSoundPosition(const char *soundName, Vector3d pos) { Vector3d cameraPos = _currSetup->_pos; - Vector3d vector; + Vector3d vector, vector2; vector.set(fabs(cameraPos.x() - pos.x()), fabs(cameraPos.y() - pos.y()), fabs(cameraPos.z() - pos.z())); float distance = vector.magnitude(); float maxDistance = 8.0f; @@ -238,8 +238,16 @@ void Scene::setSoundPosition(const char *soundName, Vector3d pos) { newVolume += _minVolume; g_imuse->setVolume(soundName, newVolume); - // TODO: pan - // roll, fov + vector.set(_currSetup->_interest.x() - cameraPos.x(), _currSetup->_interest.y() - cameraPos.y(), + _currSetup->_interest.z() - cameraPos.z()); + vector2.set(pos.x() - cameraPos.x(), pos.y() - cameraPos.y(), pos.z() - cameraPos.z()); +// printf("a pos (%2.2f, %2.2f, %2.2f) i pos (%2.2f, %2.2f, %2.2f) c pos (%2.2f, %2.2f, %2.2f)\n", pos.x(), pos.y(), pos.z(), +// _currSetup->_interest.x(), _currSetup->_interest.y(), _currSetup->_interest.z(), +// cameraPos.x(), cameraPos.y(), cameraPos.z()); + float a = angle(vector, vector2); + int pan = a * 127 * 1.5; + pan = (pan / 2) + 64; +// g_imuse->setPan(soundName, pan); } void Scene::setSoundParameters(int minVolume, int maxVolume) { diff --git a/screen.cpp b/screen.cpp index 0592fcbaa1f..13f28aba5cb 100644 --- a/screen.cpp +++ b/screen.cpp @@ -46,7 +46,7 @@ float getZbufferBlockDepth(char *zbuffer, int x, int y) { unsigned short int bDepth = 0xFFFF; - for (i = 0; i < SCREEN_BLOCK_SIZE; i++ ) { + for (i = 0; i < SCREEN_BLOCK_SIZE; i++) { if (bDepth > buffer[i]) bDepth = buffer[i]; } @@ -105,19 +105,14 @@ void screenBlocksAddRectangle( int top, int right, int left, int bottom, float d if ((left > right) || (top > bottom)) return; - int firstLeft; - int firstTop; - int width; - int height; + int firstLeft = left / 16; + int firstTop = top /16; - firstLeft = left / 16; - firstTop = top /16; - - width = (right - left) / 16; - if ((right-left) % 16) + int width = (right - left) / 16; + if ((right - left) % 16) width++; - height = (bottom - top) / 16; + int height = (bottom - top) / 16; if ((bottom - top) % 16) height++; @@ -142,7 +137,7 @@ void screenBlocksDrawDebug() { glDisable(GL_DEPTH_TEST); glColor4f(1.f, 0.3f, 1.f, 0.4f); - glDisable(GL_TEXTURE_2D ); + glDisable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -173,10 +168,10 @@ void screenBlocksBlitDirtyBlocks() { glEnable(GL_DEPTH_TEST); glDepthFunc(GL_ALWAYS); - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glDepthMask(GL_TRUE); - for (int j = 0;j < 30; j++) { + for (int j = 0; j < 30; j++) { for (int i = 0; i < 40; i++) { if (screenBlockData[i][j].isDirty) { int width = 1; @@ -197,4 +192,3 @@ void screenBlocksBlitDirtyBlocks() { glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDepthFunc(GL_LESS); } - diff --git a/screen.h b/screen.h index eeda9bb236c..80b9c013ff7 100644 --- a/screen.h +++ b/screen.h @@ -48,4 +48,3 @@ void screenBlocksDrawDebug(); void screenBlocksBlitDirtyBlocks(); #endif // _SCREEN_H_ -