From 1eb2018bd37a15982ee37418ec9dc957d2ec3509 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Mon, 9 Aug 2021 17:08:22 +0200 Subject: [PATCH] Fix issues with double precision floating values --- src/collision/TriangleVertexArray.cpp | 22 ++++--- test/tests/collision/TestCollisionWorld.h | 76 ++++++++++++----------- test/tests/collision/TestPointInside.h | 20 +++--- test/tests/collision/TestRaycast.h | 20 +++--- test/tests/engine/TestRigidBody.h | 20 +++--- test/tests/mathematics/TestTransform.h | 34 +++++----- 6 files changed, 100 insertions(+), 92 deletions(-) diff --git a/src/collision/TriangleVertexArray.cpp b/src/collision/TriangleVertexArray.cpp index 36cdfa2b..62abd3cd 100644 --- a/src/collision/TriangleVertexArray.cpp +++ b/src/collision/TriangleVertexArray.cpp @@ -160,16 +160,20 @@ void TriangleVertexArray::computeVerticesNormals() { Vector3 b = triangleVertices[previousVertex] - triangleVertices[v]; Vector3 crossProduct = a.cross(b); - decimal sinA = crossProduct.length() / (edgesLengths[previousVertex] * edgesLengths[v]); - sinA = std::min(std::max(sinA, decimal(0.0)), decimal(1.0)); - decimal arcSinA = std::asin(sinA); - assert(arcSinA >= decimal(0.0)); - Vector3 normalComponent = arcSinA * crossProduct; + decimal edgeLengths = (edgesLengths[previousVertex] * edgesLengths[v]); + if (std::abs(edgeLengths) > decimal(MACHINE_EPSILON)) { - // Add the normal component of this vertex into the normals array - verticesNormals[verticesIndices[v] * 3] += normalComponent.x; - verticesNormals[verticesIndices[v] * 3 + 1] += normalComponent.y; - verticesNormals[verticesIndices[v] * 3 + 2] += normalComponent.z; + decimal sinA = crossProduct.length() / edgeLengths; + sinA = std::min(std::max(sinA, decimal(0.0)), decimal(1.0)); + decimal arcSinA = std::asin(sinA); + assert(arcSinA >= decimal(0.0)); + Vector3 normalComponent = arcSinA * crossProduct; + + // Add the normal component of this vertex into the normals array + verticesNormals[verticesIndices[v] * 3] += normalComponent.x; + verticesNormals[verticesIndices[v] * 3 + 1] += normalComponent.y; + verticesNormals[verticesIndices[v] * 3 + 2] += normalComponent.z; + } } } diff --git a/test/tests/collision/TestCollisionWorld.h b/test/tests/collision/TestCollisionWorld.h index ef37ce66..ef058792 100644 --- a/test/tests/collision/TestCollisionWorld.h +++ b/test/tests/collision/TestCollisionWorld.h @@ -310,11 +310,11 @@ class TestCollisionWorld : public Test { PolygonVertexArray::PolygonFace* mConvexMeshPolygonFaces; TriangleVertexArray* mConcaveMeshTriangleVertexArray; - Vector3 mConvexMesh1CubeVertices[8]; - Vector3 mConvexMesh2CubeVertices[8]; + float mConvexMesh1CubeVertices[8 * 3]; + float mConvexMesh2CubeVertices[8 * 3]; int mConvexMeshCubeIndices[24]; - Vector3 mConcaveMeshPlaneVertices[36]; + float mConcaveMeshPlaneVertices[36 * 3]; int mConcaveMeshPlaneIndices[25 * 2 * 3]; TriangleMesh* mConcaveTriangleMesh; @@ -368,30 +368,30 @@ class TestCollisionWorld : public Test { mCapsuleCollider2 = mCapsuleBody2->addCollider(mCapsuleShape2, Transform::identity()); // ---------- Convex Meshes ---------- // - mConvexMesh1CubeVertices[0] = Vector3(-3, -3, 3); - mConvexMesh1CubeVertices[1] = Vector3(3, -3, 3); - mConvexMesh1CubeVertices[2] = Vector3(3, -3, -3); - mConvexMesh1CubeVertices[3] = Vector3(-3, -3, -3); - mConvexMesh1CubeVertices[4] = Vector3(-3, 3, 3); - mConvexMesh1CubeVertices[5] = Vector3(3, 3, 3); - mConvexMesh1CubeVertices[6] = Vector3(3, 3, -3); - mConvexMesh1CubeVertices[7] = Vector3(-3, 3, -3); + mConvexMesh1CubeVertices[0] = -3; mConvexMesh1CubeVertices[1] = -3; mConvexMesh1CubeVertices[2] = 3; + mConvexMesh1CubeVertices[3] = 3; mConvexMesh1CubeVertices[4] = -3; mConvexMesh1CubeVertices[5] = 3; + mConvexMesh1CubeVertices[6] = 3; mConvexMesh1CubeVertices[7] = -3; mConvexMesh1CubeVertices[8] = -3; + mConvexMesh1CubeVertices[9] = -3; mConvexMesh1CubeVertices[10] = -3; mConvexMesh1CubeVertices[11] = -3; + mConvexMesh1CubeVertices[12] = -3; mConvexMesh1CubeVertices[13] = 3; mConvexMesh1CubeVertices[14] = 3; + mConvexMesh1CubeVertices[15] = 3; mConvexMesh1CubeVertices[16] = 3; mConvexMesh1CubeVertices[17] = 3; + mConvexMesh1CubeVertices[18] = 3; mConvexMesh1CubeVertices[19] = 3; mConvexMesh1CubeVertices[20] = -3; + mConvexMesh1CubeVertices[21] = -3; mConvexMesh1CubeVertices[22] = 3; mConvexMesh1CubeVertices[23] = -3; - mConvexMeshCubeIndices[0] = 0; mConvexMeshCubeIndices[1] = 3; mConvexMeshCubeIndices[2] = 2; mConvexMeshCubeIndices[3] = 1; - mConvexMeshCubeIndices[4] = 4; mConvexMeshCubeIndices[5] = 5; mConvexMeshCubeIndices[6] = 6; mConvexMeshCubeIndices[7] = 7; - mConvexMeshCubeIndices[8] = 0; mConvexMeshCubeIndices[9] = 1; mConvexMeshCubeIndices[10] = 5; mConvexMeshCubeIndices[11] = 4; - mConvexMeshCubeIndices[12] = 1; mConvexMeshCubeIndices[13] = 2; mConvexMeshCubeIndices[14] = 6; mConvexMeshCubeIndices[15] = 5; - mConvexMeshCubeIndices[16] = 2; mConvexMeshCubeIndices[17] = 3; mConvexMeshCubeIndices[18] = 7; mConvexMeshCubeIndices[19] = 6; - mConvexMeshCubeIndices[20] = 0; mConvexMeshCubeIndices[21] = 4; mConvexMeshCubeIndices[22] = 7; mConvexMeshCubeIndices[23] = 3; + mConvexMeshCubeIndices[0] = 0; mConvexMeshCubeIndices[1] = 3; mConvexMeshCubeIndices[2] = 2; mConvexMeshCubeIndices[3] = 1; + mConvexMeshCubeIndices[4] = 4; mConvexMeshCubeIndices[5] = 5; mConvexMeshCubeIndices[6] = 6; mConvexMeshCubeIndices[7] = 7; + mConvexMeshCubeIndices[8] = 0; mConvexMeshCubeIndices[9] = 1; mConvexMeshCubeIndices[10] = 5; mConvexMeshCubeIndices[11] = 4; + mConvexMeshCubeIndices[12] = 1; mConvexMeshCubeIndices[13] = 2; mConvexMeshCubeIndices[14] = 6; mConvexMeshCubeIndices[15] = 5; + mConvexMeshCubeIndices[16] = 2; mConvexMeshCubeIndices[17] = 3; mConvexMeshCubeIndices[18] = 7; mConvexMeshCubeIndices[19] = 6; + mConvexMeshCubeIndices[20] = 0; mConvexMeshCubeIndices[21] = 4; mConvexMeshCubeIndices[22] = 7; mConvexMeshCubeIndices[23] = 3; mConvexMeshPolygonFaces = new rp3d::PolygonVertexArray::PolygonFace[6]; rp3d::PolygonVertexArray::PolygonFace* face = mConvexMeshPolygonFaces; for (int f = 0; f < 6; f++) { - face->indexBase = f * 4; + face->indexBase = f * 4; face->nbVertices = 4; face++; } - mConvexMesh1PolygonVertexArray = new rp3d::PolygonVertexArray(8, &(mConvexMesh1CubeVertices[0]), sizeof(Vector3), + mConvexMesh1PolygonVertexArray = new rp3d::PolygonVertexArray(8, &(mConvexMesh1CubeVertices[0]), 3 * sizeof(float), &(mConvexMeshCubeIndices[0]), sizeof(int), 6, mConvexMeshPolygonFaces, rp3d::PolygonVertexArray::VertexDataType::VERTEX_FLOAT_TYPE, rp3d::PolygonVertexArray::IndexDataType::INDEX_INTEGER_TYPE); @@ -401,16 +401,16 @@ class TestCollisionWorld : public Test { mConvexMeshBody1 = mWorld->createCollisionBody(convexMeshTransform1); mConvexMeshCollider1 = mConvexMeshBody1->addCollider(mConvexMeshShape1, Transform::identity()); - mConvexMesh2CubeVertices[0] = Vector3(-4, -2, 8); - mConvexMesh2CubeVertices[1] = Vector3(4, -2, 8); - mConvexMesh2CubeVertices[2] = Vector3(4, -2, -8); - mConvexMesh2CubeVertices[3] = Vector3(-4, -2, -8); - mConvexMesh2CubeVertices[4] = Vector3(-4, 2, 8); - mConvexMesh2CubeVertices[5] = Vector3(4, 2, 8); - mConvexMesh2CubeVertices[6] = Vector3(4, 2, -8); - mConvexMesh2CubeVertices[7] = Vector3(-4, 2, -8); + mConvexMesh2CubeVertices[0] = -4; mConvexMesh2CubeVertices[1] = -2; mConvexMesh2CubeVertices[2] = 8; + mConvexMesh2CubeVertices[3] = 4; mConvexMesh2CubeVertices[4] = -2; mConvexMesh2CubeVertices[5] = 8; + mConvexMesh2CubeVertices[6] = 4; mConvexMesh2CubeVertices[7] = -2; mConvexMesh2CubeVertices[8] = -8; + mConvexMesh2CubeVertices[9] = -4; mConvexMesh2CubeVertices[10] = -2; mConvexMesh2CubeVertices[11] = -8; + mConvexMesh2CubeVertices[12] = -4; mConvexMesh2CubeVertices[13] = 2; mConvexMesh2CubeVertices[14] = 8; + mConvexMesh2CubeVertices[15] = 4; mConvexMesh2CubeVertices[16] = 2; mConvexMesh2CubeVertices[17] = 8; + mConvexMesh2CubeVertices[18] = 4; mConvexMesh2CubeVertices[19] = 2; mConvexMesh2CubeVertices[20] = -8; + mConvexMesh2CubeVertices[21] = -4; mConvexMesh2CubeVertices[22] = 2; mConvexMesh2CubeVertices[23] = -8; - mConvexMesh2PolygonVertexArray = new rp3d::PolygonVertexArray(8, &(mConvexMesh2CubeVertices[0]), sizeof(Vector3), + mConvexMesh2PolygonVertexArray = new rp3d::PolygonVertexArray(8, &(mConvexMesh2CubeVertices[0]), 3 * sizeof(float), &(mConvexMeshCubeIndices[0]), sizeof(int), 6, mConvexMeshPolygonFaces, rp3d::PolygonVertexArray::VertexDataType::VERTEX_FLOAT_TYPE, rp3d::PolygonVertexArray::IndexDataType::INDEX_INTEGER_TYPE); @@ -423,30 +423,32 @@ class TestCollisionWorld : public Test { // ---------- Concave Meshes ---------- // for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { - mConcaveMeshPlaneVertices[i * 6 + j] = Vector3(-2.5f + i, 0, -2.5f + j); - } + mConcaveMeshPlaneVertices[i * 6 * 3 + j * 3] = -2.5f + i; + mConcaveMeshPlaneVertices[i * 6 * 3+ (j * 3) + 1] = 0; + mConcaveMeshPlaneVertices[i * 6 * 3+ (j * 3) + 2] = -2.5f + j; + } } int triangleIndex = 0; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { // Triangle 1 - mConcaveMeshPlaneIndices[triangleIndex * 3] = i * 6 + j; - mConcaveMeshPlaneIndices[triangleIndex * 3 + 1] = (i+1) * 6 + (j+1); - mConcaveMeshPlaneIndices[triangleIndex * 3 + 2] = i * 6 + (j+1); + mConcaveMeshPlaneIndices[triangleIndex * 3] = i * 6+ j; + mConcaveMeshPlaneIndices[triangleIndex * 3 + 1] = (i+1) * 6 + (j+1); + mConcaveMeshPlaneIndices[triangleIndex * 3 + 2] = i * 6+ (j+1); triangleIndex++; // Triangle 2 - mConcaveMeshPlaneIndices[triangleIndex * 3] = i * 6 + j; - mConcaveMeshPlaneIndices[triangleIndex * 3 + 1] = (i+1) * 6 + j; + mConcaveMeshPlaneIndices[triangleIndex * 3] = i * 6+ j; + mConcaveMeshPlaneIndices[triangleIndex * 3 + 1] = (i+1) * 6 + j; mConcaveMeshPlaneIndices[triangleIndex * 3 + 2] = (i+1) * 6 + (j+1); triangleIndex++; } } - mConcaveMeshTriangleVertexArray = new rp3d::TriangleVertexArray(36, &(mConcaveMeshPlaneVertices[0]), sizeof(Vector3), + mConcaveMeshTriangleVertexArray = new rp3d::TriangleVertexArray(36, &(mConcaveMeshPlaneVertices[0]), 3 * sizeof(float), 50, &(mConcaveMeshPlaneIndices[0]), 3 * sizeof(int), - rp3d::TriangleVertexArray::VertexDataType::VERTEX_FLOAT_TYPE, + rp3d::TriangleVertexArray::VertexDataType::VERTEX_FLOAT_TYPE, rp3d::TriangleVertexArray::IndexDataType::INDEX_INTEGER_TYPE); // Add the triangle vertex array of the subpart to the triangle mesh diff --git a/test/tests/collision/TestPointInside.h b/test/tests/collision/TestPointInside.h index 63fac628..f5203f2f 100644 --- a/test/tests/collision/TestPointInside.h +++ b/test/tests/collision/TestPointInside.h @@ -65,7 +65,7 @@ class TestPointInside : public Test { CollisionBody* mCylinderBody; CollisionBody* mCompoundBody; - Vector3 mConvexMeshCubeVertices[8]; + float mConvexMeshCubeVertices[8 * 3]; int mConvexMeshCubeIndices[24]; PolygonVertexArray* mConvexMeshPolygonVertexArray; PolyhedronMesh* mConvexMeshPolyhedronMesh; @@ -133,14 +133,14 @@ class TestPointInside : public Test { mCapsuleShape = mPhysicsCommon.createCapsuleShape(3, 10); mCapsuleCollider = mCapsuleBody->addCollider(mCapsuleShape, mShapeTransform); - mConvexMeshCubeVertices[0] = Vector3(-2, -3, 4); - mConvexMeshCubeVertices[1] = Vector3(2, -3, 4); - mConvexMeshCubeVertices[2] = Vector3(2, -3, -4); - mConvexMeshCubeVertices[3] = Vector3(-2, -3, -4); - mConvexMeshCubeVertices[4] = Vector3(-2, 3, 4); - mConvexMeshCubeVertices[5] = Vector3(2, 3, 4); - mConvexMeshCubeVertices[6] = Vector3(2, 3, -4); - mConvexMeshCubeVertices[7] = Vector3(-2, 3, -4); + mConvexMeshCubeVertices[0] = -2; mConvexMeshCubeVertices[1] = -3; mConvexMeshCubeVertices[2] = 4; + mConvexMeshCubeVertices[3] = 2; mConvexMeshCubeVertices[4] = -3; mConvexMeshCubeVertices[5] = 4; + mConvexMeshCubeVertices[6] = 2; mConvexMeshCubeVertices[7] = -3; mConvexMeshCubeVertices[8] = -4; + mConvexMeshCubeVertices[9] = -2; mConvexMeshCubeVertices[10] = -3; mConvexMeshCubeVertices[11] = -4; + mConvexMeshCubeVertices[12] = -2; mConvexMeshCubeVertices[13] = 3; mConvexMeshCubeVertices[14] = 4; + mConvexMeshCubeVertices[15] = 2; mConvexMeshCubeVertices[16] = 3; mConvexMeshCubeVertices[17] = 4; + mConvexMeshCubeVertices[18] = 2; mConvexMeshCubeVertices[19] = 3; mConvexMeshCubeVertices[20] = -4; + mConvexMeshCubeVertices[21] = -2; mConvexMeshCubeVertices[22] = 3; mConvexMeshCubeVertices[23] = -4; mConvexMeshCubeIndices[0] = 0; mConvexMeshCubeIndices[1] = 3; mConvexMeshCubeIndices[2] = 2; mConvexMeshCubeIndices[3] = 1; mConvexMeshCubeIndices[4] = 4; mConvexMeshCubeIndices[5] = 5; mConvexMeshCubeIndices[6] = 6; mConvexMeshCubeIndices[7] = 7; @@ -156,7 +156,7 @@ class TestPointInside : public Test { face->nbVertices = 4; face++; } - mConvexMeshPolygonVertexArray = new PolygonVertexArray(8, &(mConvexMeshCubeVertices[0]), sizeof(Vector3), + mConvexMeshPolygonVertexArray = new PolygonVertexArray(8, &(mConvexMeshCubeVertices[0]), 3 * sizeof(float), &(mConvexMeshCubeIndices[0]), sizeof(int), 6, mConvexMeshPolygonFaces, PolygonVertexArray::VertexDataType::VERTEX_FLOAT_TYPE, PolygonVertexArray::IndexDataType::INDEX_INTEGER_TYPE); diff --git a/test/tests/collision/TestRaycast.h b/test/tests/collision/TestRaycast.h index f2b0a248..b9d680a1 100644 --- a/test/tests/collision/TestRaycast.h +++ b/test/tests/collision/TestRaycast.h @@ -159,7 +159,7 @@ class TestRaycast : public Test { PolygonVertexArray::PolygonFace mPolygonFaces[6]; PolygonVertexArray* mPolygonVertexArray; PolyhedronMesh* mPolyhedronMesh; - Vector3 mPolyhedronVertices[8]; + float mPolyhedronVertices[8 * 3]; int mPolyhedronIndices[4 * 6]; public : @@ -207,14 +207,14 @@ class TestRaycast : public Test { mCapsuleShape = mPhysicsCommon.createCapsuleShape(2, 5); mCapsuleCollider = mCapsuleBody->addCollider(mCapsuleShape, mShapeTransform); - mPolyhedronVertices[0] = Vector3(-2, -3, 4); - mPolyhedronVertices[1] = Vector3(2, -3, 4); - mPolyhedronVertices[2] = Vector3(2, -3, -4); - mPolyhedronVertices[3] = Vector3(-2, -3, -4); - mPolyhedronVertices[4] = Vector3(-2, 3, 4); - mPolyhedronVertices[5] = Vector3(2, 3, 4); - mPolyhedronVertices[6] = Vector3(2, 3, -4); - mPolyhedronVertices[7] = Vector3(-2, 3, -4); + mPolyhedronVertices[0] = -2; mPolyhedronVertices[1] = -3; mPolyhedronVertices[2] = 4; + mPolyhedronVertices[3] = 2; mPolyhedronVertices[4] = -3; mPolyhedronVertices[5] = 4; + mPolyhedronVertices[6] = 2; mPolyhedronVertices[7] = -3; mPolyhedronVertices[8] = -4; + mPolyhedronVertices[9] = -2; mPolyhedronVertices[10] = -3; mPolyhedronVertices[11] = -4; + mPolyhedronVertices[12] = -2; mPolyhedronVertices[13] = 3; mPolyhedronVertices[14] = 4; + mPolyhedronVertices[15] = 2; mPolyhedronVertices[16] = 3; mPolyhedronVertices[17] = 4; + mPolyhedronVertices[18] = 2; mPolyhedronVertices[19] = 3; mPolyhedronVertices[20] = -4; + mPolyhedronVertices[21] = -2; mPolyhedronVertices[22] = 3; mPolyhedronVertices[23] = -4; mPolyhedronIndices[0] = 0; mPolyhedronIndices[1] = 3; mPolyhedronIndices[2] = 2; mPolyhedronIndices[3] = 1; mPolyhedronIndices[4] = 4; mPolyhedronIndices[5] = 5; mPolyhedronIndices[6] = 6; mPolyhedronIndices[7] = 7; @@ -232,7 +232,7 @@ class TestRaycast : public Test { } // Create the polygon vertex array - mPolygonVertexArray = new PolygonVertexArray(8, mPolyhedronVertices, sizeof(Vector3), + mPolygonVertexArray = new PolygonVertexArray(8, mPolyhedronVertices, 3 * sizeof(float), mPolyhedronIndices, sizeof(int), 6, mPolygonFaces, PolygonVertexArray::VertexDataType::VERTEX_FLOAT_TYPE, PolygonVertexArray::IndexDataType::INDEX_INTEGER_TYPE); diff --git a/test/tests/engine/TestRigidBody.h b/test/tests/engine/TestRigidBody.h index 4d6b24c2..1b539d50 100644 --- a/test/tests/engine/TestRigidBody.h +++ b/test/tests/engine/TestRigidBody.h @@ -59,7 +59,7 @@ class TestRigidBody : public Test { PolyhedronMesh* mConvexMeshPolyhedronMesh; PolygonVertexArray::PolygonFace* mConvexMeshPolygonFaces; TriangleVertexArray* mConcaveMeshTriangleVertexArray; - Vector3 mConvexMeshCubeVertices[8]; + float mConvexMeshCubeVertices[8 * 3]; int mConvexMeshCubeIndices[24]; public : @@ -89,14 +89,14 @@ class TestRigidBody : public Test { // Convex Meshes (in the shape of a box) - mConvexMeshCubeVertices[0] = Vector3(-3, -3, 3); - mConvexMeshCubeVertices[1] = Vector3(3, -3, 3); - mConvexMeshCubeVertices[2] = Vector3(3, -3, -3); - mConvexMeshCubeVertices[3] = Vector3(-3, -3, -3); - mConvexMeshCubeVertices[4] = Vector3(-3, 3, 3); - mConvexMeshCubeVertices[5] = Vector3(3, 3, 3); - mConvexMeshCubeVertices[6] = Vector3(3, 3, -3); - mConvexMeshCubeVertices[7] = Vector3(-3, 3, -3); + mConvexMeshCubeVertices[0] = -3; mConvexMeshCubeVertices[1] = -3; mConvexMeshCubeVertices[2] = 3; + mConvexMeshCubeVertices[3] = 3; mConvexMeshCubeVertices[4] = -3; mConvexMeshCubeVertices[5] = 3; + mConvexMeshCubeVertices[6] = 3; mConvexMeshCubeVertices[7] = -3; mConvexMeshCubeVertices[8] = -3; + mConvexMeshCubeVertices[9] = -3; mConvexMeshCubeVertices[10] = -3; mConvexMeshCubeVertices[11] = -3; + mConvexMeshCubeVertices[12] = -3; mConvexMeshCubeVertices[13] = 3; mConvexMeshCubeVertices[14] = 3; + mConvexMeshCubeVertices[15] = 3; mConvexMeshCubeVertices[16] = 3; mConvexMeshCubeVertices[17] = 3; + mConvexMeshCubeVertices[18] = 3; mConvexMeshCubeVertices[19] = 3; mConvexMeshCubeVertices[20] = -3; + mConvexMeshCubeVertices[21] = -3; mConvexMeshCubeVertices[22] = 3; mConvexMeshCubeVertices[23] = -3; mConvexMeshCubeIndices[0] = 0; mConvexMeshCubeIndices[1] = 3; mConvexMeshCubeIndices[2] = 2; mConvexMeshCubeIndices[3] = 1; mConvexMeshCubeIndices[4] = 4; mConvexMeshCubeIndices[5] = 5; mConvexMeshCubeIndices[6] = 6; mConvexMeshCubeIndices[7] = 7; @@ -112,7 +112,7 @@ class TestRigidBody : public Test { face->nbVertices = 4; face++; } - mConvexMeshPolygonVertexArray = new rp3d::PolygonVertexArray(8, &(mConvexMeshCubeVertices[0]), sizeof(Vector3), + mConvexMeshPolygonVertexArray = new rp3d::PolygonVertexArray(8, &(mConvexMeshCubeVertices[0]), 3 * sizeof(float), &(mConvexMeshCubeIndices[0]), sizeof(int), 6, mConvexMeshPolygonFaces, rp3d::PolygonVertexArray::VertexDataType::VERTEX_FLOAT_TYPE, rp3d::PolygonVertexArray::IndexDataType::INDEX_INTEGER_TYPE); diff --git a/test/tests/mathematics/TestTransform.h b/test/tests/mathematics/TestTransform.h index 74006034..0c267cdb 100644 --- a/test/tests/mathematics/TestTransform.h +++ b/test/tests/mathematics/TestTransform.h @@ -53,6 +53,8 @@ class TestTransform : public Test { /// Second example transform Transform mTransform2; + const float mEpsilon = 0.0001; + public : // ---------- Methods ---------- // @@ -137,22 +139,22 @@ class TestTransform : public Test { transform.setFromOpenGL(openglMatrix); decimal openglMatrix2[16]; transform.getOpenGLMatrix(openglMatrix2); - rp3d_test(approxEqual(openglMatrix2[0], orientation[0][0])); - rp3d_test(approxEqual(openglMatrix2[1], orientation[1][0])); - rp3d_test(approxEqual(openglMatrix2[2], orientation[2][0])); - rp3d_test(approxEqual(openglMatrix2[3], 0)); - rp3d_test(approxEqual(openglMatrix2[4], orientation[0][1])); - rp3d_test(approxEqual(openglMatrix2[5], orientation[1][1])); - rp3d_test(approxEqual(openglMatrix2[6], orientation[2][1])); - rp3d_test(approxEqual(openglMatrix2[7], 0)); - rp3d_test(approxEqual(openglMatrix2[8], orientation[0][2])); - rp3d_test(approxEqual(openglMatrix2[9], orientation[1][2])); - rp3d_test(approxEqual(openglMatrix2[10], orientation[2][2])); - rp3d_test(approxEqual(openglMatrix2[11], 0)); - rp3d_test(approxEqual(openglMatrix2[12], position.x)); - rp3d_test(approxEqual(openglMatrix2[13], position.y)); - rp3d_test(approxEqual(openglMatrix2[14], position.z)); - rp3d_test(approxEqual(openglMatrix2[15], 1)); + rp3d_test(approxEqual(openglMatrix2[0], orientation[0][0], mEpsilon)); + rp3d_test(approxEqual(openglMatrix2[1], orientation[1][0], mEpsilon)); + rp3d_test(approxEqual(openglMatrix2[2], orientation[2][0], mEpsilon)); + rp3d_test(approxEqual(openglMatrix2[3], 0, mEpsilon)); + rp3d_test(approxEqual(openglMatrix2[4], orientation[0][1], mEpsilon)); + rp3d_test(approxEqual(openglMatrix2[5], orientation[1][1], mEpsilon)); + rp3d_test(approxEqual(openglMatrix2[6], orientation[2][1], mEpsilon)); + rp3d_test(approxEqual(openglMatrix2[7], 0, mEpsilon)); + rp3d_test(approxEqual(openglMatrix2[8], orientation[0][2], mEpsilon)); + rp3d_test(approxEqual(openglMatrix2[9], orientation[1][2], mEpsilon)); + rp3d_test(approxEqual(openglMatrix2[10], orientation[2][2], mEpsilon)); + rp3d_test(approxEqual(openglMatrix2[11], 0, mEpsilon)); + rp3d_test(approxEqual(openglMatrix2[12], position.x, mEpsilon)); + rp3d_test(approxEqual(openglMatrix2[13], position.y, mEpsilon)); + rp3d_test(approxEqual(openglMatrix2[14], position.z, mEpsilon)); + rp3d_test(approxEqual(openglMatrix2[15], 1, mEpsilon)); } /// Test the method to interpolate transforms