From 7eb22ce304daeee69fb970cc88ff0b881dff0d0f Mon Sep 17 00:00:00 2001 From: shashclp Date: Tue, 24 Apr 2007 21:07:10 +0000 Subject: [PATCH] - Fixed normal transformation, as, obviously, normals MUST NOT be transformed by a 4x4 matrix: translation is meaningless on normals :P - Added matrix.h to the .vcproj --- desmume/src/matrix.c | 13 ++++++++++++- desmume/src/matrix.h | 3 ++- desmume/src/windows/OGLRender.c | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/desmume/src/matrix.c b/desmume/src/matrix.c index 1bb804b29..555d62b15 100644 --- a/desmume/src/matrix.c +++ b/desmume/src/matrix.c @@ -30,7 +30,7 @@ void MatrixInit (float *matrix) matrix[0] = matrix[5] = matrix[10] = matrix[15] = 1.f; } -void MatrixMultVec (float *matrix, float *vecPtr) +void MatrixMultVec4x4 (float *matrix, float *vecPtr) { float x = vecPtr[0]; float y = vecPtr[1]; @@ -41,6 +41,17 @@ void MatrixMultVec (float *matrix, float *vecPtr) vecPtr[2] = x * matrix[2] + y * matrix[6] + z * matrix[10] + matrix[14]; } +void MatrixMultVec3x3 (float *matrix, float *vecPtr) +{ + float x = vecPtr[0]; + float y = vecPtr[1]; + float z = vecPtr[2]; + + vecPtr[0] = x * matrix[0] + y * matrix[4] + z * matrix[ 8]; + vecPtr[1] = x * matrix[1] + y * matrix[5] + z * matrix[ 9]; + vecPtr[2] = x * matrix[2] + y * matrix[6] + z * matrix[10]; +} + void MatrixIdentity (float *matrix) { memset (matrix, 0, sizeof(float)*16); diff --git a/desmume/src/matrix.h b/desmume/src/matrix.h index c15639cef..05c0786e2 100644 --- a/desmume/src/matrix.h +++ b/desmume/src/matrix.h @@ -29,7 +29,8 @@ typedef struct MatrixStack } MatrixStack; void MatrixInit (float *matrix); -void MatrixMultVec (float *matrix, float *vecPtr); +void MatrixMultVec3x3 (float *matrix, float *vecPtr); +void MatrixMultVec4x4 (float *matrix, float *vecPtr); void MatrixIdentity (float *matrix); void MatrixMultiply (float *matrix, float *rightMatrix); float MatrixGetMultipliedIndex(int index, float *matrix, float *rightMatrix); diff --git a/desmume/src/windows/OGLRender.c b/desmume/src/windows/OGLRender.c index 85496b401..554e7183e 100644 --- a/desmume/src/windows/OGLRender.c +++ b/desmume/src/windows/OGLRender.c @@ -971,7 +971,7 @@ static __inline void SetVertex() SetTextureCoordinate (s2, t2); } - MatrixMultVec (mtxCurrent[1], coordTransformed); + MatrixMultVec4x4 (mtxCurrent[1], coordTransformed); glVertex3fv (coordTransformed); //glVertex3fv (coord); @@ -1377,7 +1377,7 @@ void NDS_glNormal(unsigned long v) SetTextureCoordinate (s2, t2); } - MatrixMultVec (mtxCurrent[2], normal); + MatrixMultVec3x3 (mtxCurrent[2], normal); glNormal3fv(normal); }