diff options
author | Strangerke | 2017-01-18 07:24:39 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2017-01-25 22:42:24 +0100 |
commit | 2b80514c0efd7b336eeff4672f767c8d416ebde9 (patch) | |
tree | e74552672710d80324dd5df8cc9779f5179771bc /engines/cryo | |
parent | 77a79e8da33d1bfca73790023fcd49a320b6c688 (diff) | |
download | scummvm-rg350-2b80514c0efd7b336eeff4672f767c8d416ebde9.tar.gz scummvm-rg350-2b80514c0efd7b336eeff4672f767c8d416ebde9.tar.bz2 scummvm-rg350-2b80514c0efd7b336eeff4672f767c8d416ebde9.zip |
CRYO: Refactor projection
Diffstat (limited to 'engines/cryo')
-rw-r--r-- | engines/cryo/defs.h | 8 | ||||
-rw-r--r-- | engines/cryo/eden.cpp | 70 |
2 files changed, 38 insertions, 40 deletions
diff --git a/engines/cryo/defs.h b/engines/cryo/defs.h index 1cbd54ca83..01e94572d5 100644 --- a/engines/cryo/defs.h +++ b/engines/cryo/defs.h @@ -825,10 +825,16 @@ struct cubeface_t { int16 *_uv; }; +struct Projection { + int16 x; + int16 y; + int16 z; +}; + struct cube_t { int _num; cubeface_t **_faces; - int16 *_projection; // projected XYZ coords + Projection *_projection; // projected XYZ coords int16 *_vertices; }; diff --git a/engines/cryo/eden.cpp b/engines/cryo/eden.cpp index 190f36f9b9..9801542c11 100644 --- a/engines/cryo/eden.cpp +++ b/engines/cryo/eden.cpp @@ -8606,9 +8606,9 @@ void EdenGame::projectionFix(cube_t *cubep, int n) { transformZ >>= 8; if (transformZ == -256) transformZ++; - cubep->_projection[i * 4 ] = transformX / (transformZ + 256) + _cursorPosX + 14 + _scrollPos; - cubep->_projection[i * 4 + 1] = transformY / (transformZ + 256) + _cursorPosY + 14; - cubep->_projection[i * 4 + 2] = transformZ; + cubep->_projection[i].x = transformX / (transformZ + 256) + _cursorPosX + 14 + _scrollPos; + cubep->_projection[i].y = transformY / (transformZ + 256) + _cursorPosY + 14; + cubep->_projection[i].z = transformZ; } } @@ -8695,7 +8695,7 @@ void EdenGame::NEWcharge_objet_mob(cube_t *cubep, int fileNum, byte *texturePtr) char error; _cubeFaces = nextVal(&next, &error); int16 *vertices = (int16 *)malloc(_cubeFaces * 4 * sizeof(*vertices)); - int16 *projection = (int16 *)malloc(_cubeFaces * 4 * sizeof(*projection)); + Projection *projection = (Projection *)malloc(_cubeFaces * sizeof(*projection)); for (int i = 0; i < _cubeFaces; i++) { vertices[i * 4] = nextVal(&next, &error); vertices[i * 4 + 1] = nextVal(&next, &error); @@ -8902,64 +8902,56 @@ void EdenGame::restoreZDEP() { // Original name: affiche_polygone_mapping void EdenGame::displayPolygoneMapping(cube_t *cubep, cubeface_t *face) { uint16 *indices = face->_indices; - int idx = indices[0] * 4; - int16 v46 = cubep->_projection[idx]; - int16 v48 = cubep->_projection[idx + 1]; + int idx = indices[0]; + int16 projX0 = cubep->_projection[idx].x; + int16 projY0 = cubep->_projection[idx].y; - idx = indices[1] * 4; - int16 v4A = cubep->_projection[idx]; - int16 v4C = cubep->_projection[idx + 1]; + idx = indices[1]; + int16 projX1 = cubep->_projection[idx].x; + int16 projY1 = cubep->_projection[idx].y; - idx = indices[2] * 4; - int16 v4E = cubep->_projection[idx]; - int16 v50 = cubep->_projection[idx + 1]; + idx = indices[2]; + int16 projX2 = cubep->_projection[idx].x; + int16 projY2 = cubep->_projection[idx].y; - if ((v4C - v48) * (v4E - v46) - (v50 - v48) * (v4A - v46) > 0) + if ((projY1 - projY0) * (projX2 - projX0) - (projY2 - projY0) * (projX1 - projX0) > 0) return; int16 *uv = face->_uv; int16 ymin = 200; // min y int16 ymax = 0; // max y - idx = indices[0] * 4; - int16 r20 = cubep->_projection[idx]; - int16 r30 = cubep->_projection[idx + 1]; + idx = indices[0]; + int16 r20 = cubep->_projection[idx].x; + int16 r30 = cubep->_projection[idx].y; int16 r19 = *uv++; int16 r18 = *uv++; indices++; for (int i = 0; i < face->tri - 1; i++, indices++) { - idx = indices[0] * 4; - int16 r26 = cubep->_projection[idx]; - int16 r31 = cubep->_projection[idx + 1]; + idx = indices[0]; + int16 r26 = cubep->_projection[idx].x; + int16 r31 = cubep->_projection[idx].y; uint16 r25 = *uv++; //TODO: unsigned int16 r24 = *uv++; //TODO: unsigned - if (r30 < ymin) - ymin = r30; - if (r30 > ymax) - ymax = r30; - if (r31 < ymin) - ymin = r31; - if (r31 > ymax) - ymax = r31; + ymin = MIN(r30, ymin); + ymax = MAX(r30, ymax); + ymin = MIN(r31, ymin); + ymax = MAX(r31, ymax); drawMappingLine(r20, r30, r26, r31, r19, r18, r25, r24, _lines); r20 = r26; r30 = r31; r19 = r25; r18 = r24; } - idx = face->_indices[0] * 4; - int16 r26 = cubep->_projection[idx]; - int16 r31 = cubep->_projection[idx + 1]; + idx = face->_indices[0]; + int16 r26 = cubep->_projection[idx].x; + int16 r31 = cubep->_projection[idx].y; uv = face->_uv; uint16 r25 = *uv++; int16 r24 = *uv; - if (r30 < ymin) - ymin = r30; - if (r30 > ymax) - ymax = r30; - if (r31 < ymin) - ymin = r31; - if (r31 > ymax) - ymax = r31; + ymin = MIN(r30, ymin); + ymax = MAX(r30, ymax); + ymin = MIN(r31, ymin); + ymax = MAX(r31, ymax); drawMappingLine(r20, r30, r26, r31, r19, r18, r25, r24, _lines); displayMappingLine(ymin, ymax, _mainView->_bufferPtr, face->_texturePtr); } |