# HG changeset patch # User Sam # Date 1674206012 -25200 # Node ID 5d406c17bbcb2a9f5ef545a15a68be629bb57759 # Parent 836790efab4890c374d1167a6305d21371beb1a7 did: refactor Vector names diff -r 836790efab48 -r 5d406c17bbcb README.md --- a/README.md Fri Jan 20 00:41:55 2023 +0700 +++ b/README.md Fri Jan 20 16:13:32 2023 +0700 @@ -42,6 +42,7 @@ - [ ] Mipmaps - [ ] Multisampling - [~] Instanced drawing (using it currently but number of instances is hardcoded to 1 +- [ ] Fullscreen mode + switch between modes Build-system: - [x] move all of Makefile to config.nims diff -r 836790efab48 -r 5d406c17bbcb examples/alotof_triangles.nim --- a/examples/alotof_triangles.nim Fri Jan 20 00:41:55 2023 +0700 +++ b/examples/alotof_triangles.nim Fri Jan 20 16:13:32 2023 +0700 @@ -8,8 +8,8 @@ type VertexDataA = object - position11: PositionAttribute[Vec2[float32]] - color22: ColorAttribute[Vec3[float32]] + position11: PositionAttribute[TVec2[float32]] + color22: ColorAttribute[TVec3[float32]] Uniforms = object dt: Descriptor[float32] @@ -26,42 +26,42 @@ randomize() var myengine = igniteEngine("A lot of triangles") const baseTriangle = [ - Vec3([-0.1'f32, -0.1'f32, 1'f32]), - Vec3([ 0.1'f32, 0.1'f32, 1'f32]), - Vec3([-0.1'f32, 0.1'f32, 1'f32]), + TVec3([-0.1'f32, -0.1'f32, 1'f32]), + TVec3([ 0.1'f32, 0.1'f32, 1'f32]), + TVec3([-0.1'f32, 0.1'f32, 1'f32]), ] var scene = new Thing for i in 1 .. 300: var randommesh = new Mesh[VertexDataA] - let randomcolor1 = Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]) + let randomcolor1 = TVec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]) let transform1 = randomtransform() randommesh.vertexData = VertexDataA( - position11: PositionAttribute[Vec2[float32]]( + position11: PositionAttribute[TVec2[float32]]( data: @[ - Vec2[float32](transform1 * baseTriangle[0]), - Vec2[float32](transform1 * baseTriangle[1]), - Vec2[float32](transform1 * baseTriangle[2]), + TVec2[float32](transform1 * baseTriangle[0]), + TVec2[float32](transform1 * baseTriangle[1]), + TVec2[float32](transform1 * baseTriangle[2]), ] ), - color22: ColorAttribute[Vec3[float32]]( + color22: ColorAttribute[TVec3[float32]]( data: @[randomcolor1, randomcolor1, randomcolor1] ) ) - let randomcolor2 = Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]) + let randomcolor2 = TVec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]) let transform2 = randomtransform() var randomindexedmesh = new IndexedMesh[VertexDataA, uint16] randomindexedmesh.vertexData = VertexDataA( - position11: PositionAttribute[Vec2[float32]]( + position11: PositionAttribute[TVec2[float32]]( data: @[ - Vec2[float32](transform2 * baseTriangle[0]), - Vec2[float32](transform2 * baseTriangle[1]), - Vec2[float32](transform2 * baseTriangle[2]), + TVec2[float32](transform2 * baseTriangle[0]), + TVec2[float32](transform2 * baseTriangle[1]), + TVec2[float32](transform2 * baseTriangle[2]), ] ), - color22: ColorAttribute[Vec3[float32]]( + color22: ColorAttribute[TVec3[float32]]( data: @[randomcolor2, randomcolor2, randomcolor2] ) ) diff -r 836790efab48 -r 5d406c17bbcb examples/hello_cube.nim --- a/examples/hello_cube.nim Fri Jan 20 00:41:55 2023 +0700 +++ b/examples/hello_cube.nim Fri Jan 20 16:13:32 2023 +0700 @@ -17,8 +17,8 @@ type # define type of vertex VertexDataA = object - position: PositionAttribute[Vec3[float32]] - color: ColorAttribute[Vec3[float32]] + position: PositionAttribute[TVec3[float32]] + color: ColorAttribute[TVec3[float32]] Uniforms = object model: Descriptor[Mat44[float32]] view: Descriptor[Mat44[float32]] @@ -47,14 +47,14 @@ buffer.updateData(uniforms) const - TopLeftFront = Vec3([ -0.5'f32, -0.5'f32, -0.5'f32]) - TopRightFront = Vec3([ 0.5'f32, -0.5'f32, -0.5'f32]) - BottomRightFront = Vec3([ 0.5'f32, 0.5'f32, -0.5'f32]) - BottomLeftFront = Vec3([ -0.5'f32, 0.5'f32, -0.5'f32]) - TopLeftBack = Vec3([ 0.5'f32, -0.5'f32, 0.5'f32]) - TopRightBack = Vec3([ -0.5'f32, -0.5'f32, 0.5'f32]) - BottomRightBack = Vec3([ -0.5'f32, 0.5'f32, 0.5'f32]) - BottomLeftBack = Vec3([ 0.5'f32, 0.5'f32, 0.5'f32]) + TopLeftFront = TVec3([ -0.5'f32, -0.5'f32, -0.5'f32]) + TopRightFront = TVec3([ 0.5'f32, -0.5'f32, -0.5'f32]) + BottomRightFront = TVec3([ 0.5'f32, 0.5'f32, -0.5'f32]) + BottomLeftFront = TVec3([ -0.5'f32, 0.5'f32, -0.5'f32]) + TopLeftBack = TVec3([ 0.5'f32, -0.5'f32, 0.5'f32]) + TopRightBack = TVec3([ -0.5'f32, -0.5'f32, 0.5'f32]) + BottomRightBack = TVec3([ -0.5'f32, 0.5'f32, 0.5'f32]) + BottomLeftBack = TVec3([ 0.5'f32, 0.5'f32, 0.5'f32]) const cube_pos = @[ TopLeftFront, TopRightFront, BottomRightFront, BottomLeftFront, # front @@ -97,8 +97,8 @@ # build a mesh var trianglemesh = new IndexedMesh[VertexDataA, uint16] trianglemesh.vertexData = VertexDataA( - position: PositionAttribute[Vec3[float32]](data: cube_pos), - color: ColorAttribute[Vec3[float32]](data: cube_color), + position: PositionAttribute[TVec3[float32]](data: cube_pos), + color: ColorAttribute[TVec3[float32]](data: cube_color), ) trianglemesh.indices = tris # build a single-object scene graph diff -r 836790efab48 -r 5d406c17bbcb examples/hello_triangle.nim --- a/examples/hello_triangle.nim Fri Jan 20 00:41:55 2023 +0700 +++ b/examples/hello_triangle.nim Fri Jan 20 16:13:32 2023 +0700 @@ -7,9 +7,9 @@ type # define type of vertex VertexDataA = object - position: PositionAttribute[Vec2[float32]] - color: ColorAttribute[Vec3[float32]] - id: InstanceAttribute[Vec3[float32]] + position: PositionAttribute[TVec2[float32]] + color: ColorAttribute[TVec3[float32]] + id: InstanceAttribute[TVec3[float32]] var pipeline: RenderPipeline[VertexDataA, void] @@ -19,14 +19,14 @@ # vertex data (types must match the above VertexAttributes) const triangle_pos = @[ - Vec2([ 0.0'f32, -0.5'f32]), - Vec2([ 0.5'f32, 0.5'f32]), - Vec2([-0.5'f32, 0.5'f32]), + TVec2([ 0.0'f32, -0.5'f32]), + TVec2([ 0.5'f32, 0.5'f32]), + TVec2([-0.5'f32, 0.5'f32]), ] triangle_color = @[ - Vec3([1.0'f32, 0.0'f32, 0.0'f32]), - Vec3([0.0'f32, 1.0'f32, 0.0'f32]), - Vec3([0.0'f32, 0.0'f32, 1.0'f32]), + TVec3([1.0'f32, 0.0'f32, 0.0'f32]), + TVec3([0.0'f32, 1.0'f32, 0.0'f32]), + TVec3([0.0'f32, 0.0'f32, 1.0'f32]), ] when isMainModule: @@ -35,9 +35,9 @@ # build a mesh var trianglemesh = new Mesh[VertexDataA] trianglemesh.vertexData = VertexDataA( - position: PositionAttribute[Vec2[float32]](data: triangle_pos), - color: ColorAttribute[Vec3[float32]](data: triangle_color), - id: InstanceAttribute[Vec3[float32]](data: @[Vec3[float32]([0.5'f32, 0.5'f32, 0.5'f32])]), + position: PositionAttribute[TVec2[float32]](data: triangle_pos), + color: ColorAttribute[TVec3[float32]](data: triangle_color), + id: InstanceAttribute[TVec3[float32]](data: @[TVec3[float32]([0.5'f32, 0.5'f32, 0.5'f32])]), ) # build a single-object scene graph var triangle = new Thing diff -r 836790efab48 -r 5d406c17bbcb examples/input.nim --- a/examples/input.nim Fri Jan 20 00:41:55 2023 +0700 +++ b/examples/input.nim Fri Jan 20 16:13:32 2023 +0700 @@ -7,12 +7,12 @@ type # define type of vertex VertexDataA = object - position: PositionAttribute[Vec2[float32]] - color: ColorAttribute[Vec3[float32]] - translate: InstanceAttribute[Vec2[float32]] + position: PositionAttribute[TVec2[float32]] + color: ColorAttribute[TVec3[float32]] + iscursor: GenericAttribute[int32] Uniforms = object projection: Descriptor[Mat44[float32]] - cursor: Descriptor[Vec2[float32]] + cursor: Descriptor[TVec2[float32]] var pipeline: RenderPipeline[VertexDataA, Uniforms] @@ -35,20 +35,20 @@ # vertex data (types must match the above VertexAttributes) const shape = @[ - Vec2([- 1'f32, - 1'f32]), - Vec2([ 1'f32, - 1'f32]), - Vec2([-0.3'f32, -0.3'f32]), - Vec2([-0.3'f32, -0.3'f32]), - Vec2([- 1'f32, 1'f32]), - Vec2([- 1'f32, - 1'f32]), + TVec2([- 1'f32, - 1'f32]), + TVec2([ 1'f32, - 1'f32]), + TVec2([-0.3'f32, -0.3'f32]), + TVec2([-0.3'f32, -0.3'f32]), + TVec2([- 1'f32, 1'f32]), + TVec2([- 1'f32, - 1'f32]), ] colors = @[ - Vec3([1'f32, 0'f32, 0'f32]), - Vec3([1'f32, 0'f32, 0'f32]), - Vec3([1'f32, 0'f32, 0'f32]), - Vec3([0.8'f32, 0'f32, 0'f32]), - Vec3([0.8'f32, 0'f32, 0'f32]), - Vec3([0.8'f32, 0'f32, 0'f32]), + TVec3([1'f32, 0'f32, 0'f32]), + TVec3([1'f32, 0'f32, 0'f32]), + TVec3([1'f32, 0'f32, 0'f32]), + TVec3([0.8'f32, 0'f32, 0'f32]), + TVec3([0.8'f32, 0'f32, 0'f32]), + TVec3([0.8'f32, 0'f32, 0'f32]), ] when isMainModule: @@ -56,14 +56,14 @@ # build a single-object scene graph var cursor = new Thing - var cursorpart = new Mesh[VertexDataA] - cursorpart.vertexData = VertexDataA( - position: PositionAttribute[Vec2[float32]](data: shape), - color: ColorAttribute[Vec3[float32]](data: colors), - translate: InstanceAttribute[Vec2[float32]](data: @[Vec2[float32]([100'f32, 100'f32])]), + var cursormesh = new Mesh[VertexDataA] + cursormesh.vertexData = VertexDataA( + position: PositionAttribute[TVec2[float32]](data: shape), + color: ColorAttribute[TVec3[float32]](data: colors), + iscursor: GenericAttribute[int32](data: @[1'i32, 1'i32, 1'i32, 1'i32, 1'i32, 1'i32]), ) # transform the cursor a bit to make it look nice - for i in 0 ..< cursorpart.vertexData.position.data.len: + for i in 0 ..< cursormesh.vertexData.position.data.len: let cursorscale = ( scale2d(20'f32, 20'f32) * translate2d(1'f32, 1'f32) * @@ -71,16 +71,24 @@ scale2d(0.5'f32, 1'f32) * rotate2d(float32(PI) / 4'f32) ) - let pos = Vec3[float32]([cursorpart.vertexData.position.data[i][0], cursorpart.vertexData.position.data[i][1], 1'f32]) - cursorpart.vertexData.position.data[i] = (cursorscale * pos).xy - cursor.parts.add cursorpart + let pos = TVec3[float32]([cursormesh.vertexData.position.data[i][0], cursormesh.vertexData.position.data[i][1], 1'f32]) + cursormesh.vertexData.position.data[i] = (cursorscale * pos).xy + cursor.parts.add cursormesh + + var box = new Thing + var boxmesh = new Mesh[VertexDataA] + boxmesh.vertexData = VertexDataA( + position: PositionAttribute[TVec2[float32]](data: shape), + color: ColorAttribute[TVec3[float32]](data: colors), + iscursor: GenericAttribute[int32](data: @[1'i32, 1'i32, 1'i32, 1'i32, 1'i32, 1'i32]), + ) var scene = new Thing scene.children.add cursor # upload data, prepare shaders, etc const vertexShader = generateVertexShaderCode[VertexDataA, Uniforms](""" - out_position = uniforms.projection * vec4(in_position + uniforms.cursor, 0, 1); + out_position = uniforms.projection * vec4(in_position + (uniforms.cursor * iscursor), 0, 1); """) const fragmentShader = generateFragmentShaderCode[VertexDataA]() echo vertexShader diff -r 836790efab48 -r 5d406c17bbcb examples/squares.nim --- a/examples/squares.nim Fri Jan 20 00:41:55 2023 +0700 +++ b/examples/squares.nim Fri Jan 20 16:13:32 2023 +0700 @@ -8,8 +8,8 @@ type VertexDataA = object - position11: PositionAttribute[Vec2[float32]] - color22: ColorAttribute[Vec3[float32]] + position11: PositionAttribute[TVec2[float32]] + color22: ColorAttribute[TVec3[float32]] index: GenericAttribute[uint32] Uniforms = object t: Descriptor[float32] @@ -32,8 +32,8 @@ WIDTH = 2'f32 / COLUMNS HEIGHT = 2'f32 / ROWS var - vertices: array[COLUMNS * ROWS * 4, Vec2[float32]] - colors: array[COLUMNS * ROWS * 4, Vec3[float32]] + vertices: array[COLUMNS * ROWS * 4, TVec2[float32]] + colors: array[COLUMNS * ROWS * 4, TVec3[float32]] iValues: array[COLUMNS * ROWS * 4, uint32] indices: array[COLUMNS * ROWS * 2, array[3, uint16]] @@ -42,13 +42,13 @@ let y: float32 = (row * 2 / COLUMNS) - 1 x: float32 = (col * 2 / ROWS) - 1 - color = Vec3[float32]([(x + 1) / 2, (y + 1) / 2, 0'f32]) + color = TVec3[float32]([(x + 1) / 2, (y + 1) / 2, 0'f32]) squareIndex = row * COLUMNS + col vertIndex = squareIndex * 4 - vertices[vertIndex + 0] = Vec2[float32]([x, y]) - vertices[vertIndex + 1] = Vec2[float32]([x + WIDTH, y]) - vertices[vertIndex + 2] = Vec2[float32]([x + WIDTH, y + HEIGHT]) - vertices[vertIndex + 3] = Vec2[float32]([x, y + HEIGHT]) + vertices[vertIndex + 0] = TVec2[float32]([x, y]) + vertices[vertIndex + 1] = TVec2[float32]([x + WIDTH, y]) + vertices[vertIndex + 2] = TVec2[float32]([x + WIDTH, y + HEIGHT]) + vertices[vertIndex + 3] = TVec2[float32]([x, y + HEIGHT]) colors[vertIndex + 0] = color colors[vertIndex + 1] = color colors[vertIndex + 2] = color @@ -64,8 +64,8 @@ type PIndexedMesh = ref IndexedMesh[VertexDataA, uint16] # required so we can use ctor with ref/on heap var squaremesh = PIndexedMesh( vertexData: VertexDataA( - position11: PositionAttribute[Vec2[float32]](data: @vertices), - color22: ColorAttribute[Vec3[float32]](data: @colors), + position11: PositionAttribute[TVec2[float32]](data: @vertices), + color22: ColorAttribute[TVec3[float32]](data: @colors), index: GenericAttribute[uint32](data: @iValues), ), indices: @indices diff -r 836790efab48 -r 5d406c17bbcb src/semicongine/descriptor.nim --- a/src/semicongine/descriptor.nim Fri Jan 20 00:41:55 2023 +0700 +++ b/src/semicongine/descriptor.nim Fri Jan 20 16:13:32 2023 +0700 @@ -13,7 +13,7 @@ # TODO: check for alignment in uniform blocks # type - DescriptorType = SomeNumber|Vec|Mat + DescriptorType = SomeNumber|TVec|Mat Descriptor*[T:DescriptorType] = object value*: T diff -r 836790efab48 -r 5d406c17bbcb src/semicongine/glsl_helpers.nim --- a/src/semicongine/glsl_helpers.nim Fri Jan 20 00:41:55 2023 +0700 +++ b/src/semicongine/glsl_helpers.nim Fri Jan 20 16:13:32 2023 +0700 @@ -17,38 +17,38 @@ elif T is float32: "float" elif T is float64: "double" - elif T is Vec2[uint8]: "uvec2" - elif T is Vec2[int8]: "ivec2" - elif T is Vec2[uint16]: "uvec2" - elif T is Vec2[int16]: "ivec2" - elif T is Vec2[uint32]: "uvec2" - elif T is Vec2[int32]: "ivec2" - elif T is Vec2[uint64]: "uvec2" - elif T is Vec2[int64]: "ivec2" - elif T is Vec2[float32]: "vec2" - elif T is Vec2[float64]: "dvec2" + elif T is TVec2[uint8]: "uvec2" + elif T is TVec2[int8]: "ivec2" + elif T is TVec2[uint16]: "uvec2" + elif T is TVec2[int16]: "ivec2" + elif T is TVec2[uint32]: "uvec2" + elif T is TVec2[int32]: "ivec2" + elif T is TVec2[uint64]: "uvec2" + elif T is TVec2[int64]: "ivec2" + elif T is TVec2[float32]: "vec2" + elif T is TVec2[float64]: "dvec2" - elif T is Vec3[uint8]: "uvec3" - elif T is Vec3[int8]: "ivec3" - elif T is Vec3[uint16]: "uvec3" - elif T is Vec3[int16]: "ivec3" - elif T is Vec3[uint32]: "uvec3" - elif T is Vec3[int32]: "ivec3" - elif T is Vec3[uint64]: "uvec3" - elif T is Vec3[int64]: "ivec3" - elif T is Vec3[float32]: "vec3" - elif T is Vec3[float64]: "dvec3" + elif T is TVec3[uint8]: "uvec3" + elif T is TVec3[int8]: "ivec3" + elif T is TVec3[uint16]: "uvec3" + elif T is TVec3[int16]: "ivec3" + elif T is TVec3[uint32]: "uvec3" + elif T is TVec3[int32]: "ivec3" + elif T is TVec3[uint64]: "uvec3" + elif T is TVec3[int64]: "ivec3" + elif T is TVec3[float32]: "vec3" + elif T is TVec3[float64]: "dvec3" - elif T is Vec4[uint8]: "uvec4" - elif T is Vec4[int8]: "ivec4" - elif T is Vec4[uint16]: "uvec4" - elif T is Vec4[int16]: "ivec4" - elif T is Vec4[uint32]: "uvec4" - elif T is Vec4[int32]: "ivec4" - elif T is Vec4[uint64]: "uvec4" - elif T is Vec4[int64]: "ivec4" - elif T is Vec4[float32]: "vec4" - elif T is Vec4[float64]: "dvec4" + elif T is TVec4[uint8]: "uvec4" + elif T is TVec4[int8]: "ivec4" + elif T is TVec4[uint16]: "uvec4" + elif T is TVec4[int16]: "ivec4" + elif T is TVec4[uint32]: "uvec4" + elif T is TVec4[int32]: "ivec4" + elif T is TVec4[uint64]: "uvec4" + elif T is TVec4[int64]: "ivec4" + elif T is TVec4[float32]: "vec4" + elif T is TVec4[float64]: "dvec4" elif T is Mat22[float32]: "mat2" elif T is Mat23[float32]: "mat32" diff -r 836790efab48 -r 5d406c17bbcb src/semicongine/math/matrix.nim --- a/src/semicongine/math/matrix.nim Fri Jan 20 00:41:55 2023 +0700 +++ b/src/semicongine/math/matrix.nim Fri Jan 20 16:13:32 2023 +0700 @@ -130,21 +130,21 @@ 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 row*[T: Mat22](m: T, i: 0..1): auto = Vec2([m[i, 0], m[i, 1]]) -func row*[T: Mat32](m: T, i: 0..2): auto = Vec2([m[i, 0], m[i, 1]]) -func row*[T: Mat23](m: T, i: 0..1): auto = Vec3([m[i, 0], m[i, 1], m[i, 2]]) -func row*[T: Mat33](m: T, i: 0..2): auto = Vec3([m[i, 0], m[i, 1], m[i, 2]]) -func row*[T: Mat43](m: T, i: 0..3): auto = Vec3([m[i, 0], m[i, 1], m[i, 2]]) -func row*[T: Mat34](m: T, i: 0..2): auto = Vec4([m[i, 0], m[i, 1], m[i, 2], m[i, 3]]) -func row*[T: Mat44](m: T, i: 0..3): auto = Vec4([m[i, 0], m[i, 1], m[i, 2], m[i, 3]]) +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 col*[T: Mat22](m: T, i: 0..1): auto = Vec2([m[0, i], m[1, i]]) -func col*[T: Mat23](m: T, i: 0..2): auto = Vec2([m[0, i], m[1, i]]) -func col*[T: Mat32](m: T, i: 0..1): auto = Vec3([m[0, i], m[1, i], m[2, i]]) -func col*[T: Mat33](m: T, i: 0..2): auto = Vec3([m[0, i], m[1, i], m[2, i]]) -func col*[T: Mat34](m: T, i: 0..3): auto = Vec3([m[0, i], m[1, i], m[2, i]]) -func col*[T: Mat43](m: T, i: 0..2): auto = Vec4([m[0, i], m[1, i], m[2, i], m[3, i]]) -func col*[T: Mat44](m: T, i: 0..3): auto = Vec4([m[0, i], m[1, i], m[2, i], m[3, i]]) +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]]) proc createMatMatMultiplicationOperator(leftType: typedesc, rightType: typedesc, outType: typedesc): NimNode = var data = nnkBracket.newTree() @@ -271,9 +271,9 @@ result.add(createMatMatMultiplicationOperator(Mat44, Mat43, Mat43)) result.add(createMatMatMultiplicationOperator(Mat44, Mat44, Mat44)) - result.add(createVecMatMultiplicationOperator(Mat22, Vec2)) - result.add(createVecMatMultiplicationOperator(Mat33, Vec3)) - result.add(createVecMatMultiplicationOperator(Mat44, Vec4)) + result.add(createVecMatMultiplicationOperator(Mat22, TVec2)) + result.add(createVecMatMultiplicationOperator(Mat33, TVec3)) + result.add(createVecMatMultiplicationOperator(Mat44, TVec4)) createAllMultiplicationOperators() @@ -341,7 +341,7 @@ T(0), T(0), sz, T(0), T(0), T(0), T(0), T(1), ]) -func rotate3d*[T](angle: T, a: Vec3[T]): Mat44[T] = +func rotate3d*[T](angle: T, a: TVec3[T]): Mat44[T] = let cosa = cos(angle) sina = sin(angle) diff -r 836790efab48 -r 5d406c17bbcb src/semicongine/math/vector.nim --- a/src/semicongine/math/vector.nim Fri Jan 20 00:41:55 2023 +0700 +++ b/src/semicongine/math/vector.nim Fri Jan 20 16:13:32 2023 +0700 @@ -9,26 +9,26 @@ type - Vec2*[T: SomeNumber] = array[2, T] - Vec3*[T: SomeNumber] = array[3, T] - Vec4*[T: SomeNumber] = array[4, T] - Vec* = Vec2|Vec3|Vec4 + TVec2*[T: SomeNumber] = array[2, T] + TVec3*[T: SomeNumber] = array[3, T] + TVec4*[T: SomeNumber] = array[4, T] + TVec* = TVec2|TVec3|TVec4 -converter toVec2*[T: SomeNumber](orig: Vec3[T]|Vec4[T]): Vec2[T] = - Vec2[T]([orig[0], orig[1]]) -converter toVec3*[T: SomeNumber](orig: Vec4[T]): Vec3[T] = - Vec2[T]([orig[0], orig[1], orig[2]]) +converter toVec2*[T: SomeNumber](orig: TVec3[T]|TVec4[T]): TVec2[T] = + TVec2[T]([orig[0], orig[1]]) +converter toVec3*[T: SomeNumber](orig: TVec4[T]): TVec3[T] = + TVec2[T]([orig[0], orig[1], orig[2]]) # define some often used constants -func ConstOne2[T: SomeNumber](): auto {.compiletime.} = Vec2[T]([T(1), T(1)]) -func ConstOne3[T: SomeNumber](): auto {.compiletime.} = Vec3[T]([T(1), T(1), T(1)]) -func ConstOne4[T: SomeNumber](): auto {.compiletime.} = Vec4[T]([T(1), T(1), T(1), T(1)]) -func ConstX[T: SomeNumber](): auto {.compiletime.} = Vec3[T]([T(1), T(0), T(0)]) -func ConstY[T: SomeNumber](): auto {.compiletime.} = Vec3[T]([T(0), T(1), T(0)]) -func ConstZ[T: SomeNumber](): auto {.compiletime.} = Vec3[T]([T(0), T(0), T(1)]) -func ConstR[T: SomeNumber](): auto {.compiletime.} = Vec3[T]([T(1), T(0), T(0)]) -func ConstG[T: SomeNumber](): auto {.compiletime.} = Vec3[T]([T(0), T(1), T(0)]) -func ConstB[T: SomeNumber](): auto {.compiletime.} = Vec3[T]([T(0), T(0), T(1)]) +func ConstOne2[T: SomeNumber](): auto {.compiletime.} = TVec2[T]([T(1), T(1)]) +func ConstOne3[T: SomeNumber](): auto {.compiletime.} = TVec3[T]([T(1), T(1), T(1)]) +func ConstOne4[T: SomeNumber](): auto {.compiletime.} = TVec4[T]([T(1), T(1), T(1), T(1)]) +func ConstX[T: SomeNumber](): auto {.compiletime.} = TVec3[T]([T(1), T(0), T(0)]) +func ConstY[T: SomeNumber](): auto {.compiletime.} = TVec3[T]([T(0), T(1), T(0)]) +func ConstZ[T: SomeNumber](): auto {.compiletime.} = TVec3[T]([T(0), T(0), T(1)]) +func ConstR[T: SomeNumber](): auto {.compiletime.} = TVec3[T]([T(1), T(0), T(0)]) +func ConstG[T: SomeNumber](): auto {.compiletime.} = TVec3[T]([T(0), T(1), T(0)]) +func ConstB[T: SomeNumber](): auto {.compiletime.} = TVec3[T]([T(0), T(0), T(1)]) # generates constants: Xf, Xf32, Xf64, Xi, Xi8, Xi16, Xi32, Xi64 # Also for Y, Z, R, G, B and One @@ -58,13 +58,13 @@ const One3* = ConstOne3[float]() const One4* = ConstOne4[float]() -func newVec2*[T](x, y: T): auto = Vec2([x, y]) -func newVec3*[T](x, y, z: T): auto = Vec3([x, y, z]) -func newVec4*[T](x, y, z, w: T): auto = Vec4([x, y, z, w]) +func newVec2*[T](x, y: T): auto = TVec2([x, y]) +func newVec3*[T](x, y, z: T): auto = TVec3([x, y, z]) +func newVec4*[T](x, y, z, w: T): auto = TVec4([x, y, z, w]) -func to*[T](v: Vec2): auto = Vec2([T(v[0]), T(v[1])]) -func to*[T](v: Vec3): auto = Vec3([T(v[0]), T(v[1]), T(v[2])]) -func to*[T](v: Vec4): auto = Vec4([T(v[0]), T(v[1]), T(v[2]), T(v[3])]) +func to*[T](v: TVec2): auto = TVec2([T(v[0]), T(v[1])]) +func to*[T](v: TVec3): auto = TVec3([T(v[0]), T(v[1]), T(v[2])]) +func to*[T](v: TVec4): auto = TVec4([T(v[0]), T(v[1]), T(v[2]), T(v[3])]) func toString[T](value: T): string = var items: seq[string] @@ -72,94 +72,94 @@ items.add($item) $T & "(" & join(items, " ") & ")" -func `$`*(v: Vec2[SomeNumber]): string = toString[Vec2[SomeNumber]](v) -func `$`*(v: Vec3[SomeNumber]): string = toString[Vec3[SomeNumber]](v) -func `$`*(v: Vec4[SomeNumber]): string = toString[Vec4[SomeNumber]](v) +func `$`*(v: TVec2[SomeNumber]): string = toString[TVec2[SomeNumber]](v) +func `$`*(v: TVec3[SomeNumber]): string = toString[TVec3[SomeNumber]](v) +func `$`*(v: TVec4[SomeNumber]): string = toString[TVec4[SomeNumber]](v) -func length*(vec: Vec2[SomeFloat]): auto = sqrt(vec[0] * vec[0] + vec[1] * vec[1]) -func length*(vec: Vec2[SomeInteger]): auto = sqrt(float(vec[0] * vec[0] + vec[1] * vec[1])) -func length*(vec: Vec3[SomeFloat]): auto = sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]) -func length*(vec: Vec3[SomeInteger]): auto = sqrt(float(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2])) -func length*(vec: Vec4[SomeFloat]): auto = sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2] + vec[3] * vec[3]) -func length*(vec: Vec4[SomeInteger]): auto = sqrt(float(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2] + vec[3] * vec[3])) +func length*(vec: TVec2[SomeFloat]): auto = sqrt(vec[0] * vec[0] + vec[1] * vec[1]) +func length*(vec: TVec2[SomeInteger]): auto = sqrt(float(vec[0] * vec[0] + vec[1] * vec[1])) +func length*(vec: TVec3[SomeFloat]): auto = sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]) +func length*(vec: TVec3[SomeInteger]): auto = sqrt(float(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2])) +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 normalized*[T](vec: Vec2[T]): auto = +func normalized*[T](vec: TVec2[T]): auto = let l = vec.length when T is SomeFloat: - Vec2[T]([vec[0] / l, vec[1] / l]) + TVec2[T]([vec[0] / l, vec[1] / l]) else: - Vec2[float]([float(vec[0]) / l, float(vec[1]) / l]) -func normalized*[T](vec: Vec3[T]): auto = + TVec2[float]([float(vec[0]) / l, float(vec[1]) / l]) +func normalized*[T](vec: TVec3[T]): auto = let l = vec.length when T is SomeFloat: - Vec3[T]([vec[0] / l, vec[1] / l, vec[2] / l]) + TVec3[T]([vec[0] / l, vec[1] / l, vec[2] / l]) else: - Vec3[float]([float(vec[0]) / l, float(vec[1]) / l, float(vec[2]) / l]) -func normalized*[T](vec: Vec4[T]): auto = + TVec3[float]([float(vec[0]) / l, float(vec[1]) / l, float(vec[2]) / l]) +func normalized*[T](vec: TVec4[T]): auto = let l = vec.length when T is SomeFloat: - Vec4[T]([vec[0] / l, vec[1] / l, vec[2] / l, vec[3] / l]) + TVec4[T]([vec[0] / l, vec[1] / l, vec[2] / l, vec[3] / l]) else: - Vec4[float]([float(vec[0]) / l, float(vec[1]) / l, float(vec[2]) / l, float(vec[3]) / l]) + TVec4[float]([float(vec[0]) / l, float(vec[1]) / l, float(vec[2]) / l, float(vec[3]) / l]) # scalar operations -func `+`*(a: Vec2, b: SomeNumber): auto = Vec2([a[0] + b, a[1] + b]) -func `+`*(a: Vec3, b: SomeNumber): auto = Vec3([a[0] + b, a[1] + b, a[2] + b]) -func `+`*(a: Vec4, b: SomeNumber): auto = Vec4([a[0] + b, a[1] + b, a[2] + b, a[3] + b]) -func `-`*(a: Vec2, b: SomeNumber): auto = Vec2([a[0] - b, a[1] - b]) -func `-`*(a: Vec3, b: SomeNumber): auto = Vec3([a[0] - b, a[1] - b, a[2] - b]) -func `-`*(a: Vec4, b: SomeNumber): auto = Vec4([a[0] - b, a[1] - b, a[2] - b, a[3] - b]) -func `*`*(a: Vec2, b: SomeNumber): auto = Vec2([a[0] * b, a[1] * b]) -func `*`*(a: Vec3, b: SomeNumber): auto = Vec3([a[0] * b, a[1] * b, a[2] * b]) -func `*`*(a: Vec4, b: SomeNumber): auto = Vec4([a[0] * b, a[1] * b, a[2] * b, a[3] * b]) -func `/`*[T: SomeInteger](a: Vec2[T], b: SomeInteger): auto = Vec2([a[0] div b, a[1] div b]) -func `/`*[T: SomeFloat](a: Vec2[T], b: SomeFloat): auto = Vec2([a[0] / b, a[1] / b]) -func `/`*[T: SomeInteger](a: Vec3[T], b: SomeInteger): auto = Vec3([a[0] div b, a[1] div b, a[2] div b]) -func `/`*[T: SomeFloat](a: Vec3[T], b: SomeFloat): auto = Vec3([a[0] / b, a[1] / b, a[2] / b]) -func `/`*[T: SomeInteger](a: Vec4[T], b: SomeInteger): auto = Vec4([a[0] div b, a[1] div b, a[2] div b, a[3] div b]) -func `/`*[T: SomeFloat](a: Vec4[T], b: SomeFloat): auto = Vec4([a[0] / b, a[1] / b, a[2] / b, a[3] / b]) +func `+`*(a: TVec2, b: SomeNumber): auto = TVec2([a[0] + b, a[1] + b]) +func `+`*(a: TVec3, b: SomeNumber): auto = TVec3([a[0] + b, a[1] + b, a[2] + b]) +func `+`*(a: TVec4, b: SomeNumber): auto = TVec4([a[0] + b, a[1] + b, a[2] + b, a[3] + b]) +func `-`*(a: TVec2, b: SomeNumber): auto = TVec2([a[0] - b, a[1] - b]) +func `-`*(a: TVec3, b: SomeNumber): auto = TVec3([a[0] - b, a[1] - b, a[2] - b]) +func `-`*(a: TVec4, b: SomeNumber): auto = TVec4([a[0] - b, a[1] - b, a[2] - b, a[3] - b]) +func `*`*(a: TVec2, b: SomeNumber): auto = TVec2([a[0] * b, a[1] * b]) +func `*`*(a: TVec3, b: SomeNumber): auto = TVec3([a[0] * b, a[1] * b, a[2] * b]) +func `*`*(a: TVec4, b: SomeNumber): auto = TVec4([a[0] * b, a[1] * b, a[2] * b, a[3] * b]) +func `/`*[T: SomeInteger](a: TVec2[T], b: SomeInteger): auto = TVec2([a[0] div b, a[1] div b]) +func `/`*[T: SomeFloat](a: TVec2[T], b: SomeFloat): auto = TVec2([a[0] / b, a[1] / b]) +func `/`*[T: SomeInteger](a: TVec3[T], b: SomeInteger): auto = TVec3([a[0] div b, a[1] div b, a[2] div b]) +func `/`*[T: SomeFloat](a: TVec3[T], b: SomeFloat): auto = TVec3([a[0] / b, a[1] / b, a[2] / b]) +func `/`*[T: SomeInteger](a: TVec4[T], b: SomeInteger): auto = TVec4([a[0] div b, a[1] div b, a[2] div b, a[3] div b]) +func `/`*[T: SomeFloat](a: TVec4[T], b: SomeFloat): auto = TVec4([a[0] / b, a[1] / b, a[2] / b, a[3] / b]) -func `+`*(a: SomeNumber, b: Vec2): auto = Vec2([a + b[0], a + b[1]]) -func `+`*(a: SomeNumber, b: Vec3): auto = Vec3([a + b[0], a + b[1], a + b[2]]) -func `+`*(a: SomeNumber, b: Vec4): auto = Vec4([a + b[0], a + b[1], a + b[2], a + b[3]]) -func `-`*(a: SomeNumber, b: Vec2): auto = Vec2([a - b[0], a - b[1]]) -func `-`*(a: SomeNumber, b: Vec3): auto = Vec3([a - b[0], a - b[1], a - b[2]]) -func `-`*(a: SomeNumber, b: Vec4): auto = Vec4([a - b[0], a - b[1], a - b[2], a - b[3]]) -func `*`*(a: SomeNumber, b: Vec2): auto = Vec2([a * b[0], a * b[1]]) -func `*`*(a: SomeNumber, b: Vec3): auto = Vec3([a * b[0], a * b[1], a * b[2]]) -func `*`*(a: SomeNumber, b: Vec4): auto = Vec4([a * b[0], a * b[1], a * b[2], a * b[3]]) -func `/`*[T: SomeInteger](a: SomeInteger, b: Vec2[T]): auto = Vec2([a div b[0], a div b[1]]) -func `/`*[T: SomeFloat](a: SomeFloat, b: Vec2[T]): auto = Vec2([a / b[0], a / b[1]]) -func `/`*[T: SomeInteger](a: SomeInteger, b: Vec3[T]): auto = Vec3([a div b[0], a div b[1], a div b[2]]) -func `/`*[T: SomeFloat](a: SomeFloat, b: Vec3[T]): auto = Vec3([a / b[0], a / b[1], a / b[2]]) -func `/`*[T: SomeInteger](a: SomeInteger, b: Vec4[T]): auto = Vec4([a div b[0], a div b[1], a div b[2], a div b[3]]) -func `/`*[T: SomeFloat](a: SomeFloat, b: Vec4[T]): auto = Vec4([a / b[0], a / b[1], a / b[2], a / b[3]]) +func `+`*(a: SomeNumber, b: TVec2): auto = TVec2([a + b[0], a + b[1]]) +func `+`*(a: SomeNumber, b: TVec3): auto = TVec3([a + b[0], a + b[1], a + b[2]]) +func `+`*(a: SomeNumber, b: TVec4): auto = TVec4([a + b[0], a + b[1], a + b[2], a + b[3]]) +func `-`*(a: SomeNumber, b: TVec2): auto = TVec2([a - b[0], a - b[1]]) +func `-`*(a: SomeNumber, b: TVec3): auto = TVec3([a - b[0], a - b[1], a - b[2]]) +func `-`*(a: SomeNumber, b: TVec4): auto = TVec4([a - b[0], a - b[1], a - b[2], a - b[3]]) +func `*`*(a: SomeNumber, b: TVec2): auto = TVec2([a * b[0], a * b[1]]) +func `*`*(a: SomeNumber, b: TVec3): auto = TVec3([a * b[0], a * b[1], a * b[2]]) +func `*`*(a: SomeNumber, b: TVec4): auto = TVec4([a * b[0], a * b[1], a * b[2], a * b[3]]) +func `/`*[T: SomeInteger](a: SomeInteger, b: TVec2[T]): auto = TVec2([a div b[0], a div b[1]]) +func `/`*[T: SomeFloat](a: SomeFloat, b: TVec2[T]): auto = TVec2([a / b[0], a / b[1]]) +func `/`*[T: SomeInteger](a: SomeInteger, b: TVec3[T]): auto = TVec3([a div b[0], a div b[1], a div b[2]]) +func `/`*[T: SomeFloat](a: SomeFloat, b: TVec3[T]): auto = TVec3([a / b[0], a / b[1], a / b[2]]) +func `/`*[T: SomeInteger](a: SomeInteger, b: TVec4[T]): auto = TVec4([a div b[0], a div b[1], a div b[2], a div b[3]]) +func `/`*[T: SomeFloat](a: SomeFloat, b: TVec4[T]): auto = TVec4([a / b[0], a / b[1], a / b[2], a / b[3]]) # compontent-wise operations -func `+`*(a, b: Vec2): auto = Vec2([a[0] + b[0], a[1] + b[1]]) -func `+`*(a, b: Vec3): auto = Vec3([a[0] + b[0], a[1] + b[1], a[2] + b[2]]) -func `+`*(a, b: Vec4): auto = Vec4([a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3]]) -func `-`*(a: Vec2): auto = Vec2([-a[0], -a[1]]) -func `-`*(a: Vec3): auto = Vec3([-a[0], -a[1], -a[2]]) -func `-`*(a: Vec4): auto = Vec4([-a[0], -a[1], -a[2], -a[3]]) -func `-`*(a, b: Vec2): auto = Vec2([a[0] - b[0], a[1] - b[1]]) -func `-`*(a, b: Vec3): auto = Vec3([a[0] - b[0], a[1] - b[1], a[2] - b[2]]) -func `-`*(a, b: Vec4): auto = Vec4([a[0] - b[0], a[1] - b[1], a[2] - b[2], a[3] - b[3]]) -func `*`*(a, b: Vec2): auto = Vec2([a[0] * b[0], a[1] * b[1]]) -func `*`*(a, b: Vec3): auto = Vec3([a[0] * b[0], a[1] * b[1], a[2] * b[2]]) -func `*`*(a, b: Vec4): auto = Vec4([a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3]]) -func `/`*[T: SomeInteger](a, b: Vec2[T]): auto = Vec2([a[0] div b[0], a[1] div b[1]]) -func `/`*[T: SomeFloat](a, b: Vec2[T]): auto = Vec2([a[0] / b[0], a[1] / b[1]]) -func `/`*[T: SomeInteger](a, b: Vec3[T]): auto = Vec3([a[0] div b[0], a[1] div b[1], a[2] div b[2]]) -func `/`*[T: SomeFloat](a, b: Vec3[T]): auto = Vec3([a[0] / b[0], a[1] / b[1], a[2] / b[2]]) -func `/`*[T: SomeInteger](a, b: Vec4[T]): auto = Vec4([a[0] div b[0], a[1] div b[1], a[2] div b[2], a[3] div b[3]]) -func `/`*[T: SomeFloat](a, b: Vec4[T]): auto = Vec4([a[0] / b[0], a[1] / b[1], a[2] / b[2], a[3] / b[3]]) +func `+`*(a, b: TVec2): auto = TVec2([a[0] + b[0], a[1] + b[1]]) +func `+`*(a, b: TVec3): auto = TVec3([a[0] + b[0], a[1] + b[1], a[2] + b[2]]) +func `+`*(a, b: TVec4): auto = TVec4([a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3]]) +func `-`*(a: TVec2): auto = TVec2([-a[0], -a[1]]) +func `-`*(a: TVec3): auto = TVec3([-a[0], -a[1], -a[2]]) +func `-`*(a: TVec4): auto = TVec4([-a[0], -a[1], -a[2], -a[3]]) +func `-`*(a, b: TVec2): auto = TVec2([a[0] - b[0], a[1] - b[1]]) +func `-`*(a, b: TVec3): auto = TVec3([a[0] - b[0], a[1] - b[1], a[2] - b[2]]) +func `-`*(a, b: TVec4): auto = TVec4([a[0] - b[0], a[1] - b[1], a[2] - b[2], a[3] - b[3]]) +func `*`*(a, b: TVec2): auto = TVec2([a[0] * b[0], a[1] * b[1]]) +func `*`*(a, b: TVec3): auto = TVec3([a[0] * b[0], a[1] * b[1], a[2] * b[2]]) +func `*`*(a, b: TVec4): auto = TVec4([a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3]]) +func `/`*[T: SomeInteger](a, b: TVec2[T]): auto = TVec2([a[0] div b[0], a[1] div b[1]]) +func `/`*[T: SomeFloat](a, b: TVec2[T]): auto = TVec2([a[0] / b[0], a[1] / b[1]]) +func `/`*[T: SomeInteger](a, b: TVec3[T]): auto = TVec3([a[0] div b[0], a[1] div b[1], a[2] div b[2]]) +func `/`*[T: SomeFloat](a, b: TVec3[T]): auto = TVec3([a[0] / b[0], a[1] / b[1], a[2] / b[2]]) +func `/`*[T: SomeInteger](a, b: TVec4[T]): auto = TVec4([a[0] div b[0], a[1] div b[1], a[2] div b[2], a[3] div b[3]]) +func `/`*[T: SomeFloat](a, b: TVec4[T]): auto = TVec4([a[0] / b[0], a[1] / b[1], a[2] / b[2], a[3] / b[3]]) # special operations -func dot*(a, b: Vec2): auto = a[0] * b[0] + a[1] * b[1] -func dot*(a, b: Vec3): auto = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] -func dot*(a, b: Vec4): auto = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3] -func cross*(a, b: Vec3): auto = Vec3([ +func dot*(a, b: TVec2): auto = a[0] * b[0] + a[1] * b[1] +func dot*(a, b: TVec3): auto = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] +func dot*(a, b: TVec4): auto = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3] +func cross*(a, b: TVec3): auto = TVec3([ a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0], @@ -191,11 +191,11 @@ var attrs = nnkBracket.newTree() for attrname in accessorvalue: attrs.add(nnkBracketExpr.newTree(ident("value"), newLit(ACCESSOR_INDICES[attrname]))) - ret = nnkCall.newTree(ident("Vec" & $accessorvalue.len), attrs) + ret = nnkCall.newTree(ident("TVec" & $accessorvalue.len), attrs) newProc( name=nnkPostfix.newTree(ident("*"), ident(accessor)), - params=[ident("auto"), nnkIdentDefs.newTree(ident("value"), ident("Vec"), newEmptyNode())], + params=[ident("auto"), nnkIdentDefs.newTree(ident("value"), ident("TVec"), newEmptyNode())], body=newStmtList(ret), procType = nnkFuncDef, ) @@ -225,6 +225,6 @@ for i in 0 ..< result.len: result[i] = rand(1.0) -makeRandomInit(Vec2) -makeRandomInit(Vec3) -makeRandomInit(Vec4) +makeRandomInit(TVec2) +makeRandomInit(TVec3) +makeRandomInit(TVec4) diff -r 836790efab48 -r 5d406c17bbcb src/semicongine/mesh.nim --- a/src/semicongine/mesh.nim Fri Jan 20 00:41:55 2023 +0700 +++ b/src/semicongine/mesh.nim Fri Jan 20 16:13:32 2023 +0700 @@ -103,8 +103,8 @@ result[3] = getVkIndexType(mesh) -func squareData*[T:SomeFloat](): auto = PositionAttribute[Vec2[T]]( - data: @[Vec2[T]([T(0), T(0)]), Vec2[T]([T(0), T(1)]), Vec2[T]([T(1), T(1)]), Vec2[T]([T(1), T(0)])] +func squareData*[T:SomeFloat](): auto = PositionAttribute[TVec2[T]]( + data: @[TVec2[T]([T(0), T(0)]), TVec2[T]([T(0), T(1)]), TVec2[T]([T(1), T(1)]), TVec2[T]([T(1), T(0)])] ) func squareIndices*[T:uint16|uint32](): auto = seq[array[3, T]]( @[[T(0), T(1), T(3)], [T(2), T(1), T(3)]] diff -r 836790efab48 -r 5d406c17bbcb src/semicongine/shader.nim --- a/src/semicongine/shader.nim Fri Jan 20 00:41:55 2023 +0700 +++ b/src/semicongine/shader.nim Fri Jan 20 16:13:32 2023 +0700 @@ -13,7 +13,7 @@ import ./math/vector type - AllowedUniformType = SomeNumber|Vec + AllowedUniformType = SomeNumber|TVec UniformSlot *[T:AllowedUniformType] = object ShaderProgram*[VertexType, Uniforms] = object entryPoint*: string @@ -102,11 +102,11 @@ when typeof(value) is PositionAttribute: let glsltype = getGLSLType[getAttributeType(value)]() lines.add &" {glsltype} in_position = " & name & ";" - if getAttributeType(value) is Vec2: + if getAttributeType(value) is TVec2: lines.add " vec4 out_position = vec4(in_position, 0.0, 1.0);" - elif getAttributeType(value) is Vec3: + elif getAttributeType(value) is TVec3: lines.add " vec4 out_position = vec4(in_position, 1.0);" - elif getAttributeType(value) is Vec4: + elif getAttributeType(value) is TVec4: lines.add " vec4 out_position = in_position;" hasPosition += 1 when typeof(value) is ColorAttribute: diff -r 836790efab48 -r 5d406c17bbcb src/semicongine/vertex.nim --- a/src/semicongine/vertex.nim Fri Jan 20 00:41:55 2023 +0700 +++ b/src/semicongine/vertex.nim Fri Jan 20 16:13:32 2023 +0700 @@ -9,16 +9,16 @@ import ./glsl_helpers type - VertexAttributeType = SomeNumber|Vec + VertexAttributeType = SomeNumber|TVec AttributePurpose* = enum Unknown, Position Color GenericAttribute*[T:VertexAttributeType] = object data*: seq[T] - PositionAttribute*[T:Vec] = object + PositionAttribute*[T:TVec] = object data*: seq[T] - ColorAttribute*[T:Vec] = object + ColorAttribute*[T:TVec] = object data*: seq[T] - InstanceAttribute*[T:Vec] = object + InstanceAttribute*[T:TVec] = object data*: seq[T] VertexAttribute* = GenericAttribute|PositionAttribute|ColorAttribute|InstanceAttribute @@ -33,7 +33,7 @@ 8 elif (T is Mat44[float32]): 4 - elif (T is Vec3[float64] or T is Vec3[uint64] or T is Vec4[float64] or T is Vec4[float64]): + elif (T is TVec3[float64] or T is TVec3[uint64] or T is TVec4[float64] or T is TVec4[float64]): 2 else: 1 @@ -50,36 +50,36 @@ elif T is int64: VK_FORMAT_R64_SINT elif T is float32: VK_FORMAT_R32_SFLOAT elif T is float64: VK_FORMAT_R64_SFLOAT - elif T is Vec2[uint8]: VK_FORMAT_R8G8_UINT - elif T is Vec2[int8]: VK_FORMAT_R8G8_SINT - elif T is Vec2[uint16]: VK_FORMAT_R16G16_UINT - elif T is Vec2[int16]: VK_FORMAT_R16G16_SINT - elif T is Vec2[uint32]: VK_FORMAT_R32G32_UINT - elif T is Vec2[int32]: VK_FORMAT_R32G32_SINT - elif T is Vec2[uint64]: VK_FORMAT_R64G64_UINT - elif T is Vec2[int64]: VK_FORMAT_R64G64_SINT - elif T is Vec2[float32]: VK_FORMAT_R32G32_SFLOAT - elif T is Vec2[float64]: VK_FORMAT_R64G64_SFLOAT - elif T is Vec3[uint8]: VK_FORMAT_R8G8B8_UINT - elif T is Vec3[int8]: VK_FORMAT_R8G8B8_SINT - elif T is Vec3[uint16]: VK_FORMAT_R16G16B16_UINT - elif T is Vec3[int16]: VK_FORMAT_R16G16B16_SINT - elif T is Vec3[uint32]: VK_FORMAT_R32G32B32_UINT - elif T is Vec3[int32]: VK_FORMAT_R32G32B32_SINT - elif T is Vec3[uint64]: VK_FORMAT_R64G64B64_UINT - elif T is Vec3[int64]: VK_FORMAT_R64G64B64_SINT - elif T is Vec3[float32]: VK_FORMAT_R32G32B32_SFLOAT - elif T is Vec3[float64]: VK_FORMAT_R64G64B64_SFLOAT - elif T is Vec4[uint8]: VK_FORMAT_R8G8B8A8_UINT - elif T is Vec4[int8]: VK_FORMAT_R8G8B8A8_SINT - elif T is Vec4[uint16]: VK_FORMAT_R16G16B16A16_UINT - elif T is Vec4[int16]: VK_FORMAT_R16G16B16A16_SINT - elif T is Vec4[uint32]: VK_FORMAT_R32G32B32A32_UINT - elif T is Vec4[int32]: VK_FORMAT_R32G32B32A32_SINT - elif T is Vec4[uint64]: VK_FORMAT_R64G64B64A64_UINT - elif T is Vec4[int64]: VK_FORMAT_R64G64B64A64_SINT - elif T is Vec4[float32]: VK_FORMAT_R32G32B32A32_SFLOAT - elif T is Vec4[float64]: VK_FORMAT_R64G64B64A64_SFLOAT + elif T is TVec2[uint8]: VK_FORMAT_R8G8_UINT + elif T is TVec2[int8]: VK_FORMAT_R8G8_SINT + elif T is TVec2[uint16]: VK_FORMAT_R16G16_UINT + elif T is TVec2[int16]: VK_FORMAT_R16G16_SINT + elif T is TVec2[uint32]: VK_FORMAT_R32G32_UINT + elif T is TVec2[int32]: VK_FORMAT_R32G32_SINT + elif T is TVec2[uint64]: VK_FORMAT_R64G64_UINT + elif T is TVec2[int64]: VK_FORMAT_R64G64_SINT + elif T is TVec2[float32]: VK_FORMAT_R32G32_SFLOAT + elif T is TVec2[float64]: VK_FORMAT_R64G64_SFLOAT + elif T is TVec3[uint8]: VK_FORMAT_R8G8B8_UINT + elif T is TVec3[int8]: VK_FORMAT_R8G8B8_SINT + elif T is TVec3[uint16]: VK_FORMAT_R16G16B16_UINT + elif T is TVec3[int16]: VK_FORMAT_R16G16B16_SINT + elif T is TVec3[uint32]: VK_FORMAT_R32G32B32_UINT + elif T is TVec3[int32]: VK_FORMAT_R32G32B32_SINT + elif T is TVec3[uint64]: VK_FORMAT_R64G64B64_UINT + elif T is TVec3[int64]: VK_FORMAT_R64G64B64_SINT + elif T is TVec3[float32]: VK_FORMAT_R32G32B32_SFLOAT + elif T is TVec3[float64]: VK_FORMAT_R64G64B64_SFLOAT + elif T is TVec4[uint8]: VK_FORMAT_R8G8B8A8_UINT + elif T is TVec4[int8]: VK_FORMAT_R8G8B8A8_SINT + elif T is TVec4[uint16]: VK_FORMAT_R16G16B16A16_UINT + elif T is TVec4[int16]: VK_FORMAT_R16G16B16A16_SINT + elif T is TVec4[uint32]: VK_FORMAT_R32G32B32A32_UINT + elif T is TVec4[int32]: VK_FORMAT_R32G32B32A32_SINT + elif T is TVec4[uint64]: VK_FORMAT_R64G64B64A64_UINT + elif T is TVec4[int64]: VK_FORMAT_R64G64B64A64_SINT + elif T is TVec4[float32]: VK_FORMAT_R32G32B32A32_SFLOAT + elif T is TVec4[float64]: VK_FORMAT_R64G64B64A64_SFLOAT diff -r 836790efab48 -r 5d406c17bbcb tests/test_matrix.nim --- a/tests/test_matrix.nim Fri Jan 20 00:41:55 2023 +0700 +++ b/tests/test_matrix.nim Fri Jan 20 16:13:32 2023 +0700 @@ -1,11 +1,11 @@ import random import math -import zamikongine/math/vector -import zamikongine/math/matrix +import semicongine/math/vector +import semicongine/math/matrix -proc echoInfo(v: Vec) = +proc echoInfo(v: TVec) = echo v echo " Length: ", v.length echo " Normlized: ", v.normalized diff -r 836790efab48 -r 5d406c17bbcb tests/test_vector.nim --- a/tests/test_vector.nim Fri Jan 20 00:41:55 2023 +0700 +++ b/tests/test_vector.nim Fri Jan 20 16:13:32 2023 +0700 @@ -1,10 +1,10 @@ import random import math -import vector +import semicongine/math/vector -proc echoInfo(v: Vec) = +proc echoInfo(v: TVec) = echo v echo " Length: ", v.length echo " Normlized: ", v.normalized