[Scummvm-git-logs] scummvm master -> 658fb4ccbc301b425e593a9370560e02e3106f62
mgerhardy
noreply at scummvm.org
Sun Jan 29 18:33:59 UTC 2023
This automated email contains information about 15 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
4f67edaa38 TWINE: replaced setAngleCamera
afb3359f4d TWINE: unified holomap code and fixed weird rotations from one location to another
611722d419 TWINE: continue renaming
6c5b867d3a TWINE: removed duplicated rotate method
1491e37f16 TWINE: fixed short overflow error in setAngleCamera
f476804699 TWINE: use int64 for the rotation
179061b7df TWINE: fixed cast warnings
d4aae98ac4 TWINE: fixed cast warnings
4c74a3410e TWINE: renamed method to match the original sources
dd77f4bd8b TWINE: renamed variables
f7aeef424d TWINE: renamed variables
7e72fb59f2 TWINE: renamed variables
302b65ed74 TWINE: renamed methods
252b4670e6 TWINE: again renaming
658fb4ccbc TWINE: reverted implementation of getAngle
Commit: 4f67edaa3834ab4d2bef3d7decd3a6463f2bf28c
https://github.com/scummvm/scummvm/commit/4f67edaa3834ab4d2bef3d7decd3a6463f2bf28c
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2023-01-29T19:32:50+01:00
Commit Message:
TWINE: replaced setAngleCamera
Changed paths:
engines/twine/renderer/renderer.cpp
diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index 2d101c694a9..22cc0c004df 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -142,28 +142,39 @@ IVec3 Renderer::setInverseAngleCamera(int32 x, int32 y, int32 z) {
return _cameraRot;
}
-IVec3 Renderer::setAngleCamera(int32 x, int32 y, int32 z) {
- const double Xradians = (double)((LBAAngles::ANGLE_90 - x) % LBAAngles::ANGLE_360) * 2 * M_PI / LBAAngles::ANGLE_360;
- const double Yradians = (double)((LBAAngles::ANGLE_90 - y) % LBAAngles::ANGLE_360) * 2 * M_PI / LBAAngles::ANGLE_360;
- const double Zradians = (double)((LBAAngles::ANGLE_90 - z) % LBAAngles::ANGLE_360) * 2 * M_PI / LBAAngles::ANGLE_360;
-
- _matrixWorld.row1.x = (int32)(sin(Zradians) * sin(Yradians) * SCENE_SIZE_HALFF);
- _matrixWorld.row1.y = (int32)(-cos(Zradians) * SCENE_SIZE_HALFF);
- _matrixWorld.row1.z = (int32)(sin(Zradians) * cos(Yradians) * SCENE_SIZE_HALFF);
- _matrixWorld.row2.x = (int32)(cos(Zradians) * sin(Xradians) * SCENE_SIZE_HALFF);
- _matrixWorld.row2.y = (int32)(sin(Zradians) * sin(Xradians) * SCENE_SIZE_HALFF);
- _matrixWorld.row3.x = (int32)(cos(Zradians) * cos(Xradians) * SCENE_SIZE_HALFF);
- _matrixWorld.row3.y = (int32)(sin(Zradians) * cos(Xradians) * SCENE_SIZE_HALFF);
-
- int32 matrixElem = _matrixWorld.row2.x;
-
- _matrixWorld.row2.x = (int32)(sin(Yradians) * matrixElem + SCENE_SIZE_HALFF * cos(Yradians) * cos(Xradians));
- _matrixWorld.row2.z = (int32)(cos(Yradians) * matrixElem - SCENE_SIZE_HALFF * sin(Yradians) * cos(Xradians));
-
- matrixElem = _matrixWorld.row3.x;
-
- _matrixWorld.row3.x = (int32)(sin(Yradians) * matrixElem - SCENE_SIZE_HALFF * sin(Xradians) * cos(Yradians));
- _matrixWorld.row3.z = (int32)(cos(Yradians) * matrixElem + SCENE_SIZE_HALFF * sin(Xradians) * sin(Yradians));
+IVec3 Renderer::setAngleCamera(int32 alpha, int32 beta, int32 gamma) {
+ const int32 cAlpha = ClampAngle(alpha);
+ const int32 cBeta = ClampAngle(beta);
+ const int32 cGamma = ClampAngle(gamma);
+ const int32 cAlpha2 = ClampAngle(alpha + LBAAngles::ANGLE_90);
+ const int32 cBeta2 = ClampAngle(beta + LBAAngles::ANGLE_90);
+ const int32 cGamma2 = ClampAngle(gamma + LBAAngles::ANGLE_90);
+ const int16 sinus1 = sinTab[cAlpha];
+ const int16 cosinus1 = sinTab[cAlpha2];
+ int16 sinus2 = sinTab[cGamma];
+ int16 cosinus2 = sinTab[cGamma2];
+
+ _matrixWorld.row1.x = cosinus2;
+ _matrixWorld.row1.y = -sinus2;
+ _matrixWorld.row2.x = (sinus2 * cosinus1) * SCENE_SIZE_HALF;
+ _matrixWorld.row2.y = (cosinus2 * cosinus1) * SCENE_SIZE_HALF;
+ _matrixWorld.row3.x = (sinus2 * sinus1) * SCENE_SIZE_HALF;
+ _matrixWorld.row3.y = (cosinus2 * sinus1) * SCENE_SIZE_HALF;
+
+ sinus2 = sinTab[cBeta];
+ cosinus2 = sinTab[cBeta2];
+
+ int32 x = _matrixWorld.row1.x;
+ _matrixWorld.row1.x = (cosinus2 * x) * SCENE_SIZE_HALF;
+ _matrixWorld.row1.z = (sinus2 * x) * SCENE_SIZE_HALF;
+
+ x = _matrixWorld.row2.x;
+ _matrixWorld.row2.x = ((cosinus2 * x) + (sinus2 * sinus1)) * SCENE_SIZE_HALF;
+ _matrixWorld.row2.z = ((sinus2 * x) - (cosinus2 * sinus1)) * SCENE_SIZE_HALF;
+
+ x = _matrixWorld.row3.x;
+ _matrixWorld.row3.x = ((cosinus2 * x) - (sinus2 * cosinus1)) * SCENE_SIZE_HALF;
+ _matrixWorld.row3.z = ((cosinus2 * cosinus1) + (sinus2 * x)) * SCENE_SIZE_HALF;
_cameraRot = longWorldRot(_cameraPos.x, _cameraPos.y, _cameraPos.z);
Commit: afb3359f4d79961c1e5b7b05ada8c3ef42d44e97
https://github.com/scummvm/scummvm/commit/afb3359f4d79961c1e5b7b05ada8c3ef42d44e97
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2023-01-29T19:32:51+01:00
Commit Message:
TWINE: unified holomap code and fixed weird rotations from one location to another
Changed paths:
engines/twine/holomap.cpp
diff --git a/engines/twine/holomap.cpp b/engines/twine/holomap.cpp
index 73917c708c4..7625eeb394d 100644
--- a/engines/twine/holomap.cpp
+++ b/engines/twine/holomap.cpp
@@ -446,18 +446,20 @@ int32 Holomap::searchNextArrow(int32 currentLocation, int32 dir) const {
return -1;
}
-void Holomap::drawListPos(int xRot, int yRot, int zRot, bool pos) {
- int n = 0;
- DrawListStruct drawListArray[NUM_LOCATIONS];
- for (int locationIdx = 0; locationIdx < NUM_LOCATIONS; ++locationIdx) {
- if (!(_engine->_gameState->_holomapFlags[locationIdx] & HOLOMAP_CAN_FOCUS) && locationIdx != _engine->_scene->_currentSceneIdx) {
+void Holomap::drawListPos(int calpha, int cbeta, int cgamma, bool pos) {
+ int nbobjets = 0;
+ DrawListStruct listTri[NUM_LOCATIONS];
+ const int numCube = _engine->_scene->_currentSceneIdx;
+ const int maxHoloPos = _engine->numLocations();
+ for (int n = 0; n < maxHoloPos; ++n) {
+ if (!(_engine->_gameState->_holomapFlags[n] & HOLOMAP_CAN_FOCUS) && n != numCube) {
continue;
}
- const Location &loc = _locations[locationIdx];
+ const Location &loc = _locations[n];
_engine->_renderer->setAngleCamera(loc.angleX, loc.angleY, 0);
const IVec3 &m = _engine->_renderer->worldRotatePoint(IVec3(0, 0, 1000 + loc.size));
const IVec3 &m1 = _engine->_renderer->worldRotatePoint(IVec3(0, 0, 1500));
- _engine->_renderer->setInverseAngleCamera(xRot, yRot, zRot);
+ _engine->_renderer->setInverseAngleCamera(calpha, cbeta, cgamma);
_engine->_renderer->setCameraRotation(0, 0, distance(ZOOM_BIG_HOLO));
const IVec3 &destPos3 = _engine->_renderer->worldRotatePoint(m);
@@ -472,22 +474,22 @@ void Holomap::drawListPos(int xRot, int yRot, int zRot, bool pos) {
continue;
}
}
- uint32 flags = _engine->_gameState->_holomapFlags[locationIdx] & HOLOMAP_ARROW;
- if (locationIdx == _engine->_scene->_currentSceneIdx) {
- flags |= HOLOMAP_VISITED; // model type
+ uint32 t = (uint32)_engine->_gameState->_holomapFlags[n] & HOLOMAP_ARROW;
+ if (n == numCube) {
+ t |= HOLOMAP_VISITED; // model type
}
- DrawListStruct &drawList = drawListArray[n];
+ DrawListStruct &drawList = listTri[nbobjets];
drawList.posValue = destPos3.z;
- drawList.actorIdx = locationIdx;
- drawList.type = flags;
+ drawList.actorIdx = n;
+ drawList.type = t;
drawList.x = m.x;
drawList.y = m.y;
drawList.z = m.z;
- ++n;
+ ++nbobjets;
}
- _engine->_redraw->sortDrawingList(drawListArray, n);
- for (int i = 0; i < n; ++i) {
- const DrawListStruct &drawList = drawListArray[i];
+ _engine->_redraw->sortDrawingList(listTri, nbobjets);
+ for (int i = 0; i < nbobjets; ++i) {
+ const DrawListStruct &drawList = listTri[i];
const uint32 flags = drawList.type;
const BodyData *bodyData = nullptr;
if (flags == HOLOMAP_ARROW) {
@@ -540,13 +542,18 @@ void Holomap::holoMap() {
int32 currentLocation = _engine->_scene->_currentSceneIdx;
_engine->_text->drawHolomapLocation(_locations[currentLocation].textIndex);
- int32 time = _engine->timerRef;
- int32 xRot = _locations[currentLocation].angleX;
- int32 yRot = _locations[currentLocation].angleY;
+ int32 otimer = _engine->timerRef;
+ int32 dalpha = _locations[currentLocation].angleX;
+ int32 dbeta = _locations[currentLocation].angleY;
+ int32 calpha = dalpha;
+ int32 cbeta = dbeta;
+ int32 cgamma = 0;
+ int32 oalpha = dalpha;
+ int32 obeta = dbeta;
bool automove = false;
bool redraw = true;
int waterPaletteChangeTimer = 0;
- bool fadeInPalette = true;
+ bool flagpal = true;
_engine->_input->enableKeyMap(holomapKeyMapId);
for (;;) {
FrameMarker frame(_engine);
@@ -556,51 +563,66 @@ void Holomap::holoMap() {
}
if (_engine->_input->toggleActionIfActive(TwinEActionType::HolomapPrev)) {
- const int32 nextLocation = searchNextArrow(currentLocation, -1);
- if (nextLocation != -1 && currentLocation != nextLocation) {
- currentLocation = nextLocation;
- _engine->_text->drawHolomapLocation(_locations[currentLocation].textIndex);
- time = _engine->timerRef;
- automove = true;
+ currentLocation = searchNextArrow(currentLocation, -1);
+ if (currentLocation == -1) {
+ currentLocation = _engine->_scene->_currentSceneIdx;
}
+ _engine->_text->drawHolomapLocation(_locations[currentLocation].textIndex);
+ oalpha = calpha;
+ obeta = cbeta;
+ otimer = _engine->timerRef;
+ dalpha = _locations[currentLocation].angleX;
+ dbeta = _locations[currentLocation].angleY;
+ automove = true;
+ redraw = true;
} else if (_engine->_input->toggleActionIfActive(TwinEActionType::HolomapNext)) {
- const int32 nextLocation = searchNextArrow(currentLocation, 1);
- if (nextLocation != -1 && currentLocation != nextLocation) {
- currentLocation = nextLocation;
- _engine->_text->drawHolomapLocation(_locations[currentLocation].textIndex);
- time = _engine->timerRef;
- automove = true;
+ currentLocation = searchNextArrow(currentLocation, 1);
+ if (currentLocation == -1) {
+ currentLocation = _engine->_scene->_currentSceneIdx;
}
- }
-
- if (_engine->_input->isActionActive(TwinEActionType::HolomapDown)) {
- xRot += LBAAngles::ANGLE_2;
- automove = true;
- time = _engine->timerRef;
- } else if (_engine->_input->isActionActive(TwinEActionType::HolomapUp)) {
- xRot -= LBAAngles::ANGLE_2;
+ _engine->_text->drawHolomapLocation(_locations[currentLocation].textIndex);
+ oalpha = calpha;
+ obeta = cbeta;
+ otimer = _engine->timerRef;
+ dalpha = _locations[currentLocation].angleX;
+ dbeta = _locations[currentLocation].angleY;
automove = true;
- time = _engine->timerRef;
+ redraw = true;
}
- if (_engine->_input->isActionActive(TwinEActionType::HolomapRight)) {
- yRot += LBAAngles::ANGLE_2;
- automove = true;
- time = _engine->timerRef;
- } else if (_engine->_input->isActionActive(TwinEActionType::HolomapLeft)) {
- yRot -= LBAAngles::ANGLE_2;
- automove = true;
- time = _engine->timerRef;
+ if (!automove) {
+ if (_engine->_input->isActionActive(TwinEActionType::HolomapDown)) {
+ calpha += LBAAngles::ANGLE_2;
+ calpha = ClampAngle(calpha);
+ cbeta = ClampAngle(cbeta);
+ redraw = true;
+ } else if (_engine->_input->isActionActive(TwinEActionType::HolomapUp)) {
+ calpha -= LBAAngles::ANGLE_2;
+ calpha = ClampAngle(calpha);
+ cbeta = ClampAngle(cbeta);
+ redraw = true;
+ }
+ if (_engine->_input->isActionActive(TwinEActionType::HolomapRight)) {
+ cbeta += LBAAngles::ANGLE_2;
+ calpha = ClampAngle(calpha);
+ cbeta = ClampAngle(cbeta);
+ redraw = true;
+ } else if (_engine->_input->isActionActive(TwinEActionType::HolomapLeft)) {
+ cbeta -= LBAAngles::ANGLE_2;
+ calpha = ClampAngle(calpha);
+ cbeta = ClampAngle(cbeta);
+ redraw = true;
+ }
}
if (automove) {
- const int32 dt = _engine->timerRef - time;
- xRot = _engine->_collision->clampedLerp(ClampAngle(xRot), _locations[currentLocation].angleX, 75, dt);
- yRot = _engine->_collision->clampedLerp(ClampAngle(yRot), _locations[currentLocation].angleY, 75, dt);
+ const int32 dt = _engine->timerRef - otimer;
+ calpha = _engine->_collision->clampedLerp(oalpha, dalpha, 75, dt);
+ cbeta = _engine->_collision->clampedLerp(obeta, dbeta, 75, dt);
redraw = true;
}
- if (!fadeInPalette && waterPaletteChangeTimer < _engine->timerRef) {
+ if (!flagpal && waterPaletteChangeTimer < _engine->timerRef) {
// animate the water surface
_engine->setPalette(HOLOMAP_PALETTE_INDEX, NUM_HOLOMAPCOLORS, &_paletteHolomap[3 * _holomapPaletteIndex++]);
if (_holomapPaletteIndex == NUM_HOLOMAPCOLORS) {
@@ -618,13 +640,13 @@ void Holomap::holoMap() {
_engine->_interface->memoClip();
_engine->_interface->setClip(rect);
_engine->_interface->drawFilledRect(rect, COLOR_BLACK);
- _engine->_renderer->setInverseAngleCamera(xRot, yRot, 0);
- _engine->_renderer->setLightVector(xRot, yRot, 0);
- drawListPos(xRot, yRot, 0, false);
- _engine->_renderer->setInverseAngleCamera(xRot, yRot, 0);
+ _engine->_renderer->setInverseAngleCamera(calpha, cbeta, cgamma);
+ _engine->_renderer->setLightVector(calpha, cbeta, 0);
+ drawListPos(calpha, cbeta, cgamma, false);
+ _engine->_renderer->setInverseAngleCamera(calpha, cbeta, cgamma);
_engine->_renderer->setCameraRotation(0, 0, distance(ZOOM_BIG_HOLO));
drawHoloMap(holomapImagePtr, holomapImageSize);
- drawListPos(xRot, yRot, 0, true);
+ drawListPos(calpha, cbeta, cgamma, true);
_engine->_interface->restoreClip();
drawHolomapText(_engine->width() / 2, 25, "HoloMap");
if (automove) {
@@ -634,14 +656,14 @@ void Holomap::holoMap() {
}
}
- if (automove && xRot == _locations[currentLocation].angleX && yRot == _locations[currentLocation].angleY) {
+ if (automove && dalpha == calpha && dbeta == cbeta) {
automove = false;
}
++_engine->timerRef;
- if (fadeInPalette) {
- fadeInPalette = false;
+ if (flagpal) {
+ flagpal = false;
_engine->_screens->fadeToPal(_engine->_screens->_paletteRGBACustom);
}
}
Commit: 611722d4192973cac345c186df8321b21ec996f1
https://github.com/scummvm/scummvm/commit/611722d4192973cac345c186df8321b21ec996f1
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2023-01-29T19:32:51+01:00
Commit Message:
TWINE: continue renaming
Changed paths:
engines/twine/renderer/renderer.cpp
engines/twine/renderer/renderer.h
diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index 22cc0c004df..14e4db457d6 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -129,7 +129,7 @@ void Renderer::setIsoProjection(int32 x, int32 y, int32 scale) {
_isUsingIsoProjection = true;
}
-void Renderer::flipMatrix() {
+void Renderer::flipMatrix() { // FlipMatrice
SWAP(_matrixWorld.row1.y, _matrixWorld.row2.x);
SWAP(_matrixWorld.row1.z, _matrixWorld.row3.x);
SWAP(_matrixWorld.row2.z, _matrixWorld.row3.y);
@@ -318,10 +318,11 @@ void Renderer::rotList(const Common::Array<BodyVertex> &vertices, int32 firstPoi
}
}
-void Renderer::processRotatedElement(IMatrix3x3 *targetMatrix, const Common::Array<BodyVertex> &vertices, int32 rotX, int32 rotY, int32 rotZ, const BodyBone &bone, ModelData *modelData) {
+// RotateGroupe
+void Renderer::processRotatedElement(IMatrix3x3 *targetMatrix, const Common::Array<BodyVertex> &vertices, int32 alpha, int32 beta, int32 gamma, const BodyBone &bone, ModelData *modelData) {
const int32 firstPoint = bone.firstVertex;
const int32 numOfPoints = bone.numVertices;
- const IVec3 renderAngle(rotX, rotY, rotZ);
+ const IVec3 renderAngle(alpha, beta, gamma);
const IMatrix3x3 *currentMatrix;
IVec3 destPos;
@@ -346,7 +347,7 @@ void Renderer::processRotatedElement(IMatrix3x3 *targetMatrix, const Common::Arr
rotList(vertices, firstPoint, numOfPoints, &modelData->computedPoints[firstPoint], targetMatrix, destPos);
}
-void Renderer::applyPointsTranslation(const Common::Array<BodyVertex> &vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *translationMatrix, const IVec3 &angleVec, const IVec3 &destPos) {
+void Renderer::transRotList(const Common::Array<BodyVertex> &vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *translationMatrix, const IVec3 &angleVec, const IVec3 &destPos) {
for (int32 i = 0; i < numPoints; ++i) {
const BodyVertex &vertex = vertices[i + firstPoint];
const int32 tmpX = vertex.x + angleVec.x;
@@ -361,6 +362,7 @@ void Renderer::applyPointsTranslation(const Common::Array<BodyVertex> &vertices,
}
}
+// TranslateGroupe
void Renderer::processTranslatedElement(IMatrix3x3 *targetMatrix, const Common::Array<BodyVertex> &vertices, int32 rotX, int32 rotY, int32 rotZ, const BodyBone &bone, ModelData *modelData) {
IVec3 renderAngle;
renderAngle.x = rotX;
@@ -380,7 +382,7 @@ void Renderer::processTranslatedElement(IMatrix3x3 *targetMatrix, const Common::
*targetMatrix = _matricesTable[matrixIndex];
}
- applyPointsTranslation(vertices, bone.firstVertex, bone.numVertices, &modelData->computedPoints[bone.firstVertex], targetMatrix, renderAngle, destPos);
+ transRotList(vertices, bone.firstVertex, bone.numVertices, &modelData->computedPoints[bone.firstVertex], targetMatrix, renderAngle, destPos);
}
void Renderer::setLightVector(int32 angleX, int32 angleY, int32 angleZ) {
@@ -1691,11 +1693,11 @@ void Renderer::animModel(ModelData *modelData, const BodyData &bodyData, RenderC
}
}
-bool Renderer::affObjetIso(int32 x, int32 y, int32 z, int32 angleX, int32 angleY, int32 angleZ, const BodyData &bodyData, Common::Rect &modelRect) {
+bool Renderer::affObjetIso(int32 x, int32 y, int32 z, int32 alpha, int32 beta, int32 gamma, const BodyData &bodyData, Common::Rect &modelRect) {
IVec3 renderAngle;
- renderAngle.x = angleX;
- renderAngle.y = angleY;
- renderAngle.z = angleZ;
+ renderAngle.x = alpha;
+ renderAngle.y = beta;
+ renderAngle.z = gamma;
// model render size reset
modelRect.left = SCENE_SIZE_MAX;
diff --git a/engines/twine/renderer/renderer.h b/engines/twine/renderer/renderer.h
index e07f3954071..739022c83d8 100644
--- a/engines/twine/renderer/renderer.h
+++ b/engines/twine/renderer/renderer.h
@@ -160,7 +160,7 @@ private:
void rotMatIndex2(IMatrix3x3 *targetMatrix, const IMatrix3x3 *currentMatrix, const IVec3 &angleVec);
void rotList(const Common::Array<BodyVertex>& vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *rotationMatrix, const IVec3 &destPos);
void processRotatedElement(IMatrix3x3 *targetMatrix, const Common::Array<BodyVertex>& vertices, int32 rotX, int32 rotY, int32 rotZ, const BodyBone &bone, ModelData *modelData);
- void applyPointsTranslation(const Common::Array<BodyVertex>& vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *translationMatrix, const IVec3 &angleVec, const IVec3 &destPos);
+ void transRotList(const Common::Array<BodyVertex>& vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *translationMatrix, const IVec3 &angleVec, const IVec3 &destPos);
void processTranslatedElement(IMatrix3x3 *targetMatrix, const Common::Array<BodyVertex>& vertices, int32 rotX, int32 rotY, int32 rotZ, const BodyBone &bone, ModelData *modelData);
IVec3 rot(const IMatrix3x3 &matrix, int32 x, int32 y, int32 z);
Commit: 6c5b867d3a114e96b0212af29f711f8bb7e162b1
https://github.com/scummvm/scummvm/commit/6c5b867d3a114e96b0212af29f711f8bb7e162b1
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2023-01-29T19:32:51+01:00
Commit Message:
TWINE: removed duplicated rotate method
Changed paths:
engines/twine/holomap.cpp
engines/twine/renderer/renderer.cpp
engines/twine/renderer/renderer.h
engines/twine/scene/animations.cpp
engines/twine/scene/collision.cpp
engines/twine/scene/extra.cpp
engines/twine/scene/movements.cpp
engines/twine/scene/movements.h
engines/twine/scene/scene.cpp
engines/twine/shared.h
engines/twine/twine.cpp
diff --git a/engines/twine/holomap.cpp b/engines/twine/holomap.cpp
index 7625eeb394d..0b82382d8b8 100644
--- a/engines/twine/holomap.cpp
+++ b/engines/twine/holomap.cpp
@@ -158,8 +158,8 @@ void Holomap::computeCoorGlobe(Common::SeekableReadStream *holomapSurfaceStream)
holomapSurfaceStream->seek(-1, SEEK_CUR);
for (int beta = 0; beta < LBAAngles::ANGLE_360; beta += LBAAngles::ANGLE_11_25) {
const int32 normal = 1000 + holomapSurfaceStream->readByte() * 2;
- const IVec3 &rotVec = _engine->_renderer->getHolomapRotation(normal, 0, alpha);
- const IVec3 &rotVec2 = _engine->_renderer->getHolomapRotation(rotVec.x, 0, beta);
+ const IVec2 &rotVec = _engine->_renderer->rotate(normal, 0, alpha);
+ const IVec2 &rotVec2 = _engine->_renderer->rotate(rotVec.x, 0, beta);
const IVec3 &rotVec3 = _engine->_renderer->worldRotatePoint(IVec3(rotVec2.x, rotVec.y, rotVec2.y));
_holomapSurface[holomapSurfaceArrayIdx].x = rotVec3.x;
@@ -168,8 +168,8 @@ void Holomap::computeCoorGlobe(Common::SeekableReadStream *holomapSurfaceStream)
++holomapSurfaceArrayIdx;
}
const int32 normal = 1000 + rot * 2;
- const IVec3 &rotVec = _engine->_renderer->getHolomapRotation(normal, 0, alpha);
- const IVec3 &rotVec2 = _engine->_renderer->getHolomapRotation(rotVec.x, 0, 0);
+ const IVec2 &rotVec = _engine->_renderer->rotate(normal, 0, alpha);
+ const IVec2 &rotVec2 = _engine->_renderer->rotate(rotVec.x, 0, 0);
const IVec3 &rotVec3 = _engine->_renderer->worldRotatePoint(IVec3(rotVec2.x, rotVec.y, rotVec2.y));
_holomapSurface[holomapSurfaceArrayIdx].x = rotVec3.x;
_holomapSurface[holomapSurfaceArrayIdx].y = rotVec3.y;
diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index 14e4db457d6..7e5cf3e9ac4 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -220,16 +220,16 @@ void Renderer::setFollowCamera(int32 transPosX, int32 transPosY, int32 transPosZ
_cameraPos = longInverseRot(_cameraRot.x, _cameraRot.y, _cameraRot.z);
}
-IVec3 Renderer::getHolomapRotation(const int32 x, const int32 y, const int32 angle) const {
+IVec2 Renderer::rotate(int32 side, int32 forward, int32 angle) const {
if (angle) {
const int32 nSin = sinTab[ClampAngle(angle)];
const int32 nCos = sinTab[ClampAngle((angle + LBAAngles::ANGLE_90))];
- const int32 x0 = ((x * nCos) + (y * nSin)) >> 14;
- const int32 y0 = ((y * nCos) - (x * nSin)) >> 14;
- return IVec3(x0, y0, 0);
+ const int32 x0 = ((side * nCos) + (forward * nSin)) >> 14;
+ const int32 y0 = ((forward * nCos) - (side * nSin)) >> 14;
+ return IVec2(x0, y0);
}
- return IVec3(x, y, 0);
+ return IVec2(side, forward);
}
void Renderer::rotMatIndex2(IMatrix3x3 *targetMatrix, const IMatrix3x3 *currentMatrix, const IVec3 &angleVec) {
diff --git a/engines/twine/renderer/renderer.h b/engines/twine/renderer/renderer.h
index 739022c83d8..947e52a3a1e 100644
--- a/engines/twine/renderer/renderer.h
+++ b/engines/twine/renderer/renderer.h
@@ -231,7 +231,14 @@ public:
void init(int32 w, int32 h);
void setCameraRotation(int32 x, int32 y, int32 z);
- IVec3 getHolomapRotation(const int32 angleX, const int32 angleY, const int32 angleZ) const;
+
+ /**
+ * Calculate offset for the side and forward distances by the given angle of an actor
+ * @param side Actor current X coordinate
+ * @param forward Actor current Z coordinate
+ * @param angle Actor angle to rotate
+ */
+ IVec2 rotate(int32 side, int32 forward, int32 angle) const;
void setLightVector(int32 angleX, int32 angleY, int32 angleZ);
IVec3 longWorldRot(int32 x, int32 y, int32 z);
diff --git a/engines/twine/scene/animations.cpp b/engines/twine/scene/animations.cpp
index 2b3eaa825a9..b5366a2c42b 100644
--- a/engines/twine/scene/animations.cpp
+++ b/engines/twine/scene/animations.cpp
@@ -336,11 +336,11 @@ void Animations::processAnimActions(int32 actorIdx) { // GereAnimAction
break;
case ActionType::ACTION_THROW_3D:
if (action.animFrame == actor->_frame) {
- const IVec3 &destPos = _engine->_movements->rotate(action.distanceX, action.distanceZ, actor->_beta);
+ const IVec2 &destPos = _engine->_renderer->rotate(action.distanceX, action.distanceZ, actor->_beta);
const int32 throwX = destPos.x + actor->_pos.x;
const int32 throwY = action.distanceY + actor->_pos.y;
- const int32 throwZ = destPos.z + actor->_pos.z;
+ const int32 throwZ = destPos.y + actor->_pos.z;
_engine->_extra->throwExtra(actorIdx, throwX, throwY, throwZ, action.spriteIndex,
action.xAngle, action.yAngle + actor->_beta, action.xRotPoint, action.extraAngle, action.strength);
@@ -351,11 +351,11 @@ void Animations::processAnimActions(int32 actorIdx) { // GereAnimAction
const int32 distance = getDistance2D(actor->posObj(), _engine->_scene->_sceneHero->posObj());
const int32 newAngle = _engine->_movements->getAngle(actor->_pos.y, 0, _engine->_scene->_sceneHero->_pos.y, distance);
- const IVec3 &destPos = _engine->_movements->rotate(action.distanceX, action.distanceZ, actor->_beta);
+ const IVec2 &destPos = _engine->_renderer->rotate(action.distanceX, action.distanceZ, actor->_beta);
const int32 throwX = destPos.x + actor->_pos.x;
const int32 throwY = action.distanceY + actor->_pos.y;
- const int32 throwZ = destPos.z + actor->_pos.z;
+ const int32 throwZ = destPos.y + actor->_pos.z;
_engine->_extra->throwExtra(actorIdx, throwX, throwY, throwZ, action.spriteIndex,
action.xAngle + newAngle, action.yAngle + actor->_beta, action.xRotPoint, action.extraAngle, action.strength);
@@ -363,20 +363,20 @@ void Animations::processAnimActions(int32 actorIdx) { // GereAnimAction
break;
case ActionType::ACTION_THROW_3D_SEARCH:
if (action.animFrame == actor->_frame) {
- const IVec3 &destPos = _engine->_movements->rotate(action.distanceX, action.distanceZ, actor->_beta);
+ const IVec2 &destPos = _engine->_renderer->rotate(action.distanceX, action.distanceZ, actor->_beta);
const int32 x = actor->_pos.x + destPos.x;
const int32 y = actor->_pos.y + action.distanceY;
- const int32 z = actor->_pos.z + destPos.z;
+ const int32 z = actor->_pos.z + destPos.y;
_engine->_extra->addExtraAiming(actorIdx, x, y, z, action.spriteIndex,
action.targetActor, action.finalAngle, action.strength);
}
break;
case ActionType::ACTION_THROW_3D_MAGIC:
if (_engine->_gameState->_magicBall == -1 && action.animFrame == actor->_frame) {
- const IVec3 &destPos = _engine->_movements->rotate(action.distanceX, action.distanceZ, actor->_beta);
+ const IVec2 &destPos = _engine->_renderer->rotate(action.distanceX, action.distanceZ, actor->_beta);
const int32 x = actor->_pos.x + destPos.x;
const int32 y = actor->_pos.y + action.distanceY;
- const int32 z = actor->_pos.z + destPos.z;
+ const int32 z = actor->_pos.z + destPos.y;
_engine->_extra->addExtraThrowMagicball(x, y, z, action.xAngle, actor->_beta, action.yAngle, action.finalAngle);
}
break;
@@ -492,14 +492,14 @@ void Animations::doAnim(int32 actorIdx) {
}
}
- const IVec3 xRotPos = _engine->_movements->rotate(xAxisRotation, 0, actor->_spriteActorRotation);
+ const IVec2 xRotPos = _engine->_renderer->rotate(xAxisRotation, 0, actor->_spriteActorRotation);
- processActor.y = actor->_pos.y - xRotPos.z;
+ processActor.y = actor->_pos.y - xRotPos.y;
- const IVec3 destPos = _engine->_movements->rotate(0, xRotPos.x, actor->_beta);
+ const IVec2 destPos = _engine->_renderer->rotate(0, xRotPos.x, actor->_beta);
processActor.x = actor->_pos.x + destPos.x;
- processActor.z = actor->_pos.z + destPos.z;
+ processActor.z = actor->_pos.z + destPos.y;
_engine->_movements->setActorAngle(LBAAngles::LBAAngles::ANGLE_0, actor->_speed, LBAAngles::LBAAngles::ANGLE_17, &actor->realAngle);
@@ -579,10 +579,10 @@ void Animations::doAnim(int32 actorIdx) {
actor->_beta = ClampAngle(actor->_beta + _processLastRotationAngle - actor->_animStepBeta);
actor->_animStepBeta = _processLastRotationAngle;
- const IVec3 &destPos = _engine->_movements->rotate(_currentStep.x, _currentStep.z, actor->_beta);
+ const IVec2 &destPos = _engine->_renderer->rotate(_currentStep.x, _currentStep.z, actor->_beta);
_currentStep.x = destPos.x;
- _currentStep.z = destPos.z;
+ _currentStep.z = destPos.y;
processActor = actor->posObj() + _currentStep - actor->_animStep;
@@ -697,13 +697,13 @@ void Animations::doAnim(int32 actorIdx) {
// process wall hit while running
if (collision->_causeActorDamage && !actor->_dynamicFlags.bIsFalling && IS_HERO(actorIdx) && _engine->_actor->_heroBehaviour == HeroBehaviourType::kAthletic && actor->_genAnim == AnimationTypes::kForward) {
- IVec3 destPos = _engine->_movements->rotate(actor->_boundingBox.mins.x, actor->_boundingBox.mins.z, actor->_beta + LBAAngles::LBAAngles::ANGLE_360 + LBAAngles::LBAAngles::ANGLE_135);
+ IVec2 destPos = _engine->_renderer->rotate(actor->_boundingBox.mins.x, actor->_boundingBox.mins.z, actor->_beta + LBAAngles::LBAAngles::ANGLE_360 + LBAAngles::LBAAngles::ANGLE_135);
destPos.x += processActor.x;
- destPos.z += processActor.z;
+ destPos.y += processActor.z;
- if (destPos.x >= 0 && destPos.z >= 0 && destPos.x <= SCENE_SIZE_MAX && destPos.z <= SCENE_SIZE_MAX) {
- if (_engine->_grid->worldColBrick(destPos.x, processActor.y + SIZE_BRICK_Y, destPos.z) != ShapeType::kNone && _engine->_cfgfile.WallCollision) { // avoid wall hit damage
+ if (destPos.x >= 0 && destPos.y >= 0 && destPos.x <= SCENE_SIZE_MAX && destPos.y <= SCENE_SIZE_MAX) {
+ if (_engine->_grid->worldColBrick(destPos.x, processActor.y + SIZE_BRICK_Y, destPos.y) != ShapeType::kNone && _engine->_cfgfile.WallCollision) { // avoid wall hit damage
_engine->_extra->initSpecial(actor->_pos.x, actor->_pos.y + 1000, actor->_pos.z, ExtraSpecialType::kHitStars);
initAnim(AnimationTypes::kBigHit, AnimType::kAnimationAllThen, AnimationTypes::kStanding, actorIdx);
diff --git a/engines/twine/scene/collision.cpp b/engines/twine/scene/collision.cpp
index 75a68e3c5e4..2e57aa33bde 100644
--- a/engines/twine/scene/collision.cpp
+++ b/engines/twine/scene/collision.cpp
@@ -312,14 +312,14 @@ int32 Collision::checkObjCol(int32 actorIdx) {
}
if (actor->_dynamicFlags.bIsHitting) {
- const IVec3 &destPos = _engine->_movements->rotate(0, 200, actor->_beta);
+ const IVec2 &destPos = _engine->_renderer->rotate(0, 200, actor->_beta);
mins = processActor + actor->_boundingBox.mins;
mins.x += destPos.x;
- mins.z += destPos.z;
+ mins.z += destPos.y;
maxs = processActor + actor->_boundingBox.maxs;
maxs.x += destPos.x;
- maxs.z += destPos.z;
+ maxs.z += destPos.y;
for (int32 a = 0; a < _engine->_scene->_sceneNumActors; a++) {
const ActorStruct *actorTest = _engine->_scene->getActor(a);
diff --git a/engines/twine/scene/extra.cpp b/engines/twine/scene/extra.cpp
index bc847ac786a..18766248baf 100644
--- a/engines/twine/scene/extra.cpp
+++ b/engines/twine/scene/extra.cpp
@@ -135,14 +135,14 @@ void Extra::initFly(ExtraListStruct *extra, int32 xAngle, int32 yAngle, int32 x,
extra->lastPos = extra->pos;
- IVec3 destPos = _engine->_movements->rotate(x, 0, xAngle);
+ IVec2 destPos = _engine->_renderer->rotate(x, 0, xAngle);
- extra->destPos.y = -destPos.z;
+ extra->destPos.y = -destPos.y;
- destPos = _engine->_movements->rotate(0, destPos.x, yAngle);
+ destPos = _engine->_renderer->rotate(0, destPos.x, yAngle);
extra->destPos.x = destPos.x;
- extra->destPos.z = destPos.z;
+ extra->destPos.z = destPos.y;
extra->angle = extraAngle;
extra->spawnTime = _engine->timerRef;
@@ -403,10 +403,10 @@ void Extra::aff2DShape(const ExtraShape &shapeTable, int32 x, int32 y, int32 col
_engine->clearScreenMinMax(renderRect);
- IVec3 destPos = _engine->_movements->rotate(shapeX, shapeZ, angle);
+ IVec2 destPos = _engine->_renderer->rotate(shapeX, shapeZ, angle);
const int32 computedX = destPos.x + x;
- const int32 computedY = destPos.z + y;
+ const int32 computedY = destPos.y + y;
_engine->adjustScreenMax(renderRect, computedX, computedY);
@@ -421,10 +421,10 @@ void Extra::aff2DShape(const ExtraShape &shapeTable, int32 x, int32 y, int32 col
const int32 oldComputedX = currentX;
const int32 oldComputedY = currentY;
- destPos = _engine->_movements->rotate(shapeX, shapeZ, angle);
+ destPos = _engine->_renderer->rotate(shapeX, shapeZ, angle);
currentX = destPos.x + x;
- currentY = destPos.z + y;
+ currentY = destPos.y + y;
_engine->adjustScreenMax(renderRect, currentX, currentY);
_engine->_interface->drawLine(oldComputedX, oldComputedY, currentX, currentY, color);
@@ -584,12 +584,12 @@ void Extra::gereExtras() {
pos = 1;
}
- IVec3 destPos = _engine->_movements->rotate(pos, 0, angle2);
- extra->pos.y -= destPos.z;
+ IVec2 destPos = _engine->_renderer->rotate(pos, 0, angle2);
+ extra->pos.y -= destPos.y;
- destPos = _engine->_movements->rotate(0, destPos.x, tmpAngle);
+ destPos = _engine->_renderer->rotate(0, destPos.x, tmpAngle);
extra->pos.x += destPos.x;
- extra->pos.z += destPos.z;
+ extra->pos.z += destPos.y;
_engine->_movements->setActorAngle(LBAAngles::ANGLE_0, extra->destPos.z, LBAAngles::ANGLE_17, &extra->trackActorMove);
@@ -634,12 +634,12 @@ void Extra::gereExtras() {
pos = 1;
}
- IVec3 destPos = _engine->_movements->rotate(pos, 0, angle2);
- extra->pos.y -= destPos.z;
+ IVec2 destPos = _engine->_renderer->rotate(pos, 0, angle2);
+ extra->pos.y -= destPos.y;
- destPos = _engine->_movements->rotate(0, destPos.x, tmpAngle);
+ destPos = _engine->_renderer->rotate(0, destPos.x, tmpAngle);
extra->pos.x += destPos.x;
- extra->pos.z += destPos.z;
+ extra->pos.z += destPos.y;
_engine->_movements->setActorAngle(LBAAngles::ANGLE_0, extra->destPos.z, LBAAngles::ANGLE_17, &extra->trackActorMove);
diff --git a/engines/twine/scene/movements.cpp b/engines/twine/scene/movements.cpp
index 7fa76aa8e57..234cc75f07c 100644
--- a/engines/twine/scene/movements.cpp
+++ b/engines/twine/scene/movements.cpp
@@ -129,16 +129,6 @@ int32 Movements::getAngle(int32 x0, int32 z0, int32 x1, int32 z1) {
return ClampAngle(angle);
}
-IVec3 Movements::rotate(int32 side, int32 forward, int32 angle) {
- if (angle) {
- const double radians = AngleToRadians(angle);
- const int32 vx = (int32)((side * cos(radians) + forward * sin(radians)));
- const int32 vz = (int32)((forward * cos(radians) - side * sin(radians)));
- return IVec3(vx, 0, vz);
- }
- return IVec3(side, 0, forward);
-}
-
void Movements::initRealAngleConst(int32 start, int32 end, int32 duration, ActorMoveStruct *movePtr) const { // ManualRealAngle
const int16 cstart = ClampAngle(start);
const int16 cend = ClampAngle(end);
diff --git a/engines/twine/scene/movements.h b/engines/twine/scene/movements.h
index 88364390098..d860e4a0689 100644
--- a/engines/twine/scene/movements.h
+++ b/engines/twine/scene/movements.h
@@ -176,14 +176,6 @@ public:
return getAngle(v1.x, v1.z, v2.x, v2.z);
}
- /**
- * Calculate offset for the side and forward distances by the given angle of an actor
- * @param side Actor current X coordinate
- * @param forward Actor current Z coordinate
- * @param angle Actor angle to rotate
- */
- IVec3 rotate(int32 side, int32 forward, int32 angle);
-
/**
* Move actor around the scene
* @param start Current actor angle
diff --git a/engines/twine/scene/scene.cpp b/engines/twine/scene/scene.cpp
index ff1d30090c1..19fa63113d5 100644
--- a/engines/twine/scene/scene.cpp
+++ b/engines/twine/scene/scene.cpp
@@ -781,12 +781,12 @@ void Scene::checkZoneSce(int32 actorIdx) {
break;
case ZoneType::kLadder:
if (IS_HERO(actorIdx) && _engine->_actor->_heroBehaviour != HeroBehaviourType::kProtoPack && (actor->_genAnim == AnimationTypes::kForward || actor->_genAnim == AnimationTypes::kTopLadder || actor->_genAnim == AnimationTypes::kClimbLadder)) {
- IVec3 destPos = _engine->_movements->rotate(actor->_boundingBox.mins.x, actor->_boundingBox.mins.z, actor->_beta + LBAAngles::ANGLE_360 + LBAAngles::ANGLE_135);
+ IVec2 destPos = _engine->_renderer->rotate(actor->_boundingBox.mins.x, actor->_boundingBox.mins.z, actor->_beta + LBAAngles::ANGLE_360 + LBAAngles::ANGLE_135);
destPos.x += actor->_processActor.x;
- destPos.z += actor->_processActor.z;
+ destPos.y += actor->_processActor.z;
- if (destPos.x >= 0 && destPos.z >= 0 && destPos.x <= SCENE_SIZE_MAX && destPos.z <= SCENE_SIZE_MAX) {
- if (_engine->_grid->worldColBrick(destPos.x, actor->_pos.y + SIZE_BRICK_Y, destPos.z) != ShapeType::kNone) {
+ if (destPos.x >= 0 && destPos.y >= 0 && destPos.x <= SCENE_SIZE_MAX && destPos.y <= SCENE_SIZE_MAX) {
+ if (_engine->_grid->worldColBrick(destPos.x, actor->_pos.y + SIZE_BRICK_Y, destPos.y) != ShapeType::kNone) {
_flagClimbing = true;
if (actor->_pos.y >= (zone->mins.y + zone->maxs.y) / 2) {
_engine->_animations->initAnim(AnimationTypes::kTopLadder, AnimType::kAnimationAllThen, AnimationTypes::kStanding, actorIdx); // reached end of ladder
diff --git a/engines/twine/shared.h b/engines/twine/shared.h
index 4258552d105..8fed0ee0061 100644
--- a/engines/twine/shared.h
+++ b/engines/twine/shared.h
@@ -91,6 +91,25 @@ struct I16Vec3 {
#include "common/pack-end.h"
STATIC_ASSERT(sizeof(I16Vec3) == 6, "Unexpected pointTab size");
+struct IVec2 {
+ constexpr IVec2() : x(0), y(0) {}
+ constexpr IVec2(int32 _x, int32 _y) : x(_x), y(_y) {}
+ int32 x;
+ int32 y;
+
+ inline IVec2& operator+=(const IVec2 &other) {
+ x += other.x;
+ y += other.y;
+ return *this;
+ }
+
+ inline IVec2& operator-=(const IVec2 &other) {
+ x -= other.x;
+ y -= other.y;
+ return *this;
+ }
+};
+
struct IVec3 {
constexpr IVec3() : x(0), y(0), z(0) {}
constexpr IVec3(int32 _x, int32 _y, int32 _z) : x(_x), y(_y), z(_z) {}
diff --git a/engines/twine/twine.cpp b/engines/twine/twine.cpp
index 83a0bb6a23e..8d4ccb901ce 100644
--- a/engines/twine/twine.cpp
+++ b/engines/twine/twine.cpp
@@ -749,11 +749,11 @@ void TwinEEngine::processInventoryAction() {
case kiPenguin: {
ActorStruct *penguin = _scene->getActor(_scene->_mecaPenguinIdx);
- const IVec3 &destPos = _movements->rotate(0, 800, _scene->_sceneHero->_beta);
+ const IVec2 &destPos = _renderer->rotate(0, 800, _scene->_sceneHero->_beta);
penguin->_pos = _scene->_sceneHero->posObj();
penguin->_pos.x += destPos.x;
- penguin->_pos.z += destPos.z;
+ penguin->_pos.z += destPos.y;
penguin->_beta = _scene->_sceneHero->_beta;
debug("penguin angle: %i", penguin->_beta);
Commit: 1491e37f16485f9ef2af0da5ddefec277bcc280e
https://github.com/scummvm/scummvm/commit/1491e37f16485f9ef2af0da5ddefec277bcc280e
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2023-01-29T19:32:51+01:00
Commit Message:
TWINE: fixed short overflow error in setAngleCamera
Changed paths:
engines/twine/renderer/renderer.cpp
diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index 7e5cf3e9ac4..77ce7375aa2 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -144,37 +144,37 @@ IVec3 Renderer::setInverseAngleCamera(int32 x, int32 y, int32 z) {
IVec3 Renderer::setAngleCamera(int32 alpha, int32 beta, int32 gamma) {
const int32 cAlpha = ClampAngle(alpha);
- const int32 cBeta = ClampAngle(beta);
- const int32 cGamma = ClampAngle(gamma);
const int32 cAlpha2 = ClampAngle(alpha + LBAAngles::ANGLE_90);
- const int32 cBeta2 = ClampAngle(beta + LBAAngles::ANGLE_90);
+ const int32 nSin = sinTab[cAlpha];
+ const int32 nCos = sinTab[cAlpha2];
+ const int32 cGamma = ClampAngle(gamma);
const int32 cGamma2 = ClampAngle(gamma + LBAAngles::ANGLE_90);
- const int16 sinus1 = sinTab[cAlpha];
- const int16 cosinus1 = sinTab[cAlpha2];
- int16 sinus2 = sinTab[cGamma];
- int16 cosinus2 = sinTab[cGamma2];
-
- _matrixWorld.row1.x = cosinus2;
- _matrixWorld.row1.y = -sinus2;
- _matrixWorld.row2.x = (sinus2 * cosinus1) * SCENE_SIZE_HALF;
- _matrixWorld.row2.y = (cosinus2 * cosinus1) * SCENE_SIZE_HALF;
- _matrixWorld.row3.x = (sinus2 * sinus1) * SCENE_SIZE_HALF;
- _matrixWorld.row3.y = (cosinus2 * sinus1) * SCENE_SIZE_HALF;
-
- sinus2 = sinTab[cBeta];
- cosinus2 = sinTab[cBeta2];
-
- int32 x = _matrixWorld.row1.x;
- _matrixWorld.row1.x = (cosinus2 * x) * SCENE_SIZE_HALF;
- _matrixWorld.row1.z = (sinus2 * x) * SCENE_SIZE_HALF;
-
- x = _matrixWorld.row2.x;
- _matrixWorld.row2.x = ((cosinus2 * x) + (sinus2 * sinus1)) * SCENE_SIZE_HALF;
- _matrixWorld.row2.z = ((sinus2 * x) - (cosinus2 * sinus1)) * SCENE_SIZE_HALF;
-
- x = _matrixWorld.row3.x;
- _matrixWorld.row3.x = ((cosinus2 * x) - (sinus2 * cosinus1)) * SCENE_SIZE_HALF;
- _matrixWorld.row3.z = ((cosinus2 * cosinus1) + (sinus2 * x)) * SCENE_SIZE_HALF;
+ int32 nSin2 = sinTab[cGamma];
+ int32 nCos2 = sinTab[cGamma2];
+
+ _matrixWorld.row1.x = nCos2;
+ _matrixWorld.row1.y = -nSin2;
+ _matrixWorld.row2.x = (nSin2 * nCos) >> 14;
+ _matrixWorld.row2.y = (nCos2 * nCos) >> 14;
+ _matrixWorld.row3.x = (nSin2 * nSin) >> 14;
+ _matrixWorld.row3.y = (nCos2 * nSin) >> 14;
+
+ const int32 cBeta = ClampAngle(beta);
+ const int32 cBeta2 = ClampAngle(beta + LBAAngles::ANGLE_90);
+ nSin2 = sinTab[cBeta];
+ nCos2 = sinTab[cBeta2];
+
+ int32 h = _matrixWorld.row1.x;
+ _matrixWorld.row1.x = (nCos2 * h) >> 14;
+ _matrixWorld.row1.z = (nSin2 * h) >> 14;
+
+ h = _matrixWorld.row2.x;
+ _matrixWorld.row2.x = ((nCos2 * h) + (nSin2 * nSin)) >> 14;
+ _matrixWorld.row2.z = ((nSin2 * h) - (nCos2 * nSin)) >> 14;
+
+ h = _matrixWorld.row3.x;
+ _matrixWorld.row3.x = ((nCos2 * h) - (nSin2 * nCos)) >> 14;
+ _matrixWorld.row3.z = ((nCos2 * nCos) + (nSin2 * h)) >> 14;
_cameraRot = longWorldRot(_cameraPos.x, _cameraPos.y, _cameraPos.z);
Commit: f4768046997cfeabc8b29ef8676153289cfe592a
https://github.com/scummvm/scummvm/commit/f4768046997cfeabc8b29ef8676153289cfe592a
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2023-01-29T19:32:51+01:00
Commit Message:
TWINE: use int64 for the rotation
Changed paths:
engines/twine/renderer/renderer.cpp
diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index 77ce7375aa2..53f67309985 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -196,10 +196,10 @@ IVec3 Renderer::longWorldRot(int32 x, int32 y, int32 z) {
}
IVec3 Renderer::longInverseRot(int32 x, int32 y, int32 z) {
- const int32 vx = (_matrixWorld.row1.x * x + _matrixWorld.row2.x * y + _matrixWorld.row3.x * z) / SCENE_SIZE_HALF;
- const int32 vy = (_matrixWorld.row1.y * x + _matrixWorld.row2.y * y + _matrixWorld.row3.y * z) / SCENE_SIZE_HALF;
- const int32 vz = (_matrixWorld.row1.z * x + _matrixWorld.row2.z * y + _matrixWorld.row3.z * z) / SCENE_SIZE_HALF;
- return IVec3(vx, vy, vz);
+ const int64 vx = ((int64)_matrixWorld.row1.x * (int64)x + (int64)_matrixWorld.row2.x * (int64)y + (int64)_matrixWorld.row3.x * (int64)z) / SCENE_SIZE_HALF;
+ const int64 vy = ((int64)_matrixWorld.row1.y * (int64)x + (int64)_matrixWorld.row2.y * (int64)y + (int64)_matrixWorld.row3.y * (int64)z) / SCENE_SIZE_HALF;
+ const int64 vz = ((int64)_matrixWorld.row1.z * (int64)x + (int64)_matrixWorld.row2.z * (int64)y + (int64)_matrixWorld.row3.z * (int64)z) / SCENE_SIZE_HALF;
+ return IVec3((int32)vx, (int32)vy, (int32)vz);
}
IVec3 Renderer::rot(const IMatrix3x3 &matrix, int32 x, int32 y, int32 z) {
Commit: 179061b7df2db7c455fd411959f64f14be81deba
https://github.com/scummvm/scummvm/commit/179061b7df2db7c455fd411959f64f14be81deba
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2023-01-29T19:32:51+01:00
Commit Message:
TWINE: fixed cast warnings
Changed paths:
engines/twine/renderer/renderer.cpp
diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index 53f67309985..6a88990825e 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -310,9 +310,9 @@ bool isPolygonVisible(const ComputedVertex *vertices) { // TestVuePoly
void Renderer::rotList(const Common::Array<BodyVertex> &vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *rotationMatrix, const IVec3 &destPos) {
for (int32 i = 0; i < numPoints; ++i) {
const BodyVertex &vertex = vertices[i + firstPoint];
- destPoints->x = (int16)((rotationMatrix->row1.x * vertex.x + rotationMatrix->row1.y * vertex.y + rotationMatrix->row1.z * vertex.z) / SCENE_SIZE_HALF) + destPos.x;
- destPoints->y = (int16)((rotationMatrix->row2.x * vertex.x + rotationMatrix->row2.y * vertex.y + rotationMatrix->row2.z * vertex.z) / SCENE_SIZE_HALF) + destPos.y;
- destPoints->z = (int16)((rotationMatrix->row3.x * vertex.x + rotationMatrix->row3.y * vertex.y + rotationMatrix->row3.z * vertex.z) / SCENE_SIZE_HALF) + destPos.z;
+ destPoints->x = (int16)(((rotationMatrix->row1.x * vertex.x + rotationMatrix->row1.y * vertex.y + rotationMatrix->row1.z * vertex.z) / SCENE_SIZE_HALF) + destPos.x);
+ destPoints->y = (int16)(((rotationMatrix->row2.x * vertex.x + rotationMatrix->row2.y * vertex.y + rotationMatrix->row2.z * vertex.z) / SCENE_SIZE_HALF) + destPos.y);
+ destPoints->z = (int16)(((rotationMatrix->row3.x * vertex.x + rotationMatrix->row3.y * vertex.y + rotationMatrix->row3.z * vertex.z) / SCENE_SIZE_HALF) + destPos.z);
destPoints++;
}
Commit: d4aae98ac466a2ab5837a2ec42b2bb981e856290
https://github.com/scummvm/scummvm/commit/d4aae98ac466a2ab5837a2ec42b2bb981e856290
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2023-01-29T19:32:51+01:00
Commit Message:
TWINE: fixed cast warnings
Changed paths:
engines/twine/renderer/renderer.cpp
diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index 6a88990825e..278fec75883 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -350,9 +350,9 @@ void Renderer::processRotatedElement(IMatrix3x3 *targetMatrix, const Common::Arr
void Renderer::transRotList(const Common::Array<BodyVertex> &vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *translationMatrix, const IVec3 &angleVec, const IVec3 &destPos) {
for (int32 i = 0; i < numPoints; ++i) {
const BodyVertex &vertex = vertices[i + firstPoint];
- const int32 tmpX = vertex.x + angleVec.x;
- const int32 tmpY = vertex.y + angleVec.y;
- const int32 tmpZ = vertex.z + angleVec.z;
+ const int16 tmpX = (int16)(vertex.x + angleVec.x);
+ const int16 tmpY = (int16)(vertex.y + angleVec.y);
+ const int16 tmpZ = (int16)(vertex.z + angleVec.z);
destPoints->x = ((translationMatrix->row1.x * tmpX + translationMatrix->row1.y * tmpY + translationMatrix->row1.z * tmpZ) / SCENE_SIZE_HALF) + destPos.x;
destPoints->y = ((translationMatrix->row2.x * tmpX + translationMatrix->row2.y * tmpY + translationMatrix->row2.z * tmpZ) / SCENE_SIZE_HALF) + destPos.y;
Commit: 4c74a3410e10f6fa4cc34d81b04c0e14462ca9ba
https://github.com/scummvm/scummvm/commit/4c74a3410e10f6fa4cc34d81b04c0e14462ca9ba
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2023-01-29T19:32:51+01:00
Commit Message:
TWINE: renamed method to match the original sources
Changed paths:
engines/twine/renderer/renderer.cpp
engines/twine/renderer/renderer.h
diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index 278fec75883..f476a0107ff 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -363,7 +363,7 @@ void Renderer::transRotList(const Common::Array<BodyVertex> &vertices, int32 fir
}
// TranslateGroupe
-void Renderer::processTranslatedElement(IMatrix3x3 *targetMatrix, const Common::Array<BodyVertex> &vertices, int32 rotX, int32 rotY, int32 rotZ, const BodyBone &bone, ModelData *modelData) {
+void Renderer::translateGroup(IMatrix3x3 *targetMatrix, const Common::Array<BodyVertex> &vertices, int32 rotX, int32 rotY, int32 rotZ, const BodyBone &bone, ModelData *modelData) {
IVec3 renderAngle;
renderAngle.x = rotX;
renderAngle.y = rotY;
@@ -1565,7 +1565,7 @@ void Renderer::animModel(ModelData *modelData, const BodyData &bodyData, RenderC
if (boneData->type == 0) {
processRotatedElement(modelMatrix, vertices, boneData->x, boneData->y, boneData->z, bone, modelData);
} else if (boneData->type == 1) {
- processTranslatedElement(modelMatrix, vertices, boneData->x, boneData->y, boneData->z, bone, modelData);
+ translateGroup(modelMatrix, vertices, boneData->x, boneData->y, boneData->z, bone, modelData);
}
++modelMatrix;
diff --git a/engines/twine/renderer/renderer.h b/engines/twine/renderer/renderer.h
index 947e52a3a1e..2428c7fcc16 100644
--- a/engines/twine/renderer/renderer.h
+++ b/engines/twine/renderer/renderer.h
@@ -161,7 +161,7 @@ private:
void rotList(const Common::Array<BodyVertex>& vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *rotationMatrix, const IVec3 &destPos);
void processRotatedElement(IMatrix3x3 *targetMatrix, const Common::Array<BodyVertex>& vertices, int32 rotX, int32 rotY, int32 rotZ, const BodyBone &bone, ModelData *modelData);
void transRotList(const Common::Array<BodyVertex>& vertices, int32 firstPoint, int32 numPoints, I16Vec3 *destPoints, const IMatrix3x3 *translationMatrix, const IVec3 &angleVec, const IVec3 &destPos);
- void processTranslatedElement(IMatrix3x3 *targetMatrix, const Common::Array<BodyVertex>& vertices, int32 rotX, int32 rotY, int32 rotZ, const BodyBone &bone, ModelData *modelData);
+ void translateGroup(IMatrix3x3 *targetMatrix, const Common::Array<BodyVertex>& vertices, int32 rotX, int32 rotY, int32 rotZ, const BodyBone &bone, ModelData *modelData);
IVec3 rot(const IMatrix3x3 &matrix, int32 x, int32 y, int32 z);
IVec3 _cameraPos;
Commit: dd77f4bd8b6d460fd811333d6e00f7a9ce7f478e
https://github.com/scummvm/scummvm/commit/dd77f4bd8b6d460fd811333d6e00f7a9ce7f478e
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2023-01-29T19:32:51+01:00
Commit Message:
TWINE: renamed variables
Changed paths:
engines/twine/renderer/renderer.cpp
diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index f476a0107ff..1d4e8de3e13 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -238,61 +238,58 @@ void Renderer::rotMatIndex2(IMatrix3x3 *targetMatrix, const IMatrix3x3 *currentM
if (angleVec.x) {
int32 angle = angleVec.x;
- int32 angleVar2 = sinTab[ClampAngle(angle)];
- angle += LBAAngles::ANGLE_90;
- int32 angleVar1 = sinTab[ClampAngle(angle)];
+ int32 nSin = sinTab[ClampAngle(angle)];
+ int32 nCos = sinTab[ClampAngle(angle + LBAAngles::ANGLE_90)];
matrix1.row1.x = currentMatrix->row1.x;
matrix1.row2.x = currentMatrix->row2.x;
matrix1.row3.x = currentMatrix->row3.x;
- matrix1.row1.y = (currentMatrix->row1.z * angleVar2 + currentMatrix->row1.y * angleVar1) / SCENE_SIZE_HALF;
- matrix1.row1.z = (currentMatrix->row1.z * angleVar1 - currentMatrix->row1.y * angleVar2) / SCENE_SIZE_HALF;
- matrix1.row2.y = (currentMatrix->row2.z * angleVar2 + currentMatrix->row2.y * angleVar1) / SCENE_SIZE_HALF;
- matrix1.row2.z = (currentMatrix->row2.z * angleVar1 - currentMatrix->row2.y * angleVar2) / SCENE_SIZE_HALF;
- matrix1.row3.y = (currentMatrix->row3.z * angleVar2 + currentMatrix->row3.y * angleVar1) / SCENE_SIZE_HALF;
- matrix1.row3.z = (currentMatrix->row3.z * angleVar1 - currentMatrix->row3.y * angleVar2) / SCENE_SIZE_HALF;
+ matrix1.row1.y = (currentMatrix->row1.z * nSin + currentMatrix->row1.y * nCos) / SCENE_SIZE_HALF;
+ matrix1.row1.z = (currentMatrix->row1.z * nCos - currentMatrix->row1.y * nSin) / SCENE_SIZE_HALF;
+ matrix1.row2.y = (currentMatrix->row2.z * nSin + currentMatrix->row2.y * nCos) / SCENE_SIZE_HALF;
+ matrix1.row2.z = (currentMatrix->row2.z * nCos - currentMatrix->row2.y * nSin) / SCENE_SIZE_HALF;
+ matrix1.row3.y = (currentMatrix->row3.z * nSin + currentMatrix->row3.y * nCos) / SCENE_SIZE_HALF;
+ matrix1.row3.z = (currentMatrix->row3.z * nCos - currentMatrix->row3.y * nSin) / SCENE_SIZE_HALF;
} else {
matrix1 = *currentMatrix;
}
if (angleVec.z) {
int32 angle = angleVec.z;
- int32 angleVar2 = sinTab[ClampAngle(angle)];
- angle += LBAAngles::ANGLE_90;
- int32 angleVar1 = sinTab[ClampAngle(angle)];
+ int32 nSin = sinTab[ClampAngle(angle)];
+ int32 nCos = sinTab[ClampAngle(angle + LBAAngles::ANGLE_90)];
matrix2.row1.z = matrix1.row1.z;
matrix2.row2.z = matrix1.row2.z;
matrix2.row3.z = matrix1.row3.z;
- matrix2.row1.x = (matrix1.row1.y * angleVar2 + matrix1.row1.x * angleVar1) / SCENE_SIZE_HALF;
- matrix2.row1.y = (matrix1.row1.y * angleVar1 - matrix1.row1.x * angleVar2) / SCENE_SIZE_HALF;
- matrix2.row2.x = (matrix1.row2.y * angleVar2 + matrix1.row2.x * angleVar1) / SCENE_SIZE_HALF;
- matrix2.row2.y = (matrix1.row2.y * angleVar1 - matrix1.row2.x * angleVar2) / SCENE_SIZE_HALF;
- matrix2.row3.x = (matrix1.row3.y * angleVar2 + matrix1.row3.x * angleVar1) / SCENE_SIZE_HALF;
- matrix2.row3.y = (matrix1.row3.y * angleVar1 - matrix1.row3.x * angleVar2) / SCENE_SIZE_HALF;
+ matrix2.row1.x = (matrix1.row1.y * nSin + matrix1.row1.x * nCos) / SCENE_SIZE_HALF;
+ matrix2.row1.y = (matrix1.row1.y * nCos - matrix1.row1.x * nSin) / SCENE_SIZE_HALF;
+ matrix2.row2.x = (matrix1.row2.y * nSin + matrix1.row2.x * nCos) / SCENE_SIZE_HALF;
+ matrix2.row2.y = (matrix1.row2.y * nCos - matrix1.row2.x * nSin) / SCENE_SIZE_HALF;
+ matrix2.row3.x = (matrix1.row3.y * nSin + matrix1.row3.x * nCos) / SCENE_SIZE_HALF;
+ matrix2.row3.y = (matrix1.row3.y * nCos - matrix1.row3.x * nSin) / SCENE_SIZE_HALF;
} else {
matrix2 = matrix1;
}
if (angleVec.y) {
int32 angle = angleVec.y;
- int32 angleVar2 = sinTab[ClampAngle(angle)];
- angle += LBAAngles::ANGLE_90;
- int32 angleVar1 = sinTab[ClampAngle(angle)];
+ int32 nSin = sinTab[ClampAngle(angle)];
+ int32 nCos = sinTab[ClampAngle(angle + LBAAngles::ANGLE_90)];
targetMatrix->row1.y = matrix2.row1.y;
targetMatrix->row2.y = matrix2.row2.y;
targetMatrix->row3.y = matrix2.row3.y;
- targetMatrix->row1.x = (matrix2.row1.x * angleVar1 - matrix2.row1.z * angleVar2) / SCENE_SIZE_HALF;
- targetMatrix->row1.z = (matrix2.row1.x * angleVar2 + matrix2.row1.z * angleVar1) / SCENE_SIZE_HALF;
- targetMatrix->row2.x = (matrix2.row2.x * angleVar1 - matrix2.row2.z * angleVar2) / SCENE_SIZE_HALF;
- targetMatrix->row2.z = (matrix2.row2.x * angleVar2 + matrix2.row2.z * angleVar1) / SCENE_SIZE_HALF;
+ targetMatrix->row1.x = (matrix2.row1.x * nCos - matrix2.row1.z * nSin) / SCENE_SIZE_HALF;
+ targetMatrix->row1.z = (matrix2.row1.x * nSin + matrix2.row1.z * nCos) / SCENE_SIZE_HALF;
+ targetMatrix->row2.x = (matrix2.row2.x * nCos - matrix2.row2.z * nSin) / SCENE_SIZE_HALF;
+ targetMatrix->row2.z = (matrix2.row2.x * nSin + matrix2.row2.z * nCos) / SCENE_SIZE_HALF;
- targetMatrix->row3.x = (matrix2.row3.x * angleVar1 - matrix2.row3.z * angleVar2) / SCENE_SIZE_HALF;
- targetMatrix->row3.z = (matrix2.row3.x * angleVar2 + matrix2.row3.z * angleVar1) / SCENE_SIZE_HALF;
+ targetMatrix->row3.x = (matrix2.row3.x * nCos - matrix2.row3.z * nSin) / SCENE_SIZE_HALF;
+ targetMatrix->row3.z = (matrix2.row3.x * nSin + matrix2.row3.z * nCos) / SCENE_SIZE_HALF;
} else {
*targetMatrix = matrix2;
}
Commit: f7aeef424d826f93b221a7d0b7669414a78a690e
https://github.com/scummvm/scummvm/commit/f7aeef424d826f93b221a7d0b7669414a78a690e
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2023-01-29T19:32:51+01:00
Commit Message:
TWINE: renamed variables
Changed paths:
engines/twine/renderer/renderer.cpp
diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index 1d4e8de3e13..0b61d18f236 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -232,33 +232,34 @@ IVec2 Renderer::rotate(int32 side, int32 forward, int32 angle) const {
return IVec2(side, forward);
}
-void Renderer::rotMatIndex2(IMatrix3x3 *targetMatrix, const IMatrix3x3 *currentMatrix, const IVec3 &angleVec) {
+void Renderer::rotMatIndex2(IMatrix3x3 *pDest, const IMatrix3x3 *pSrc, const IVec3 &angleVec) {
IMatrix3x3 matrix1;
IMatrix3x3 matrix2;
-
- if (angleVec.x) {
- int32 angle = angleVec.x;
- int32 nSin = sinTab[ClampAngle(angle)];
- int32 nCos = sinTab[ClampAngle(angle + LBAAngles::ANGLE_90)];
-
- matrix1.row1.x = currentMatrix->row1.x;
- matrix1.row2.x = currentMatrix->row2.x;
- matrix1.row3.x = currentMatrix->row3.x;
-
- matrix1.row1.y = (currentMatrix->row1.z * nSin + currentMatrix->row1.y * nCos) / SCENE_SIZE_HALF;
- matrix1.row1.z = (currentMatrix->row1.z * nCos - currentMatrix->row1.y * nSin) / SCENE_SIZE_HALF;
- matrix1.row2.y = (currentMatrix->row2.z * nSin + currentMatrix->row2.y * nCos) / SCENE_SIZE_HALF;
- matrix1.row2.z = (currentMatrix->row2.z * nCos - currentMatrix->row2.y * nSin) / SCENE_SIZE_HALF;
- matrix1.row3.y = (currentMatrix->row3.z * nSin + currentMatrix->row3.y * nCos) / SCENE_SIZE_HALF;
- matrix1.row3.z = (currentMatrix->row3.z * nCos - currentMatrix->row3.y * nSin) / SCENE_SIZE_HALF;
+ const int32 lAlpha = angleVec.x;
+ const int32 lBeta = angleVec.y;
+ const int32 lGamma = angleVec.z;
+
+ if (lAlpha) {
+ int32 nSin = sinTab[ClampAngle(lAlpha)];
+ int32 nCos = sinTab[ClampAngle(lAlpha + LBAAngles::ANGLE_90)];
+
+ matrix1.row1.x = pSrc->row1.x;
+ matrix1.row2.x = pSrc->row2.x;
+ matrix1.row3.x = pSrc->row3.x;
+
+ matrix1.row1.y = (pSrc->row1.z * nSin + pSrc->row1.y * nCos) / SCENE_SIZE_HALF;
+ matrix1.row1.z = (pSrc->row1.z * nCos - pSrc->row1.y * nSin) / SCENE_SIZE_HALF;
+ matrix1.row2.y = (pSrc->row2.z * nSin + pSrc->row2.y * nCos) / SCENE_SIZE_HALF;
+ matrix1.row2.z = (pSrc->row2.z * nCos - pSrc->row2.y * nSin) / SCENE_SIZE_HALF;
+ matrix1.row3.y = (pSrc->row3.z * nSin + pSrc->row3.y * nCos) / SCENE_SIZE_HALF;
+ matrix1.row3.z = (pSrc->row3.z * nCos - pSrc->row3.y * nSin) / SCENE_SIZE_HALF;
} else {
- matrix1 = *currentMatrix;
+ matrix1 = *pSrc;
}
- if (angleVec.z) {
- int32 angle = angleVec.z;
- int32 nSin = sinTab[ClampAngle(angle)];
- int32 nCos = sinTab[ClampAngle(angle + LBAAngles::ANGLE_90)];
+ if (lGamma) {
+ int32 nSin = sinTab[ClampAngle(lGamma)];
+ int32 nCos = sinTab[ClampAngle(lGamma + LBAAngles::ANGLE_90)];
matrix2.row1.z = matrix1.row1.z;
matrix2.row2.z = matrix1.row2.z;
@@ -274,24 +275,23 @@ void Renderer::rotMatIndex2(IMatrix3x3 *targetMatrix, const IMatrix3x3 *currentM
matrix2 = matrix1;
}
- if (angleVec.y) {
- int32 angle = angleVec.y;
- int32 nSin = sinTab[ClampAngle(angle)];
- int32 nCos = sinTab[ClampAngle(angle + LBAAngles::ANGLE_90)];
+ if (lBeta) {
+ int32 nSin = sinTab[ClampAngle(lBeta)];
+ int32 nCos = sinTab[ClampAngle(lBeta + LBAAngles::ANGLE_90)];
- targetMatrix->row1.y = matrix2.row1.y;
- targetMatrix->row2.y = matrix2.row2.y;
- targetMatrix->row3.y = matrix2.row3.y;
+ pDest->row1.y = matrix2.row1.y;
+ pDest->row2.y = matrix2.row2.y;
+ pDest->row3.y = matrix2.row3.y;
- targetMatrix->row1.x = (matrix2.row1.x * nCos - matrix2.row1.z * nSin) / SCENE_SIZE_HALF;
- targetMatrix->row1.z = (matrix2.row1.x * nSin + matrix2.row1.z * nCos) / SCENE_SIZE_HALF;
- targetMatrix->row2.x = (matrix2.row2.x * nCos - matrix2.row2.z * nSin) / SCENE_SIZE_HALF;
- targetMatrix->row2.z = (matrix2.row2.x * nSin + matrix2.row2.z * nCos) / SCENE_SIZE_HALF;
+ pDest->row1.x = (matrix2.row1.x * nCos - matrix2.row1.z * nSin) / SCENE_SIZE_HALF;
+ pDest->row1.z = (matrix2.row1.x * nSin + matrix2.row1.z * nCos) / SCENE_SIZE_HALF;
+ pDest->row2.x = (matrix2.row2.x * nCos - matrix2.row2.z * nSin) / SCENE_SIZE_HALF;
+ pDest->row2.z = (matrix2.row2.x * nSin + matrix2.row2.z * nCos) / SCENE_SIZE_HALF;
- targetMatrix->row3.x = (matrix2.row3.x * nCos - matrix2.row3.z * nSin) / SCENE_SIZE_HALF;
- targetMatrix->row3.z = (matrix2.row3.x * nSin + matrix2.row3.z * nCos) / SCENE_SIZE_HALF;
+ pDest->row3.x = (matrix2.row3.x * nCos - matrix2.row3.z * nSin) / SCENE_SIZE_HALF;
+ pDest->row3.z = (matrix2.row3.x * nSin + matrix2.row3.z * nCos) / SCENE_SIZE_HALF;
} else {
- *targetMatrix = matrix2;
+ *pDest = matrix2;
}
}
Commit: 7e72fb59f249170d9a302472b0de90ae11111c24
https://github.com/scummvm/scummvm/commit/7e72fb59f249170d9a302472b0de90ae11111c24
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2023-01-29T19:32:51+01:00
Commit Message:
TWINE: renamed variables
Changed paths:
engines/twine/parser/anim.cpp
engines/twine/parser/anim.h
engines/twine/parser/body.cpp
engines/twine/renderer/renderer.cpp
engines/twine/renderer/renderer.h
diff --git a/engines/twine/parser/anim.cpp b/engines/twine/parser/anim.cpp
index 0b9dde8aa45..e2ec42390f6 100644
--- a/engines/twine/parser/anim.cpp
+++ b/engines/twine/parser/anim.cpp
@@ -26,7 +26,7 @@ namespace TwinE {
bool AnimData::loadBoneFrame(KeyFrame &keyframe, Common::SeekableReadStream &stream) {
BoneFrame boneframe;
- boneframe.type = stream.readSint16LE();
+ boneframe.type = (BoneType)stream.readSint16LE();
boneframe.x = stream.readSint16LE();
boneframe.y = stream.readSint16LE();
boneframe.z = stream.readSint16LE();
diff --git a/engines/twine/parser/anim.h b/engines/twine/parser/anim.h
index 6df7e7ba1fc..b4e7c2b93f1 100644
--- a/engines/twine/parser/anim.h
+++ b/engines/twine/parser/anim.h
@@ -29,13 +29,14 @@
namespace TwinE {
+enum BoneType : uint16 {
+ TYPE_ROTATE = 0,
+ TYPE_TRANSLATE = 1,
+ TYPE_ZOOM = 2,
+};
+
struct BoneFrame {
- /**
- * 0 = allow global rotate
- * 1 = disallow global rotate
- * 2 = disallow global rotate and hide
- */
- uint16 type = 0;
+ BoneType type = BoneType::TYPE_ROTATE;
int16 x = 0;
int16 y = 0;
int16 z = 0;
diff --git a/engines/twine/parser/body.cpp b/engines/twine/parser/body.cpp
index 9417cb2dbe7..619f1e5ae92 100644
--- a/engines/twine/parser/body.cpp
+++ b/engines/twine/parser/body.cpp
@@ -61,7 +61,7 @@ void BodyData::loadBones(Common::SeekableReadStream &stream) {
const int16 basePoint = stream.readSint16LE() / 6;
const int16 baseElementOffset = stream.readSint16LE();
BoneFrame boneframe;
- boneframe.type = stream.readSint16LE();
+ boneframe.type = (BoneType)stream.readSint16LE();
boneframe.x = stream.readSint16LE();
boneframe.y = stream.readSint16LE();
boneframe.z = stream.readSint16LE();
diff --git a/engines/twine/renderer/renderer.cpp b/engines/twine/renderer/renderer.cpp
index 0b61d18f236..bef508ba7d5 100644
--- a/engines/twine/renderer/renderer.cpp
+++ b/engines/twine/renderer/renderer.cpp
@@ -385,9 +385,9 @@ void Renderer::translateGroup(IMatrix3x3 *targetMatrix, const Common::Array<Body
void Renderer::setLightVector(int32 angleX, int32 angleY, int32 angleZ) {
const int32 normalUnit = 64;
const IVec3 renderAngle(angleX, angleY, angleZ);
- IMatrix3x3 matrix;
- rotMatIndex2(&matrix, &_matrixWorld, renderAngle);
- _normalLight = rot(matrix, 0, 0, normalUnit - 5);
+ IMatrix3x3 rotationMatrix;
+ rotMatIndex2(&rotationMatrix, &_matrixWorld, renderAngle);
+ _normalLight = rot(rotationMatrix, 0, 0, normalUnit - 5);
}
int16 Renderer::leftClip(int16 polyRenderType, ComputedVertex** offTabPoly, int32 numVertices) {
@@ -1537,7 +1537,7 @@ bool Renderer::renderObjectIso(const BodyData &bodyData, RenderCommand **renderC
return true;
}
-void Renderer::animModel(ModelData *modelData, const BodyData &bodyData, RenderCommand *renderCmds, const IVec3 &angleVec, const IVec3 &renderPos, Common::Rect &modelRect) {
+void Renderer::animModel(ModelData *modelData, const BodyData &bodyData, RenderCommand *renderCmds, const IVec3 &angleVec, const IVec3 &poswr, Common::Rect &modelRect) {
const int32 numVertices = bodyData.getNumVertices();
const int32 numBones = bodyData.getNumBones();
@@ -1559,10 +1559,12 @@ void Renderer::animModel(ModelData *modelData, const BodyData &bodyData, RenderC
const BodyBone &bone = bodyData.getBone(boneIdx);
const BoneFrame *boneData = bodyData.getBoneState(boneIdx);
- if (boneData->type == 0) {
+ if (boneData->type == BoneType::TYPE_ROTATE) {
processRotatedElement(modelMatrix, vertices, boneData->x, boneData->y, boneData->z, bone, modelData);
- } else if (boneData->type == 1) {
+ } else if (boneData->type == BoneType::TYPE_TRANSLATE) {
translateGroup(modelMatrix, vertices, boneData->x, boneData->y, boneData->z, bone, modelData);
+ } else if (boneData->type == BoneType::TYPE_ZOOM) {
+ // unsupported type
}
++modelMatrix;
@@ -1577,13 +1579,13 @@ void Renderer::animModel(ModelData *modelData, const BodyData &bodyData, RenderC
if (_isUsingIsoProjection) {
do {
- const int32 coX = pointPtr->x + renderPos.x;
- const int32 coY = pointPtr->y + renderPos.y;
- const int32 coZ = -(pointPtr->z + renderPos.z);
+ const int32 coX = pointPtr->x + poswr.x;
+ const int32 coY = pointPtr->y + poswr.y;
+ const int32 coZ = -(pointPtr->z + poswr.z);
- pointPtrDest->x = (coX + coZ) * 24 / ISO_SCALE + _projectionCenter.x;
- pointPtrDest->y = (((coX - coZ) * 12) - coY * 30) / ISO_SCALE + _projectionCenter.y;
- pointPtrDest->z = coZ - coX - coY;
+ pointPtrDest->x = (int16)((coX + coZ) * 24 / ISO_SCALE + _projectionCenter.x);
+ pointPtrDest->y = (int16)((((coX - coZ) * 12) - coY * 30) / ISO_SCALE + _projectionCenter.y);
+ pointPtrDest->z = (int16)(coZ - coX - coY);
if (pointPtrDest->x < modelRect.left) {
modelRect.left = pointPtrDest->x;
@@ -1604,16 +1606,16 @@ void Renderer::animModel(ModelData *modelData, const BodyData &bodyData, RenderC
} while (--numOfPrimitives);
} else {
do {
- int32 coZ = _kFactor - (pointPtr->z + renderPos.z);
+ int32 coZ = _kFactor - (pointPtr->z + poswr.z);
if (coZ <= 0) {
coZ = 0x7FFFFFFF;
}
- int32 coX = (((pointPtr->x + renderPos.x) * _lFactorX) / coZ) + _projectionCenter.x;
+ int32 coX = (((pointPtr->x + poswr.x) * _lFactorX) / coZ) + _projectionCenter.x;
if (coX > 0xFFFF) {
coX = 0x7FFF;
}
- pointPtrDest->x = coX;
+ pointPtrDest->x = (int16)coX;
if (pointPtrDest->x < modelRect.left) {
modelRect.left = pointPtrDest->x;
}
@@ -1621,11 +1623,11 @@ void Renderer::animModel(ModelData *modelData, const BodyData &bodyData, RenderC
modelRect.right = pointPtrDest->x;
}
- int32 coY = _projectionCenter.y - (((pointPtr->y + renderPos.y) * _lFactorY) / coZ);
+ int32 coY = _projectionCenter.y - (((pointPtr->y + poswr.y) * _lFactorY) / coZ);
if (coY > 0xFFFF) {
coY = 0x7FFF;
}
- pointPtrDest->y = coY;
+ pointPtrDest->y = (int16)coY;
if (pointPtrDest->y < modelRect.top) {
modelRect.top = pointPtrDest->y;
}
@@ -1636,7 +1638,7 @@ void Renderer::animModel(ModelData *modelData, const BodyData &bodyData, RenderC
if (coZ > 0xFFFF) {
coZ = 0x7FFF;
}
- pointPtrDest->z = coZ;
+ pointPtrDest->z = (int16)coZ;
pointPtr++;
pointPtrDest++;
@@ -1644,7 +1646,7 @@ void Renderer::animModel(ModelData *modelData, const BodyData &bodyData, RenderC
} while (--numOfPrimitives);
}
- int32 numNormals = bodyData.getNormals().size();
+ int32 numNormals = (int32)bodyData.getNormals().size();
if (numNormals) { // process normal data
uint16 *currentShadeDestination = (uint16 *)modelData->normalTable;
@@ -1652,8 +1654,8 @@ void Renderer::animModel(ModelData *modelData, const BodyData &bodyData, RenderC
numOfPrimitives = numBones;
- int shadeIndex = 0;
- int boneIdx = 0;
+ int16 shadeIndex = 0;
+ int16 boneIdx = 0;
do { // for each element
numNormals = bodyData.getBone(boneIdx).numNormals;
@@ -1702,13 +1704,13 @@ bool Renderer::affObjetIso(int32 x, int32 y, int32 z, int32 alpha, int32 beta, i
modelRect.right = SCENE_SIZE_MIN;
modelRect.bottom = SCENE_SIZE_MIN;
- IVec3 renderPos;
+ IVec3 poswr; // PosXWr, PosYWr, PosZWr
if (!_isUsingIsoProjection) {
- renderPos = longWorldRot(x, y, z) - _cameraRot;
+ poswr = longWorldRot(x, y, z) - _cameraRot;
} else {
- renderPos.x = x;
- renderPos.y = y;
- renderPos.z = z;
+ poswr.x = x;
+ poswr.y = y;
+ poswr.z = z;
}
if (!bodyData.isAnimated()) {
@@ -1723,7 +1725,7 @@ bool Renderer::affObjetIso(int32 x, int32 y, int32 z, int32 alpha, int32 beta, i
}
// restart at the beginning of the renderTable
RenderCommand *renderCmds = _renderCmds;
- animModel(&_modelData, bodyData, renderCmds, renderAngle, renderPos, modelRect);
+ animModel(&_modelData, bodyData, renderCmds, renderAngle, poswr, modelRect);
if (!renderObjectIso(bodyData, &renderCmds, &_modelData, modelRect)) {
modelRect.right = -1;
modelRect.bottom = -1;
diff --git a/engines/twine/renderer/renderer.h b/engines/twine/renderer/renderer.h
index 2428c7fcc16..a3f97b3462f 100644
--- a/engines/twine/renderer/renderer.h
+++ b/engines/twine/renderer/renderer.h
@@ -173,7 +173,7 @@ private:
IMatrix3x3 _matrixWorld;
IMatrix3x3 _matricesTable[30 + 1];
- IVec3 _normalLight; // NormalXLight
+ IVec3 _normalLight; // NormalXLight, NormalYLight, NormalZLight
IVec3 _cameraRot;
RenderCommand _renderCmds[1000];
Commit: 302b65ed74a02f6e64ee7948e4f2371ea0a40c12
https://github.com/scummvm/scummvm/commit/302b65ed74a02f6e64ee7948e4f2371ea0a40c12
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2023-01-29T19:32:51+01:00
Commit Message:
TWINE: renamed methods
Changed paths:
engines/twine/scene/animations.cpp
engines/twine/scene/animations.h
diff --git a/engines/twine/scene/animations.cpp b/engines/twine/scene/animations.cpp
index b5366a2c42b..3e2134a0f08 100644
--- a/engines/twine/scene/animations.cpp
+++ b/engines/twine/scene/animations.cpp
@@ -60,7 +60,7 @@ int32 Animations::searchAnim(AnimationTypes animIdx, int32 actorIdx) {
return bodyAnimIndex;
}
-int16 Animations::applyAnimStepRotation(int32 deltaTime, int32 keyFrameLength, int16 newAngle1, int16 lastAngle1) const {
+int16 Animations::patchInterAngle(int32 deltaTime, int32 keyFrameLength, int16 newAngle1, int16 lastAngle1) const {
const int16 lastAngle = ClampAngle(lastAngle1);
const int16 newAngle = ClampAngle(newAngle1);
@@ -82,7 +82,7 @@ int16 Animations::applyAnimStepRotation(int32 deltaTime, int32 keyFrameLength, i
return ClampAngle(computedAngle);
}
-int16 Animations::applyAnimStepTranslation(int32 deltaTime, int32 keyFrameLength, int16 newPos, int16 lastPos) const {
+int16 Animations::patchInterStep(int32 deltaTime, int32 keyFrameLength, int16 newPos, int16 lastPos) const {
int16 distance = newPos - lastPos;
int16 computedPos;
@@ -145,16 +145,16 @@ bool Animations::setModelAnimation(int32 keyframeIdx, const AnimData &animData,
boneState->type = boneFrame.type;
switch (boneFrame.type) {
- case 0:
- boneState->x = applyAnimStepRotation(deltaTime, keyFrameLength, boneFrame.x, lastBoneFrame.x);
- boneState->y = applyAnimStepRotation(deltaTime, keyFrameLength, boneFrame.y, lastBoneFrame.y);
- boneState->z = applyAnimStepRotation(deltaTime, keyFrameLength, boneFrame.z, lastBoneFrame.z);
+ case BoneType::TYPE_ROTATE:
+ boneState->x = patchInterAngle(deltaTime, keyFrameLength, boneFrame.x, lastBoneFrame.x);
+ boneState->y = patchInterAngle(deltaTime, keyFrameLength, boneFrame.y, lastBoneFrame.y);
+ boneState->z = patchInterAngle(deltaTime, keyFrameLength, boneFrame.z, lastBoneFrame.z);
break;
- case 1:
- case 2:
- boneState->x = applyAnimStepTranslation(deltaTime, keyFrameLength, boneFrame.x, lastBoneFrame.x);
- boneState->y = applyAnimStepTranslation(deltaTime, keyFrameLength, boneFrame.y, lastBoneFrame.y);
- boneState->z = applyAnimStepTranslation(deltaTime, keyFrameLength, boneFrame.z, lastBoneFrame.z);
+ case BoneType::TYPE_TRANSLATE:
+ case BoneType::TYPE_ZOOM:
+ boneState->x = patchInterStep(deltaTime, keyFrameLength, boneFrame.x, lastBoneFrame.x);
+ boneState->y = patchInterStep(deltaTime, keyFrameLength, boneFrame.y, lastBoneFrame.y);
+ boneState->z = patchInterStep(deltaTime, keyFrameLength, boneFrame.z, lastBoneFrame.z);
break;
default:
error("Unsupported animation rotation mode %d", boneFrame.type);
diff --git a/engines/twine/scene/animations.h b/engines/twine/scene/animations.h
index 388bcd5daaa..126c9f4114b 100644
--- a/engines/twine/scene/animations.h
+++ b/engines/twine/scene/animations.h
@@ -34,8 +34,8 @@ class TwinEEngine;
class Animations {
private:
TwinEEngine *_engine;
- int16 applyAnimStepRotation(int32 deltaTime, int32 keyFrameLength, int16 newAngle1, int16 lastAngle1) const;
- int16 applyAnimStepTranslation(int32 deltaTime, int32 keyFrameLength, int16 newPos, int16 lastPos) const;
+ int16 patchInterAngle(int32 deltaTime, int32 keyFrameLength, int16 newAngle1, int16 lastAngle1) const;
+ int16 patchInterStep(int32 deltaTime, int32 keyFrameLength, int16 newPos, int16 lastPos) const;
/**
* Verify animation at keyframe
@@ -52,7 +52,7 @@ private:
KeyFrame _animKeyframeBuf[32];
/** Rotation by anim and not by engine */
- int16 _processRotationByAnim = 0; // processActorVar5
+ int16 _processRotationByAnim = 0; // AnimMasterRot
/** Last rotation angle */
int16 _processLastRotationAngle = 0; // processActorVar6
Commit: 252b4670e6133b0f37099ce651279a646a78b9a3
https://github.com/scummvm/scummvm/commit/252b4670e6133b0f37099ce651279a646a78b9a3
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2023-01-29T19:32:51+01:00
Commit Message:
TWINE: again renaming
Changed paths:
engines/twine/holomap.cpp
engines/twine/menu/menu.cpp
engines/twine/parser/anim.cpp
engines/twine/parser/anim.h
engines/twine/renderer/redraw.cpp
engines/twine/scene/animations.cpp
engines/twine/scene/animations.h
engines/twine/scene/gamestate.cpp
diff --git a/engines/twine/holomap.cpp b/engines/twine/holomap.cpp
index 0b82382d8b8..8a8a507e712 100644
--- a/engines/twine/holomap.cpp
+++ b/engines/twine/holomap.cpp
@@ -303,7 +303,7 @@ void Holomap::renderHolomapVehicle(uint &frameNumber, ActorMoveStruct &move, Ani
_engine->_movements->initRealAngle(LBAAngles::ANGLE_0, -LBAAngles::ANGLE_90, 500, &move);
}
- if (_engine->_animations->setModelAnimation(frameNumber, animData, bodyData, &animTimerData)) {
+ if (_engine->_animations->doSetInterAnimObjet(frameNumber, animData, bodyData, &animTimerData)) {
frameNumber++;
if (frameNumber >= animData.getNumKeyframes()) {
frameNumber = animData.getLoopFrame();
diff --git a/engines/twine/menu/menu.cpp b/engines/twine/menu/menu.cpp
index 96b5b7ba15f..9ee1e035358 100644
--- a/engines/twine/menu/menu.cpp
+++ b/engines/twine/menu/menu.cpp
@@ -1021,7 +1021,7 @@ void Menu::drawBehaviour(int32 left, int32 top, HeroBehaviourType behaviour, int
uint currentAnimState = _behaviourAnimState[(byte)behaviour];
- if (_engine->_animations->setModelAnimation(currentAnimState, currentAnimData, *_behaviourEntity, &_behaviourAnimData[(byte)behaviour])) {
+ if (_engine->_animations->doSetInterAnimObjet(currentAnimState, currentAnimData, *_behaviourEntity, &_behaviourAnimData[(byte)behaviour])) {
currentAnimState++; // keyframe
if (currentAnimState >= currentAnimData.getNumKeyframes()) {
currentAnimState = currentAnimData.getLoopFrame();
diff --git a/engines/twine/parser/anim.cpp b/engines/twine/parser/anim.cpp
index e2ec42390f6..dc3415bb3dd 100644
--- a/engines/twine/parser/anim.cpp
+++ b/engines/twine/parser/anim.cpp
@@ -24,14 +24,13 @@
namespace TwinE {
-bool AnimData::loadBoneFrame(KeyFrame &keyframe, Common::SeekableReadStream &stream) {
+void AnimData::loadBoneFrame(KeyFrame &keyframe, Common::SeekableReadStream &stream) {
BoneFrame boneframe;
boneframe.type = (BoneType)stream.readSint16LE();
boneframe.x = stream.readSint16LE();
boneframe.y = stream.readSint16LE();
boneframe.z = stream.readSint16LE();
keyframe.boneframes.push_back(boneframe);
- return boneframe.type != 0;
}
void AnimData::loadKeyFrames(Common::SeekableReadStream &stream) {
@@ -42,6 +41,12 @@ void AnimData::loadKeyFrames(Common::SeekableReadStream &stream) {
keyframe.y = stream.readSint16LE();
keyframe.z = stream.readSint16LE();
+ keyframe.animMasterRot = stream.readSint16LE();
+ keyframe.animStepAlpha = stream.readSint16LE();
+ keyframe.animStepBeta = stream.readSint16LE();
+ keyframe.animStepGamma = stream.readSint16LE();
+ stream.seek(-8, SEEK_CUR);
+
for (uint16 j = 0U; j < _numBoneframes; ++j) {
loadBoneFrame(keyframe, stream);
}
diff --git a/engines/twine/parser/anim.h b/engines/twine/parser/anim.h
index b4e7c2b93f1..a10b948aa21 100644
--- a/engines/twine/parser/anim.h
+++ b/engines/twine/parser/anim.h
@@ -47,6 +47,10 @@ struct KeyFrame {
int16 x = 0;
int16 y = 0;
int16 z = 0;
+ int16 animMasterRot = 0;
+ int16 animStepAlpha = 0;
+ int16 animStepBeta = 0;
+ int16 animStepGamma = 0;
Common::Array<BoneFrame> boneframes;
};
@@ -54,7 +58,7 @@ class AnimData : public Parser {
private:
Common::Array<KeyFrame> _keyframes;
- bool loadBoneFrame(KeyFrame &keyframe, Common::SeekableReadStream &stream);
+ void loadBoneFrame(KeyFrame &keyframe, Common::SeekableReadStream &stream);
void loadKeyFrames(Common::SeekableReadStream &stream);
uint16 _numKeyframes;
diff --git a/engines/twine/renderer/redraw.cpp b/engines/twine/renderer/redraw.cpp
index fb8c3e015fa..9639b6dd19b 100644
--- a/engines/twine/renderer/redraw.cpp
+++ b/engines/twine/renderer/redraw.cpp
@@ -360,7 +360,7 @@ void Redraw::processDrawListActors(const DrawListStruct &drawCmd, bool bgRedraw)
ActorStruct *actor = _engine->_scene->getActor(actorIdx);
if (actor->_anim >= 0) {
const AnimData &animData = _engine->_resources->_animData[actor->_anim];
- _engine->_animations->setModelAnimation(actor->_frame, animData, _engine->_resources->_bodyData[actor->_body], &actor->_animTimerData);
+ _engine->_animations->doSetInterAnimObjet(actor->_frame, animData, _engine->_resources->_bodyData[actor->_body], &actor->_animTimerData);
}
const IVec3 &delta = actor->posObj() - _engine->_grid->_worldCube;
diff --git a/engines/twine/scene/animations.cpp b/engines/twine/scene/animations.cpp
index 3e2134a0f08..d9effeaee42 100644
--- a/engines/twine/scene/animations.cpp
+++ b/engines/twine/scene/animations.cpp
@@ -95,7 +95,7 @@ int16 Animations::patchInterStep(int32 deltaTime, int32 keyFrameLength, int16 ne
return computedPos;
}
-bool Animations::setModelAnimation(int32 keyframeIdx, const AnimData &animData, BodyData &bodyData, AnimTimerDataStruct *animTimerDataPtr) {
+bool Animations::doSetInterAnimObjet(int32 keyframeIdx, const AnimData &animData, BodyData &bodyData, AnimTimerDataStruct *animTimerDataPtr) {
if (!bodyData.isAnimated()) {
return false;
}
@@ -105,8 +105,8 @@ bool Animations::setModelAnimation(int32 keyframeIdx, const AnimData &animData,
_currentStep.y = keyFrame->y;
_currentStep.z = keyFrame->z;
- _processRotationByAnim = keyFrame->boneframes[0].type;
- _processLastRotationAngle = ToAngle(keyFrame->boneframes[0].y);
+ _animMasterRot = keyFrame->animMasterRot;
+ _animStepBeta = ToAngle(keyFrame->animStepBeta);
const int16 numBones = bodyData.getNumBones();
@@ -130,7 +130,7 @@ bool Animations::setModelAnimation(int32 keyframeIdx, const AnimData &animData,
return true;
}
- _processLastRotationAngle = (_processLastRotationAngle * deltaTime) / keyFrameLength;
+ _animStepBeta = (_animStepBeta * deltaTime) / keyFrameLength;
if (numOfBonesInAnim <= 1) {
return false;
@@ -182,8 +182,8 @@ void Animations::setAnimObjet(int32 keyframeIdx, const AnimData &animData, BodyD
_currentStep.y = keyFrame->y;
_currentStep.z = keyFrame->z;
- _processRotationByAnim = keyFrame->boneframes[0].type;
- _processLastRotationAngle = ToAngle(keyFrame->boneframes[0].y);
+ _animMasterRot = keyFrame->animMasterRot;
+ _animStepBeta = ToAngle(keyFrame->animStepBeta);
animTimerDataPtr->ptr = animData.getKeyframe(keyframeIdx);
animTimerDataPtr->time = _engine->timerRef;
@@ -244,9 +244,8 @@ bool Animations::verifyAnimAtKeyframe(int32 keyframeIdx, const AnimData &animDat
_currentStep.y = keyFrame->y;
_currentStep.z = keyFrame->z;
- const BoneFrame &boneFrame = keyFrame->boneframes[0];
- _processRotationByAnim = boneFrame.type;
- _processLastRotationAngle = ToAngle(boneFrame.y);
+ _animMasterRot = keyFrame->animMasterRot;
+ _animStepBeta = ToAngle(keyFrame->animStepBeta);
if (deltaTime >= keyFrameLength) {
animTimerDataPtr->ptr = animData.getKeyframe(keyframeIdx);
@@ -254,7 +253,7 @@ bool Animations::verifyAnimAtKeyframe(int32 keyframeIdx, const AnimData &animDat
return true;
}
- _processLastRotationAngle = (_processLastRotationAngle * deltaTime) / keyFrameLength;
+ _animStepBeta = (_animStepBeta * deltaTime) / keyFrameLength;
_currentStep.x = (_currentStep.x * deltaTime) / keyFrameLength;
_currentStep.y = (_currentStep.y * deltaTime) / keyFrameLength;
_currentStep.z = (_currentStep.z * deltaTime) / keyFrameLength;
@@ -570,14 +569,14 @@ void Animations::doAnim(int32 actorIdx) {
keyFramePassed = verifyAnimAtKeyframe(actor->_frame, animData, &actor->_animTimerData);
}
- if (_processRotationByAnim) {
+ if (_animMasterRot) {
actor->_dynamicFlags.bIsRotationByAnim = 1;
} else {
actor->_dynamicFlags.bIsRotationByAnim = 0;
}
- actor->_beta = ClampAngle(actor->_beta + _processLastRotationAngle - actor->_animStepBeta);
- actor->_animStepBeta = _processLastRotationAngle;
+ actor->_beta = ClampAngle(actor->_beta + _animStepBeta - actor->_animStepBeta);
+ actor->_animStepBeta = _animStepBeta;
const IVec2 &destPos = _engine->_renderer->rotate(_currentStep.x, _currentStep.z, actor->_beta);
diff --git a/engines/twine/scene/animations.h b/engines/twine/scene/animations.h
index 126c9f4114b..17cc49a2e87 100644
--- a/engines/twine/scene/animations.h
+++ b/engines/twine/scene/animations.h
@@ -52,9 +52,9 @@ private:
KeyFrame _animKeyframeBuf[32];
/** Rotation by anim and not by engine */
- int16 _processRotationByAnim = 0; // AnimMasterRot
+ int16 _animMasterRot = 0; // AnimMasterRot
/** Last rotation angle */
- int16 _processLastRotationAngle = 0; // processActorVar6
+ int16 _animStepBeta = 0; // AnimStepBeta
/** Current step coordinates */
IVec3 _currentStep;
@@ -81,7 +81,7 @@ public:
* @param bodyData Body model data
* @param animTimerDataPtr Animation time data
*/
- bool setModelAnimation(int32 keyframeIdx, const AnimData &animData, BodyData &bodyData, AnimTimerDataStruct *animTimerDataPtr);
+ bool doSetInterAnimObjet(int32 keyframeIdx, const AnimData &animData, BodyData &bodyData, AnimTimerDataStruct *animTimerDataPtr);
/**
* Get entity anim index (This is taken from File3D entities)
diff --git a/engines/twine/scene/gamestate.cpp b/engines/twine/scene/gamestate.cpp
index b40f3bbb1a1..7ebb9cfcb39 100644
--- a/engines/twine/scene/gamestate.cpp
+++ b/engines/twine/scene/gamestate.cpp
@@ -405,7 +405,7 @@ void GameState::doFoundObj(InventoryItems item) {
_engine->_interface->unsetClip();
init3DGame();
- if (_engine->_animations->setModelAnimation(currentAnimState, currentAnimData, bodyData, &_engine->_scene->_sceneHero->_animTimerData)) {
+ if (_engine->_animations->doSetInterAnimObjet(currentAnimState, currentAnimData, bodyData, &_engine->_scene->_sceneHero->_animTimerData)) {
currentAnimState++; // keyframe
if (currentAnimState >= currentAnimData.getNumKeyframes()) {
currentAnimState = currentAnimData.getLoopFrame();
Commit: 658fb4ccbc301b425e593a9370560e02e3106f62
https://github.com/scummvm/scummvm/commit/658fb4ccbc301b425e593a9370560e02e3106f62
Author: Martin Gerhardy (martin.gerhardy at gmail.com)
Date: 2023-01-29T19:32:51+01:00
Commit Message:
TWINE: reverted implementation of getAngle
to the state before 2e53c0fa3fb5d9c52fd396ff3ba5c63fda72da5d - it broke the sokoban scene
Changed paths:
engines/twine/scene/movements.cpp
diff --git a/engines/twine/scene/movements.cpp b/engines/twine/scene/movements.cpp
index 234cc75f07c..5993c03150f 100644
--- a/engines/twine/scene/movements.cpp
+++ b/engines/twine/scene/movements.cpp
@@ -75,6 +75,58 @@ void Movements::setActorAngle(int16 startAngle, int16 endAngle, int16 stepAngle,
}
int32 Movements::getAngle(int32 x0, int32 z0, int32 x1, int32 z1) {
+#if 1
+ int32 difZ = z1 - z0;
+ const int32 newZ = difZ * difZ;
+
+ int32 difX = x1 - x0;
+ const int32 newX = difX * difX;
+
+ bool flag;
+ // Exchange X and Z
+ if (newX < newZ) {
+ const int32 tmpEx = difX;
+ difX = difZ;
+ difZ = tmpEx;
+
+ flag = true;
+ } else {
+ flag = false;
+ }
+
+ _targetActorDistance = (int32)sqrt((float)(newX + newZ));
+
+ if (!_targetActorDistance) {
+ return 0;
+ }
+
+ const int32 destAngle = (difZ * SCENE_SIZE_HALF) / _targetActorDistance;
+
+ int32 startAngle = LBAAngles::ANGLE_0;
+ // stopAngle = LBAAngles::ANGLE_90;
+ const int16 *shadeAngleTab3(&sinTab[LBAAngles::ANGLE_135]);
+ while (shadeAngleTab3[startAngle] > destAngle) {
+ startAngle++;
+ }
+
+ if (shadeAngleTab3[startAngle] != destAngle) {
+ if ((shadeAngleTab3[startAngle - 1] + shadeAngleTab3[startAngle]) / 2 <= destAngle) {
+ startAngle--;
+ }
+ }
+
+ int32 finalAngle = LBAAngles::ANGLE_45 + startAngle;
+
+ if (difX <= 0) {
+ finalAngle = -finalAngle;
+ }
+
+ if (flag) {
+ finalAngle = -finalAngle + LBAAngles::ANGLE_90;
+ }
+
+ return ClampAngle(finalAngle);
+#else
z1 -= z0;
x1 -= x0;
const int32 x2 = x1 * x1;
@@ -127,6 +179,7 @@ int32 Movements::getAngle(int32 x0, int32 z0, int32 x1, int32 z1) {
}
return ClampAngle(angle);
+#endif
}
void Movements::initRealAngleConst(int32 start, int32 end, int32 duration, ActorMoveStruct *movePtr) const { // ManualRealAngle
More information about the Scummvm-git-logs
mailing list