[Scummvm-git-logs] scummvm master -> 888f8726314ded52f3554b5bbc590018d18855ff
aquadran
noreply at scummvm.org
Sun Oct 27 16:29:42 UTC 2024
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
888f872631 WINTERMUTE: Moved 3d helpers to original location
Commit: 888f8726314ded52f3554b5bbc590018d18855ff
https://github.com/scummvm/scummvm/commit/888f8726314ded52f3554b5bbc590018d18855ff
Author: PaweÅ KoÅodziejski (aquadran at gmail.com)
Date: 2024-10-27T17:29:37+01:00
Commit Message:
WINTERMUTE: Moved 3d helpers to original location
Changed paths:
A engines/wintermute/base/gfx/3dutils.cpp
A engines/wintermute/base/gfx/3dutils.h
engines/wintermute/ad/ad_actor_3dx.cpp
engines/wintermute/ad/ad_scene_geometry.cpp
engines/wintermute/base/base_object.cpp
engines/wintermute/base/gfx/3dcamera.cpp
engines/wintermute/base/gfx/3dloader_3ds.cpp
engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp
engines/wintermute/base/gfx/xanimation.cpp
engines/wintermute/base/gfx/xmesh.cpp
engines/wintermute/math/math_util.cpp
engines/wintermute/math/math_util.h
engines/wintermute/module.mk
diff --git a/engines/wintermute/ad/ad_actor_3dx.cpp b/engines/wintermute/ad/ad_actor_3dx.cpp
index 9fe8f51a51f..e676b8187f5 100644
--- a/engines/wintermute/ad/ad_actor_3dx.cpp
+++ b/engines/wintermute/ad/ad_actor_3dx.cpp
@@ -49,12 +49,12 @@
#include "engines/wintermute/base/gfx/opengl/base_render_opengl3d.h"
#include "engines/wintermute/base/gfx/xmodel.h"
#include "engines/wintermute/base/gfx/xmath.h"
+#include "engines/wintermute/base/gfx/3dutils.h"
#include "engines/wintermute/base/particles/part_emitter.h"
#include "engines/wintermute/base/scriptables/script.h"
#include "engines/wintermute/base/scriptables/script_stack.h"
#include "engines/wintermute/base/scriptables/script_value.h"
#include "engines/wintermute/base/sound/base_sound.h"
-#include "engines/wintermute/math/math_util.h"
#include "engines/wintermute/utils/path_util.h"
#include "engines/wintermute/utils/utils.h"
diff --git a/engines/wintermute/ad/ad_scene_geometry.cpp b/engines/wintermute/ad/ad_scene_geometry.cpp
index 39fa3760641..891c5e91dcd 100644
--- a/engines/wintermute/ad/ad_scene_geometry.cpp
+++ b/engines/wintermute/ad/ad_scene_geometry.cpp
@@ -48,8 +48,8 @@
#include "engines/wintermute/base/gfx/3dloader_3ds.h"
#include "engines/wintermute/base/gfx/3dmesh.h"
#include "engines/wintermute/base/gfx/xmath.h"
+#include "engines/wintermute/base/gfx/3dutils.h"
#include "engines/wintermute/utils/path_util.h"
-#include "engines/wintermute/math/math_util.h"
#include "engines/wintermute/system/sys_class_registry.h"
#include "engines/wintermute/wintermute.h"
@@ -479,7 +479,7 @@ float AdSceneGeometry::getHeightAt(DXVector3 pos, float tolerance, bool *intFoun
for (uint32 i = 0; i < _planes.size(); i++) {
for (int j = 0; j < _planes[i]->_mesh->_numFaces; j++) {
- if (intersectTriangle(pos, dir,
+ if (C3DUtils::intersectTriangle(pos, dir,
_planes[i]->_mesh->_vertices[_planes[i]->_mesh->_faces[j]._vertices[0]]._pos,
_planes[i]->_mesh->_vertices[_planes[i]->_mesh->_faces[j]._vertices[1]]._pos,
_planes[i]->_mesh->_vertices[_planes[i]->_mesh->_faces[j]._vertices[2]]._pos,
@@ -518,12 +518,12 @@ bool AdSceneGeometry::directPathExists(DXVector3 *p1, DXVector3 *p2) {
DXVector3 intersection;
float dist;
- if (pickGetIntersect(*p1, *p2, v0, v1, v2, &intersection, &dist)) {
- if (intersectTriangle(*p1, *p1 - *p2, v0, v1, v2, &intersection._x, &intersection._y, &intersection._z)) {
+ if (C3DUtils::pickGetIntersect(*p1, *p2, v0, v1, v2, &intersection, &dist)) {
+ if (C3DUtils::intersectTriangle(*p1, *p1 - *p2, v0, v1, v2, &intersection._x, &intersection._y, &intersection._z)) {
return false;
}
- if (intersectTriangle(*p2, *p2 - *p1, v0, v1, v2, &intersection._x, &intersection._y, &intersection._z)) {
+ if (C3DUtils::intersectTriangle(*p2, *p2 - *p1, v0, v1, v2, &intersection._x, &intersection._y, &intersection._z)) {
return false;
}
}
@@ -544,13 +544,13 @@ bool AdSceneGeometry::directPathExists(DXVector3 *p1, DXVector3 *p2) {
DXVector3 intersection;
float dist;
- if (pickGetIntersect(*p1, *p2, v0, v1, v2, &intersection, &dist)) {
- if (intersectTriangle(*p1, *p1 - *p2, v0, v1, v2,
+ if (C3DUtils::pickGetIntersect(*p1, *p2, v0, v1, v2, &intersection, &dist)) {
+ if (C3DUtils::intersectTriangle(*p1, *p1 - *p2, v0, v1, v2,
&intersection._x, &intersection._y, &intersection._z)) {
return false;
}
- if (intersectTriangle(*p2, *p2 - *p1, v0, v1, v2,
+ if (C3DUtils::intersectTriangle(*p2, *p2 - *p1, v0, v1, v2,
&intersection._x, &intersection._y, &intersection._z)) {
return false;
}
@@ -579,12 +579,12 @@ DXVector3 AdSceneGeometry::getBlockIntersection(DXVector3 *p1, DXVector3 *p2) {
DXVector3 intersection;
float dist;
- if (pickGetIntersect(*p1, *p2, v0, v1, v2, &intersection, &dist)) {
- if (intersectTriangle(*p1, *p1 - *p2, v0, v1, v2, &intersection._x, &intersection._y, &intersection._z)) {
+ if (C3DUtils::pickGetIntersect(*p1, *p2, v0, v1, v2, &intersection, &dist)) {
+ if (C3DUtils::intersectTriangle(*p1, *p1 - *p2, v0, v1, v2, &intersection._x, &intersection._y, &intersection._z)) {
return intersection;
}
- if (intersectTriangle(*p2, *p2 - *p1, v0, v1, v2, &intersection._x, &intersection._y, &intersection._z)) {
+ if (C3DUtils::intersectTriangle(*p2, *p2 - *p1, v0, v1, v2, &intersection._x, &intersection._y, &intersection._z)) {
return intersection;
}
}
@@ -728,7 +728,7 @@ bool AdSceneGeometry::convert2Dto3D(int x, int y, DXVector3 *pos) {
DXVector3 intersection, ray;
for (uint32 i = 0; i < _planes.size(); i++) {
for (int j = 0; j < _planes[i]->_mesh->_numFaces; j++) {
- if (intersectTriangle(vPickRayOrig, vPickRayDir,
+ if (C3DUtils::intersectTriangle(vPickRayOrig, vPickRayDir,
_planes[i]->_mesh->_vertices[_planes[i]->_mesh->_faces[j]._vertices[0]]._pos,
_planes[i]->_mesh->_vertices[_planes[i]->_mesh->_faces[j]._vertices[1]]._pos,
_planes[i]->_mesh->_vertices[_planes[i]->_mesh->_faces[j]._vertices[2]]._pos,
diff --git a/engines/wintermute/base/base_object.cpp b/engines/wintermute/base/base_object.cpp
index d28e1c1574c..821fbea0a55 100644
--- a/engines/wintermute/base/base_object.cpp
+++ b/engines/wintermute/base/base_object.cpp
@@ -42,7 +42,7 @@
#include "engines/wintermute/base/gfx/base_renderer3d.h"
#include "engines/wintermute/base/gfx/xmodel.h"
#include "engines/wintermute/base/gfx/xmath.h"
-#include "engines/wintermute/math/math_util.h"
+#include "engines/wintermute/base/gfx/3dutils.h"
#include "engines/wintermute/wintermute.h"
#endif
diff --git a/engines/wintermute/base/gfx/3dcamera.cpp b/engines/wintermute/base/gfx/3dcamera.cpp
index 35ab9deccf3..3c1d0063f54 100644
--- a/engines/wintermute/base/gfx/3dcamera.cpp
+++ b/engines/wintermute/base/gfx/3dcamera.cpp
@@ -27,7 +27,7 @@
#include "engines/wintermute/base/gfx/3dcamera.h"
#include "engines/wintermute/base/gfx/3dloader_3ds.h"
-#include "engines/wintermute/math/math_util.h"
+#include "engines/wintermute/base/gfx/3dutils.h"
#include "math/angle.h"
#include "math/glmath.h"
diff --git a/engines/wintermute/base/gfx/3dloader_3ds.cpp b/engines/wintermute/base/gfx/3dloader_3ds.cpp
index 6123b7a9ff6..4e45b2eb2d2 100644
--- a/engines/wintermute/base/gfx/3dloader_3ds.cpp
+++ b/engines/wintermute/base/gfx/3dloader_3ds.cpp
@@ -25,6 +25,7 @@
#include "engines/wintermute/base/gfx/3dloader_3ds.h"
#include "engines/wintermute/base/gfx/3dface.h"
#include "engines/wintermute/base/gfx/3dvertex.h"
+#include "engines/wintermute/base/gfx/3dutils.h"
namespace Wintermute {
diff --git a/engines/wintermute/base/gfx/3dutils.cpp b/engines/wintermute/base/gfx/3dutils.cpp
new file mode 100644
index 00000000000..846d7cd8b48
--- /dev/null
+++ b/engines/wintermute/base/gfx/3dutils.cpp
@@ -0,0 +1,188 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+/*
+ * This file is based on WME.
+ * http://dead-code.org/redir.php?target=wme
+ * Copyright (c) 2003-2013 Jan Nedoma and contributors
+ */
+
+#include "engines/wintermute/base/gfx/3dutils.h"
+#include "common/scummsys.h"
+
+#ifdef ENABLE_WME3D
+#include "common/util.h"
+#endif
+
+namespace Wintermute {
+
+#ifdef ENABLE_WME3D
+
+bool C3DUtils::intersectTriangle(const DXVector3 &orig, const DXVector3 &dir,
+ DXVector3 &v0, DXVector3 &v1, DXVector3 &v2,
+ float *t, float *u, float *v) {
+ // Find vectors for two edges sharing vert0
+ DXVector3 edge1 = v1 - v0;
+ DXVector3 edge2 = v2 - v0;
+
+ // Begin calculating determinant - also used to calculate U parameter
+ DXVector3 pvec;
+ DXVec3Cross(&pvec, &dir, &edge2);
+
+ // If determinant is near zero, ray lies in plane of triangle
+ float det = DXVec3Dot(&edge1, &pvec);
+ if (det < 0.0001f)
+ return false;
+
+ // Calculate distance from vert0 to ray origin
+ DXVector3 tvec = orig - v0;
+
+ // Calculate U parameter and test bounds
+ *u = DXVec3Dot(&tvec, &pvec);
+ if (*u < 0.0f || *u > det)
+ return false;
+
+ // Prepare to test V parameter
+ DXVector3 qvec;
+ DXVec3Cross(&qvec, &tvec, &edge1);
+
+ // Calculate V parameter and test bounds
+ *v = DXVec3Dot(&dir, &qvec);
+ if (*v < 0.0f || *u + *v > det)
+ return false;
+
+ // Calculate t, scale parameters, ray intersects triangle
+ *t = DXVec3Dot(&edge2, &qvec);
+
+ float fInvDet = 1.0f / det;
+ *t *= fInvDet;
+ *u *= fInvDet;
+ *v *= fInvDet;
+
+ DXVector3 intersection;
+ DXVector3 dest = orig + dir;
+ DXPlane plane;
+ DXPlaneFromPoints(&plane, &v0, &v1, &v2);
+ DXPlaneIntersectLine(&intersection, &plane, &orig, &dest);
+ *t = intersection._x;
+ *u = intersection._y;
+ *v = intersection._z;
+
+ return true;
+}
+
+DXMatrix *C3DUtils::matrixSetTranslation(DXMatrix *mat, DXVector3 *vec) {
+ mat->matrix._41 = vec->_x;
+ mat->matrix._42 = vec->_y;
+ mat->matrix._43 = vec->_z;
+
+ return mat;
+}
+
+DXMatrix *C3DUtils::matrixSetRotation(DXMatrix *mat, DXVector3 *vec) {
+ double cr = cos(vec->_x);
+ double sr = sin(vec->_x);
+ double cp = cos(vec->_y);
+ double sp = sin(vec->_y);
+ double cy = cos(vec->_z);
+ double sy = sin(vec->_z);
+
+ mat->matrix._11 = (float)(cp * cy);
+ mat->matrix._12 = (float)(cp * sy);
+ mat->matrix._13 = (float)(-sp);
+
+ double srsp = sr * sp;
+ double crsp = cr * sp;
+
+ mat->matrix._21 = (float)(srsp * cy - cr * sy);
+ mat->matrix._22 = (float)(srsp * sy + cr * cy);
+ mat->matrix._23 = (float)(sr * cp);
+
+ mat->matrix._31 = (float)(crsp * cy + sr * sy);
+ mat->matrix._32 = (float)(crsp * sy - sr * cy);
+ mat->matrix._33 = (float)(cr * cp);
+
+ return mat;
+}
+
+
+bool C3DUtils::pickGetIntersect(DXVector3 lineStart, DXVector3 lineEnd,
+ DXVector3 v0, DXVector3 v1, DXVector3 v2,
+ DXVector3 *intersection, float *distance) {
+ // compute plane's normal
+ DXVector3 vertex;
+ DXVector3 normal;
+
+ DXVector3 edge1 = v1 - v0;
+ DXVector3 edge2 = v2 - v1;
+
+ DXVec3Cross(&normal, &edge1, &edge2);
+ DXVec3Normalize(&normal, &normal);
+
+ vertex = v0;
+
+ DXVector3 direction, l1;
+ float lineLength, distFromPlane, percentage;
+
+ direction._x = lineEnd._x - lineStart._x; // calculate the lines direction vector
+ direction._y = lineEnd._y - lineStart._y;
+ direction._z = lineEnd._z - lineStart._z;
+
+ lineLength = DXVec3Dot(&direction, &normal); // This gives us the line length (the blue dot L3 + L4 in figure d)
+
+ if (fabsf(lineLength) < 0.00001f)
+ return false;
+
+ l1._x = vertex._x - lineStart._x; // calculate vector L1 (the PINK line in figure d)
+ l1._y = vertex._y - lineStart._y;
+ l1._z = vertex._z - lineStart._z;
+
+ distFromPlane = DXVec3Dot(&l1, &normal); // gives the distance from the plane (ORANGE Line L3 in figure d)
+ percentage = distFromPlane / lineLength; // How far from Linestart , intersection is as a percentage of 0 to 1
+ if (percentage < 0.0)
+ return false;
+ else if (percentage > 1.0)
+ return false;
+
+ *distance = percentage; //record the distance from beginning of ray (0.0 -1.0)
+
+ intersection->_x = lineStart._x + direction._x * percentage; // add the percentage of the line to line start
+ intersection->_y = lineStart._y + direction._y * percentage;
+ intersection->_z = lineStart._z + direction._z * percentage;
+
+ return true;
+}
+
+void C3DUtils::decomposeMatrixSimple(const DXMatrix *mat, DXVector3 *transVec, DXVector3 *scaleVec, DXQuaternion *rotQ) {
+ *transVec = DXVector3(mat->matrix._41, mat->matrix._42, mat->matrix._43);
+ *scaleVec = DXVector3(sqrtf(mat->matrix._11 * mat->matrix._11 + mat->matrix._21 * mat->matrix._21 + mat->matrix._31 * mat->matrix._31),
+ sqrtf(mat->matrix._12 * mat->matrix._12 + mat->matrix._22 * mat->matrix._22 + mat->matrix._32 * mat->matrix._32),
+ sqrtf(mat->matrix._13 * mat->matrix._13 + mat->matrix._23 * mat->matrix._23 + mat->matrix._33 * mat->matrix._33));
+
+ DXQuaternion q;
+ DXQuaternionRotationMatrix(&q, mat);
+
+ *rotQ = q;
+}
+
+#endif
+
+} // End of namespace Wintermute
diff --git a/engines/wintermute/base/gfx/3dutils.h b/engines/wintermute/base/gfx/3dutils.h
new file mode 100644
index 00000000000..6601b2420e8
--- /dev/null
+++ b/engines/wintermute/base/gfx/3dutils.h
@@ -0,0 +1,61 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+/*
+ * This file is based on WME.
+ * http://dead-code.org/redir.php?target=wme
+ * Copyright (c) 2003-2013 Jan Nedoma and contributors
+ */
+
+#ifndef WINTERMUTE_3DUTILS_H
+#define WINTERMUTE_3DUTILS_H
+
+#ifdef ENABLE_WME3D
+#include "engines/wintermute/base/gfx/xmath.h"
+#endif
+
+namespace Wintermute {
+
+#ifdef ENABLE_WME3D
+
+#define DX_PI ((float)3.141592654)
+#define degToRad(_val) (_val * DX_PI * (1.0f / 180.0f))
+#define radToDeg(_val) (_val * (180.0f / DX_PI))
+
+class C3DUtils {
+public:
+ static bool intersectTriangle(const DXVector3 &orig, const DXVector3 &dir,
+ DXVector3 &v0, DXVector3 &v1, DXVector3 &v2,
+ float *t, float *u, float *v);
+ static bool pickGetIntersect(DXVector3 linestart, DXVector3 lineend,
+ DXVector3 v0, DXVector3 v1, DXVector3 v2,
+ DXVector3 *intersection, float *distance);
+ static DXMatrix *matrixSetTranslation(DXMatrix *mat, DXVector3 *vec);
+ static DXMatrix *matrixSetRotation(DXMatrix *mat, DXVector3 *vec);
+ static void decomposeMatrixSimple(const DXMatrix *mat, DXVector3 *transVec,
+ DXVector3 *scaleVec, DXQuaternion *rotQ);
+};
+
+#endif
+
+} // End of namespace Wintermute
+
+#endif
diff --git a/engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp b/engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp
index 60032429148..fbac853bad0 100644
--- a/engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp
+++ b/engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp
@@ -35,7 +35,7 @@
#if defined(USE_OPENGL_GAME)
-#include "engines/wintermute/math/math_util.h"
+#include "engines/wintermute/base/gfx/3dutils.h"
#include "engines/wintermute/base/gfx/opengl/base_render_opengl3d.h"
#include "engines/wintermute/base/gfx/opengl/base_surface_opengl3d.h"
#include "engines/wintermute/base/gfx/opengl/mesh3ds_opengl.h"
diff --git a/engines/wintermute/base/gfx/xanimation.cpp b/engines/wintermute/base/gfx/xanimation.cpp
index 47aa4779909..4c2408a29c0 100644
--- a/engines/wintermute/base/gfx/xanimation.cpp
+++ b/engines/wintermute/base/gfx/xanimation.cpp
@@ -27,7 +27,7 @@
#include "engines/wintermute/base/base_game.h"
#include "engines/wintermute/base/base_engine.h"
-#include "engines/wintermute/math/math_util.h"
+#include "engines/wintermute/base/gfx/3dutils.h"
#include "engines/wintermute/base/gfx/xanimation.h"
#include "engines/wintermute/base/gfx/xanimation_set.h"
#include "engines/wintermute/base/gfx/xframe_node.h"
@@ -217,7 +217,7 @@ bool Animation::loadAnimationKeyData(XAnimationKeyObject *animationKey) {
}
// we always convert matrix keys to T-R-S
- decomposeMatrixSimple(&keyData, &transVec, &scaleVec, &qRot);
+ C3DUtils::decomposeMatrixSimple(&keyData, &transVec, &scaleVec, &qRot);
BonePositionKey *positionKey = new BonePositionKey;
BoneScaleKey *scaleKey = new BoneScaleKey;
diff --git a/engines/wintermute/base/gfx/xmesh.cpp b/engines/wintermute/base/gfx/xmesh.cpp
index b7e775cd33a..d09b7b71204 100644
--- a/engines/wintermute/base/gfx/xmesh.cpp
+++ b/engines/wintermute/base/gfx/xmesh.cpp
@@ -34,8 +34,8 @@
#include "engines/wintermute/base/gfx/xmodel.h"
#include "engines/wintermute/base/gfx/xbuffer.h"
#include "engines/wintermute/base/gfx/xskinmesh.h"
+#include "engines/wintermute/base/gfx/3dutils.h"
#include "engines/wintermute/base/base_engine.h"
-#include "engines/wintermute/math/math_util.h"
#include "engines/wintermute/utils/path_util.h"
namespace Wintermute {
@@ -296,7 +296,7 @@ bool XMesh::pickPoly(DXVector3 *pickRayOrig, DXVector3 *pickRayDir) {
if (isnan(v0._x))
continue;
- found = intersectTriangle(*pickRayOrig, *pickRayDir, v0, v1, v2, &intersection._x, &intersection._y, &intersection._z) != false;
+ found = C3DUtils::intersectTriangle(*pickRayOrig, *pickRayDir, v0, v1, v2, &intersection._x, &intersection._y, &intersection._z) != false;
if (found)
break;
}
diff --git a/engines/wintermute/math/math_util.cpp b/engines/wintermute/math/math_util.cpp
index 791578e6930..7f8f3725cd8 100644
--- a/engines/wintermute/math/math_util.cpp
+++ b/engines/wintermute/math/math_util.cpp
@@ -28,10 +28,6 @@
#include "engines/wintermute/math/math_util.h"
#include "common/scummsys.h"
-#ifdef ENABLE_WME3D
-#include "common/util.h"
-#endif
-
namespace Wintermute {
//////////////////////////////////////////////////////////////////////////
@@ -52,154 +48,4 @@ float MathUtil::roundUp(float val) {
return result;
}
-#ifdef ENABLE_WME3D
-
-bool intersectTriangle(const DXVector3 &orig, const DXVector3 &dir,
- DXVector3 &v0, DXVector3 &v1, DXVector3 &v2,
- float *t, float *u, float *v) {
- // Find vectors for two edges sharing vert0
- DXVector3 edge1 = v1 - v0;
- DXVector3 edge2 = v2 - v0;
-
- // Begin calculating determinant - also used to calculate U parameter
- DXVector3 pvec;
- DXVec3Cross(&pvec, &dir, &edge2);
-
- // If determinant is near zero, ray lies in plane of triangle
- float det = DXVec3Dot(&edge1, &pvec);
- if (det < 0.0001f)
- return false;
-
- // Calculate distance from vert0 to ray origin
- DXVector3 tvec = orig - v0;
-
- // Calculate U parameter and test bounds
- *u = DXVec3Dot(&tvec, &pvec);
- if (*u < 0.0f || *u > det)
- return false;
-
- // Prepare to test V parameter
- DXVector3 qvec;
- DXVec3Cross(&qvec, &tvec, &edge1);
-
- // Calculate V parameter and test bounds
- *v = DXVec3Dot(&dir, &qvec);
- if (*v < 0.0f || *u + *v > det)
- return false;
-
- // Calculate t, scale parameters, ray intersects triangle
- *t = DXVec3Dot(&edge2, &qvec);
-
- float fInvDet = 1.0f / det;
- *t *= fInvDet;
- *u *= fInvDet;
- *v *= fInvDet;
-
- DXVector3 intersection;
- DXVector3 dest = orig + dir;
- DXPlane plane;
- DXPlaneFromPoints(&plane, &v0, &v1, &v2);
- DXPlaneIntersectLine(&intersection, &plane, &orig, &dest);
- *t = intersection._x;
- *u = intersection._y;
- *v = intersection._z;
-
- return true;
-}
-
-bool pickGetIntersect(DXVector3 lineStart, DXVector3 lineEnd,
- DXVector3 v0, DXVector3 v1, DXVector3 v2,
- DXVector3 *intersection, float *distance) {
- // compute plane's normal
- DXVector3 vertex;
- DXVector3 normal;
-
- DXVector3 edge1 = v1 - v0;
- DXVector3 edge2 = v2 - v1;
-
- DXVec3Cross(&normal, &edge1, &edge2);
- DXVec3Normalize(&normal, &normal);
-
- vertex = v0;
-
- DXVector3 direction, l1;
- float lineLength, distFromPlane, percentage;
-
- direction._x = lineEnd._x - lineStart._x; // calculate the lines direction vector
- direction._y = lineEnd._y - lineStart._y;
- direction._z = lineEnd._z - lineStart._z;
-
- lineLength = DXVec3Dot(&direction, &normal); // This gives us the line length (the blue dot L3 + L4 in figure d)
-
- if (fabsf(lineLength) < 0.00001f)
- return false;
-
- l1._x = vertex._x - lineStart._x; // calculate vector L1 (the PINK line in figure d)
- l1._y = vertex._y - lineStart._y;
- l1._z = vertex._z - lineStart._z;
-
- distFromPlane = DXVec3Dot(&l1, &normal); // gives the distance from the plane (ORANGE Line L3 in figure d)
- percentage = distFromPlane / lineLength; // How far from Linestart , intersection is as a percentage of 0 to 1
- if (percentage < 0.0)
- return false;
- else if (percentage > 1.0)
- return false;
-
- *distance = percentage; //record the distance from beginning of ray (0.0 -1.0)
-
- intersection->_x = lineStart._x + direction._x * percentage; // add the percentage of the line to line start
- intersection->_y = lineStart._y + direction._y * percentage;
- intersection->_z = lineStart._z + direction._z * percentage;
-
- return true;
-}
-
-void decomposeMatrixSimple(const DXMatrix *mat, DXVector3 *transVec, DXVector3 *scaleVec, DXQuaternion *rotQ) {
- *transVec = DXVector3(mat->matrix._41, mat->matrix._42, mat->matrix._43);
- *scaleVec = DXVector3(sqrtf(mat->matrix._11 * mat->matrix._11 + mat->matrix._21 * mat->matrix._21 + mat->matrix._31 * mat->matrix._31),
- sqrtf(mat->matrix._12 * mat->matrix._12 + mat->matrix._22 * mat->matrix._22 + mat->matrix._32 * mat->matrix._32),
- sqrtf(mat->matrix._13 * mat->matrix._13 + mat->matrix._23 * mat->matrix._23 + mat->matrix._33 * mat->matrix._33));
-
- DXQuaternion q;
- DXQuaternionRotationMatrix(&q, mat);
-
- *rotQ = q;
-}
-
-DXMatrix *matrixSetTranslation(DXMatrix *mat, DXVector3 *vec) {
- mat->matrix._41 = vec->_x;
- mat->matrix._42 = vec->_y;
- mat->matrix._43 = vec->_z;
-
- return mat;
-}
-
-DXMatrix *matrixSetRotation(DXMatrix *mat, DXVector3 *vec) {
- double cr = cos(vec->_x);
- double sr = sin(vec->_x);
- double cp = cos(vec->_y);
- double sp = sin(vec->_y);
- double cy = cos(vec->_z);
- double sy = sin(vec->_z);
-
- mat->matrix._11 = (float)(cp * cy);
- mat->matrix._12 = (float)(cp * sy);
- mat->matrix._13 = (float)(-sp);
-
- double srsp = sr * sp;
- double crsp = cr * sp;
-
- mat->matrix._21 = (float)(srsp * cy - cr * sy);
- mat->matrix._22 = (float)(srsp * sy + cr * cy);
- mat->matrix._23 = (float)(sr * cp);
-
- mat->matrix._31 = (float)(crsp * cy + sr * sy);
- mat->matrix._32 = (float)(crsp * sy - sr * cy);
- mat->matrix._33 = (float)(cr * cp);
-
- return mat;
-}
-
-#endif
-
} // End of namespace Wintermute
diff --git a/engines/wintermute/math/math_util.h b/engines/wintermute/math/math_util.h
index 690f57d63f3..5c0b7fd8e59 100644
--- a/engines/wintermute/math/math_util.h
+++ b/engines/wintermute/math/math_util.h
@@ -28,11 +28,6 @@
#ifndef WINTERMUTE_MATHUTIL_H
#define WINTERMUTE_MATHUTIL_H
-#ifdef ENABLE_WME3D
-#include "math/vector3d.h"
-#include "engines/wintermute/base/gfx/xmath.h"
-#endif
-
namespace Wintermute {
class MathUtil {
@@ -41,24 +36,6 @@ public:
static float roundUp(float val);
};
-#ifdef ENABLE_WME3D
-
-#define DX_PI ((float)3.141592654)
-#define degToRad(_val) (_val * DX_PI * (1.0f / 180.0f))
-#define radToDeg(_val) (_val * (180.0f / DX_PI))
-
-bool intersectTriangle(const DXVector3 &orig, const DXVector3 &dir,
- DXVector3 &v0, DXVector3 &v1, DXVector3 &v2,
- float *t, float *u, float *v);
-bool pickGetIntersect(DXVector3 linestart, DXVector3 lineend,
- DXVector3 v0, DXVector3 v1, DXVector3 v2,
- DXVector3 *intersection, float *distance);
-DXMatrix *matrixSetTranslation(DXMatrix *mat, DXVector3 *vec);
-DXMatrix *matrixSetRotation(DXMatrix *mat, DXVector3 *vec);
-void decomposeMatrixSimple(const DXMatrix *mat, DXVector3 *transVec, DXVector3 *scaleVec, DXQuaternion *rotQ);
-
-#endif
-
} // End of namespace Wintermute
#endif
diff --git a/engines/wintermute/module.mk b/engines/wintermute/module.mk
index f79c2254ad9..28bc8fded9d 100644
--- a/engines/wintermute/module.mk
+++ b/engines/wintermute/module.mk
@@ -165,6 +165,7 @@ MODULE_OBJS += \
base/gfx/3dloader_3ds.o \
base/gfx/3dmesh.o \
base/gfx/3dshadow_volume.o \
+ base/gfx/3dutils.o \
base/gfx/3dvertex.o \
base/gfx/base_renderer3d.o \
base/gfx/skin_mesh_helper.o \
More information about the Scummvm-git-logs
mailing list