# HG changeset patch # User sam # Date 1723535118 -25200 # Node ID 03400de84910491e2738d2e99de9d3fcc14406fe # Parent c5a23e910feabb893b750d406ad8cca02f10d81b add: more utils diff -r c5a23e910fea -r 03400de84910 semicongine/core/matrix.nim --- a/semicongine/core/matrix.nim Mon Aug 12 21:33:08 2024 +0700 +++ b/semicongine/core/matrix.nim Tue Aug 13 14:45:18 2024 +0700 @@ -453,6 +453,14 @@ result[3, 2] = (-a[3, 0] * s3 + a[3, 1] * s1 - a[3, 2] * s0) * invdet; result[3, 3] = ( a[2, 0] * s3 - a[2, 1] * s1 + a[2, 2] * s0) * invdet; +func transformed*[T, S](points: openArray[S], mat: TMat4[T]): seq[S] = + for p in points: + result.add mat * p + +func transform*[T, S](points: var openArray[S], mat: TMat4[T]) = + for p in points.mitems: + p = mat * p + func projection*(fovy, aspect, zNear, zFar: float32): Mat4 = let tanHalfFovy = 1 / tan(fovy / 2) return Mat4(data: [ diff -r c5a23e910fea -r 03400de84910 semicongine/core/vector.nim --- a/semicongine/core/vector.nim Mon Aug 12 21:33:08 2024 +0700 +++ b/semicongine/core/vector.nim Tue Aug 13 14:45:18 2024 +0700 @@ -172,6 +172,12 @@ func length*(vec: TVec4[SomeFloat]): auto = sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2] + vec[3] * vec[3]) func length*(vec: TVec4[SomeInteger]): auto = sqrt(float(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2] + vec[3] * vec[3])) + +func abs*[T](vec: TVec1[T]): auto = TVec1([abs(vec[0])]) +func abs*[T](vec: TVec2[T]): auto = TVec2([abs(vec[0]), abs(vec[1])]) +func abs*[T](vec: TVec3[T]): auto = TVec3([abs(vec[0]), abs(vec[1]), abs(vec[2])]) +func abs*[T](vec: TVec4[T]): auto = TVec4([abs(vec[0]), abs(vec[1]), abs(vec[2]), abs(vec[3])]) + func manhattan*(vec: TVec1): auto = abs(vec[0]) func manhattan*(vec: TVec2): auto = abs(vec[0]) + abs(vec[1]) func manhattan*(vec: TVec3): auto = abs(vec[0]) + abs(vec[1]) + abs(vec[2])