Merge pull request #64 from treeform/dev

Fix for lookAt: https://github.com/treeform/vmath/issues/63
This commit is contained in:
Andre von Houck 2023-03-01 07:40:50 -08:00 committed by GitHub
commit b0782541e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View file

@ -475,7 +475,8 @@ proc `zmod`*(a, b: float32): float32 =
template lowerType(a: typed): string =
($type(a)).toLowerAscii()
template genConstructor(lower, upper, typ: untyped) =
template genVecConstructor*(lower, upper, typ: untyped) =
## Generate vector constructor for your own type.
proc `lower 2`*(): `upper 2` = gvec2[typ](typ(0), typ(0))
proc `lower 3`*(): `upper 3` = gvec3[typ](typ(0), typ(0), typ(0))
@ -511,11 +512,11 @@ template genConstructor(lower, upper, typ: untyped) =
proc `$`*(a: `upper 4`): string =
lowerType(a) & "(" & $a.x & ", " & $a.y & ", " & $a.z & ", " & $a.w & ")"
genConstructor(bvec, BVec, bool)
genConstructor(ivec, IVec, int32)
genConstructor(uvec, UVec, uint32)
genConstructor(vec, Vec, float32)
genConstructor(dvec, DVec, float64)
genVecConstructor(bvec, BVec, bool)
genVecConstructor(ivec, IVec, int32)
genVecConstructor(uvec, UVec, uint32)
genVecConstructor(vec, Vec, float32)
genVecConstructor(dvec, DVec, float64)
proc vec2*(ivec2: Ivec2): Vec2 =
vec2(ivec2.x.float32, ivec2.y.float32)
@ -872,8 +873,8 @@ proc matToString[T](a: T, n: int): string =
result.setLen(result.len - 2)
result.add "\n)"
template genMatConstructor(lower, upper, T: untyped) =
template genMatConstructor*(lower, upper, T: untyped) =
## Generate matrix constructor for your own type.
proc `lower 2`*(
m00, m01,
m10, m11: T
@ -1345,7 +1346,7 @@ proc lookAt*[T](eye, center, up: GVec3[T]): GMat4[T] =
centerz = center[2]
if eyex == centerx and eyey == centery and eyez == centerz:
return mat4[T]()
return
var
# vec3.direction(eye, center, z)
@ -1434,7 +1435,8 @@ type
Quat* = GVec4[float32]
DQuat* = GVec4[float64]
template genQuatConstructor(lower, upper, typ: untyped) =
template genQuatConstructor*(lower, upper, typ: untyped) =
## Generate quaternion constructor for your own type.
proc `lower`*(): `upper` = gvec4[typ](0, 0, 0, 1)
proc `lower`*(x, y, z, w: typ): `upper` = gvec4[typ](x, y, z, w)
proc `lower`*(x: typ): `upper` = gvec4[typ](x, x, x, x)

View file

@ -882,6 +882,10 @@ block:
)
doAssert lookAt(vec3(0, 0, 1), vec3(0, 0, 0)).quat ~= quat(0.0, 0.0, 0.0, 1.0)
let
a = lookAt(vec3(1, 2, 3), vec3(0, 0, 0))
b = lookAt(dvec3(1, 2, 3), dvec3(0, 0, 0))
doAssert ortho[float32](-1, 1, 1, -1, -1000, 1000) ~= mat4(
1.0, 0.0, 0.0, 0.0,
0.0, -1.0, 0.0, 0.0,