# HG changeset patch # User Sam # Date 1674207412 -25200 # Node ID 8287a91e5d564452280651fd0a32c738ba68d5dd # Parent 547f3a37427187e30f5708d5b614c1530a6e5bed did: refactor Matrix names diff -r 547f3a374271 -r 8287a91e5d56 examples/alotof_triangles.nim --- a/examples/alotof_triangles.nim Fri Jan 20 16:13:32 2023 +0700 +++ b/examples/alotof_triangles.nim Fri Jan 20 16:36:52 2023 +0700 @@ -16,7 +16,7 @@ proc globalUpdate(engine: var Engine, dt: float32) = discard -proc randomtransform(): Mat33[float32] = +proc randomtransform(): TMat33[float32] = let randomscale = scale2d(float32(rand(1.0) + 0.5), float32(rand(1.0) + 0.5)) let randomrotate = rotate2d(float32(rand(2 * PI))) let randomtranslate = translate2d(float32(rand(1.6) - 0.8), float32(rand(1.6) - 0.8)) diff -r 547f3a374271 -r 8287a91e5d56 examples/hello_cube.nim --- a/examples/hello_cube.nim Fri Jan 20 16:13:32 2023 +0700 +++ b/examples/hello_cube.nim Fri Jan 20 16:36:52 2023 +0700 @@ -20,9 +20,9 @@ position: PositionAttribute[TVec3[float32]] color: ColorAttribute[TVec3[float32]] Uniforms = object - model: Descriptor[Mat44[float32]] - view: Descriptor[Mat44[float32]] - projection: Descriptor[Mat44[float32]] + model: Descriptor[TMat44[float32]] + view: Descriptor[TMat44[float32]] + projection: Descriptor[TMat44[float32]] var pipeline: RenderPipeline[VertexDataA, Uniforms] @@ -36,7 +36,7 @@ uniforms.model.value = translate3d(0'f32, 0'f32, 10'f32) * rotate3d(t, Yf32) # * rotate3d(float32(PI), Yf32) uniforms.view.value = Unit44f32 - uniforms.projection.value = Mat44[float32](data:[ + uniforms.projection.value = TMat44[float32](data:[ ratio, 0'f32, 0'f32, 0'f32, 0'f32, 1'f32, 0'f32, 0'f32, 0'f32, 0'f32, 1'f32, 0'f32, diff -r 547f3a374271 -r 8287a91e5d56 examples/input.nim --- a/examples/input.nim Fri Jan 20 16:13:32 2023 +0700 +++ b/examples/input.nim Fri Jan 20 16:36:52 2023 +0700 @@ -11,7 +11,7 @@ color: ColorAttribute[TVec3[float32]] iscursor: GenericAttribute[int32] Uniforms = object - projection: Descriptor[Mat44[float32]] + projection: Descriptor[TMat44[float32]] cursor: Descriptor[TVec2[float32]] var diff -r 547f3a374271 -r 8287a91e5d56 src/semicongine/descriptor.nim --- a/src/semicongine/descriptor.nim Fri Jan 20 16:13:32 2023 +0700 +++ b/src/semicongine/descriptor.nim Fri Jan 20 16:36:52 2023 +0700 @@ -13,7 +13,7 @@ # TODO: check for alignment in uniform blocks # type - DescriptorType = SomeNumber|TVec|Mat + DescriptorType = SomeNumber|TVec|TMat Descriptor*[T:DescriptorType] = object value*: T diff -r 547f3a374271 -r 8287a91e5d56 src/semicongine/glsl_helpers.nim --- a/src/semicongine/glsl_helpers.nim Fri Jan 20 16:13:32 2023 +0700 +++ b/src/semicongine/glsl_helpers.nim Fri Jan 20 16:36:52 2023 +0700 @@ -50,18 +50,18 @@ elif T is TVec4[float32]: "vec4" elif T is TVec4[float64]: "dvec4" - elif T is Mat22[float32]: "mat2" - elif T is Mat23[float32]: "mat32" - elif T is Mat32[float32]: "mat23" - elif T is Mat33[float32]: "mat3" - elif T is Mat34[float32]: "mat43" - elif T is Mat43[float32]: "mat34" - elif T is Mat44[float32]: "mat4" + elif T is TMat22[float32]: "mat2" + elif T is TMat23[float32]: "mat32" + elif T is TMat32[float32]: "mat23" + elif T is TMat33[float32]: "mat3" + elif T is TMat34[float32]: "mat43" + elif T is TMat43[float32]: "mat34" + elif T is TMat44[float32]: "mat4" - elif T is Mat22[float64]: "dmat2" - elif T is Mat23[float64]: "dmat32" - elif T is Mat32[float64]: "dmat23" - elif T is Mat33[float64]: "dmat3" - elif T is Mat34[float64]: "dmat43" - elif T is Mat43[float64]: "dmat34" - elif T is Mat44[float64]: "dmat4" + elif T is TMat22[float64]: "dmat2" + elif T is TMat23[float64]: "dmat32" + elif T is TMat32[float64]: "dmat23" + elif T is TMat33[float64]: "dmat3" + elif T is TMat34[float64]: "dmat43" + elif T is TMat43[float64]: "dmat34" + elif T is TMat44[float64]: "dmat4" diff -r 547f3a374271 -r 8287a91e5d56 src/semicongine/math/matrix.nim --- a/src/semicongine/math/matrix.nim Fri Jan 20 16:13:32 2023 +0700 +++ b/src/semicongine/math/matrix.nim Fri Jan 20 16:36:52 2023 +0700 @@ -12,38 +12,43 @@ # layout is row-first # having an object instead of directly aliasing the array seems a bit ugly at # first, but is necessary to be able to work correctly with distinguished - # types (i.e. Mat23 and Mat32 would be an alias for the same type array[6, T] + # types (i.e. TMat23 and TMat32 would be an alias for the same type array[6, T] # which prevents the type system from identifying the correct type at times) # # Though, great news is that objects have zero overhead! - Mat22*[T: SomeNumber] = object + TMat22*[T: SomeNumber] = object data*: array[4, T] - Mat23*[T: SomeNumber] = object + TMat23*[T: SomeNumber] = object + data*: array[6, T] + TMat32*[T: SomeNumber] = object data*: array[6, T] - Mat32*[T: SomeNumber] = object - data*: array[6, T] - Mat33*[T: SomeNumber] = object + TMat33*[T: SomeNumber] = object data*: array[9, T] - Mat34*[T: SomeNumber] = object + TMat34*[T: SomeNumber] = object + data*: array[12, T] + TMat43*[T: SomeNumber] = object data*: array[12, T] - Mat43*[T: SomeNumber] = object - data*: array[12, T] - Mat44*[T: SomeNumber] = object + TMat44*[T: SomeNumber] = object data*: array[16, T] - MatMM* = Mat22|Mat33|Mat44 - MatMN* = Mat23|Mat32|Mat34|Mat43 - Mat* = MatMM|MatMN + TMat* = TMat22|TMat33|TMat44|TMat23|TMat32|TMat34|TMat43 + Mat22 = TMat22[float32] + Mat23 = TMat22[float32] + Mat32 = TMat22[float32] + Mat33 = TMat22[float32] + Mat34 = TMat22[float32] + Mat43 = TMat22[float32] + Mat44 = TMat22[float32] -func unit22[T: SomeNumber](): auto {.compiletime.} = Mat22[T](data:[ +func unit22[T: SomeNumber](): auto {.compiletime.} = TMat22[T](data:[ T(1), T(0), T(0), T(1), ]) -func unit33[T: SomeNumber](): auto {.compiletime.} = Mat33[T](data:[ +func unit33[T: SomeNumber](): auto {.compiletime.} = TMat33[T](data:[ T(1), T(0), T(0), T(0), T(1), T(0), T(0), T(0), T(1), ]) -func unit44[T: SomeNumber](): auto {.compiletime.} = Mat44[T](data: [ +func unit44[T: SomeNumber](): auto {.compiletime.} = TMat44[T](data: [ T(1), T(0), T(0), T(0), T(0), T(1), T(0), T(0), T(0), T(0), T(1), T(0), @@ -81,21 +86,21 @@ const Unit44* = unit44[float]() template rowCount*(m: typedesc): int = - when m is Mat22: 2 - elif m is Mat23: 2 - elif m is Mat32: 3 - elif m is Mat33: 3 - elif m is Mat34: 3 - elif m is Mat43: 4 - elif m is Mat44: 4 + when m is TMat22: 2 + elif m is TMat23: 2 + elif m is TMat32: 3 + elif m is TMat33: 3 + elif m is TMat34: 3 + elif m is TMat43: 4 + elif m is TMat44: 4 template columnCount*(m: typedesc): int = - when m is Mat22: 2 - elif m is Mat23: 3 - elif m is Mat32: 2 - elif m is Mat33: 3 - elif m is Mat34: 4 - elif m is Mat43: 3 - elif m is Mat44: 4 + when m is TMat22: 2 + elif m is TMat23: 3 + elif m is TMat32: 2 + elif m is TMat33: 3 + elif m is TMat34: 4 + elif m is TMat43: 3 + elif m is TMat44: 4 func toString[T](value: T): string = @@ -119,32 +124,32 @@ result &= filler & strvalues[i] & " " result = $T & "\n" & result -func `$`*(v: Mat22[SomeNumber]): string = toString[Mat22[SomeNumber]](v) -func `$`*(v: Mat23[SomeNumber]): string = toString[Mat23[SomeNumber]](v) -func `$`*(v: Mat32[SomeNumber]): string = toString[Mat32[SomeNumber]](v) -func `$`*(v: Mat33[SomeNumber]): string = toString[Mat33[SomeNumber]](v) -func `$`*(v: Mat34[SomeNumber]): string = toString[Mat34[SomeNumber]](v) -func `$`*(v: Mat43[SomeNumber]): string = toString[Mat43[SomeNumber]](v) -func `$`*(v: Mat44[SomeNumber]): string = toString[Mat44[SomeNumber]](v) +func `$`*(v: TMat22[SomeNumber]): string = toString[TMat22[SomeNumber]](v) +func `$`*(v: TMat23[SomeNumber]): string = toString[TMat23[SomeNumber]](v) +func `$`*(v: TMat32[SomeNumber]): string = toString[TMat32[SomeNumber]](v) +func `$`*(v: TMat33[SomeNumber]): string = toString[TMat33[SomeNumber]](v) +func `$`*(v: TMat34[SomeNumber]): string = toString[TMat34[SomeNumber]](v) +func `$`*(v: TMat43[SomeNumber]): string = toString[TMat43[SomeNumber]](v) +func `$`*(v: TMat44[SomeNumber]): string = toString[TMat44[SomeNumber]](v) -func `[]`*[T: Mat](m: T, row, col: int): auto = m.data[col + row * T.columnCount] -proc `[]=`*[T: Mat, U](m: var T, row, col: int, value: U) = m.data[col + row * T.columnCount] = value +func `[]`*[T: TMat](m: T, row, col: int): auto = m.data[col + row * T.columnCount] +proc `[]=`*[T: TMat, U](m: var T, row, col: int, value: U) = m.data[col + row * T.columnCount] = value -func row*[T: Mat22](m: T, i: 0..1): auto = TVec2([m[i, 0], m[i, 1]]) -func row*[T: Mat32](m: T, i: 0..2): auto = TVec2([m[i, 0], m[i, 1]]) -func row*[T: Mat23](m: T, i: 0..1): auto = TVec3([m[i, 0], m[i, 1], m[i, 2]]) -func row*[T: Mat33](m: T, i: 0..2): auto = TVec3([m[i, 0], m[i, 1], m[i, 2]]) -func row*[T: Mat43](m: T, i: 0..3): auto = TVec3([m[i, 0], m[i, 1], m[i, 2]]) -func row*[T: Mat34](m: T, i: 0..2): auto = TVec4([m[i, 0], m[i, 1], m[i, 2], m[i, 3]]) -func row*[T: Mat44](m: T, i: 0..3): auto = TVec4([m[i, 0], m[i, 1], m[i, 2], m[i, 3]]) +func row*[T: TMat22](m: T, i: 0..1): auto = TVec2([m[i, 0], m[i, 1]]) +func row*[T: TMat32](m: T, i: 0..2): auto = TVec2([m[i, 0], m[i, 1]]) +func row*[T: TMat23](m: T, i: 0..1): auto = TVec3([m[i, 0], m[i, 1], m[i, 2]]) +func row*[T: TMat33](m: T, i: 0..2): auto = TVec3([m[i, 0], m[i, 1], m[i, 2]]) +func row*[T: TMat43](m: T, i: 0..3): auto = TVec3([m[i, 0], m[i, 1], m[i, 2]]) +func row*[T: TMat34](m: T, i: 0..2): auto = TVec4([m[i, 0], m[i, 1], m[i, 2], m[i, 3]]) +func row*[T: TMat44](m: T, i: 0..3): auto = TVec4([m[i, 0], m[i, 1], m[i, 2], m[i, 3]]) -func col*[T: Mat22](m: T, i: 0..1): auto = TVec2([m[0, i], m[1, i]]) -func col*[T: Mat23](m: T, i: 0..2): auto = TVec2([m[0, i], m[1, i]]) -func col*[T: Mat32](m: T, i: 0..1): auto = TVec3([m[0, i], m[1, i], m[2, i]]) -func col*[T: Mat33](m: T, i: 0..2): auto = TVec3([m[0, i], m[1, i], m[2, i]]) -func col*[T: Mat34](m: T, i: 0..3): auto = TVec3([m[0, i], m[1, i], m[2, i]]) -func col*[T: Mat43](m: T, i: 0..2): auto = TVec4([m[0, i], m[1, i], m[2, i], m[3, i]]) -func col*[T: Mat44](m: T, i: 0..3): auto = TVec4([m[0, i], m[1, i], m[2, i], m[3, i]]) +func col*[T: TMat22](m: T, i: 0..1): auto = TVec2([m[0, i], m[1, i]]) +func col*[T: TMat23](m: T, i: 0..2): auto = TVec2([m[0, i], m[1, i]]) +func col*[T: TMat32](m: T, i: 0..1): auto = TVec3([m[0, i], m[1, i], m[2, i]]) +func col*[T: TMat33](m: T, i: 0..2): auto = TVec3([m[0, i], m[1, i], m[2, i]]) +func col*[T: TMat34](m: T, i: 0..3): auto = TVec3([m[0, i], m[1, i], m[2, i]]) +func col*[T: TMat43](m: T, i: 0..2): auto = TVec4([m[0, i], m[1, i], m[2, i], m[3, i]]) +func col*[T: TMat44](m: T, i: 0..3): auto = TVec4([m[0, i], m[1, i], m[2, i], m[3, i]]) proc createMatMatMultiplicationOperator(leftType: typedesc, rightType: typedesc, outType: typedesc): NimNode = var data = nnkBracket.newTree() @@ -249,106 +254,106 @@ result = newStmtList() for op in ["+", "-", "*", "/"]: - result.add(createMatScalarOperator(Mat22, op)) - result.add(createMatScalarOperator(Mat23, op)) - result.add(createMatScalarOperator(Mat32, op)) - result.add(createMatScalarOperator(Mat33, op)) - result.add(createMatScalarOperator(Mat34, op)) - result.add(createMatScalarOperator(Mat43, op)) - result.add(createMatScalarOperator(Mat44, op)) + result.add(createMatScalarOperator(TMat22, op)) + result.add(createMatScalarOperator(TMat23, op)) + result.add(createMatScalarOperator(TMat32, op)) + result.add(createMatScalarOperator(TMat33, op)) + result.add(createMatScalarOperator(TMat34, op)) + result.add(createMatScalarOperator(TMat43, op)) + result.add(createMatScalarOperator(TMat44, op)) - result.add(createMatMatMultiplicationOperator(Mat22, Mat22, Mat22)) - result.add(createMatMatMultiplicationOperator(Mat22, Mat23, Mat23)) - result.add(createMatMatMultiplicationOperator(Mat23, Mat32, Mat22)) - result.add(createMatMatMultiplicationOperator(Mat23, Mat33, Mat23)) - result.add(createMatMatMultiplicationOperator(Mat32, Mat22, Mat32)) - result.add(createMatMatMultiplicationOperator(Mat32, Mat23, Mat33)) - result.add(createMatMatMultiplicationOperator(Mat33, Mat32, Mat32)) - result.add(createMatMatMultiplicationOperator(Mat33, Mat33, Mat33)) - result.add(createMatMatMultiplicationOperator(Mat33, Mat34, Mat34)) - result.add(createMatMatMultiplicationOperator(Mat43, Mat33, Mat43)) - result.add(createMatMatMultiplicationOperator(Mat43, Mat34, Mat44)) - result.add(createMatMatMultiplicationOperator(Mat44, Mat43, Mat43)) - result.add(createMatMatMultiplicationOperator(Mat44, Mat44, Mat44)) + result.add(createMatMatMultiplicationOperator(TMat22, TMat22, TMat22)) + result.add(createMatMatMultiplicationOperator(TMat22, TMat23, TMat23)) + result.add(createMatMatMultiplicationOperator(TMat23, TMat32, TMat22)) + result.add(createMatMatMultiplicationOperator(TMat23, TMat33, TMat23)) + result.add(createMatMatMultiplicationOperator(TMat32, TMat22, TMat32)) + result.add(createMatMatMultiplicationOperator(TMat32, TMat23, TMat33)) + result.add(createMatMatMultiplicationOperator(TMat33, TMat32, TMat32)) + result.add(createMatMatMultiplicationOperator(TMat33, TMat33, TMat33)) + result.add(createMatMatMultiplicationOperator(TMat33, TMat34, TMat34)) + result.add(createMatMatMultiplicationOperator(TMat43, TMat33, TMat43)) + result.add(createMatMatMultiplicationOperator(TMat43, TMat34, TMat44)) + result.add(createMatMatMultiplicationOperator(TMat44, TMat43, TMat43)) + result.add(createMatMatMultiplicationOperator(TMat44, TMat44, TMat44)) - result.add(createVecMatMultiplicationOperator(Mat22, TVec2)) - result.add(createVecMatMultiplicationOperator(Mat33, TVec3)) - result.add(createVecMatMultiplicationOperator(Mat44, TVec4)) + result.add(createVecMatMultiplicationOperator(TMat22, TVec2)) + result.add(createVecMatMultiplicationOperator(TMat33, TVec3)) + result.add(createVecMatMultiplicationOperator(TMat44, TVec4)) createAllMultiplicationOperators() -func transposed*[T](m: Mat22[T]): Mat22[T] = Mat22[T](data: [ +func transposed*[T](m: TMat22[T]): TMat22[T] = TMat22[T](data: [ m[0, 0], m[1, 0], m[0, 1], m[1, 1], ]) -func transposed*[T](m: Mat23[T]): Mat32[T] = Mat32[T](data: [ +func transposed*[T](m: TMat23[T]): TMat32[T] = TMat32[T](data: [ m[0, 0], m[1, 0], m[0, 1], m[1, 1], m[0, 2], m[1, 2], ]) -func transposed*[T](m: Mat32[T]): Mat23[T] = Mat23[T](data: [ +func transposed*[T](m: TMat32[T]): TMat23[T] = TMat23[T](data: [ m[0, 0], m[1, 0], m[2, 0], m[0, 1], m[1, 1], m[2, 1], ]) -func transposed*[T](m: Mat33[T]): Mat33[T] = Mat33[T](data: [ +func transposed*[T](m: TMat33[T]): TMat33[T] = TMat33[T](data: [ m[0, 0], m[1, 0], m[2, 0], m[0, 1], m[1, 1], m[2, 1], m[0, 2], m[1, 2], m[2, 2], ]) -func transposed*[T](m: Mat43[T]): Mat34[T] = Mat34[T](data: [ +func transposed*[T](m: TMat43[T]): TMat34[T] = TMat34[T](data: [ m[0, 0], m[1, 0], m[2, 0], m[3, 0], m[0, 1], m[1, 1], m[2, 1], m[3, 1], m[0, 2], m[1, 2], m[2, 2], m[3, 2], ]) -func transposed*[T](m: Mat34[T]): Mat43[T] = Mat43[T](data: [ +func transposed*[T](m: TMat34[T]): TMat43[T] = TMat43[T](data: [ m[0, 0], m[1, 0], m[2, 0], m[0, 1], m[1, 1], m[2, 1], m[0, 2], m[1, 2], m[2, 2], m[0, 3], m[1, 3], m[2, 3], ]) -func transposed*[T](m: Mat44[T]): Mat44[T] = Mat44[T](data: [ +func transposed*[T](m: TMat44[T]): TMat44[T] = TMat44[T](data: [ m[0, 0], m[1, 0], m[2, 0], m[3, 0], m[0, 1], m[1, 1], m[2, 1], m[3, 1], m[0, 2], m[1, 2], m[2, 2], m[3, 2], m[0, 3], m[1, 3], m[2, 3], m[3, 3], ]) -func translate2d*[T](x, y: T): Mat33[T] = Mat33[T](data: [ +func translate2d*[T](x, y: T): TMat33[T] = TMat33[T](data: [ T(1), T(0), x, T(0), T(1), y, T(0), T(0), T(1), ]) -func scale2d*[T](sx, sy: T): Mat33[T] = Mat33[T](data: [ +func scale2d*[T](sx, sy: T): TMat33[T] = TMat33[T](data: [ sx, T(0), T(0), T(0), sy, T(0), T(0), T(0), T(1), ]) -func rotate2d*[T](angle: T): Mat33[T] = Mat33[T](data: [ +func rotate2d*[T](angle: T): TMat33[T] = TMat33[T](data: [ cos(angle), -sin(angle), T(0), sin(angle), cos(angle), T(0), T(0), T(0), T(1), ]) -func translate3d*[T](x, y, z: T): Mat44[T] = Mat44[T](data: [ +func translate3d*[T](x, y, z: T): TMat44[T] = TMat44[T](data: [ T(1), T(0), T(0), x, T(0), T(1), T(0), y, T(0), T(0), T(1), z, T(0), T(0), T(0), T(1), ]) -func scale3d*[T](sx, sy, sz: T): Mat44[T] = Mat44[T](data: [ +func scale3d*[T](sx, sy, sz: T): TMat44[T] = TMat44[T](data: [ sx, T(0), T(0), T(0), T(0), sy, T(0), T(0), T(0), T(0), sz, T(0), T(0), T(0), T(0), T(1), ]) -func rotate3d*[T](angle: T, a: TVec3[T]): Mat44[T] = +func rotate3d*[T](angle: T, a: TVec3[T]): TMat44[T] = let cosa = cos(angle) sina = sin(angle) x = a[0] y = a[1] z = a[2] - Mat44[T](data: [ + TMat44[T](data: [ x * x * (1 - cosa) + cosa, y * x * (1 - cosa) - z * sina, z * x * (1 - cosa) + y * sina, T(0), x * y * (1 - cosa) + z * sina, y * y * (1 - cosa) + cosa, z * y * (1 - cosa) - x * sina, T(0), x * z * (1 - cosa) - y * sina, y * z * (1 - cosa) + x * sina, z * z * (1 - cosa) + cosa, T(0), @@ -356,7 +361,7 @@ ]) -# call e.g. Mat32[int]().randomized() to get a random matrix +# call e.g. TMat32[int]().randomized() to get a random matrix template makeRandomInit(mattype: typedesc) = proc randomized*[T: SomeInteger](m: mattype[T]): mattype[T] = for i in 0 ..< result.data.len: @@ -365,25 +370,25 @@ for i in 0 ..< result.data.len: result.data[i] = rand(1.0) -makeRandomInit(Mat22) -makeRandomInit(Mat23) -makeRandomInit(Mat32) -makeRandomInit(Mat33) -makeRandomInit(Mat34) -makeRandomInit(Mat43) -makeRandomInit(Mat44) +makeRandomInit(TMat22) +makeRandomInit(TMat23) +makeRandomInit(TMat32) +makeRandomInit(TMat33) +makeRandomInit(TMat34) +makeRandomInit(TMat43) +makeRandomInit(TMat44) -func perspective*[T: SomeFloat](fovy, aspect, zNear, zFar: T): Mat44[T] = +func perspective*[T: SomeFloat](fovy, aspect, zNear, zFar: T): TMat44[T] = let tanHalfFovy = tan(fovy / T(2)) - return Mat44[T](data:[ + return TMat44[T](data:[ T(1) / (aspect * tanHalfFovy), T(0), T(0), T(0), T(0), T(1) / tanHalfFovy, T(0), T(0), T(0), T(0), T(zFar / (zFar - zNear)), T(-(zFar * zNear) / (zFar - zNear)), T(0), T(0), T(1), T(1), ]) -func ortho*[T: SomeFloat](left, right, top, bottom, zNear, zFar: T): Mat44[T] = - Mat44[T](data:[ +func ortho*[T: SomeFloat](left, right, top, bottom, zNear, zFar: T): TMat44[T] = + TMat44[T](data:[ T(2) / (right - left), T(0), T(0), -(right + left) / (right - left), T(0), T(2) / (bottom - top), T(0), -(bottom + top) / (bottom - top), T(0), T(0), T(1) / (zFar - zNear), -zNear / (zFar - zNear), diff -r 547f3a374271 -r 8287a91e5d56 src/semicongine/math/vector.nim --- a/src/semicongine/math/vector.nim Fri Jan 20 16:13:32 2023 +0700 +++ b/src/semicongine/math/vector.nim Fri Jan 20 16:36:52 2023 +0700 @@ -13,6 +13,9 @@ TVec3*[T: SomeNumber] = array[3, T] TVec4*[T: SomeNumber] = array[4, T] TVec* = TVec2|TVec3|TVec4 + Vec2 = TVec2[float32] + Vec3 = TVec3[float32] + Vec4 = TVec4[float32] converter toVec2*[T: SomeNumber](orig: TVec3[T]|TVec4[T]): TVec2[T] = TVec2[T]([orig[0], orig[1]]) diff -r 547f3a374271 -r 8287a91e5d56 src/semicongine/vertex.nim --- a/src/semicongine/vertex.nim Fri Jan 20 16:13:32 2023 +0700 +++ b/src/semicongine/vertex.nim Fri Jan 20 16:36:52 2023 +0700 @@ -29,9 +29,9 @@ # from https://registry.khronos.org/vulkan/specs/1.3-extensions/html/chap15.html func nLocationSlots[T: VertexAttributeType](): int = - when (T is Mat44[float64]): + when (T is TMat44[float64]): 8 - elif (T is Mat44[float32]): + elif (T is TMat44[float32]): 4 elif (T is TVec3[float64] or T is TVec3[uint64] or T is TVec4[float64] or T is TVec4[float64]): 2 diff -r 547f3a374271 -r 8287a91e5d56 tests/test_matrix.nim --- a/tests/test_matrix.nim Fri Jan 20 16:13:32 2023 +0700 +++ b/tests/test_matrix.nim Fri Jan 20 16:36:52 2023 +0700 @@ -33,52 +33,52 @@ template withAllIntegerMats(stuff: untyped) = - stuff(Mat22[int32]) - stuff(Mat23[int32]) - stuff(Mat32[int32]) - stuff(Mat33[int32]) - stuff(Mat34[int32]) - stuff(Mat43[int32]) - stuff(Mat44[int32]) - stuff(Mat22[int64]) - stuff(Mat23[int64]) - stuff(Mat32[int64]) - stuff(Mat33[int64]) - stuff(Mat34[int64]) - stuff(Mat43[int64]) - stuff(Mat44[int64]) + stuff(TMat22[int32]) + stuff(TMat23[int32]) + stuff(TMat32[int32]) + stuff(TMat33[int32]) + stuff(TMat34[int32]) + stuff(TMat43[int32]) + stuff(TMat44[int32]) + stuff(TMat22[int64]) + stuff(TMat23[int64]) + stuff(TMat32[int64]) + stuff(TMat33[int64]) + stuff(TMat34[int64]) + stuff(TMat43[int64]) + stuff(TMat44[int64]) template withAllFloatMats(stuff: untyped) = - stuff(Mat22[float32]) - stuff(Mat23[float32]) - stuff(Mat32[float32]) - stuff(Mat33[float32]) - stuff(Mat34[float32]) - stuff(Mat43[float32]) - stuff(Mat44[float32]) - stuff(Mat22[float64]) - stuff(Mat23[float64]) - stuff(Mat32[float64]) - stuff(Mat33[float64]) - stuff(Mat34[float64]) - stuff(Mat43[float64]) - stuff(Mat44[float64]) + stuff(TMat22[float32]) + stuff(TMat23[float32]) + stuff(TMat32[float32]) + stuff(TMat33[float32]) + stuff(TMat34[float32]) + stuff(TMat43[float32]) + stuff(TMat44[float32]) + stuff(TMat22[float64]) + stuff(TMat23[float64]) + stuff(TMat32[float64]) + stuff(TMat33[float64]) + stuff(TMat34[float64]) + stuff(TMat43[float64]) + stuff(TMat44[float64]) template withAllMats(stuff: untyped) = - stuff(Mat22[int]) - stuff(Mat23[int]) - stuff(Mat32[int]) - stuff(Mat33[int]) - stuff(Mat34[int]) - stuff(Mat43[int]) - stuff(Mat44[int]) - stuff(Mat22[float]) - stuff(Mat23[float]) - stuff(Mat32[float]) - stuff(Mat33[float]) - stuff(Mat34[float]) - stuff(Mat43[float]) - stuff(Mat44[float]) + stuff(TMat22[int]) + stuff(TMat23[int]) + stuff(TMat32[int]) + stuff(TMat33[int]) + stuff(TMat34[int]) + stuff(TMat43[int]) + stuff(TMat44[int]) + stuff(TMat22[float]) + stuff(TMat23[float]) + stuff(TMat32[float]) + stuff(TMat33[float]) + stuff(TMat34[float]) + stuff(TMat43[float]) + stuff(TMat44[float]) template testTranspose(t: typedesc) = echo "testTranspose: ", t @@ -133,9 +133,9 @@ echo Unit44i32 echo Unit44i64 - echo Mat22[float]().randomized() * One2.randomized() - echo Mat33[float]().randomized() * One3.randomized() - echo Mat44[float]().randomized() * One4.randomized() + echo TMat22[float]().randomized() * One2.randomized() + echo TMat33[float]().randomized() * One3.randomized() + echo TMat44[float]().randomized() * One4.randomized() randomize() testMatrix()