# HG changeset patch # User sam # Date 1717494710 -25200 # Node ID 71315636ba821f09d5a02752820ffc4571093013 # Parent 74957cbf589ba779e7625a5dea3f195f5d050ccf did: refactor naming in tons of places diff -r 74957cbf589b -r 71315636ba82 examples/E01_hello_triangle.nim --- a/examples/E01_hello_triangle.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/examples/E01_hello_triangle.nim Tue Jun 04 16:51:50 2024 +0700 @@ -20,8 +20,8 @@ var scene = Scene(name: "scene", meshes: @[newMesh( - positions = [newVec3f(-0.5, 0.5), newVec3f(0, -0.5), newVec3f(0.5, 0.5)], - colors = [newVec4f(1, 0, 0, 1), newVec4f(0, 1, 0, 1), newVec4f(0, 0, 1, 1)], + positions = [NewVec3f(-0.5, 0.5), NewVec3f(0, -0.5), NewVec3f(0.5, 0.5)], + colors = [NewVec4f(1, 0, 0, 1), NewVec4f(0, 1, 0, 1), NewVec4f(0, 0, 1, 1)], material = VERTEX_COLORED_MATERIAL.initMaterialData() )] ) diff -r 74957cbf589b -r 71315636ba82 examples/E02_squares.nim --- a/examples/E02_squares.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/examples/E02_squares.nim Tue Jun 04 16:51:50 2024 +0700 @@ -23,13 +23,13 @@ let y: float32 = (row * 2 / COLUMNS) - 1 x: float32 = (col * 2 / ROWS) - 1 - color = newVec4f((x + 1) / 2, (y + 1) / 2, 0, 1) + color = NewVec4f((x + 1) / 2, (y + 1) / 2, 0, 1) squareIndex = row * COLUMNS + col vertIndex = squareIndex * 4 - vertices[vertIndex + 0] = newVec3f(x, y) - vertices[vertIndex + 1] = newVec3f(x + WIDTH, y) - vertices[vertIndex + 2] = newVec3f(x + WIDTH, y + HEIGHT) - vertices[vertIndex + 3] = newVec3f(x, y + HEIGHT) + vertices[vertIndex + 0] = NewVec3f(x, y) + vertices[vertIndex + 1] = NewVec3f(x + WIDTH, y) + vertices[vertIndex + 2] = NewVec3f(x + WIDTH, y + HEIGHT) + vertices[vertIndex + 3] = NewVec3f(x, y + HEIGHT) colors[vertIndex + 0] = color colors[vertIndex + 1] = color colors[vertIndex + 2] = color diff -r 74957cbf589b -r 71315636ba82 examples/E03_hello_cube.nim --- a/examples/E03_hello_cube.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/examples/E03_hello_cube.nim Tue Jun 04 16:51:50 2024 +0700 @@ -4,14 +4,14 @@ import ../semicongine const - TopLeftFront = newVec3f(-0.5'f32, -0.5'f32, -0.5'f32) - TopRightFront = newVec3f(0.5'f32, -0.5'f32, -0.5'f32) - BottomRightFront = newVec3f(0.5'f32, 0.5'f32, -0.5'f32) - BottomLeftFront = newVec3f(-0.5'f32, 0.5'f32, -0.5'f32) - TopLeftBack = newVec3f(0.5'f32, -0.5'f32, 0.5'f32) - TopRightBack = newVec3f(-0.5'f32, -0.5'f32, 0.5'f32) - BottomRightBack = newVec3f(-0.5'f32, 0.5'f32, 0.5'f32) - BottomLeftBack = newVec3f(0.5'f32, 0.5'f32, 0.5'f32) + TopLeftFront = NewVec3f(-0.5'f32, -0.5'f32, -0.5'f32) + TopRightFront = NewVec3f(0.5'f32, -0.5'f32, -0.5'f32) + BottomRightFront = NewVec3f(0.5'f32, 0.5'f32, -0.5'f32) + BottomLeftFront = NewVec3f(-0.5'f32, 0.5'f32, -0.5'f32) + TopLeftBack = NewVec3f(0.5'f32, -0.5'f32, 0.5'f32) + TopRightBack = NewVec3f(-0.5'f32, -0.5'f32, 0.5'f32) + BottomRightBack = NewVec3f(-0.5'f32, 0.5'f32, 0.5'f32) + BottomLeftBack = NewVec3f(0.5'f32, 0.5'f32, 0.5'f32) const cube_pos = @[ TopLeftFront, TopRightFront, BottomRightFront, BottomLeftFront, # front @@ -21,9 +21,9 @@ TopLeftBack, TopRightBack, TopRightFront, TopLeftFront, # top BottomLeftFront, BottomRightFront, BottomRightBack, BottomLeftBack, # bottom ] - R = newVec4f(1, 0, 0, 1) - G = newVec4f(0, 1, 0, 1) - B = newVec4f(0, 0, 1, 1) + R = NewVec4f(1, 0, 0, 1) + G = NewVec4f(0, 1, 0, 1) + B = NewVec4f(0, 0, 1, 1) cube_color = @[ R, R, R, R, R * 0.5'f32, R * 0.5'f32, R * 0.5'f32, R * 0.5'f32, diff -r 74957cbf589b -r 71315636ba82 examples/E04_input.nim --- a/examples/E04_input.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/examples/E04_input.nim Tue Jun 04 16:51:50 2024 +0700 @@ -7,12 +7,12 @@ const arrow = @[ - newVec3f(-1, -1), - newVec3f(1, -1), - newVec3f(-0.3, -0.3), - newVec3f(-0.3, -0.3), - newVec3f(-1, 1), - newVec3f(-1, -1), + NewVec3f(-1, -1), + NewVec3f(1, -1), + NewVec3f(-0.3, -0.3), + NewVec3f(-0.3, -0.3), + NewVec3f(-1, 1), + NewVec3f(-1, -1), ] # keyboard layout, specifying rows with key widths, negative numbers are empty spaces keyrows = ( @@ -25,9 +25,9 @@ ) keyDimension = 50'f32 keyGap = 10'f32 - backgroundColor = newVec4f(0.6705882352941176, 0.6078431372549019, 0.5882352941176471, 1) - baseColor = newVec4f(0.9411764705882353, 0.9058823529411765, 0.8470588235294118, 1) - activeColor = newVec4f(0.6509803921568628, 0.22745098039215686, 0.3137254901960784, 1) + backgroundColor = NewVec4f(0.6705882352941176, 0.6078431372549019, 0.5882352941176471, 1) + baseColor = NewVec4f(0.9411764705882353, 0.9058823529411765, 0.8470588235294118, 1) + activeColor = NewVec4f(0.6509803921568628, 0.22745098039215686, 0.3137254901960784, 1) arrow_colors = @[ baseColor * 0.9'f32, baseColor * 0.9'f32, @@ -61,7 +61,7 @@ keyvertexpos: seq[Vec3f] keyvertexcolor: seq[Vec4f] keymeshindices: seq[array[3, uint16]] - rowpos = newVec2f(0, 0) + rowpos = NewVec2f(0, 0) i = 0'u16 firstRow = true rowWidth = 0'f32 @@ -70,13 +70,13 @@ let keySpace = float32(keyDimension * key) if key > 0: if keyIndices[i div 4] == Enter: - keyvertexpos.add newVec3f(rowpos[0], rowpos[1] - keyDimension - keyGap) - keyvertexpos.add newVec3f(rowpos[0] + keySpace, rowpos[1] - keyDimension - keyGap) + keyvertexpos.add NewVec3f(rowpos[0], rowpos[1] - keyDimension - keyGap) + keyvertexpos.add NewVec3f(rowpos[0] + keySpace, rowpos[1] - keyDimension - keyGap) else: - keyvertexpos.add newVec3f(rowpos[0], rowpos[1]) - keyvertexpos.add newVec3f(rowpos[0] + keySpace, rowpos[1]) - keyvertexpos.add newVec3f(rowpos[0] + keySpace, rowpos[1] + keyDimension) - keyvertexpos.add newVec3f(rowpos[0], rowpos[1] + keyDimension) + keyvertexpos.add NewVec3f(rowpos[0], rowpos[1]) + keyvertexpos.add NewVec3f(rowpos[0] + keySpace, rowpos[1]) + keyvertexpos.add NewVec3f(rowpos[0] + keySpace, rowpos[1] + keyDimension) + keyvertexpos.add NewVec3f(rowpos[0], rowpos[1] + keyDimension) keyvertexcolor.add [baseColor, baseColor, baseColor, baseColor] keymeshindices.add [i, i + 1, i + 2] keymeshindices.add [i + 2, i + 3, i] @@ -104,7 +104,7 @@ ) var positions = arrow for i in 0 ..< positions.len: - positions[i] = cursorscale * newVec3f(positions[i].x, positions[i].y) + positions[i] = cursorscale * NewVec3f(positions[i].x, positions[i].y) # define mesh objects var @@ -125,10 +125,10 @@ ) backgroundmesh = newMesh( positions = @[ - newVec3f(0'f32, 0'f32), - newVec3f(1'f32, 0'f32), - newVec3f(1'f32, 1'f32), - newVec3f(0'f32, 1'f32), + NewVec3f(0'f32, 0'f32), + NewVec3f(1'f32, 0'f32), + NewVec3f(1'f32, 1'f32), + NewVec3f(0'f32, 1'f32), ], colors = @[ backgroundColor, diff -r 74957cbf589b -r 71315636ba82 examples/E10_pong.nim --- a/examples/E10_pong.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/examples/E10_pong.nim Tue Jun 04 16:51:50 2024 +0700 @@ -17,7 +17,7 @@ var level: Scene - ballVelocity = newVec2f(1, 1).normalized * ballSpeed + ballVelocity = NewVec2f(1, 1).normalized * ballSpeed when isMainModule: var myengine = initEngine("Pong") @@ -88,7 +88,7 @@ # loose if ball.transform.col(3).x - ballSize/2 <= 0: ball.transform = scale(ballSize, ballSize, 1'f) * translate(30'f, 30'f, 0'f) - ballVelocity = newVec2f(1, 1).normalized * ballSpeed + ballVelocity = NewVec2f(1, 1).normalized * ballSpeed # bar if ball.transform.col(3).x - ballSize/2 <= barWidth: diff -r 74957cbf589b -r 71315636ba82 semicongine/collision.nim --- a/semicongine/collision.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/semicongine/collision.nim Tue Jun 04 16:51:50 2024 +0700 @@ -21,25 +21,25 @@ case collider.theType: of Box: let - P1 = collider.transform * newVec3f(0, 0, 0) # origin + P1 = collider.transform * NewVec3f(0, 0, 0) # origin P2 = collider.transform * Z P4 = collider.transform * X P5 = collider.transform * Y - u = (P1 - P4).cross(P1 - P5) - v = (P1 - P2).cross(P1 - P5) - w = (P1 - P2).cross(P1 - P4) - uP1 = u.dot(P1) - uP2 = u.dot(P2) - vP1 = v.dot(P1) - vP4 = v.dot(P4) - wP1 = w.dot(P1) - wP5 = w.dot(P5) - ux = u.dot(x) - vx = v.dot(x) - wx = w.dot(x) + u = (P1 - P4).Cross(P1 - P5) + v = (P1 - P2).Cross(P1 - P5) + w = (P1 - P2).Cross(P1 - P4) + uP1 = u.Dot(P1) + uP2 = u.Dot(P2) + vP1 = v.Dot(P1) + vP4 = v.Dot(P4) + wP1 = w.Dot(P1) + wP5 = w.Dot(P5) + ux = u.Dot(x) + vx = v.Dot(x) + wx = w.Dot(x) ux.between(uP1, uP2) and vx.between(vP1, vP4) and wx.between(wP1, wP5) of Sphere: - (collider.transform * x).length < (collider.transform * newVec3f()).length + (collider.transform * x).Length < (collider.transform * NewVec3f()).Length of Points: raise newException(Exception, "Points are not supported yet for 'contains'") @@ -51,7 +51,7 @@ func findFurthestPoint(points: openArray[Vec3f], direction: Vec3f): Vec3f = var maxDist = low(float32) for p in points: - let dist = direction.dot(p) + let dist = direction.Dot(p) if dist > maxDist: maxDist = dist result = p @@ -59,7 +59,7 @@ func findFurthestPoint(transform: Mat4, direction: Vec3f): Vec3f = return findFurthestPoint( [ - transform * newVec3f(0, 0, 0), + transform * NewVec3f(0, 0, 0), transform * X, transform * Y, transform * Z, @@ -73,7 +73,7 @@ func findFurthestPoint(collider: Collider, direction: Vec3f): Vec3f = case collider.theType of Sphere: - let directionNormalizedToSphere = ((direction / direction.length) * collider.radius) + let directionNormalizedToSphere = ((direction / direction.Length) * collider.radius) collider.transform * directionNormalizedToSphere of Box: findFurthestPoint(collider.transform, direction) @@ -84,7 +84,7 @@ a.findFurthestPoint(direction) - b.findFurthestPoint(-direction) func sameDirection(direction: Vec3f, ao: Vec3f): bool = - direction.dot(ao) > 0 + direction.Dot(ao) > 0 func line(simplex: var seq[Vec3f], direction: var Vec3f): bool = let @@ -94,7 +94,7 @@ ao = - a if sameDirection(ab, ao): - direction = cross(cross(ab, ao), ab) + direction = Cross(Cross(ab, ao), ab) else: simplex = @[a] direction = ao @@ -109,17 +109,17 @@ ab = b - a ac = c - a ao = - a - abc = ab.cross(ac) + abc = ab.Cross(ac) - if sameDirection(abc.cross(ac), ao): + if sameDirection(abc.Cross(ac), ao): if sameDirection(ac, ao): simplex = @[a, c] - direction = ac.cross(ao).cross(ac) + direction = ac.Cross(ao).Cross(ac) else: simplex = @[a, b] return line(simplex, direction) else: - if (sameDirection(ab.cross(abc), ao)): + if (sameDirection(ab.Cross(abc), ao)): simplex = @[a, b] return line(simplex, direction) else: @@ -143,9 +143,9 @@ ac = c - a ad = d - a ao = - a - abc = ab.cross(ac) - acd = ac.cross(ad) - adb = ad.cross(ab) + abc = ab.Cross(ac) + acd = ac.Cross(ad) + adb = ad.Cross(ab) if sameDirection(abc, ao): simplex = @[a, b, c] @@ -171,14 +171,14 @@ b = polytope[faces[i + 1]] c = polytope[faces[i + 2]] - var normal = (b - a).cross(c - a).normalized() - var distance = normal.dot(a) + var normal = (b - a).Cross(c - a).Normalized() + var distance = normal.Dot(a) if distance < 0: normal = normal * -1'f32 distance = distance * -1'f32 - normals.add normal.toVec4(distance) + normals.add normal.ToVec4(distance) if distance < minDistance: minTriangle = i div 3 @@ -219,7 +219,7 @@ minDistance = normals[minFace].w var support = supportPoint(a, b, minNormal) - sDistance = minNormal.dot(support) + sDistance = minNormal.Dot(support) if abs(sDistance - minDistance) > 0.001'f32: minDistance = high(float32) @@ -288,8 +288,8 @@ vertexJ = polytope[j] ij = vertexJ - vertexI var - normal = newVec2f(ij.y, -ij.x).normalized() - distance = normal.dot(vertexI) + normal = NewVec2f(ij.y, -ij.x).Normalized() + distance = normal.Dot(vertexI) if (distance < 0): distance *= -1'f32 @@ -301,52 +301,52 @@ minIndex = j let - support = supportPoint(a, b, minNormal.toVec3) - sDistance = minNormal.dot(support) + support = supportPoint(a, b, minNormal.ToVec3) + sDistance = minNormal.Dot(support) if(abs(sDistance - minDistance) > 0.001): minDistance = high(float32) polytope.insert(support, minIndex) inc iterCount - result = (normal: newVec3f(minNormal.x, minNormal.y), penetrationDepth: minDistance + 0.001'f32) + result = (normal: NewVec3f(minNormal.x, minNormal.y), penetrationDepth: minDistance + 0.001'f32) func intersects*(a, b: Collider, as2D = false): bool = var - support = supportPoint(a, b, newVec3f(0.8153, -0.4239, if as2D: 0.0 else: 0.5786)) # just random initial vector + support = supportPoint(a, b, NewVec3f(0.8153, -0.4239, if as2D: 0.0 else: 0.5786)) # just random initial vector simplex = newSeq[Vec3f]() direction = -support n = 0 simplex.insert(support, 0) while n < MAX_COLLISON_DETECTION_ITERATIONS: support = supportPoint(a, b, direction) - if support.dot(direction) <= 0: + if support.Dot(direction) <= 0: return false simplex.insert(support, 0) if nextSimplex(simplex, direction, twoDimensional = as2D): return true # prevent numeric instability - if direction == newVec3f(0, 0, 0): + if direction == NewVec3f(0, 0, 0): direction[0] = 0.0001 inc n func collision*(a, b: Collider, as2D = false): tuple[hasCollision: bool, normal: Vec3f, penetrationDepth: float32] = var - support = supportPoint(a, b, newVec3f(0.8153, -0.4239, if as2D: 0.0 else: 0.5786)) # just random initial vector + support = supportPoint(a, b, NewVec3f(0.8153, -0.4239, if as2D: 0.0 else: 0.5786)) # just random initial vector simplex = newSeq[Vec3f]() direction = -support n = 0 simplex.insert(support, 0) while n < MAX_COLLISON_DETECTION_ITERATIONS: support = supportPoint(a, b, direction) - if support.dot(direction) <= 0: + if support.Dot(direction) <= 0: return result simplex.insert(support, 0) if nextSimplex(simplex, direction, twoDimensional = as2D): let (normal, depth) = if as2D: collisionPoint2D(simplex, a, b) else: collisionPoint3D(simplex, a, b) return (true, normal, depth) # prevent numeric instability - if direction == newVec3f(0, 0, 0): + if direction == NewVec3f(0, 0, 0): direction[0] = 0.0001 inc n @@ -378,9 +378,9 @@ if theType == Points: result = Collider(theType: Points, points: @points) else: - result = Collider(theType: theType, transform: translate(minX, minY, minZ) * scale(scaleX, scaleY, scaleZ)) + result = Collider(theType: theType, transform: Translate(minX, minY, minZ) * Scale(scaleX, scaleY, scaleZ)) if theType == Sphere: - result.transform = translate(center) + result.transform = Translate(center) for p in points: - result.radius = max(result.radius, (p - center).length) + result.radius = max(result.radius, (p - center).Length) diff -r 74957cbf589b -r 71315636ba82 semicongine/core/color.nim --- a/semicongine/core/color.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/semicongine/core/color.nim Tue Jun 04 16:51:50 2024 +0700 @@ -58,14 +58,14 @@ uint8(round(srgb2linear(float(value) / 255.0) * 255)) func toSRGB*(value: Vec4f): Vec4f = - newVec4f( + NewVec4f( linear2srgb(value.r), linear2srgb(value.g), linear2srgb(value.b), value.a, ) func fromSRGB*(value: Vec4f): Vec4f = - newVec4f( + NewVec4f( srgb2linear(value.r), srgb2linear(value.g), srgb2linear(value.b), diff -r 74957cbf589b -r 71315636ba82 semicongine/core/imagetypes.nim --- a/semicongine/core/imagetypes.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/semicongine/core/imagetypes.nim Tue Jun 04 16:51:50 2024 +0700 @@ -35,7 +35,7 @@ return a.colorImage == b.colorImage converter toRGBA*(p: RGBAPixel): Vec4f = - newVec4f(float32(p[0]) / 255'f32, float32(p[1]) / 255'f32, float32(p[2]) / 255'f32, float32(p[3]) / 255'f32) + NewVec4f(float32(p[0]) / 255'f32, float32(p[1]) / 255'f32, float32(p[2]) / 255'f32, float32(p[3]) / 255'f32) converter toGrayscale*(p: GrayPixel): float32 = float32(p) / 255'f32 diff -r 74957cbf589b -r 71315636ba82 semicongine/core/matrix.nim --- a/semicongine/core/matrix.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/semicongine/core/matrix.nim Tue Jun 04 16:51:50 2024 +0700 @@ -40,16 +40,16 @@ Mat43* = TMat43[float32] Mat4* = TMat4[float32] -func unit2[T: SomeNumber](): auto {.compiletime.} = TMat2[T](data: [ +func MakeUnit2*[T: SomeNumber](): auto {.compiletime.} = TMat2[T](data: [ T(1), T(0), T(0), T(1), ]) -func unit3[T: SomeNumber](): auto {.compiletime.} = TMat3[T](data: [ +func MakeUnit3*[T: SomeNumber](): auto {.compiletime.} = TMat3[T](data: [ T(1), T(0), T(0), T(0), T(1), T(0), T(0), T(0), T(1), ]) -func unit4[T: SomeNumber](): auto {.compiletime.} = TMat4[T](data: [ +func MakeUnit4*[T: SomeNumber](): auto {.compiletime.} = TMat4[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), @@ -69,24 +69,24 @@ typename = typename & theType[^1] result.add(newConstStmt( postfix(ident("Unit2" & typename), "*"), - newCall(nnkBracketExpr.newTree(ident("unit2"), ident(theType))) + newCall(nnkBracketExpr.newTree(ident("MakeUnit2"), ident(theType))) )) result.add(newConstStmt( postfix(ident("Unit3" & typename), "*"), - newCall(nnkBracketExpr.newTree(ident("unit3"), ident(theType))) + newCall(nnkBracketExpr.newTree(ident("MakeUnit3"), ident(theType))) )) result.add(newConstStmt( postfix(ident("Unit4" & typename), "*"), - newCall(nnkBracketExpr.newTree(ident("unit4"), ident(theType))) + newCall(nnkBracketExpr.newTree(ident("MakeUnit4"), ident(theType))) )) generateAllConsts() -const Unit2* = unit2[float32]() -const Unit3* = unit3[float32]() -const Unit4* = unit4[float32]() +const Unit2* = MakeUnit2[float32]() +const Unit3* = MakeUnit3[float32]() +const Unit4* = MakeUnit4[float32]() -template rowCount*(m: typedesc): int = +template RowCount*(m: typedesc): int = when m is TMat2: 2 elif m is TMat23: 2 elif m is TMat32: 3 @@ -94,7 +94,7 @@ elif m is TMat34: 3 elif m is TMat43: 4 elif m is TMat4: 4 -template columnCount*(m: typedesc): int = +template ColumnCount*(m: typedesc): int = when m is TMat2: 2 elif m is TMat23: 3 elif m is TMat32: 2 @@ -102,7 +102,7 @@ elif m is TMat34: 4 elif m is TMat43: 3 elif m is TMat4: 4 -template matlen*(m: typedesc): int = +template matlen(m: typedesc): int = when m is TMat2: 4 elif m is TMat23: 6 elif m is TMat32: 6 @@ -125,10 +125,10 @@ for i in 0 ..< strvalues.len: let filler = " ".repeat(maxwidth - strvalues[i].len) - if i mod T.columnCount == T.columnCount - 1: + if i mod T.ColumnCount == T.ColumnCount - 1: result &= filler & strvalues[i] & "\n" else: - if i mod T.columnCount == 0: + if i mod T.ColumnCount == 0: result &= " " result &= filler & strvalues[i] & " " @@ -140,37 +140,37 @@ func `$`*(v: TMat43[SomeNumber]): string = toString[TMat43[SomeNumber]](v) func `$`*(v: TMat4[SomeNumber]): string = toString[TMat4[SomeNumber]](v) -func `[]`*[T: TMat](m: T, row, col: int): auto = m.data[col + row * T.columnCount] -func `[]=`*[T: TMat, 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] +func `[]=`*[T: TMat, U](m: var T, row, col: int, value: U) = m.data[col + row * T.ColumnCount] = value func `[]`*[T: TMat](m: T, i: int): auto = m.data[i] func `[]=`*[T: TMat, U](m: var T, i: int, value: U) = m.data[i] = value -func row*[T: TMat2](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: TMat3](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: TMat4](m: T, i: 0..3): auto = TVec4([m[i, 0], m[i, 1], m[i, 2], m[i, 3]]) +func Row*[T: TMat2](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: TMat3](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: TMat4](m: T, i: 0..3): auto = TVec4([m[i, 0], m[i, 1], m[i, 2], m[i, 3]]) -func col*[T: TMat2](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: TMat3](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: TMat4](m: T, i: 0..3): auto = TVec4([m[0, i], m[1, i], m[2, i], m[3, i]]) +func Col*[T: TMat2](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: TMat3](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: TMat4](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() - for i in 0 ..< rowCount(leftType): - for j in 0 ..< rightType.columnCount: + for i in 0 ..< RowCount(leftType): + for j in 0 ..< rightType.ColumnCount: data.add(newCall( ident("sum"), infix( - newCall(newDotExpr(ident("a"), ident("row")), newLit(i)), + newCall(newDotExpr(ident("a"), ident("Row")), newLit(i)), "*", - newCall(newDotExpr(ident("b"), ident("col")), newLit(j)) + newCall(newDotExpr(ident("b"), ident("Col")), newLit(j)) ) )) @@ -208,13 +208,13 @@ proc createVecMatMultiplicationOperator(matType: typedesc, vecType: typedesc): NimNode = var data = nnkBracket.newTree() - for i in 0 ..< matType.rowCount: + for i in 0 ..< matType.RowCount: data.add(newCall( ident("sum"), infix( ident("v"), "*", - newCall(newDotExpr(ident("m"), ident("row")), newLit(i)) + newCall(newDotExpr(ident("m"), ident("Row")), newLit(i)) ) )) @@ -245,7 +245,7 @@ result = newStmtList() var data = nnkBracket.newTree() - for i in 0 ..< matType.rowCount * matType.columnCount: + for i in 0 ..< matType.RowCount * matType.ColumnCount: data.add(infix(nnkBracketExpr.newTree(newDotExpr(ident("a"), ident("data")), newLit(i)), op, ident("b"))) result.add(newProc( postfix(nnkAccQuoted.newTree(ident(op)), "*"), @@ -269,7 +269,7 @@ )) if op == "-": var data2 = nnkBracket.newTree() - for i in 0 ..< matType.rowCount * matType.columnCount: + for i in 0 ..< matType.RowCount * matType.ColumnCount: data2.add(prefix(nnkBracketExpr.newTree(newDotExpr(ident("a"), ident("data")), newLit(i)), op)) result.add(newProc( postfix(nnkAccQuoted.newTree(ident(op)), "*"), @@ -322,74 +322,74 @@ createAllMultiplicationOperators() func `*`*(mat: Mat4, vec: Vec3f): Vec3f = - (mat * vec.toVec4(1)).toVec3 + (mat * vec.ToVec4(1)).ToVec3 -func transposed*[T](m: TMat2[T]): TMat2[T] = TMat2[T](data: [ +func Transposed*[T](m: TMat2[T]): TMat2[T] = TMat2[T](data: [ m[0, 0], m[1, 0], m[0, 1], m[1, 1], ]) -func transposed*[T](m: TMat23[T]): TMat32[T] = TMat32[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: TMat32[T]): TMat23[T] = TMat23[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: TMat3[T]): TMat3[T] = TMat3[T](data: [ +func Transposed*[T](m: TMat3[T]): TMat3[T] = TMat3[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: TMat43[T]): TMat34[T] = TMat34[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: TMat34[T]): TMat43[T] = TMat43[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: TMat4[T]): TMat4[T] = TMat4[T](data: [ +func Transposed*[T](m: TMat4[T]): TMat4[T] = TMat4[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): TMat3[T] = TMat3[T](data: [ +func Translate2d*[T](x, y: T): TMat3[T] = TMat3[T](data: [ T(1), T(0), x, T(0), T(1), y, T(0), T(0), T(1), ]) -func scale2d*[T](sx, sy: T): TMat3[T] = TMat3[T](data: [ +func Scale2d*[T](sx, sy: T): TMat3[T] = TMat3[T](data: [ sx, T(0), T(0), T(0), sy, T(0), T(0), T(0), T(1), ]) -func rotate2d*[T](angle: T): TMat3[T] = TMat3[T](data: [ +func Rotate2d*[T](angle: T): TMat3[T] = TMat3[T](data: [ cos(angle), -sin(angle), T(0), sin(angle), cos(angle), T(0), T(0), T(0), T(1), ]) -func translate*(x = 0'f32, y = 0'f32, z = 0'f32): TMat4[float32] = Mat4(data: [ +func Translate*(x = 0'f32, y = 0'f32, z = 0'f32): TMat4[float32] = Mat4(data: [ 1'f32, 0'f32, 0'f32, x, 0'f32, 1'f32, 0'f32, y, 0'f32, 0'f32, 1'f32, z, 0'f32, 0'f32, 0'f32, 1'f32, ]) -func translate*[T: TVec3](v: T): TMat4[float32] = translate(v[0], v[1], v[2]) -func scale*(x = 1'f32, y = 1'f32, z = 1'f32): Mat4 = Mat4(data: [ +func Translate*[T: TVec3](v: T): TMat4[float32] = Translate(v[0], v[1], v[2]) +func Scale*(x = 1'f32, y = 1'f32, z = 1'f32): Mat4 = Mat4(data: [ x, 0'f32, 0'f32, 0'f32, 0'f32, y, 0'f32, 0'f32, 0'f32, 0'f32, z, 0'f32, 0'f32, 0'f32, 0'f32, 1'f32, ]) -func scale*[T: TVec3](v: T): TMat4[float32] = scale(v[0], v[1], v[2]) -func rotate*(angle: float32, a: Vec3f): Mat4 = +func Scale*[T: TVec3](v: T): TMat4[float32] = Scale(v[0], v[1], v[2]) +func Rotate*(angle: float32, a: Vec3f): Mat4 = let cosa = cos(angle) sina = sin(angle) @@ -411,12 +411,12 @@ ]) -func inversed*(m: Mat4): Mat4 = - var m3 = m.asMat3.transposed +func Inversed*(m: Mat4): Mat4 = + var m3 = m.asMat3.Transposed m3[0, 0] = 1'f32 / m3[0, 0] m3[1, 1] = 1'f32 / m3[1, 1] m3[2, 2] = 1'f32 / m3[2, 2] - let col3 = -(m3 * m.col(3).xyz) + let col3 = -(m3 * m.Col(3).xyz) return Mat4(data: [ m3[0, 0], m3[0, 1], m3[0, 2], col3.x, m3[1, 0], m3[1, 1], m3[1, 2], col3.y, @@ -427,10 +427,10 @@ # call e.g. TMat32[int]().randomized() to get a random matrix template makeRandomInit(mattype: typedesc) = - proc randomized*[T: SomeInteger](m: mattype[T]): mattype[T] = + proc Randomized*[T: SomeInteger](m: mattype[T]): mattype[T] = for i in 0 ..< result.data.len: result.data[i] = rand(low(typeof(m.data[0])) .. high(typeof(m.data[0]))) - proc randomized*[T: SomeFloat](m: mattype[T]): mattype[T] = + proc Randomized*[T: SomeFloat](m: mattype[T]): mattype[T] = for i in 0 ..< result.data.len: result.data[i] = rand(T(1.0)) @@ -442,7 +442,7 @@ makeRandomInit(TMat43) makeRandomInit(TMat4) -func perspective*(fovy, aspect, zNear, zFar: float32): Mat4 = +func Perspective*(fovy, aspect, zNear, zFar: float32): Mat4 = let tanHalfFovy = tan(fovy / 2) return Mat4(data: [ 1 / (aspect * tanHalfFovy), 0, 0, 0, @@ -451,7 +451,7 @@ 0, 0, 1, 1, ]) -func ortho*(left, right, top, bottom, zNear, zFar: float32): Mat4 = +func Ortho*(left, right, top, bottom, zNear, zFar: float32): Mat4 = Mat4(data: [ 2 / (right - left), 0, 0, -(right + left) / (right - left), 0, 2 / (bottom - top), 0, -(bottom + top) / (bottom - top), @@ -461,16 +461,16 @@ # create an orthographic perspective that will map from -1 .. 1 on all axis and keep a 1:1 aspect ratio # the smaller dimension (width or height) will always be 1 and the larger dimension will be larger, to keep the ratio -func orthoWindowAspect*(windowAspect: float32): Mat4 = +func OrthoWindowAspect*(windowAspect: float32): Mat4 = if windowAspect < 1: let space = 2 * (1 / windowAspect - 1) / 2 - ortho(-1, 1, -1 - space, 1 + space, 0, 1) + Ortho(-1, 1, -1 - space, 1 + space, 0, 1) else: let space = 2 * (windowAspect - 1) / 2 - ortho(-1 - space, 1 + space, -1, 1, 0, 1) + Ortho(-1 - space, 1 + space, -1, 1, 0, 1) -func position*(mat: Mat4): Vec3f = - mat.col(3).toVec3 +func Position*(mat: Mat4): Vec3f {.deprecated.} = + mat.Col(3).ToVec3 -func scaling*(mat: Mat4): Vec3f = - newVec3f(mat[0, 0], mat[1, 1], mat[2, 2]) +func Scaling*(mat: Mat4): Vec3f {.deprecated.} = + NewVec4f(mat[0, 0], mat[1, 1], mat[2, 2]) diff -r 74957cbf589b -r 71315636ba82 semicongine/core/vector.nim --- a/semicongine/core/vector.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/semicongine/core/vector.nim Tue Jun 04 16:51:50 2024 +0700 @@ -23,14 +23,14 @@ Vec3u* = TVec3[uint32] Vec4u* = TVec4[uint32] -converter toVec2*[T: SomeNumber](orig: TVec3[T]|TVec4[T]): TVec2[T] = +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] = +converter ToVec3*[T: SomeNumber](orig: TVec4[T]): TVec3[T] = TVec3[T]([orig[0], orig[1], orig[2]]) -func toVec4*[T: SomeNumber](orig: TVec3[T], value: T = default(T)): TVec4[T] = +func ToVec4*[T: SomeNumber](orig: TVec3[T], value: T = default(T)): TVec4[T] = TVec4[T]([orig[0], orig[1], orig[2], value]) -func toVec3*[T: SomeNumber](orig: TVec2[T], value: T = default(T)): TVec3[T] = +func ToVec3*[T: SomeNumber](orig: TVec2[T], value: T = default(T)): TVec3[T] = TVec3[T]([orig[0], orig[1], value]) # define some often used constants @@ -44,23 +44,23 @@ 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)]) -func newVec2f*(x = 0'f32, y = 0'f32): auto = +func NewVec2f*(x = 0'f32, y = 0'f32): auto = Vec2f([x, y]) -func newVec3f*(x = 0'f32, y = 0'f32, z = 0'f32): auto = +func NewVec3f*(x = 0'f32, y = 0'f32, z = 0'f32): auto = Vec3f([x, y, z]) -func newVec4f*(x = 0'f32, y = 0'f32, z = 0'f32, a = 0'f32): auto = +func NewVec4f*(x = 0'f32, y = 0'f32, z = 0'f32, a = 0'f32): auto = Vec4f([x, y, z, a]) -func newVec2i*(x = 0'i32, y = 0'i32): auto = +func NewVec2i*(x = 0'i32, y = 0'i32): auto = Vec2i([x, y]) -func newVec3i*(x = 0'i32, y = 0'i32, z = 0'i32): auto = +func NewVec3i*(x = 0'i32, y = 0'i32, z = 0'i32): auto = Vec3i([x, y, z]) -func newVec4i*(x = 0'i32, y = 0'i32, z = 0'i32, a = 0'i32): auto = +func NewVec4i*(x = 0'i32, y = 0'i32, z = 0'i32, a = 0'i32): auto = Vec4i([x, y, z, a]) -func newVec2u*(x = 0'u32, y = 0'u32): auto = +func NewVec2u*(x = 0'u32, y = 0'u32): auto = Vec2u([x, y]) -func newVec3u*(x = 0'u32, y = 0'u32, z = 0'u32): auto = +func NewVec3u*(x = 0'u32, y = 0'u32, z = 0'u32): auto = Vec3u([x, y, z]) -func newVec4u*(x = 0'u32, y = 0'u32, z = 0'u32, a = 0'u32): auto = +func NewVec4u*(x = 0'u32, y = 0'u32, z = 0'u32, a = 0'u32): auto = Vec4u([x, y, z, a]) # generates constants: Xf, Xf32, Xf64, Xi, Xi8, Xi16, Xi32, Xi64 @@ -91,13 +91,13 @@ const One3* = ConstOne3[float32]() const One4* = ConstOne4[float32]() -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 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: 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 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] @@ -109,26 +109,26 @@ func `$`*(v: TVec3[SomeNumber]): string = toString[TVec3[SomeNumber]](v) func `$`*(v: TVec4[SomeNumber]): string = toString[TVec4[SomeNumber]](v) -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 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 normal*[T: SomeFloat](vec: TVec2[T]): auto = +func Normal*[T: SomeFloat](vec: TVec2[T]): auto = TVec2[T]([vec[1], -vec[0]]) -func normalized*[T: SomeFloat](vec: TVec2[T]): auto = - let l = vec.length +func Normalized*[T: SomeFloat](vec: TVec2[T]): auto = + let l = vec.Length if l == 0: vec else: TVec2[T]([vec[0] / l, vec[1] / l]) -func normalized*[T: SomeFloat](vec: TVec3[T]): auto = - let l = vec.length +func Normalized*[T: SomeFloat](vec: TVec3[T]): auto = + let l = vec.Length if l == 0: return vec else: TVec3[T]([vec[0] / l, vec[1] / l, vec[2] / l]) -func normalized*[T: SomeFloat](vec: TVec4[T]): auto = - let l = vec.length +func Normalized*[T: SomeFloat](vec: TVec4[T]): auto = + let l = vec.Length if l == 0: return vec else: TVec4[T]([vec[0] / l, vec[1] / l, vec[2] / l, vec[3] / l]) @@ -238,16 +238,16 @@ # special operations -func pow*(a: TVec2, b: SomeNumber): auto = +func Pow*(a: TVec2, b: SomeNumber): auto = TVec2([pow(a[0], b), pow(a[1], b)]) -func pow*(a: TVec3, b: SomeNumber): auto = +func Pow*(a: TVec3, b: SomeNumber): auto = TVec3([pow(a[0], b), pow(a[1], b), pow(a[2], b)]) -func pow*(a: TVec4, b: SomeNumber): auto = +func Pow*(a: TVec4, b: SomeNumber): auto = TVec4([pow(a[0], b), pow(a[1], b), pow(a[2], b), pow(a[3], b)]) -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([ +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], @@ -335,10 +335,10 @@ # call e.g. Vec2[int]().randomized() to get a random matrix template makeRandomInit(mattype: typedesc) = - proc randomized*[T: SomeInteger](m: mattype[T]): mattype[T] = + proc Randomized*[T: SomeInteger](m: mattype[T]): mattype[T] = for i in 0 ..< result.len: result[i] = rand(low(typeof(m[0])) .. high(typeof(m[0]))) - proc randomized*[T: SomeFloat](m: mattype[T]): mattype[T] = + proc Randomized*[T: SomeFloat](m: mattype[T]): mattype[T] = for i in 0 ..< result.len: result[i] = rand(1.0) @@ -349,5 +349,5 @@ converter Vec2VkExtent*(vec: TVec2[uint32]): VkExtent2D = VkExtent2D(width: vec[0], height: vec[1]) converter Vec3VkExtent*(vec: TVec2[uint32]): VkExtent3D = VkExtent3D(width: vec[0], height: vec[1], depth: vec[2]) -func angleBetween*(a, b: Vec3f): float32 = - arccos(a.dot(b) / (a.length * b.length)) +func AngleBetween*(a, b: Vec3f): float32 = + arccos(a.Dot(b) / (a.Length * b.Length)) diff -r 74957cbf589b -r 71315636ba82 semicongine/engine.nim --- a/semicongine/engine.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/semicongine/engine.nim Tue Jun 04 16:51:50 2024 +0700 @@ -110,7 +110,7 @@ proc initRenderer*( engine: var Engine, shaders: openArray[(MaterialType, ShaderConfiguration)], - clearColor = newVec4f(0, 0, 0, 0), + clearColor = NewVec4f(0, 0, 0, 0), backFaceCulling = true, vSync = false, inFlightFrames = 2, @@ -132,7 +132,7 @@ inFlightFrames = inFlightFrames, )) -proc initRenderer*(engine: var Engine, clearColor = newVec4f(0, 0, 0, 0), vSync = false) = +proc initRenderer*(engine: var Engine, clearColor = NewVec4f(0, 0, 0, 0), vSync = false) = checkVkResult engine.device.vk.vkDeviceWaitIdle() engine.initRenderer(@[], clearColor, vSync = vSync) checkVkResult engine.device.vk.vkDeviceWaitIdle() diff -r 74957cbf589b -r 71315636ba82 semicongine/input.nim --- a/semicongine/input.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/semicongine/input.nim Tue Jun 04 16:51:50 2024 +0700 @@ -32,7 +32,7 @@ input.mouseWasPressed = {} input.mouseWasReleased = {} input.mouseWheel = 0 - input.mouseMove = newVec2f() + input.mouseMove = NewVec2f() input.windowWasResized = false var killed = false @@ -55,7 +55,7 @@ input.mouseWasReleased.incl event.button input.mouseIsDown.excl event.button of MouseMoved: - let newPos = newVec2(float32(event.x), float32(event.y)) + let newPos = NewVec2(float32(event.x), float32(event.y)) input.mouseMove = newPos - input.mousePosition input.mousePosition = newPos of MouseWheel: diff -r 74957cbf589b -r 71315636ba82 semicongine/mesh.nim --- a/semicongine/mesh.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/semicongine/mesh.nim Tue Jun 04 16:51:50 2024 +0700 @@ -465,12 +465,12 @@ let half_w = width / 2 half_h = height / 2 - pos = @[newVec3f(-half_w, -half_h), newVec3f(half_w, -half_h), newVec3f(half_w, half_h), newVec3f(-half_w, half_h)] + pos = @[NewVec3f(-half_w, -half_h), NewVec3f(half_w, -half_h), NewVec3f(half_w, half_h), NewVec3f(-half_w, half_h)] c = toRGBA(color) result[].initVertexAttribute(DEFAULT_POSITION_ATTRIBUTE, pos) result[].initVertexAttribute("color", @[c, c, c, c]) - result[].initVertexAttribute("uv", @[newVec2f(0, 0), newVec2f(1, 0), newVec2f(1, 1), newVec2f(0, 1)]) + result[].initVertexAttribute("uv", @[NewVec2f(0, 0), NewVec2f(1, 0), NewVec2f(1, 1), NewVec2f(0, 1)]) `material=`(result[], material) proc tri*(width = 1'f32, height = 1'f32, color = "ffffffff", material = EMPTY_MATERIAL.initMaterialData()): Mesh = @@ -485,7 +485,7 @@ half_h = height / 2 colorVec = toRGBA(color) - result[].initVertexAttribute(DEFAULT_POSITION_ATTRIBUTE, @[newVec3f(0, -half_h), newVec3f(half_w, half_h), newVec3f(-half_w, half_h)]) + result[].initVertexAttribute(DEFAULT_POSITION_ATTRIBUTE, @[NewVec3f(0, -half_h), NewVec3f(half_w, half_h), NewVec3f(-half_w, half_h)]) result[].initVertexAttribute("color", @[colorVec, colorVec, colorVec]) `material=`(result[], material) @@ -494,9 +494,9 @@ rX = 0.5 rY = 0.5 step = (2'f32 * PI) / float32(nSegments) - result[0] = @[newVec3f(0, 0), newVec3f(rX, 0)] + result[0] = @[NewVec3f(0, 0), NewVec3f(rX, 0)] for i in 1 .. nSegments: - result[0].add newVec3f(cos(float32(i) * step) * rX, sin(float32(i) * step) * rY) + result[0].add NewVec3f(cos(float32(i) * step) * rX, sin(float32(i) * step) * rY) result[1].add [uint16(0), uint16(i), uint16(i + 1)] proc circle*(width = 1'f32, height = 1'f32, nSegments = 12, color = "ffffffff", material = EMPTY_MATERIAL.initMaterialData()): Mesh = @@ -515,13 +515,13 @@ c = toRGBA(color) step = (2'f32 * PI) / float32(nSegments) var - pos = @[newVec3f(0, 0), newVec3f(rX, 0)] + pos = @[NewVec3f(0, 0), NewVec3f(rX, 0)] col = @[c, c] - uv = @[newVec2f(0.5, 0.5), newVec2f(rX, height / 2)] + uv = @[NewVec2f(0.5, 0.5), NewVec2f(rX, height / 2)] for i in 1 .. nSegments: - pos.add newVec3f(cos(float32(i) * step) * rX, sin(float32(i) * step) * rY) + pos.add NewVec3f(cos(float32(i) * step) * rX, sin(float32(i) * step) * rY) col.add c - uv.add newVec2f(cos(float32(i) * step) * 0.5 + 0.5, sin(float32(i) * step) * 0.5 + 0.5) + uv.add NewVec2f(cos(float32(i) * step) * 0.5 + 0.5, sin(float32(i) * step) * 0.5 + 0.5) result[].smallIndices.add [uint16(0), uint16(i), uint16(i + 1)] result[].initVertexAttribute(DEFAULT_POSITION_ATTRIBUTE, pos) @@ -537,10 +537,10 @@ rX = width / 2 rY = height / 2 step = (2'f32 * PI) / float32(nSegments) - result[0][0] = newVec3f(0, 0) - result[0][1] = newVec3f(rX, 0) + result[0][0] = NewVec3f(0, 0) + result[0][1] = NewVec3f(rX, 0) for i in 1 .. nSegments: - result[0][i + 1] = newVec3f(cos(float32(i) * step) * rX, sin(float32(i) * step) * rY) + result[0][i + 1] = NewVec3f(cos(float32(i) * step) * rX, sin(float32(i) * step) * rY) result[1].add [uint16(0), uint16(i), uint16(i + 1)] proc grid*(columns, rows: uint16, cellSize = 1.0'f32, color = "ffffffff", material = EMPTY_MATERIAL.initMaterialData()): Mesh = @@ -563,7 +563,7 @@ i = 0'u16 for h in 0'u16 .. rows: for w in 0'u16 .. columns: - pos.add newVec3f(center_offset_x + float32(w) * cellSize, center_offset_y + float32(h) * cellSize) + pos.add NewVec3f(center_offset_x + float32(w) * cellSize, center_offset_y + float32(h) * cellSize) col.add color if w > 0 and h > 0: result[].smallIndices.add [i, i - 1, i - rows - 2] diff -r 74957cbf589b -r 71315636ba82 semicongine/noise.nim --- a/semicongine/noise.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/semicongine/noise.nim Tue Jun 04 16:51:50 2024 +0700 @@ -6,7 +6,7 @@ proc randomGradient(pos: Vec2f, seed: int32 = 0): Vec2f = let randomAngle: float32 = TAU * (float32(int(hash((pos.x, pos.y, seed)))) / float32(high(int))) - return newVec2f(cos(randomAngle), sin(randomAngle)) + return NewVec2f(cos(randomAngle), sin(randomAngle)) proc interpolate(a: float32, b: float32, weight: float32): float32 = # with Smootherstep @@ -15,15 +15,15 @@ proc perlin*(pos: Vec2f, seed: int32 = 0): float32 = let # grid coordinates around target point - topleft = newVec2f(trunc(pos.x), trunc(pos.y)) - topright = topleft + newVec2f(1, 0) - bottomleft = topleft + newVec2f(0, 1) - bottomright = topleft + newVec2f(1, 1) + topleft = NewVec2f(trunc(pos.x), trunc(pos.y)) + topright = topleft + NewVec2f(1, 0) + bottomleft = topleft + NewVec2f(0, 1) + bottomright = topleft + NewVec2f(1, 1) # products for weights - topleft_dot = topleft.randomGradient(seed).dot((pos - topleft)) - topright_dot = topright.randomGradient(seed).dot((pos - topright)) - bottomleft_dot = bottomleft.randomGradient(seed).dot((pos - bottomleft)) - bottomright_dot = bottomright.randomGradient(seed).dot((pos - bottomright)) + topleft_dot = topleft.randomGradient(seed).Dot((pos - topleft)) + topright_dot = topright.randomGradient(seed).Dot((pos - topright)) + bottomleft_dot = bottomleft.randomGradient(seed).Dot((pos - bottomleft)) + bottomright_dot = bottomright.randomGradient(seed).Dot((pos - bottomright)) xinterpol = pos.x - topleft.x yinterpol = pos.y - topleft.y diff -r 74957cbf589b -r 71315636ba82 semicongine/panel.nim --- a/semicongine/panel.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/semicongine/panel.nim Tue Jun 04 16:51:50 2024 +0700 @@ -76,16 +76,16 @@ of Center: 0 of Bottom: -0.5 - panel.mesh[POSITION_ATTRIB, 0] = newVec3f(-0.5 + offsetX, -0.5 + offsetY) - panel.mesh[POSITION_ATTRIB, 1] = newVec3f(+0.5 + offsetX, -0.5 + offsetY) - panel.mesh[POSITION_ATTRIB, 2] = newVec3f(+0.5 + offsetX, +0.5 + offsetY) - panel.mesh[POSITION_ATTRIB, 3] = newVec3f(-0.5 + offsetX, +0.5 + offsetY) + panel.mesh[POSITION_ATTRIB, 0] = NewVec3f(-0.5 + offsetX, -0.5 + offsetY) + panel.mesh[POSITION_ATTRIB, 1] = NewVec3f(+0.5 + offsetX, -0.5 + offsetY) + panel.mesh[POSITION_ATTRIB, 2] = NewVec3f(+0.5 + offsetX, +0.5 + offsetY) + panel.mesh[POSITION_ATTRIB, 3] = NewVec3f(-0.5 + offsetX, +0.5 + offsetY) panel.dirty = false proc initPanel*( transform = Unit4, - color = newVec4f(1, 1, 1, 1), + color = NewVec4f(1, 1, 1, 1), texture = EMPTY_TEXTURE, horizontalAlignment = HorizontalAlignment.Center, verticalAlignment = VerticalAlignment.Center, @@ -115,7 +115,7 @@ [uint16(0), uint16(1), uint16(2)], [uint16(2), uint16(3), uint16(0)], ], - uvs = @[newVec2f(0, 1), newVec2f(1, 1), newVec2f(1, 0), newVec2f(0, 0)], + uvs = @[NewVec2f(0, 1), NewVec2f(1, 1), NewVec2f(1, 0), NewVec2f(0, 0)], transform = transform ) result.mesh[].renameAttribute("position", POSITION_ATTRIB) @@ -150,7 +150,7 @@ proc contains*(panel: Panel, p: Vec2f, aspectRatio: float32): bool = let - cursor = panel.mesh.transform.inversed * p.toVec3 + cursor = panel.mesh.transform.Inversed * p.ToVec3 p1 = panel.mesh[POSITION_ATTRIB, 0, Vec3f] p2 = panel.mesh[POSITION_ATTRIB, 2, Vec3f] left = min(p1.x, p2.x) diff -r 74957cbf589b -r 71315636ba82 semicongine/renderer.nim --- a/semicongine/renderer.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/semicongine/renderer.nim Tue Jun 04 16:51:50 2024 +0700 @@ -58,7 +58,7 @@ proc initRenderer*( device: Device, shaders: openArray[(MaterialType, ShaderConfiguration)], - clearColor = newVec4f(0, 0, 0, 0), + clearColor = NewVec4f(0, 0, 0, 0), backFaceCulling = true, vSync = false, inFlightFrames = 2, diff -r 74957cbf589b -r 71315636ba82 semicongine/resources/font.nim --- a/semicongine/resources/font.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/semicongine/resources/font.nim Tue Jun 04 16:51:50 2024 +0700 @@ -110,12 +110,12 @@ stbtt_GetCodepointHMetrics(addr fontinfo, cint(codePoint), addr advance, addr leftBearing) result.glyphs[codePoint] = GlyphInfo( - dimension: newVec2f(float32(image.width), float32(image.height)), + dimension: NewVec2f(float32(image.width), float32(image.height)), uvs: [ - newVec2f((coord.x + 0.5) / w, (coord.y + ih - 0.5) / h), - newVec2f((coord.x + 0.5) / w, (coord.y + 0.5) / h), - newVec2f((coord.x + iw - 0.5) / w, (coord.y + 0.5) / h), - newVec2f((coord.x + iw - 0.5) / w, (coord.y + ih - 0.5) / h), + NewVec2f((coord.x + 0.5) / w, (coord.y + ih - 0.5) / h), + NewVec2f((coord.x + 0.5) / w, (coord.y + 0.5) / h), + NewVec2f((coord.x + iw - 0.5) / w, (coord.y + 0.5) / h), + NewVec2f((coord.x + iw - 0.5) / w, (coord.y + ih - 0.5) / h), ], topOffset: float32(topOffsets[codePoint]), leftOffset: float32(leftBearing) * result.fontscale, diff -r 74957cbf589b -r 71315636ba82 semicongine/resources/mesh.nim --- a/semicongine/resources/mesh.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/semicongine/resources/mesh.nim Tue Jun 04 16:51:50 2024 +0700 @@ -171,14 +171,14 @@ if defaultMaterial.attributes.contains("color"): attributes["color"] = initDataList(thetype = Vec4F32) if pbr.hasKey(GLTF_MATERIAL_MAPPING["color"]): - attributes["color"] = @[newVec4f( + attributes["color"] = @[NewVec4f( pbr[GLTF_MATERIAL_MAPPING["color"]][0].getFloat(), pbr[GLTF_MATERIAL_MAPPING["color"]][1].getFloat(), pbr[GLTF_MATERIAL_MAPPING["color"]][2].getFloat(), pbr[GLTF_MATERIAL_MAPPING["color"]][3].getFloat(), )] else: - attributes["color"] = @[newVec4f(1, 1, 1, 1)] + attributes["color"] = @[NewVec4f(1, 1, 1, 1)] # pbr material values for factor in ["metallic", "roughness"]: @@ -213,13 +213,13 @@ if defaultMaterial.attributes.contains("emissiveColor"): attributes["emissiveColor"] = initDataList(thetype = Vec3F32) if materialNode.hasKey(GLTF_MATERIAL_MAPPING["emissiveColor"]): - attributes["emissiveColor"] = @[newVec3f( + attributes["emissiveColor"] = @[NewVec3f( materialNode[GLTF_MATERIAL_MAPPING["emissiveColor"]][0].getFloat(), materialNode[GLTF_MATERIAL_MAPPING["emissiveColor"]][1].getFloat(), materialNode[GLTF_MATERIAL_MAPPING["emissiveColor"]][2].getFloat(), )] else: - attributes["emissiveColor"] = @[newVec3f(1'f32, 1'f32, 1'f32)] + attributes["emissiveColor"] = @[NewVec3f(1'f32, 1'f32, 1'f32)] result = initMaterialData(theType = defaultMaterial, name = materialNode["name"].getStr(), attributes = attributes) @@ -279,7 +279,7 @@ else: raise newException(Exception, &"Unsupported index data type: {data.thetype}") # TODO: getting from gltf to vulkan system is still messed up somehow, see other TODO - transform[Vec3f](result[], "position", scale(1, -1, 1)) + transform[Vec3f](result[], "position", Scale(1, -1, 1)) proc loadNode(root: JsonNode, node: JsonNode, materials: seq[MaterialData], mainBuffer: var seq[uint8]): MeshTree = result = MeshTree() @@ -298,28 +298,28 @@ else: var (t, r, s) = (Unit4F32, Unit4F32, Unit4F32) if node.hasKey("translation"): - t = translate( + t = Translate( float32(node["translation"][0].getFloat()), float32(node["translation"][1].getFloat()), float32(node["translation"][2].getFloat()) ) if node.hasKey("rotation"): - t = rotate( + t = Rotate( float32(node["rotation"][3].getFloat()), - newVec3f( + NewVec3f( float32(node["rotation"][0].getFloat()), float32(node["rotation"][1].getFloat()), float32(node["rotation"][2].getFloat()) ) ) if node.hasKey("scale"): - t = scale( + t = Scale( float32(node["scale"][0].getFloat()), float32(node["scale"][1].getFloat()), float32(node["scale"][2].getFloat()) ) result.transform = t * r * s - result.transform = scale(1, -1, 1) * result.transform + result.transform = Scale(1, -1, 1) * result.transform # children if node.hasKey("children"): @@ -331,7 +331,7 @@ for nodeId in scenenode["nodes"]: result.children.add loadNode(root, root["nodes"][nodeId.getInt()], materials, mainBuffer) # TODO: getting from gltf to vulkan system is still messed up somehow (i.e. not consistent for different files), see other TODO - # result.transform = scale(1, -1, 1) + # result.transform = Scale(1, -1, 1) result.updateTransforms() diff -r 74957cbf589b -r 71315636ba82 semicongine/text.nim --- a/semicongine/text.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/semicongine/text.nim Tue Jun 04 16:51:50 2024 +0700 @@ -106,10 +106,10 @@ if text.processedText[i] == Rune('\n'): offsetX = 0 offsetY += text.font.lineAdvance - text.mesh[POSITION_ATTRIB, vertexOffset + 0] = newVec3f() - text.mesh[POSITION_ATTRIB, vertexOffset + 1] = newVec3f() - text.mesh[POSITION_ATTRIB, vertexOffset + 2] = newVec3f() - text.mesh[POSITION_ATTRIB, vertexOffset + 3] = newVec3f() + text.mesh[POSITION_ATTRIB, vertexOffset + 0] = NewVec3f() + text.mesh[POSITION_ATTRIB, vertexOffset + 1] = NewVec3f() + text.mesh[POSITION_ATTRIB, vertexOffset + 2] = NewVec3f() + text.mesh[POSITION_ATTRIB, vertexOffset + 3] = NewVec3f() inc lineIndex anchorX = case text.horizontalAlignment of Left: 0'f32 @@ -123,10 +123,10 @@ top = offsetY + glyph.topOffset bottom = offsetY + glyph.topOffset + glyph.dimension.y - text.mesh[POSITION_ATTRIB, vertexOffset + 0] = newVec3f(left - anchorX, bottom - anchorY) - text.mesh[POSITION_ATTRIB, vertexOffset + 1] = newVec3f(left - anchorX, top - anchorY) - text.mesh[POSITION_ATTRIB, vertexOffset + 2] = newVec3f(right - anchorX, top - anchorY) - text.mesh[POSITION_ATTRIB, vertexOffset + 3] = newVec3f(right - anchorX, bottom - anchorY) + text.mesh[POSITION_ATTRIB, vertexOffset + 0] = NewVec3f(left - anchorX, bottom - anchorY) + text.mesh[POSITION_ATTRIB, vertexOffset + 1] = NewVec3f(left - anchorX, top - anchorY) + text.mesh[POSITION_ATTRIB, vertexOffset + 2] = NewVec3f(right - anchorX, top - anchorY) + text.mesh[POSITION_ATTRIB, vertexOffset + 3] = NewVec3f(right - anchorX, bottom - anchorY) text.mesh[UV_ATTRIB, vertexOffset + 0] = glyph.uvs[0] text.mesh[UV_ATTRIB, vertexOffset + 1] = glyph.uvs[1] @@ -137,10 +137,10 @@ if i < text.processedText.len - 1: offsetX += text.font.kerning[(text.processedText[i], text.processedText[i + 1])] else: - text.mesh[POSITION_ATTRIB, vertexOffset + 0] = newVec3f() - text.mesh[POSITION_ATTRIB, vertexOffset + 1] = newVec3f() - text.mesh[POSITION_ATTRIB, vertexOffset + 2] = newVec3f() - text.mesh[POSITION_ATTRIB, vertexOffset + 3] = newVec3f() + text.mesh[POSITION_ATTRIB, vertexOffset + 0] = NewVec3f() + text.mesh[POSITION_ATTRIB, vertexOffset + 1] = NewVec3f() + text.mesh[POSITION_ATTRIB, vertexOffset + 2] = NewVec3f() + text.mesh[POSITION_ATTRIB, vertexOffset + 3] = NewVec3f() text.lastRenderedText = text.processedText text.dirty = false @@ -213,7 +213,7 @@ text.processedText = text.text if text.maxWidth > 0: - text.processedText = text.processedText.wordWrapped(text.font, text.maxWidth / text.mesh.transform.scaling.x) + text.processedText = text.processedText.wordWrapped(text.font, text.maxWidth / text.mesh.transform.Scaling.x) proc `text=`*(text: var Text, newText: string) = `text=`(text, newText.toRunes) @@ -238,7 +238,7 @@ text.verticalAlignment = value text.dirty = true -proc initText*(font: Font, text = "".toRunes, maxLen: int = text.len, color = newVec4f(0.07, 0.07, 0.07, 1), verticalAlignment = VerticalAlignment.Center, horizontalAlignment = HorizontalAlignment.Center, maxWidth = 0'f32, transform = Unit4): Text = +proc initText*(font: Font, text = "".toRunes, maxLen: int = text.len, color = NewVec4f(0.07, 0.07, 0.07, 1), verticalAlignment = VerticalAlignment.Center, horizontalAlignment = HorizontalAlignment.Center, maxWidth = 0'f32, transform = Unit4): Text = var positions = newSeq[Vec3f](int(maxLen * 4)) indices: seq[array[3, uint16]] diff -r 74957cbf589b -r 71315636ba82 tests/test_collision.nim --- a/tests/test_collision.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/tests/test_collision.nim Tue Jun 04 16:51:50 2024 +0700 @@ -9,8 +9,8 @@ scene.meshes[0].material = VERTEX_COLORED_MATERIAL.initMaterialData() scene.meshes[1].material = VERTEX_COLORED_MATERIAL.initMaterialData() scene.meshes[2].material = VERTEX_COLORED_MATERIAL.initMaterialData() - scene.meshes[1].transform = scale(0.8, 0.8) - scene.meshes[2].transform = scale(0.1, 0.1) + scene.meshes[1].transform = Scale(0.8, 0.8) + scene.meshes[2].transform = Scale(0.1, 0.1) scene.addShaderGlobal("perspective", Unit4F32) const @@ -36,19 +36,19 @@ while engine.UpdateInputs() and not KeyIsDown(Escape): if WindowWasResized(): var winSize = engine.GetWindow().size - scene.setShaderGlobal("perspective", orthoWindowAspect(winSize[0] / winSize[1])) - if KeyIsDown(A): scene.meshes[0].transform = scene.meshes[0].transform * translate(-0.001, 0, 0) - if KeyIsDown(D): scene.meshes[0].transform = scene.meshes[0].transform * translate(0.001, 0, 0) - if KeyIsDown(W): scene.meshes[0].transform = scene.meshes[0].transform * translate(0, -0.001, 0) - if KeyIsDown(S): scene.meshes[0].transform = scene.meshes[0].transform * translate(0, 0.001, 0) - if KeyIsDown(Q): scene.meshes[0].transform = scene.meshes[0].transform * rotate(-0.001, Z) - if KeyIsDown(Key.E): scene.meshes[0].transform = scene.meshes[0].transform * rotate(0.001, Z) + scene.setShaderGlobal("perspective", OrthoWindowAspect(winSize[0] / winSize[1])) + if KeyIsDown(A): scene.meshes[0].transform = scene.meshes[0].transform * Translate(-0.001, 0, 0) + if KeyIsDown(D): scene.meshes[0].transform = scene.meshes[0].transform * Translate(0.001, 0, 0) + if KeyIsDown(W): scene.meshes[0].transform = scene.meshes[0].transform * Translate(0, -0.001, 0) + if KeyIsDown(S): scene.meshes[0].transform = scene.meshes[0].transform * Translate(0, 0.001, 0) + if KeyIsDown(Q): scene.meshes[0].transform = scene.meshes[0].transform * Rotate(-0.001, Z) + if KeyIsDown(Key.E): scene.meshes[0].transform = scene.meshes[0].transform * Rotate(0.001, Z) - if KeyIsDown(Key.Z): scene.meshes[1].transform = scene.meshes[1].transform * rotate(-0.001, Z) - if KeyIsDown(Key.X): scene.meshes[1].transform = scene.meshes[1].transform * rotate(0.001, Z) - if KeyIsDown(Key.C): scene.meshes[1].transform = scene.meshes[1].transform * translate(0, -0.001, 0) - if KeyIsDown(Key.V): scene.meshes[1].transform = scene.meshes[1].transform * translate(0, 0.001, 0) - let hitbox = Collider(theType: Box, transform: scene.meshes[0].transform * translate(-0.5, -0.5)) + if KeyIsDown(Key.Z): scene.meshes[1].transform = scene.meshes[1].transform * Rotate(-0.001, Z) + if KeyIsDown(Key.X): scene.meshes[1].transform = scene.meshes[1].transform * Rotate(0.001, Z) + if KeyIsDown(Key.C): scene.meshes[1].transform = scene.meshes[1].transform * Translate(0, -0.001, 0) + if KeyIsDown(Key.V): scene.meshes[1].transform = scene.meshes[1].transform * Translate(0, 0.001, 0) + let hitbox = Collider(theType: Box, transform: scene.meshes[0].transform * Translate(-0.5, -0.5)) let hitsphere = Collider(theType: Sphere, transform: scene.meshes[2].transform, radius: 0.5) echo intersects(hitbox, hitsphere) engine.renderScene(scene) diff -r 74957cbf589b -r 71315636ba82 tests/test_font.nim --- a/tests/test_font.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/tests/test_font.nim Tue Jun 04 16:51:50 2024 +0700 @@ -12,8 +12,8 @@ # build scene var scene = Scene(name: "main") var font = loadFont("DejaVuSans.ttf", lineHeightPixels = 210'f32) - var origin = initPanel(transform = scale(0.01, 0.01)) - var main_text = font.initText("".toRunes, maxLen = 255, color = newVec4f(1, 0.15, 0.15, 1), maxWidth = 1.0, transform = scale(0.0005, 0.0005)) + var origin = initPanel(transform = Scale(0.01, 0.01)) + var main_text = font.initText("".toRunes, maxLen = 255, color = NewVec4f(1, 0.15, 0.15, 1), maxWidth = 1.0, transform = Scale(0.0005, 0.0005)) var help_text = font.initText("""Controls Horizontal alignment: @@ -23,7 +23,7 @@ Vertical alignment: F4: Top F5: Center - F6: Bottom""".toRunes, horizontalAlignment = Left, verticalAlignment = Top, transform = translate(-0.9, -0.9) * scale(0.0002, 0.0002)) + F6: Bottom""".toRunes, horizontalAlignment = Left, verticalAlignment = Top, transform = Translate(-0.9, -0.9) * Scale(0.0002, 0.0002)) scene.add origin scene.add main_text scene.add help_text @@ -33,7 +33,7 @@ while engine.UpdateInputs() and not KeyIsDown(Escape): var t = cpuTime() - main_text.color = newVec4f(sin(t) * 0.5 + 0.5, 0.15, 0.15, 1) + main_text.color = NewVec4f(sin(t) * 0.5 + 0.5, 0.15, 0.15, 1) if WindowWasResized(): var winSize = engine.GetWindow().size diff -r 74957cbf589b -r 71315636ba82 tests/test_materials.nim --- a/tests/test_materials.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/tests/test_materials.nim Tue Jun 04 16:51:50 2024 +0700 @@ -35,7 +35,7 @@ var flag = rect() flag.material = material var scene = Scene(name: "main", meshes: @[flag]) - scene.addShaderGlobalArray("test2", @[newVec4f(), newVec4f()]) + scene.addShaderGlobalArray("test2", @[NewVec4f(), NewVec4f()]) var engine = initEngine("Test materials") @@ -70,7 +70,7 @@ var t = cpuTime() while engine.UpdateInputs() and not KeyIsDown(Escape): var d = float32(cpuTime() - t) - setShaderGlobalArray(scene, "test2", @[newVec4f(d), newVec4f(d * 2)]) + setShaderGlobalArray(scene, "test2", @[NewVec4f(d), NewVec4f(d * 2)]) engine.renderScene(scene) engine.destroy() diff -r 74957cbf589b -r 71315636ba82 tests/test_matrix.nim --- a/tests/test_matrix.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/tests/test_matrix.nim Tue Jun 04 16:51:50 2024 +0700 @@ -23,12 +23,12 @@ proc echoCross[T, U](v1: T, v2: U) = echo v1, " x ", v2, " = ", v1.cross(v2) -proc randVec2I(): auto = newVec2(rand(1 .. 10), rand(1 .. 10)) -proc randVec2F(): auto = newVec2(rand(10'f) + 0.01, rand(10'f) + 0.01) -proc randVec3I(): auto = newVec3(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10)) -proc randVec3F(): auto = newVec3(rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01) -proc randVec4I(): auto = newVec4(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10), rand(1 .. 10)) -proc randVec4F(): auto = newVec4(rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01) +proc randVec2I(): auto = NewVec2(rand(1 .. 10), rand(1 .. 10)) +proc randVec2F(): auto = NewVec2(rand(10'f) + 0.01, rand(10'f) + 0.01) +proc randVec3I(): auto = NewVec3(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10)) +proc randVec3F(): auto = NewVec3(rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01) +proc randVec4I(): auto = NewVec4(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10), rand(1 .. 10)) +proc randVec4F(): auto = NewVec4(rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01) template withAllIntegerMats(stuff: untyped) = @@ -81,28 +81,36 @@ template testTranspose(t: typedesc) = echo "testTranspose: ", t - let m = t().randomized() - assert m == m.transposed().transposed() + let m = t().Randomized() + assert m == m.Transposed().Transposed() + +template testInversed(t: typedesc) = + echo "testTranspose: ", t + let m = t().Randomized() + var unit = t() + for i in unit.RowCount: + unit[i][i] = 1 + assert m.Transposed() * m == unit template testAssignI(t: typedesc) = echo "testAssignI: ", t var m = t() for i in 0 ..< t.data.len: - m[rand(0 ..< t.rowCount), rand(0 ..< t.columnCount)] = rand(0'i32 .. 100'i32) + m[rand(0 ..< t.RowCount), rand(0 ..< t.ColumnCount)] = rand(0'i32 .. 100'i32) template testAssignF(t: typedesc) = echo "testAssignF: ", t var m = t() for i in 0 ..< t.data.len: - m[rand(0 ..< t.rowCount), rand(0 ..< t.columnCount)] = rand(100'f) + m[rand(0 ..< t.RowCount), rand(0 ..< t.ColumnCount)] = rand(100'f) template testRowCols(t: typedesc) = echo "testRowCols: ", t - var m = t().randomized() - for i in 0 ..< t.rowCount: - echo m.row(i) - for i in 0 ..< t.columnCount: - echo m.col(i) + var m = t().Randomized() + for i in 0 ..< t.RowCount: + echo m.Row(i) + for i in 0 ..< t.ColumnCount: + echo m.Col(i) proc testMatrix() = @@ -132,19 +140,19 @@ echo Unit4i32 echo Unit4i64 - echo TMat2[float32]().randomized() * One2.randomized() - echo TMat3[float32]().randomized() * One3.randomized() - echo TMat4[float32]().randomized() * One4.randomized() + echo TMat2[float32]().Randomized() * One2.Randomized() + echo TMat3[float32]().Randomized() * One3.Randomized() + echo TMat4[float32]().Randomized() * One4.Randomized() - echo float32(rand(1'f32)) * TMat2[float32]().randomized() - echo TMat2[float]().randomized() * rand(1'f) - echo TMat2[float]().randomized() * rand(1'f) - echo TMat23[float]().randomized() * rand(1'f) - echo TMat23[float]().randomized() * rand(1'f) - echo TMat3[float]().randomized() * rand(1'f) - echo TMat34[float]().randomized() * rand(1'f) - echo TMat43[float]().randomized() * rand(1'f) - echo TMat4[float]().randomized() * rand(1'f) + echo float32(rand(1'f32)) * TMat2[float32]().Randomized() + echo TMat2[float]().Randomized() * rand(1'f) + echo TMat2[float]().Randomized() * rand(1'f) + echo TMat23[float]().Randomized() * rand(1'f) + echo TMat23[float]().Randomized() * rand(1'f) + echo TMat3[float]().Randomized() * rand(1'f) + echo TMat34[float]().Randomized() * rand(1'f) + echo TMat43[float]().Randomized() * rand(1'f) + echo TMat4[float]().Randomized() * rand(1'f) randomize() testMatrix() diff -r 74957cbf589b -r 71315636ba82 tests/test_mesh.nim --- a/tests/test_mesh.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/tests/test_mesh.nim Tue Jun 04 16:51:50 2024 +0700 @@ -82,10 +82,10 @@ size *= 1'f32 + MouseWheel() * 0.05 azimut += MouseMove().x / 180'f32 elevation -= MouseMove().y / 180'f32 - scenes[currentScene].setShaderGlobal("projection", perspective(PI / 2, ratio, -0.5, 1)) + scenes[currentScene].setShaderGlobal("projection", Perspective(PI / 2, ratio, -0.5, 1)) scenes[currentScene].setShaderGlobal( "view", - scale(size, size, size) * rotate(elevation, newVec3f(1, 0, 0)) * rotate(azimut, Yf32) + Scale(size, size, size) * Rotate(elevation, NewVec3f(1, 0, 0)) * Rotate(azimut, Yf32) ) engine.renderScene(scenes[currentScene]) engine.destroy() diff -r 74957cbf589b -r 71315636ba82 tests/test_noise.nim --- a/tests/test_noise.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/tests/test_noise.nim Tue Jun 04 16:51:50 2024 +0700 @@ -8,9 +8,9 @@ for y in 0 ..< h: for x in 0 ..< w: let v = ( - perlin(newVec2f(float(x) * 0.01, float(y) * 0.01)) * 0.7 + - perlin(newVec2f(float(x) * 0.05, float(y) * 0.05)) * 0.25 + - perlin(newVec2f(float(x) * 0.2, float(y) * 0.2)) * 0.05 + perlin(NewVec2f(float(x) * 0.01, float(y) * 0.01)) * 0.7 + + perlin(NewVec2f(float(x) * 0.05, float(y) * 0.05)) * 0.25 + + perlin(NewVec2f(float(x) * 0.2, float(y) * 0.2)) * 0.05 ) o = o & $(int((v * 0.5 + 0.5) * 255)) & " " o = o & "\n" diff -r 74957cbf589b -r 71315636ba82 tests/test_panel.nim --- a/tests/test_panel.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/tests/test_panel.nim Tue Jun 04 16:51:50 2024 +0700 @@ -12,11 +12,11 @@ counter.dec counterText.text = $counter proc enter(panel: var Panel) = - panel.mesh.transform = panel.mesh.transform * scale(1.05, 1.05) - panel.color = newVec4f(1, 0, 0, 0.3) + panel.mesh.transform = panel.mesh.transform * Scale(1.05, 1.05) + panel.color = NewVec4f(1, 0, 0, 0.3) proc leave(panel: var Panel) = - panel.mesh.transform = panel.mesh.transform * scale(1 / 1.05, 1 / 1.05) - panel.color = newVec4f(1, 0, 0, 0.5) + panel.mesh.transform = panel.mesh.transform * Scale(1 / 1.05, 1 / 1.05) + panel.color = NewVec4f(1, 0, 0, 0.5) proc main() = # setup engine @@ -31,13 +31,13 @@ font = loadFont("DejaVuSans.ttf", lineHeightPixels = 210'f32) scene = Scene(name: "main") origin = initPanel( - transform = scale(0.005, 0.005), - color = newVec4f(1, 1, 1, 1), + transform = Scale(0.005, 0.005), + color = NewVec4f(1, 1, 1, 1), texture = Texture(isGrayscale: false, colorImage: newImage[RGBAPixel](3, 3, [T, B, T, B, B, B, T, B, T]), sampler: NEAREST_SAMPLER), ) button = initPanel( - transform = translate(0.2, 0.1) * scale(0.3, 0.1), - color = newVec4f(1, 0, 0, 0.5), + transform = Translate(0.2, 0.1) * Scale(0.3, 0.1), + color = NewVec4f(1, 0, 0, 0.5), onMouseDown = click, onMouseEnter = enter, onMouseLeave = leave @@ -54,9 +54,9 @@ F6: Bottom Mouse: Left click: Increase counter - Right click: Decrease counter""".toRunes, horizontalAlignment = Left, verticalAlignment = Top, transform = translate(-0.9, -0.9) * scale(0.0002, 0.0002)) + Right click: Decrease counter""".toRunes, horizontalAlignment = Left, verticalAlignment = Top, transform = Translate(-0.9, -0.9) * Scale(0.0002, 0.0002)) - counterText = font.initText(($counter).toRunes, maxLen = 99, transform = translate(0.2, 0.1) * scale(0.0004, 0.0004)) + counterText = font.initText(($counter).toRunes, maxLen = 99, transform = Translate(0.2, 0.1) * Scale(0.0004, 0.0004)) scene.add counterText scene.add button diff -r 74957cbf589b -r 71315636ba82 tests/test_storage.nim --- a/tests/test_storage.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/tests/test_storage.nim Tue Jun 04 16:51:50 2024 +0700 @@ -1,4 +1,3 @@ -import std/os import std/strformat import semicongine diff -r 74957cbf589b -r 71315636ba82 tests/test_vector.nim --- a/tests/test_vector.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/tests/test_vector.nim Tue Jun 04 16:51:50 2024 +0700 @@ -5,9 +5,9 @@ proc echoInfo[T](v: TVec2[T] or TVec3[T] or TVec4[T]) = echo v - echo " Length: ", v.length + echo " Length: ", v.Length when T is SomeFloat: - echo " Normlized: ", v.normalized + echo " Normlized: ", v.Normalized echo " negated: ", -v proc echoAdd[T, U](v1: T, v2: U) = @@ -19,18 +19,18 @@ proc echoDiv[T, U](v1: T, v2: U) = echo v1, " / ", v2, " = ", v1 / v2 proc echoDot[T, U](v1: T, v2: U) = - echo v1, " o ", v2, " = ", v1.dot(v2) + echo v1, " o ", v2, " = ", v1.Dot(v2) proc echoCross[T, U](v1: T, v2: U) = - echo v1, " x ", v2, " = ", v1.cross(v2) + echo v1, " x ", v2, " = ", v1.Cross(v2) -proc randVec2I(): auto = newVec2(rand(1 .. 10), rand(1 .. 10)) -proc randVec2F(): auto = newVec2(rand(10'f) + 0.01, rand(10'f) + 0.01) -proc randVec3I(): auto = newVec3(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10)) -proc randVec3F(): auto = newVec3(rand(10'f) + 0.01, rand(10'f) + 0.01, rand( +proc randVec2I(): auto = NewVec2(rand(1 .. 10), rand(1 .. 10)) +proc randVec2F(): auto = NewVec2(rand(10'f) + 0.01, rand(10'f) + 0.01) +proc randVec3I(): auto = NewVec3(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10)) +proc randVec3F(): auto = NewVec3(rand(10'f) + 0.01, rand(10'f) + 0.01, rand( 10'f) + 0.01) -proc randVec4I(): auto = newVec4(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10), +proc randVec4I(): auto = NewVec4(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10), rand(1 .. 10)) -proc randVec4F(): auto = newVec4(rand(10'f) + 0.01, rand(10'f) + 0.01, rand( +proc randVec4F(): auto = NewVec4(rand(10'f) + 0.01, rand(10'f) + 0.01, rand( 10'f) + 0.01, rand(10'f) + 0.01) @@ -130,12 +130,12 @@ echoDiv(rand(10'f), randVec4F()) # test attribute syntax sugar - echo "float2int ", to[int](randVec2F()) - echo "int2float ", to[float](randVec2I()) - echo "float2int ", to[int](randVec3F()) - echo "int2float ", to[float](randVec3I()) - echo "float2int ", to[int](randVec3F()) - echo "int2float ", to[float](randVec3I()) + echo "float2int ", To[int](randVec2F()) + echo "int2float ", To[float](randVec2I()) + echo "float2int ", To[int](randVec3F()) + echo "int2float ", To[float](randVec3I()) + echo "float2int ", To[int](randVec3F()) + echo "int2float ", To[float](randVec3I()) echo "V3I.x: ", randVec3I().x echo "V3I.y: ", randVec3I().y @@ -145,20 +145,20 @@ echo "V3F.b: ", randVec3F().b # test setters - var v1 = randVec2I(); v1.x = 1 ; v1.y = 2 ; v1.r = 3 ; v1.g = 4 - v1.xy = randVec2I() ; v1.yx = randVec2I() ; v1.rg = randVec2I() ; v1.gr = randVec2I() - var v2 = randVec2F(); v2.x = 1.0 ; v2.y = 2.0 ; v2.r = 3.0 ; v2.g = 4.0 - v2.xy = randVec2F() ; v2.yx = randVec2F() ; v2.rg = randVec2F() ; v2.gr = randVec2F() + var v1 = randVec2I(); v1.x = 1; v1.y = 2; v1.r = 3; v1.g = 4 + v1.xy = randVec2I(); v1.yx = randVec2I(); v1.rg = randVec2I(); v1.gr = randVec2I() + var v2 = randVec2F(); v2.x = 1.0; v2.y = 2.0; v2.r = 3.0; v2.g = 4.0 + v2.xy = randVec2F(); v2.yx = randVec2F(); v2.rg = randVec2F(); v2.gr = randVec2F() - var v3 = randVec3I(); v3.x = 1 ; v3.y = 2 ; v3.z = 3 ; v3.r = 4 ; v3.g = 5 ; v3.b = 6 - v3.xyz = randVec3I() ; v3.rgb = randVec3I() - var v4 = randVec3F(); v4.x = 1.0 ; v4.y = 2.0 ; v4.z = 3.0 ; v4.r = 4.0 ; v4.g = 5.0 ; v4.b = 6.0 - v4.xyz = randVec3F() ; v4.rgb = randVec3F() + var v3 = randVec3I(); v3.x = 1; v3.y = 2; v3.z = 3; v3.r = 4; v3.g = 5; v3.b = 6 + v3.xyz = randVec3I(); v3.rgb = randVec3I() + var v4 = randVec3F(); v4.x = 1.0; v4.y = 2.0; v4.z = 3.0; v4.r = 4.0; v4.g = 5.0; v4.b = 6.0 + v4.xyz = randVec3F(); v4.rgb = randVec3F() - var v5 = randVec4I(); v5.x = 1 ; v5.y = 2 ; v5.z = 3; v5.w = 4 ; v5.r = 5 ; v5.g = 6 ; v5.b = 7 ; v5.a = 8 - v5.xyzw = randVec4I() ; v5.rgba = randVec4I() - var v6 = randVec4F(); v6.x = 1.0 ; v6.y = 2.0 ; v6.z = 3.0 ; v6.w = 4.0 ; v6.r = 5.0 ; v6.g = 6.0 ; v6.b = 7.0 ; v6.a = 8.0 - v6.xyzw = randVec4F() ; v6.rgba = randVec4F() + var v5 = randVec4I(); v5.x = 1; v5.y = 2; v5.z = 3; v5.w = 4; v5.r = 5; v5.g = 6; v5.b = 7; v5.a = 8 + v5.xyzw = randVec4I(); v5.rgba = randVec4I() + var v6 = randVec4F(); v6.x = 1.0; v6.y = 2.0; v6.z = 3.0; v6.w = 4.0; v6.r = 5.0; v6.g = 6.0; v6.b = 7.0; v6.a = 8.0 + v6.xyzw = randVec4F(); v6.rgba = randVec4F() echo "V2I.xx: ", randVec2I().xx echo "V2I.yx: ", randVec2I().xy diff -r 74957cbf589b -r 71315636ba82 tests/test_vulkan_wrapper.nim --- a/tests/test_vulkan_wrapper.nim Mon Jun 03 16:05:17 2024 +0700 +++ b/tests/test_vulkan_wrapper.nim Tue Jun 04 16:51:50 2024 +0700 @@ -56,95 +56,95 @@ mat3 = SINGLE_COLOR_MATERIAL.initMaterialData( name = "mat3", attributes = { - "color": initDataList(@[newVec4f(0, 1, 0, 1)]) + "color": initDataList(@[NewVec4f(0, 1, 0, 1)]) }.toTable ) proc scene_different_mesh_types(): seq[Mesh] = @[ newMesh( - positions = [newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], - uvs = [newVec2f(0.0, -0.5), newVec2f(0.5, 0.5), newVec2f(-0.5, 0.5)], - colors = [newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)], + positions = [NewVec3f(0.0, -0.5), NewVec3f(0.5, 0.5), NewVec3f(-0.5, 0.5)], + uvs = [NewVec2f(0.0, -0.5), NewVec2f(0.5, 0.5), NewVec2f(-0.5, 0.5)], + colors = [NewVec4f(1.0, 0.0, 0.0, 1), NewVec4f(0.0, 1.0, 0.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], material = mat, - transform = translate(-0.7, -0.5), + transform = Translate(-0.7, -0.5), ), newMesh( - positions = [newVec3f(0.0, -0.4), newVec3f(0.4, 0.4), newVec3f(-0.4, 0.5)], - uvs = [newVec2f(0.0, -0.4), newVec2f(0.4, 0.4), newVec2f(-0.4, 0.5)], - colors = [newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)], + positions = [NewVec3f(0.0, -0.4), NewVec3f(0.4, 0.4), NewVec3f(-0.4, 0.5)], + uvs = [NewVec2f(0.0, -0.4), NewVec2f(0.4, 0.4), NewVec2f(-0.4, 0.5)], + colors = [NewVec4f(1.0, 0.0, 0.0, 1), NewVec4f(0.0, 1.0, 0.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], material = mat, - transform = translate(0, -0.5), + transform = Translate(0, -0.5), ), newMesh( - positions = [newVec3f(0.0, 0.5), newVec3f(0.5, -0.5), newVec3f(-0.5, -0.5)], - uvs = [newVec2f(0.0, 0.5), newVec2f(0.5, -0.5), newVec2f(-0.5, -0.5)], - colors = [newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)], + positions = [NewVec3f(0.0, 0.5), NewVec3f(0.5, -0.5), NewVec3f(-0.5, -0.5)], + uvs = [NewVec2f(0.0, 0.5), NewVec2f(0.5, -0.5), NewVec2f(-0.5, -0.5)], + colors = [NewVec4f(1.0, 0.0, 0.0, 1), NewVec4f(0.0, 1.0, 0.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], indices = [[0'u16, 2'u16, 1'u16]], material = mat2, - transform = translate(0.7, -0.5), + transform = Translate(0.7, -0.5), ), newMesh( - positions = [newVec3f(0.0, 0.4), newVec3f(0.4, -0.4), newVec3f(-0.4, -0.4)], - uvs = [newVec2f(0.0, 0.4), newVec2f(0.4, -0.4), newVec2f(-0.4, -0.4)], - colors = [newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)], + positions = [NewVec3f(0.0, 0.4), NewVec3f(0.4, -0.4), NewVec3f(-0.4, -0.4)], + uvs = [NewVec2f(0.0, 0.4), NewVec2f(0.4, -0.4), NewVec2f(-0.4, -0.4)], + colors = [NewVec4f(1.0, 0.0, 0.0, 1), NewVec4f(0.0, 1.0, 0.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], indices = [[0'u16, 2'u16, 1'u16]], material = mat2, - transform = translate(-0.7, 0.5), + transform = Translate(-0.7, 0.5), ), newMesh( - positions = [newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], - uvs = [newVec2f(0.4, 0.5), newVec2f(0.9, -0.3), newVec2f(0.0, -0.3)], - colors = [newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1)], + positions = [NewVec3f(0.4, 0.5), NewVec3f(0.9, -0.3), NewVec3f(0.0, -0.3)], + uvs = [NewVec2f(0.4, 0.5), NewVec2f(0.9, -0.3), NewVec2f(0.0, -0.3)], + colors = [NewVec4f(1.0, 1.0, 0.0, 1), NewVec4f(1.0, 1.0, 0.0, 1), NewVec4f(1.0, 1.0, 0.0, 1)], indices = [[0'u32, 2'u32, 1'u32]], autoResize = false, material = mat2, - transform = translate(0, 0.5), + transform = Translate(0, 0.5), ), newMesh( - positions = [newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)], - uvs = [newVec2f(0.4, 0.5), newVec2f(0.9, -0.3), newVec2f(0.0, -0.3)], - colors = [newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1)], + positions = [NewVec3f(0.4, 0.5), NewVec3f(0.9, -0.3), NewVec3f(0.0, -0.3)], + uvs = [NewVec2f(0.4, 0.5), NewVec2f(0.9, -0.3), NewVec2f(0.0, -0.3)], + colors = [NewVec4f(1.0, 1.0, 0.0, 1), NewVec4f(1.0, 1.0, 0.0, 1), NewVec4f(1.0, 1.0, 0.0, 1)], indices = [[0'u32, 2'u32, 1'u32]], autoResize = false, material = mat2, - transform = translate(0.7, 0.5), + transform = Translate(0.7, 0.5), ), ] proc scene_simple(): seq[Mesh] = @[ newMesh( - positions = [newVec3f(0.0, -0.3), newVec3f(0.3, 0.3), newVec3f(-0.3, 0.3)], - colors = [newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)], - uvs = [newVec2f(0.0, -0.3), newVec2f(0.3, 0.3), newVec2f(-0.3, 0.3)], + positions = [NewVec3f(0.0, -0.3), NewVec3f(0.3, 0.3), NewVec3f(-0.3, 0.3)], + colors = [NewVec4f(1.0, 0.0, 0.0, 1), NewVec4f(0.0, 1.0, 0.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], + uvs = [NewVec2f(0.0, -0.3), NewVec2f(0.3, 0.3), NewVec2f(-0.3, 0.3)], material = mat, - transform = translate(0.4, 0.4), + transform = Translate(0.4, 0.4), ), newMesh( - positions = [newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)], - colors = [newVec4f(1.0, 0.0, 0.0, 1), newVec4f(0.0, 1.0, 0.0, 1), newVec4f(0.0, 0.0, 1.0, 1)], - uvs = [newVec2f(0.0, -0.5), newVec2f(0.5, 0.5), newVec2f(-0.5, 0.5)], + positions = [NewVec3f(0.0, -0.5), NewVec3f(0.5, 0.5), NewVec3f(-0.5, 0.5)], + colors = [NewVec4f(1.0, 0.0, 0.0, 1), NewVec4f(0.0, 1.0, 0.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], + uvs = [NewVec2f(0.0, -0.5), NewVec2f(0.5, 0.5), NewVec2f(-0.5, 0.5)], material = mat, - transform = translate(0.4, -0.4), + transform = Translate(0.4, -0.4), ), newMesh( - positions = [newVec3f(0.0, -0.6), newVec3f(0.6, 0.6), newVec3f(-0.6, 0.6)], - colors = [newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1), newVec4f(1.0, 1.0, 0.0, 1)], - uvs = [newVec2f(0.0, -0.6), newVec2f(0.6, 0.6), newVec2f(-0.6, 0.6)], + positions = [NewVec3f(0.0, -0.6), NewVec3f(0.6, 0.6), NewVec3f(-0.6, 0.6)], + colors = [NewVec4f(1.0, 1.0, 0.0, 1), NewVec4f(1.0, 1.0, 0.0, 1), NewVec4f(1.0, 1.0, 0.0, 1)], + uvs = [NewVec2f(0.0, -0.6), NewVec2f(0.6, 0.6), NewVec2f(-0.6, 0.6)], indices = [[0'u32, 1'u32, 2'u32]], autoResize = false, material = mat, - transform = translate(-0.4, 0.4), + transform = Translate(-0.4, 0.4), ), newMesh( - positions = [newVec3f(0.0, -0.8), newVec3f(0.8, 0.8), newVec3f(-0.8, 0.8)], - colors = [newVec4f(0.0, 0.0, 1.0, 1), newVec4f(0.0, 0.0, 1.0, 1), newVec4f(0.0, 0.0, 1.0, 1)], - uvs = [newVec2f(0.0, -0.8), newVec2f(0.8, 0.8), newVec2f(-0.8, 0.8)], + positions = [NewVec3f(0.0, -0.8), NewVec3f(0.8, 0.8), NewVec3f(-0.8, 0.8)], + colors = [NewVec4f(0.0, 0.0, 1.0, 1), NewVec4f(0.0, 0.0, 1.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], + uvs = [NewVec2f(0.0, -0.8), NewVec2f(0.8, 0.8), NewVec2f(-0.8, 0.8)], indices = [[0'u16, 1'u16, 2'u16]], instanceTransforms = [Unit4F32, Unit4F32], material = mat, - transform = translate(-0.4, -0.4), + transform = Translate(-0.4, -0.4), ) ] @@ -155,20 +155,20 @@ r.material = mat t.material = mat c.material = mat - r.transform = translate(newVec3f(0.5, -0.3)) - t.transform = translate(newVec3f(0.3, 0.3)) - c.transform = translate(newVec3f(-0.3, 0.1)) + r.transform = Translate(NewVec3f(0.5, -0.3)) + t.transform = Translate(NewVec3f(0.3, 0.3)) + c.transform = Translate(NewVec3f(-0.3, 0.1)) result = @[r, c, t] proc scene_flag(): seq[Mesh] = @[ newMesh( - positions = [newVec3f(-1.0, -1.0), newVec3f(1.0, -1.0), newVec3f(1.0, 1.0), newVec3f(-1.0, 1.0)], - uvs = [newVec2f(-1.0, -1.0), newVec2f(1.0, -1.0), newVec2f(1.0, 1.0), newVec2f(-1.0, 1.0)], - colors = [newVec4f(-1, -1, 1, 1), newVec4f(1, -1, 1, 1), newVec4f(1, 1, 1, 1), newVec4f(-1, 1, 1, 1)], + positions = [NewVec3f(-1.0, -1.0), NewVec3f(1.0, -1.0), NewVec3f(1.0, 1.0), NewVec3f(-1.0, 1.0)], + uvs = [NewVec2f(-1.0, -1.0), NewVec2f(1.0, -1.0), NewVec2f(1.0, 1.0), NewVec2f(-1.0, 1.0)], + colors = [NewVec4f(-1, -1, 1, 1), NewVec4f(1, -1, 1, 1), NewVec4f(1, 1, 1, 1), NewVec4f(-1, 1, 1, 1)], indices = [[0'u16, 1'u16, 2'u16], [2'u16, 3'u16, 0'u16]], material = mat, - transform = scale(0.5, 0.5) + transform = Scale(0.5, 0.5) ) ] @@ -178,8 +178,8 @@ r2 = rect(color = "000000") r1.material = mat r2.material = mat3 - r1.transform = translate(newVec3f(-0.5)) - r2.transform = translate(newVec3f(+0.5)) + r1.transform = Translate(NewVec3f(-0.5)) + r2.transform = Translate(NewVec3f(+0.5)) result = @[r1, r2] proc main() =