comparison examples/hello_triangle.nim @ 518:5d406c17bbcb

did: refactor Vector names
author Sam <sam@basx.dev>
date Fri, 20 Jan 2023 16:13:32 +0700
parents 836790efab48
children cd73e429fc99
comparison
equal deleted inserted replaced
517:836790efab48 518:5d406c17bbcb
5 import semicongine 5 import semicongine
6 6
7 type 7 type
8 # define type of vertex 8 # define type of vertex
9 VertexDataA = object 9 VertexDataA = object
10 position: PositionAttribute[Vec2[float32]] 10 position: PositionAttribute[TVec2[float32]]
11 color: ColorAttribute[Vec3[float32]] 11 color: ColorAttribute[TVec3[float32]]
12 id: InstanceAttribute[Vec3[float32]] 12 id: InstanceAttribute[TVec3[float32]]
13 13
14 var pipeline: RenderPipeline[VertexDataA, void] 14 var pipeline: RenderPipeline[VertexDataA, void]
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 # vertex data (types must match the above VertexAttributes) 19 # vertex data (types must match the above VertexAttributes)
20 const 20 const
21 triangle_pos = @[ 21 triangle_pos = @[
22 Vec2([ 0.0'f32, -0.5'f32]), 22 TVec2([ 0.0'f32, -0.5'f32]),
23 Vec2([ 0.5'f32, 0.5'f32]), 23 TVec2([ 0.5'f32, 0.5'f32]),
24 Vec2([-0.5'f32, 0.5'f32]), 24 TVec2([-0.5'f32, 0.5'f32]),
25 ] 25 ]
26 triangle_color = @[ 26 triangle_color = @[
27 Vec3([1.0'f32, 0.0'f32, 0.0'f32]), 27 TVec3([1.0'f32, 0.0'f32, 0.0'f32]),
28 Vec3([0.0'f32, 1.0'f32, 0.0'f32]), 28 TVec3([0.0'f32, 1.0'f32, 0.0'f32]),
29 Vec3([0.0'f32, 0.0'f32, 1.0'f32]), 29 TVec3([0.0'f32, 0.0'f32, 1.0'f32]),
30 ] 30 ]
31 31
32 when isMainModule: 32 when isMainModule:
33 var myengine = igniteEngine("Hello triangle") 33 var myengine = igniteEngine("Hello triangle")
34 34
35 # build a mesh 35 # build a mesh
36 var trianglemesh = new Mesh[VertexDataA] 36 var trianglemesh = new Mesh[VertexDataA]
37 trianglemesh.vertexData = VertexDataA( 37 trianglemesh.vertexData = VertexDataA(
38 position: PositionAttribute[Vec2[float32]](data: triangle_pos), 38 position: PositionAttribute[TVec2[float32]](data: triangle_pos),
39 color: ColorAttribute[Vec3[float32]](data: triangle_color), 39 color: ColorAttribute[TVec3[float32]](data: triangle_color),
40 id: InstanceAttribute[Vec3[float32]](data: @[Vec3[float32]([0.5'f32, 0.5'f32, 0.5'f32])]), 40 id: InstanceAttribute[TVec3[float32]](data: @[TVec3[float32]([0.5'f32, 0.5'f32, 0.5'f32])]),
41 ) 41 )
42 # build a single-object scene graph 42 # build a single-object scene graph
43 var triangle = new Thing 43 var triangle = new Thing
44 # add the triangle mesh to the object 44 # add the triangle mesh to the object
45 triangle.parts.add trianglemesh 45 triangle.parts.add trianglemesh