From dcc1f0f5c6725f38fb6f07679f7090187687a243 Mon Sep 17 00:00:00 2001 From: petsqy Date: Fri, 24 Dec 2021 11:55:10 +0200 Subject: [PATCH] fix GMat4.pos --- src/vmath.nim | 8 ++++---- tests/test.nim | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/vmath.nim b/src/vmath.nim index 8319fde..2c2010c 100644 --- a/src/vmath.nim +++ b/src/vmath.nim @@ -898,12 +898,12 @@ proc `pos=`*[T](a: var GMat3[T], pos: GVec2[T]) = a[2, 1] = pos.y proc pos*[T](a: GMat4[T]): GVec3[T] = - gvec2[T](a[2].x, a[2].y, a[2].z) + gvec3[T](a[3].x, a[3].y, a[3].z) proc `pos=`*[T](a: var GMat4[T], pos: GVec3[T]) = - a[2, 0] = pos.x - a[2, 1] = pos.y - a[2, 2] = pos.z + a[3, 0] = pos.x + a[3, 1] = pos.y + a[3, 2] = pos.z proc `*`*[T](a, b: GMat3[T]): GMat3[T] = result[0, 0] = b[0, 0] * a[0, 0] + b[0, 1] * a[1, 0] + b[0, 2] * a[2, 0] diff --git a/tests/test.nim b/tests/test.nim index d2b7d5a..2d2c0bc 100644 --- a/tests/test.nim +++ b/tests/test.nim @@ -591,11 +591,20 @@ block: 0.0, 0.0, 0.0, 1.0 ) - doAssert translate(vec2(1, 2)).pos == vec2(1, 2) - var translation = translate(vec2(1, 2)) - translation.pos = vec2(3, 4) - doAssert translation.pos == vec2(3, 4) + block: + doAssert translate(vec2(1, 2)).pos == vec2(1, 2) + + var translation = translate(vec2(1, 2)) + translation.pos = vec2(3, 4) + doAssert translation.pos == vec2(3, 4) + + block: + doAssert translate(vec3(1, 2, 3)).pos == vec3(1, 2, 3) + + var translation = translate(vec3(1, 2, 3)) + translation.pos = vec3(3, 4, 5) + doAssert translation.pos == vec3(3, 4, 5) block: # Test basic vector mat4 and quat.