[Scummvm-git-logs] scummvm master -> 30de47be4a4477a042e23e57907092cbcfbf0eab

aquadran noreply at scummvm.org
Thu Oct 24 12:52:46 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:
30de47be4a WINTERMUTE: Switch to game engine original coordinate system


Commit: 30de47be4a4477a042e23e57907092cbcfbf0eab
    https://github.com/scummvm/scummvm/commit/30de47be4a4477a042e23e57907092cbcfbf0eab
Author: Paweł Kołodziejski (aquadran at gmail.com)
Date: 2024-10-24T14:52:41+02:00

Commit Message:
WINTERMUTE: Switch to game engine original coordinate system

Changed paths:
    engines/wintermute/ad/ad_actor_3dx.cpp
    engines/wintermute/ad/ad_object_3d.cpp
    engines/wintermute/ad/ad_scene.cpp
    engines/wintermute/ad/ad_scene_geometry.cpp
    engines/wintermute/base/base_object.cpp
    engines/wintermute/base/gfx/3dcamera.cpp
    engines/wintermute/base/gfx/3dlight.cpp
    engines/wintermute/base/gfx/3dmesh.cpp
    engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp
    engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.cpp
    engines/wintermute/base/gfx/opengl/shadow_volume_opengl.cpp
    engines/wintermute/base/gfx/opengl/shadow_volume_opengl_shader.cpp
    engines/wintermute/base/gfx/xanimation.cpp
    engines/wintermute/base/gfx/xframe_node.cpp
    engines/wintermute/base/gfx/xmesh.cpp
    engines/wintermute/base/gfx/xmodel.cpp
    engines/wintermute/base/gfx/xskinmesh.cpp


diff --git a/engines/wintermute/ad/ad_actor_3dx.cpp b/engines/wintermute/ad/ad_actor_3dx.cpp
index 022fd0633bd..719982eb10f 100644
--- a/engines/wintermute/ad/ad_actor_3dx.cpp
+++ b/engines/wintermute/ad/ad_actor_3dx.cpp
@@ -173,30 +173,25 @@ bool AdActor3DX::update() {
 			float turnVel = _directTurnVelocity == 0.0f ? _angVelocity : _directTurnVelocity;
 
 			if (_directTurnMode == DIRECT_TURN_CW) {
-				// we have a right handed coordinate system now, so we subtract
-				_angle -= turnVel * (float)_gameRef->_deltaTime / 1000.f;
+				_angle += turnVel * (float)_gameRef->_deltaTime / 1000.f;
 				_angle = BaseUtils::normalizeAngle(_angle);
 			}
 
 			if (_directTurnMode == DIRECT_TURN_CCW) {
-				// we have a right handed coordinate system now, so we add
-				_angle += turnVel * (float)_gameRef->_deltaTime / 1000.f;
+				_angle -= turnVel * (float)_gameRef->_deltaTime / 1000.f;
 				_angle = BaseUtils::normalizeAngle(_angle);
 			}
 
 			float walkVel = _directWalkVelocity == 0.0f ? _velocity : _directWalkVelocity;
 			DXVector3 newPos = _posVector;
 			if (_directWalkMode == DIRECT_WALK_FW) {
-				// we add the direction vector since in a right handed coordinate system
-				// angles turn counter-clockwise (wme uses a left handed coordinate system, so there it's a subtraction)
-				newPos._x += sinf(degToRad(_angle)) * walkVel * _scale3D * (float)_gameRef->_deltaTime / 1000.f;
-				newPos._z += cosf(degToRad(_angle)) * walkVel * _scale3D * (float)_gameRef->_deltaTime / 1000.f;
+				newPos._x += -sinf(degToRad(_angle)) * walkVel * _scale3D * (float)_gameRef->_deltaTime / 1000.f;
+				newPos._z += -cosf(degToRad(_angle)) * walkVel * _scale3D * (float)_gameRef->_deltaTime / 1000.f;
 			}
 
 			if (_directWalkMode == DIRECT_WALK_BK) {
-				// but here we subtract
-				newPos._x -= sinf(degToRad(_angle)) * walkVel * _scale3D * (float)_gameRef->_deltaTime / 1000.f;
-				newPos._z -= cosf(degToRad(_angle)) * walkVel * _scale3D * (float)_gameRef->_deltaTime / 1000.f;
+				newPos._x -= -sinf(degToRad(_angle)) * walkVel * _scale3D * (float)_gameRef->_deltaTime / 1000.f;
+				newPos._z -= -cosf(degToRad(_angle)) * walkVel * _scale3D * (float)_gameRef->_deltaTime / 1000.f;
 			}
 
 			AdScene *scene = ((AdGame *)_gameRef)->_scene;
@@ -650,10 +645,8 @@ void AdActor3DX::getNextStep3D() {
 		turnToStep(_angVelocity);
 
 	DXVector3 newPos = _posVector;
-	// we add the direction vector since in a right handed coordinate system
-	// angles turn counter-clockwise (wme uses a left handed coordinate system, so there it's a subtraction)
-	newPos._x += sinf(degToRad(_targetAngle)) * _velocity * _scale3D * (float)_gameRef->_deltaTime / 1000.f;
-	newPos._z += cosf(degToRad(_targetAngle)) * _velocity * _scale3D * (float)_gameRef->_deltaTime / 1000.f;
+	newPos._x += -sinf(degToRad(_targetAngle)) * _velocity * _scale3D * (float)_gameRef->_deltaTime / 1000.f;
+	newPos._z += -cosf(degToRad(_targetAngle)) * _velocity * _scale3D * (float)_gameRef->_deltaTime / 1000.f;
 
 	DXVector3 origVec, newVec;
 	DXVector3 *currentPos = _path3D->getCurrent();
@@ -688,12 +681,9 @@ void AdActor3DX::getNextStep3D() {
 void AdActor3DX::initLine3D(DXVector3 startPt, DXVector3 endPt, bool firstStep) {
 	if (firstStep) {
 		_nextState = STATE_FOLLOWING_PATH;
-		// wme subtracted 90 dregrees from the angle, so that the angle zero points downwards
-		// and the angle 90 goes left
-		// now we have a right handed coordinate system, so we add 90 degrees instead
-		turnTo(radToDeg(-atan2(endPt._z - startPt._z, endPt._x - startPt._x)) + 90);
+		turnTo(radToDeg(-atan2(endPt._z - startPt._z, endPt._x - startPt._x)) - 90);
 	} else {
-		_turningLeft = prepareTurn(radToDeg(-atan2(endPt._z - startPt._z, endPt._x - startPt._x)) + 90);
+		_turningLeft = prepareTurn(radToDeg(-atan2(endPt._z - startPt._z, endPt._x - startPt._x)) - 90);
 	}
 }
 
@@ -712,10 +702,8 @@ void AdActor3DX::getNextStep2D() {
 	}
 
 	DXVector3 newPos = _posVector;
-	// we add the direction vector since in a right handed coordinate system
-	// angles turn counter-clockwise (wme uses a left handed coordinate system, so there it's a subtraction)
-	newPos._x += sinf(degToRad(_targetAngle)) * _velocity * _scale3D * (float)_gameRef->_deltaTime / 1000.f;
-	newPos._z += cosf(degToRad(_targetAngle)) * _velocity * _scale3D * (float)_gameRef->_deltaTime / 1000.f;
+	newPos._x += -sinf(degToRad(_targetAngle)) * _velocity * _scale3D * (float)_gameRef->_deltaTime / 1000.f;
+	newPos._z += -cosf(degToRad(_targetAngle)) * _velocity * _scale3D * (float)_gameRef->_deltaTime / 1000.f;
 
 	DXVector3 currentPoint;
 	adGame->_scene->_geom->convert2Dto3DTolerant(_path2D->getCurrent()->x,
@@ -1003,8 +991,6 @@ bool AdActor3DX::loadBuffer(byte *buffer, bool complete) {
 
 		case TOKEN_LIGHT_POSITION:
 			parser.scanStr((char *)params, "%f,%f,%f", &_shadowLightPos._x, &_shadowLightPos._y, &_shadowLightPos._z);
-			// invert z coordinate since wme uses a Direct3D coordinate system but we use OpenGL
-			_shadowLightPos._z *= -1.0f;
 			break;
 
 		case TOKEN_SHADOW: {
@@ -1223,19 +1209,19 @@ float AdActor3DX::dirToAngle(TDirection dir) {
 	case DI_UP:
 		return 180.0f;
 	case DI_UPRIGHT:
-		return 135.0f;
+		return 225.0f;
 	case DI_RIGHT:
-		return 90.0f;
+		return 270.0f;
 	case DI_DOWNRIGHT:
-		return 45.0f;
+		return 315.0f;
 	case DI_DOWN:
 		return 0.0f;
 	case DI_DOWNLEFT:
-		return 315.0f;
+		return 45.0f;
 	case DI_LEFT:
-		return 270.0f;
+		return 90.0f;
 	case DI_UPLEFT:
-		return 225.0f;
+		return 135.0f;
 	case DI_NONE:
 		return -1.0f;
 	default:
@@ -1248,19 +1234,19 @@ TDirection AdActor3DX::angleToDir(float angle) {
 	if (angle >= 337.0f || angle < 22.0f)
 		return DI_DOWN;
 	if (angle >= 22.0f && angle < 67.0f)
-		return DI_DOWNRIGHT;
+		return DI_DOWNLEFT;
 	if (angle >= 67.0f && angle < 112.0f)
-		return DI_RIGHT;
+		return DI_LEFT;
 	if (angle >= 112.0f && angle < 157.0f)
-		return DI_UPRIGHT;
+		return DI_UPLEFT;
 	if (angle >= 157.0f && angle < 202.0f)
 		return DI_UP;
 	if (angle >= 202.0f && angle < 247.0f)
-		return DI_UPLEFT;
+		return DI_UPRIGHT;
 	if (angle >= 247.0f && angle < 292.0f)
-		return DI_LEFT;
+		return DI_RIGHT;
 	if (angle >= 292.0f && angle < 337.0f)
-		return DI_DOWNLEFT;
+		return DI_DOWNRIGHT;
 
 	return DI_NONE;
 }
@@ -1520,8 +1506,7 @@ bool AdActor3DX::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta
 		DXVector3 pos;
 		pos._x = stack->pop()->getFloat();
 		pos._y = stack->pop()->getFloat();
-		// scripts will expect a Direct3D coordinate system
-		pos._z = -stack->pop()->getFloat();
+		pos._z = stack->pop()->getFloat();
 		goTo3D(pos);
 
 		if (strcmp(name, "GoTo3DAsync") != 0) {
@@ -1669,7 +1654,7 @@ bool AdActor3DX::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta
 			BaseObject *obj = (BaseObject *)val->getNative();
 			DXVector3 objPos;
 			((AdGame *)_gameRef)->_scene->_geom->convert2Dto3D(obj->_posX, obj->_posY, &objPos);
-			angle = radToDeg(-atan2(objPos._z - _posVector._z, objPos._x - _posVector._x)) + 90;
+			angle = radToDeg(-atan2(objPos._z - _posVector._z, objPos._x - _posVector._x)) - 90;
 		} else {
 			// otherwise turn to direction
 			dir = val->getInt();
@@ -1698,7 +1683,7 @@ bool AdActor3DX::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta
 	//////////////////////////////////////////////////////////////////////////
 	else if (strcmp(name, "TurnToAngle") == 0 || strcmp(name, "TurnToAngleAsync") == 0) {
 		stack->correctParams(1);
-		float angle = -stack->pop()->getFloat();
+		float angle = stack->pop()->getFloat();
 
 		if (_path2D) {
 			_path2D->reset();
diff --git a/engines/wintermute/ad/ad_object_3d.cpp b/engines/wintermute/ad/ad_object_3d.cpp
index db032e2789b..984abaecf85 100644
--- a/engines/wintermute/ad/ad_object_3d.cpp
+++ b/engines/wintermute/ad/ad_object_3d.cpp
@@ -183,8 +183,7 @@ bool AdObject3D::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta
 		stack->correctParams(3);
 		_posVector._x = stack->pop()->getFloat();
 		_posVector._y = stack->pop()->getFloat();
-		// scripts will expect a Direct3D coordinate system
-		_posVector._z = -stack->pop()->getFloat();
+		_posVector._z = stack->pop()->getFloat();
 
 		stack->pushNULL();
 
@@ -283,8 +282,7 @@ ScValue *AdObject3D::scGetProperty(const Common::String &name) {
 	// PosZ
 	//////////////////////////////////////////////////////////////////////////
 	else if (name == "PosZ") {
-		// scripts will expect a Direct3D coordinate system
-		_scValue->setFloat(-_posVector._z);
+		_scValue->setFloat(_posVector._z);
 		return _scValue;
 	}
 	//////////////////////////////////////////////////////////////////////////
@@ -403,8 +401,7 @@ bool AdObject3D::scSetProperty(const char *name, ScValue *value) {
 	// PosZ
 	//////////////////////////////////////////////////////////////////////////
 	else if (strcmp(name, "PosZ") == 0) {
-		// scripts will expect a Direct3D coordinate system
-		_posVector._z = -value->getFloat();
+		_posVector._z = value->getFloat();
 		return true;
 	}
 
diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp
index e1c396ac8e8..5adf70e4866 100644
--- a/engines/wintermute/ad/ad_scene.cpp
+++ b/engines/wintermute/ad/ad_scene.cpp
@@ -2155,8 +2155,7 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack,
 			if (val) {
 				val->setProperty("X", pos._x);
 				val->setProperty("Y", pos._y);
-				// invert z coordinate to change to OpenGL coordinate system
-				val->setProperty("Z", -pos._z);
+				val->setProperty("Z", pos._z);
 			}
 		}
 
diff --git a/engines/wintermute/ad/ad_scene_geometry.cpp b/engines/wintermute/ad/ad_scene_geometry.cpp
index 8e78e15fe8b..7be393daf55 100644
--- a/engines/wintermute/ad/ad_scene_geometry.cpp
+++ b/engines/wintermute/ad/ad_scene_geometry.cpp
@@ -665,7 +665,7 @@ bool AdSceneGeometry::convert2Dto3D(int x, int y, DXVector3 *pos) {
 	DXVector3 vec;
 	vec._x =  (((2.0f * x) / _drawingViewport.width()) - 1) / _lastProjMat.matrix._11;
 	vec._y = -(((2.0f * y) / _drawingViewport.height()) - 1) / _lastProjMat.matrix._22;
-	vec._z =  -1.0f;
+	vec._z =  1.0f;
 
 	// Get the inverse view matrix
 	DXMatrix m;
diff --git a/engines/wintermute/base/base_object.cpp b/engines/wintermute/base/base_object.cpp
index 0b273acc3dc..d28e1c1574c 100644
--- a/engines/wintermute/base/base_object.cpp
+++ b/engines/wintermute/base/base_object.cpp
@@ -563,8 +563,7 @@ bool BaseObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta
 		double x = stack->pop()->getFloat();
 		double y = stack->pop()->getFloat();
 		double z = stack->pop()->getFloat();
-		// invert z coordinate because of OpenGL coordinate system
-		_shadowLightPos = DXVector3(x, y, -z);
+		_shadowLightPos = DXVector3(x, y, z);
 
 		stack->pushNULL();
 		return STATUS_OK;
diff --git a/engines/wintermute/base/gfx/3dcamera.cpp b/engines/wintermute/base/gfx/3dcamera.cpp
index ab01a048755..6dd3a27ac9b 100644
--- a/engines/wintermute/base/gfx/3dcamera.cpp
+++ b/engines/wintermute/base/gfx/3dcamera.cpp
@@ -62,7 +62,7 @@ bool Camera3D::getViewMatrix(DXMatrix *viewMatrix) {
 		DXVec3TransformCoord(&up, &up, &rot);
 	}
 
-	DXMatrixLookAtRH(viewMatrix, &_position, &_target, &up);
+	DXMatrixLookAtLH(viewMatrix, &_position, &_target, &up);
 
 	return true;
 }
@@ -117,11 +117,11 @@ bool Camera3D::loadFrom3DS(Common::MemoryReadStream &fileStream) {
 	int32 end = fileStream.pos() + wholeChunkSize - 6;
 
 	_position._x = fileStream.readFloatLE();
-	_position._z = -fileStream.readFloatLE();
+	_position._z = fileStream.readFloatLE();
 	_position._y = fileStream.readFloatLE();
 
 	_target._x = fileStream.readFloatLE();
-	_target._z = -fileStream.readFloatLE();
+	_target._z = fileStream.readFloatLE();
 	_target._y = fileStream.readFloatLE();
 
 	_bank = fileStream.readFloatLE();
diff --git a/engines/wintermute/base/gfx/3dlight.cpp b/engines/wintermute/base/gfx/3dlight.cpp
index 9f0066b82bc..277a181a0e8 100644
--- a/engines/wintermute/base/gfx/3dlight.cpp
+++ b/engines/wintermute/base/gfx/3dlight.cpp
@@ -75,7 +75,7 @@ bool Light3D::setLight(int index) {
 //////////////////////////////////////////////////////////////////////////
 bool Light3D::getViewMatrix(DXMatrix *viewMatrix) {
 	DXVector3 up = DXVector3(0.0f, 1.0f, 0.0f);
-	DXMatrixLookAtRH(viewMatrix, &_position, &_target, &up);
+	DXMatrixLookAtLH(viewMatrix, &_position, &_target, &up);
 	return true;
 }
 
@@ -91,7 +91,7 @@ bool Light3D::loadFrom3DS(Common::MemoryReadStream &fileStream) {
 	int32 end = fileStream.pos() + wholeChunkSize - 6;
 
 	_position._x = fileStream.readFloatLE();
-	_position._z = -fileStream.readFloatLE();
+	_position._z = fileStream.readFloatLE();
 	_position._y = fileStream.readFloatLE();
 
 	while (fileStream.pos() < end) {
@@ -101,7 +101,7 @@ bool Light3D::loadFrom3DS(Common::MemoryReadStream &fileStream) {
 		switch (chunkId) {
 		case SPOTLIGHT:
 			_target._x = fileStream.readFloatLE();
-			_target._z = -fileStream.readFloatLE();
+			_target._z = fileStream.readFloatLE();
 			_target._y = fileStream.readFloatLE();
 
 			// this is appearently not used
diff --git a/engines/wintermute/base/gfx/3dmesh.cpp b/engines/wintermute/base/gfx/3dmesh.cpp
index 68c082056c9..7680f489386 100644
--- a/engines/wintermute/base/gfx/3dmesh.cpp
+++ b/engines/wintermute/base/gfx/3dmesh.cpp
@@ -48,10 +48,8 @@ bool Mesh3DS::loadFrom3DS(Common::MemoryReadStream &fileStream) {
 			_vertexData = new GeometryVertex[_vertexCount]();
 
 			for (int i = 0; i < _vertexCount; ++i) {
-				// note that .3ds has a right handed coordinate system
-				// with the z axis pointing upwards
 				_vertexData[i].x = fileStream.readFloatLE();
-				_vertexData[i].z = -fileStream.readFloatLE();
+				_vertexData[i].z = fileStream.readFloatLE();
 				_vertexData[i].y = fileStream.readFloatLE();
 			}
 			break;
@@ -63,8 +61,8 @@ bool Mesh3DS::loadFrom3DS(Common::MemoryReadStream &fileStream) {
 
 			for (int i = 0; i < faceCount; ++i) {
 				_indexData[i * 3 + 0] = fileStream.readUint16LE();
-				_indexData[i * 3 + 1] = fileStream.readUint16LE();
 				_indexData[i * 3 + 2] = fileStream.readUint16LE();
+				_indexData[i * 3 + 1] = fileStream.readUint16LE();
 				fileStream.readUint16LE(); // not used
 			}
 			break;
diff --git a/engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp b/engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp
index 400a55e6d26..75abbafa233 100644
--- a/engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp
+++ b/engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp
@@ -143,6 +143,7 @@ void BaseRenderOpenGL3D::setLightParameters(int index, const DXVector3 &position
 }
 
 void BaseRenderOpenGL3D::enableCulling() {
+	glFrontFace(GL_CW);
 	glEnable(GL_CULL_FACE);
 }
 
@@ -338,7 +339,7 @@ bool BaseRenderOpenGL3D::setProjection() {
 	int mtop = rc.top;
 	int mbottom = resHeight - viewportHeight - rc.top;
 
-	DXMatrixPerspectiveFovRH(&matProj, _fov, viewportWidth / viewportHeight, _nearClipPlane, _farClipPlane);
+	DXMatrixPerspectiveFovLH(&matProj, _fov, viewportWidth / viewportHeight, _nearClipPlane, _farClipPlane);
 
 	float scaleMod = resHeight / viewportHeight;
 	float scaleRatio = MAX(layerWidth / resWidth, layerHeight / resHeight) /** 1.05*/;
@@ -416,7 +417,7 @@ bool BaseRenderOpenGL3D::initRenderer(int width, int height, bool windowed) {
 
 	_simpleShadow[0].x = -1.0f;
 	_simpleShadow[0].y = 0.0f;
-	_simpleShadow[0].z = -1.0f;
+	_simpleShadow[0].z = 1.0f;
 	_simpleShadow[0].nx = 0.0f;
 	_simpleShadow[0].ny = 1.0f;
 	_simpleShadow[0].nz = 0.0f;
@@ -425,7 +426,7 @@ bool BaseRenderOpenGL3D::initRenderer(int width, int height, bool windowed) {
 
 	_simpleShadow[1].x = -1.0f;
 	_simpleShadow[1].y = 0.0f;
-	_simpleShadow[1].z = 1.0f;
+	_simpleShadow[1].z = -1.0f;
 	_simpleShadow[1].nx = 0.0f;
 	_simpleShadow[1].ny = 1.0f;
 	_simpleShadow[1].nz = 0.0f;
@@ -434,7 +435,7 @@ bool BaseRenderOpenGL3D::initRenderer(int width, int height, bool windowed) {
 
 	_simpleShadow[2].x = 1.0f;
 	_simpleShadow[2].y = 0.0f;
-	_simpleShadow[2].z = -1.0f;
+	_simpleShadow[2].z = 1.0f;
 	_simpleShadow[2].nx = 0.0f;
 	_simpleShadow[2].ny = 1.0f;
 	_simpleShadow[2].nz = 0.0f;
@@ -443,7 +444,7 @@ bool BaseRenderOpenGL3D::initRenderer(int width, int height, bool windowed) {
 
 	_simpleShadow[3].x = 1.0f;
 	_simpleShadow[3].y = 0.0f;
-	_simpleShadow[3].z = 1.0f;
+	_simpleShadow[3].z = -1.0f;
 	_simpleShadow[3].nx = 0.0f;
 	_simpleShadow[3].ny = 1.0f;
 	_simpleShadow[3].nz = 0.0f;
@@ -737,7 +738,7 @@ void BaseRenderOpenGL3D::renderSceneGeometry(const BaseArray<AdWalkplane *> &pla
 
 	glDisable(GL_LIGHTING);
 	glDisable(GL_DEPTH_TEST);
-	glFrontFace(GL_CCW);
+	glFrontFace(GL_CW);
 	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 	glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
 	glEnable(GL_COLOR_MATERIAL);
@@ -811,7 +812,7 @@ void BaseRenderOpenGL3D::renderShadowGeometry(const BaseArray<AdWalkplane *> &pl
 	// disable color write
 	glBlendFunc(GL_ZERO, GL_ONE);
 
-	glFrontFace(GL_CCW);
+	glFrontFace(GL_CW);
 	glDisable(GL_TEXTURE_2D);
 	glBindTexture(GL_TEXTURE_2D, 0);
 
diff --git a/engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.cpp b/engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.cpp
index b5d17f0fddf..95de6b05b9a 100644
--- a/engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.cpp
+++ b/engines/wintermute/base/gfx/opengl/base_render_opengl3d_shader.cpp
@@ -170,6 +170,7 @@ void BaseRenderOpenGL3DShader::setLightParameters(int index, const DXVector3 &po
 }
 
 void BaseRenderOpenGL3DShader::enableCulling() {
+	glFrontFace(GL_CW);
 	glEnable(GL_CULL_FACE);
 }
 
@@ -471,7 +472,7 @@ bool BaseRenderOpenGL3DShader::setProjection() {
 	int mtop = rc.top;
 	int mbottom = resHeight - viewportHeight - rc.top;
 
-	DXMatrixPerspectiveFovRH(&matProj, _fov, viewportWidth / viewportHeight, _nearClipPlane, _farClipPlane);
+	DXMatrixPerspectiveFovLH(&matProj, _fov, viewportWidth / viewportHeight, _nearClipPlane, _farClipPlane);
 
 	float scaleMod = resHeight / viewportHeight;
 	float scaleRatio = MAX(layerWidth / resWidth, layerHeight / resHeight) /** 1.05*/;
@@ -891,7 +892,7 @@ void BaseRenderOpenGL3DShader::renderShadowGeometry(const BaseArray<AdWalkplane
 	// disable color write
 	glBlendFunc(GL_ZERO, GL_ONE);
 
-	glFrontFace(GL_CCW);
+	glFrontFace(GL_CW);
 	glBindTexture(GL_TEXTURE_2D, 0);
 
 	// render walk planes
diff --git a/engines/wintermute/base/gfx/opengl/shadow_volume_opengl.cpp b/engines/wintermute/base/gfx/opengl/shadow_volume_opengl.cpp
index ed3233f0d57..0fc098d415d 100644
--- a/engines/wintermute/base/gfx/opengl/shadow_volume_opengl.cpp
+++ b/engines/wintermute/base/gfx/opengl/shadow_volume_opengl.cpp
@@ -82,14 +82,14 @@ bool ShadowVolumeOpenGL::renderToStencilBuffer() {
 	glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
 
 	// Draw back-side of shadow volume in stencil/z only
-	glCullFace(GL_FRONT);
+	glFrontFace(GL_CCW);
 	render();
 
 	// Decrement stencil buffer value
 	glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
 
 	// Draw front-side of shadow volume in stencil/z only
-	glCullFace(GL_BACK);
+	glFrontFace(GL_CW);
 	render();
 
 	// Restore render states
diff --git a/engines/wintermute/base/gfx/opengl/shadow_volume_opengl_shader.cpp b/engines/wintermute/base/gfx/opengl/shadow_volume_opengl_shader.cpp
index e35e87c35ad..dd3a590e90d 100644
--- a/engines/wintermute/base/gfx/opengl/shadow_volume_opengl_shader.cpp
+++ b/engines/wintermute/base/gfx/opengl/shadow_volume_opengl_shader.cpp
@@ -110,14 +110,14 @@ bool ShadowVolumeOpenGLShader::renderToStencilBuffer() {
 	glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
 
 	// Draw back-side of shadow volume in stencil/z only
-	glCullFace(GL_FRONT);
+	glFrontFace(GL_CCW);
 	render();
 
 	// Decrement stencil buffer value
 	glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
 
 	// Draw front-side of shadow volume in stencil/z only
-	glCullFace(GL_BACK);
+	glFrontFace(GL_CW);
 	render();
 
 	// Restore render states
diff --git a/engines/wintermute/base/gfx/xanimation.cpp b/engines/wintermute/base/gfx/xanimation.cpp
index c45aa47fe87..c7f4619f620 100644
--- a/engines/wintermute/base/gfx/xanimation.cpp
+++ b/engines/wintermute/base/gfx/xanimation.cpp
@@ -156,8 +156,7 @@ bool Animation::loadAnimationKeyData(XAnimationKeyObject *animationKey) {
 			rotKey->_rotation._w = fileRotKey->_tfkeys[0];
 			rotKey->_rotation._x = fileRotKey->_tfkeys[1];
 			rotKey->_rotation._y = fileRotKey->_tfkeys[2];
-			// mirror z component
-			rotKey->_rotation._z = -fileRotKey->_tfkeys[3];
+			rotKey->_rotation._z = fileRotKey->_tfkeys[3];
 
 			_rotKeys.push_back(rotKey);
 		}
@@ -193,8 +192,7 @@ bool Animation::loadAnimationKeyData(XAnimationKeyObject *animationKey) {
 			posKey->_time = filePosKey->_time;
 			posKey->_pos._x = filePosKey->_tfkeys[0];
 			posKey->_pos._y = filePosKey->_tfkeys[1];
-			// mirror Z
-			posKey->_pos._z = -filePosKey->_tfkeys[2];
+			posKey->_pos._z = filePosKey->_tfkeys[2];
 
 			_posKeys.push_back(posKey);
 		}
@@ -218,17 +216,6 @@ bool Animation::loadAnimationKeyData(XAnimationKeyObject *animationKey) {
 				keyData._m4x4[i] = fileMatrixKey->_tfkeys[i];
 			}
 
-			// mirror at orign
-			keyData._m[3][2] *= -1.0f;
-
-			// mirror base vectors
-			keyData._m[0][2] *= -1.0f;
-			keyData._m[1][2] *= -1.0f;
-
-			// change handedness
-			keyData._m[2][0] *= -1.0f;
-			keyData._m[2][1] *= -1.0f;
-
 			// we always convert matrix keys to T-R-S
 			decomposeMatrixSimple(&keyData, &transVec, &scaleVec, &qRot);
 
@@ -244,10 +231,9 @@ bool Animation::loadAnimationKeyData(XAnimationKeyObject *animationKey) {
 			scaleKey->_scale = scaleVec;
 			rotationKey->_rotation = qRot;
 
-			// negate for opengl
-			rotationKey->_rotation._x = -(-rotationKey->_rotation._x);
-			rotationKey->_rotation._y = -(-rotationKey->_rotation._y);
-			rotationKey->_rotation._z = -(-rotationKey->_rotation._z);
+			rotationKey->_rotation._x = -rotationKey->_rotation._x;
+			rotationKey->_rotation._y = -rotationKey->_rotation._y;
+			rotationKey->_rotation._z = -rotationKey->_rotation._z;
 
 			_posKeys.push_back(positionKey);
 			_scaleKeys.push_back(scaleKey);
@@ -342,16 +328,14 @@ bool Animation::update(int slot, uint32 localTime, float animLerpValue) {
 		// apply spherical lerp function
 		DXQuaternion q1, q2;
 
-		// negate for opengl
-		q1._x =  -(-_rotKeys[keyIndex1]->_rotation._x);
-		q1._y =  -(-_rotKeys[keyIndex1]->_rotation._y);
-		q1._z =  -(-_rotKeys[keyIndex1]->_rotation._z);
+		q1._x = -_rotKeys[keyIndex1]->_rotation._x;
+		q1._y = -_rotKeys[keyIndex1]->_rotation._y;
+		q1._z = -_rotKeys[keyIndex1]->_rotation._z;
 		q1._w =  _rotKeys[keyIndex1]->_rotation._w;
 
-		// negate for opengl
-		q2._x =  -(-_rotKeys[keyIndex2]->_rotation._x);
-		q2._y =  -(-_rotKeys[keyIndex2]->_rotation._y);
-		q2._z =  -(-_rotKeys[keyIndex2]->_rotation._z);
+		q2._x = -_rotKeys[keyIndex2]->_rotation._x;
+		q2._y = -_rotKeys[keyIndex2]->_rotation._y;
+		q2._z = -_rotKeys[keyIndex2]->_rotation._z;
 		q2._w =  _rotKeys[keyIndex2]->_rotation._w;
 
 		DXQuaternionSlerp(&resultRot, &q1, &q2, lerpValue);
diff --git a/engines/wintermute/base/gfx/xframe_node.cpp b/engines/wintermute/base/gfx/xframe_node.cpp
index 7e74793eb99..5f05a9061be 100644
--- a/engines/wintermute/base/gfx/xframe_node.cpp
+++ b/engines/wintermute/base/gfx/xframe_node.cpp
@@ -131,18 +131,6 @@ bool FrameNode::loadFromXData(const Common::String &filename, XModel *model, XFi
 			for (int i = 0; i < 16; ++i) {
 				_transformationMatrix._m4x4[i] = frameTransformMatrix->_frameMatrix[i];
 			}
-
-			// mirror at orign
-			_transformationMatrix._m[3][2] *= -1.0f;
-
-			// mirror base vectors
-			_transformationMatrix._m[0][2] *= -1.0f;
-			_transformationMatrix._m[1][2] *= -1.0f;
-
-			// change handedness
-			_transformationMatrix._m[2][0] *= -1.0f;
-			_transformationMatrix._m[2][1] *= -1.0f;
-
 			_originalMatrix = _transformationMatrix;
 			return true;
 		}
diff --git a/engines/wintermute/base/gfx/xmesh.cpp b/engines/wintermute/base/gfx/xmesh.cpp
index 0b53f681d0a..508f3fa7402 100644
--- a/engines/wintermute/base/gfx/xmesh.cpp
+++ b/engines/wintermute/base/gfx/xmesh.cpp
@@ -86,29 +86,6 @@ bool XMesh::loadFromXData(const Common::String &filename, XFileData *xobj) {
 		BaseEngine::LOG(0, "Error loading skin mesh");
 		return false;
 	}
-
-	auto fvf = mesh->getFVF();
-	uint32 vertexSize = DXGetFVFVertexSize(fvf) / sizeof(float);
-	float *vertexBuffer = (float *)mesh->getVertexBuffer().ptr();
-	uint32 offset = 0, normalOffset = 0;
-
-	if (fvf & DXFVF_XYZ) {
-		offset += sizeof(DXVector3) / sizeof(float);
-	}
-	if (fvf & DXFVF_NORMAL) {
-		normalOffset = offset;
-	}
-
-	for (uint32 i = 0; i < mesh->getNumVertices(); ++i) {
-		// mirror z coordinate to change to OpenGL coordinate system
-		vertexBuffer[i * vertexSize + 2] *= -1.0f;
-
-		if (fvf & DXFVF_NORMAL) {
-			// mirror z coordinate to change to OpenGL coordinate system
-			vertexBuffer[i * vertexSize + normalOffset + 2] *= -1.0f;
-		}
-	}
-
 	_skinMesh = new SkinMeshHelper(mesh, skinInfo);
 
 	uint32 numBones = _skinMesh->getNumBones();
diff --git a/engines/wintermute/base/gfx/xmodel.cpp b/engines/wintermute/base/gfx/xmodel.cpp
index dcff2ba5f4b..8371c93c5ae 100644
--- a/engines/wintermute/base/gfx/xmodel.cpp
+++ b/engines/wintermute/base/gfx/xmodel.cpp
@@ -572,7 +572,7 @@ bool XModel::isTransparentAt(int x, int y) {
 	DXVector3 vec;
 	vec._x =  (((2.0f * x) / (_drawingViewport.width())) - 1) / _lastProjMat.matrix._11;
 	vec._y = -(((2.0f * y) / (_drawingViewport.height())) - 1) / _lastProjMat.matrix._22;
-	vec._z =  -1.0f;
+	vec._z =  1.0f;
 
 	// Get the inverse view matrix
 	DXMatrix m;
diff --git a/engines/wintermute/base/gfx/xskinmesh.cpp b/engines/wintermute/base/gfx/xskinmesh.cpp
index bd6c2f2b0af..377a15b710b 100644
--- a/engines/wintermute/base/gfx/xskinmesh.cpp
+++ b/engines/wintermute/base/gfx/xskinmesh.cpp
@@ -504,18 +504,6 @@ bool DXSkinInfo::setBoneOffsetMatrix(uint32 boneIdx, const float *boneTransform)
 	for (int m = 0; m < 16; m++) {
 		_bones[boneIdx]._transform._m4x4[m] = boneTransform[m];
 	}
-
-	// mirror at orign
-	_bones[boneIdx]._transform._m[3][2] *= -1.0f;
-
-	// mirror base vectors
-	_bones[boneIdx]._transform._m[0][2] *= -1.0f;
-	_bones[boneIdx]._transform._m[1][2] *= -1.0f;
-
-	// change handedness
-	_bones[boneIdx]._transform._m[2][0] *= -1.0f;
-	_bones[boneIdx]._transform._m[2][1] *= -1.0f;
-
 	return true;
 }
 
@@ -1122,17 +1110,17 @@ bool DXLoadSkinMesh(XFileData *fileData, DXBuffer &materialsOut, uint32 &numMate
 	for (i = 0; i < meshData._numPolyFaces; i++) {
 		uint32 count = meshData._numTriPerFace[i];
 		uint32 firstIndex = *indexInPtr++;
-		// 1 -> 1 -> 3
-		// 2 -> 2 -> 2
-		// 3 -> 3 -> 1
-		// 1 -> 4 -> 6
-		// 3 -> 5 -> 5
-		// 4 -> 6 -> 4
+		// 1 -> 1
+		// 2 -> 2
+		// 3 -> 3
+		// 1 -> 4
+		// 3 -> 5
+		// 4 -> 6
 		while (count--) {
-			indices[2] = firstIndex;
-			indices[1] = *indexInPtr++;
-			indices[0] = *indexInPtr;
-			indices += 3;
+			*indices++ = firstIndex;
+			*indices++ = *indexInPtr;
+			indexInPtr++;
+			*indices++ = *indexInPtr;
 		}
 		indexInPtr++;
 	}




More information about the Scummvm-git-logs mailing list