comparison examples/alotof_triangles.nim @ 520:cd73e429fc99

did: use new vector and matrix names for simpler code
author Sam <sam@basx.dev>
date Fri, 20 Jan 2023 16:53:37 +0700
parents 03a94b905f1a
children c57285d292b6
comparison
equal deleted inserted replaced
519:03a94b905f1a 520:cd73e429fc99
6 6
7 import semicongine 7 import semicongine
8 8
9 type 9 type
10 VertexDataA = object 10 VertexDataA = object
11 position11: PositionAttribute[TVec2[float32]] 11 position11: PositionAttribute[Vec2]
12 color22: ColorAttribute[TVec3[float32]] 12 color22: ColorAttribute[Vec3]
13 Uniforms = object 13 Uniforms = object
14 dt: Descriptor[float32] 14 dt: Descriptor[float32]
15 15
16 proc globalUpdate(engine: var Engine, dt: float32) = 16 proc globalUpdate(engine: var Engine, dt: float32) =
17 discard 17 discard
18 18
19 proc randomtransform(): TMat33[float32] = 19 proc randomtransform(): Mat33 =
20 let randomscale = scale2d(float32(rand(1.0) + 0.5), float32(rand(1.0) + 0.5)) 20 let randomscale = scale2d(float32(rand(1.0) + 0.5), float32(rand(1.0) + 0.5))
21 let randomrotate = rotate2d(float32(rand(2 * PI))) 21 let randomrotate = rotate2d(float32(rand(2 * PI)))
22 let randomtranslate = translate2d(float32(rand(1.6) - 0.8), float32(rand(1.6) - 0.8)) 22 let randomtranslate = translate2d(float32(rand(1.6) - 0.8), float32(rand(1.6) - 0.8))
23 result = randomtranslate * randomrotate * randomscale 23 result = randomtranslate * randomrotate * randomscale
24 24
25 when isMainModule: 25 when isMainModule:
26 randomize() 26 randomize()
27 var myengine = igniteEngine("A lot of triangles") 27 var myengine = igniteEngine("A lot of triangles")
28 const baseTriangle = [ 28 const baseTriangle = [
29 TVec3([-0.1'f32, -0.1'f32, 1'f32]), 29 Vec3([-0.1'f32, -0.1'f32, 1'f32]),
30 TVec3([ 0.1'f32, 0.1'f32, 1'f32]), 30 Vec3([ 0.1'f32, 0.1'f32, 1'f32]),
31 TVec3([-0.1'f32, 0.1'f32, 1'f32]), 31 Vec3([-0.1'f32, 0.1'f32, 1'f32]),
32 ] 32 ]
33 33
34 var scene = new Thing 34 var scene = new Thing
35 35
36 for i in 1 .. 300: 36 for i in 1 .. 300:
37 var randommesh = new Mesh[VertexDataA] 37 var randommesh = new Mesh[VertexDataA]
38 let randomcolor1 = TVec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]) 38 let randomcolor1 = Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))])
39 let transform1 = randomtransform() 39 let transform1 = randomtransform()
40 randommesh.vertexData = VertexDataA( 40 randommesh.vertexData = VertexDataA(
41 position11: PositionAttribute[TVec2[float32]]( 41 position11: PositionAttribute[Vec2](
42 data: @[ 42 data: @[
43 TVec2[float32](transform1 * baseTriangle[0]), 43 Vec2(transform1 * baseTriangle[0]),
44 TVec2[float32](transform1 * baseTriangle[1]), 44 Vec2(transform1 * baseTriangle[1]),
45 TVec2[float32](transform1 * baseTriangle[2]), 45 Vec2(transform1 * baseTriangle[2]),
46 ] 46 ]
47 ), 47 ),
48 color22: ColorAttribute[TVec3[float32]]( 48 color22: ColorAttribute[Vec3](
49 data: @[randomcolor1, randomcolor1, randomcolor1] 49 data: @[randomcolor1, randomcolor1, randomcolor1]
50 ) 50 )
51 ) 51 )
52 52
53 let randomcolor2 = TVec3([float32(rand(1)), float32(rand(1)), float32(rand(1))]) 53 let randomcolor2 = Vec3([float32(rand(1)), float32(rand(1)), float32(rand(1))])
54 let transform2 = randomtransform() 54 let transform2 = randomtransform()
55 var randomindexedmesh = new IndexedMesh[VertexDataA, uint16] 55 var randomindexedmesh = new IndexedMesh[VertexDataA, uint16]
56 randomindexedmesh.vertexData = VertexDataA( 56 randomindexedmesh.vertexData = VertexDataA(
57 position11: PositionAttribute[TVec2[float32]]( 57 position11: PositionAttribute[Vec2](
58 data: @[ 58 data: @[
59 TVec2[float32](transform2 * baseTriangle[0]), 59 Vec2(transform2 * baseTriangle[0]),
60 TVec2[float32](transform2 * baseTriangle[1]), 60 Vec2(transform2 * baseTriangle[1]),
61 TVec2[float32](transform2 * baseTriangle[2]), 61 Vec2(transform2 * baseTriangle[2]),
62 ] 62 ]
63 ), 63 ),
64 color22: ColorAttribute[TVec3[float32]]( 64 color22: ColorAttribute[Vec3](
65 data: @[randomcolor2, randomcolor2, randomcolor2] 65 data: @[randomcolor2, randomcolor2, randomcolor2]
66 ) 66 )
67 ) 67 )
68 randomindexedmesh.indices = @[[0'u16, 1'u16, 2'u16]] 68 randomindexedmesh.indices = @[[0'u16, 1'u16, 2'u16]]
69 var childthing = new Thing 69 var childthing = new Thing