Mercurial > games > semicongine
comparison examples/hello_cube.nim @ 57:547f3a374271
did: refactor Vector names
author | Sam <sam@basx.dev> |
---|---|
date | Fri, 20 Jan 2023 16:13:32 +0700 |
parents | 94d7eed3f118 |
children | 8287a91e5d56 |
comparison
equal
deleted
inserted
replaced
56:94d7eed3f118 | 57:547f3a374271 |
---|---|
15 import semicongine | 15 import semicongine |
16 | 16 |
17 type | 17 type |
18 # define type of vertex | 18 # define type of vertex |
19 VertexDataA = object | 19 VertexDataA = object |
20 position: PositionAttribute[Vec3[float32]] | 20 position: PositionAttribute[TVec3[float32]] |
21 color: ColorAttribute[Vec3[float32]] | 21 color: ColorAttribute[TVec3[float32]] |
22 Uniforms = object | 22 Uniforms = object |
23 model: Descriptor[Mat44[float32]] | 23 model: Descriptor[Mat44[float32]] |
24 view: Descriptor[Mat44[float32]] | 24 view: Descriptor[Mat44[float32]] |
25 projection: Descriptor[Mat44[float32]] | 25 projection: Descriptor[Mat44[float32]] |
26 | 26 |
45 uniforms.projection.value = perspective(float32(PI / 4), float32(engine.vulkan.frameDimension.width) / float32(engine.vulkan.frameDimension.height), 0.1'f32, 100'f32) | 45 uniforms.projection.value = perspective(float32(PI / 4), float32(engine.vulkan.frameDimension.width) / float32(engine.vulkan.frameDimension.height), 0.1'f32, 100'f32) |
46 for buffer in pipeline.uniformBuffers: | 46 for buffer in pipeline.uniformBuffers: |
47 buffer.updateData(uniforms) | 47 buffer.updateData(uniforms) |
48 | 48 |
49 const | 49 const |
50 TopLeftFront = Vec3([ -0.5'f32, -0.5'f32, -0.5'f32]) | 50 TopLeftFront = TVec3([ -0.5'f32, -0.5'f32, -0.5'f32]) |
51 TopRightFront = Vec3([ 0.5'f32, -0.5'f32, -0.5'f32]) | 51 TopRightFront = TVec3([ 0.5'f32, -0.5'f32, -0.5'f32]) |
52 BottomRightFront = Vec3([ 0.5'f32, 0.5'f32, -0.5'f32]) | 52 BottomRightFront = TVec3([ 0.5'f32, 0.5'f32, -0.5'f32]) |
53 BottomLeftFront = Vec3([ -0.5'f32, 0.5'f32, -0.5'f32]) | 53 BottomLeftFront = TVec3([ -0.5'f32, 0.5'f32, -0.5'f32]) |
54 TopLeftBack = Vec3([ 0.5'f32, -0.5'f32, 0.5'f32]) | 54 TopLeftBack = TVec3([ 0.5'f32, -0.5'f32, 0.5'f32]) |
55 TopRightBack = Vec3([ -0.5'f32, -0.5'f32, 0.5'f32]) | 55 TopRightBack = TVec3([ -0.5'f32, -0.5'f32, 0.5'f32]) |
56 BottomRightBack = Vec3([ -0.5'f32, 0.5'f32, 0.5'f32]) | 56 BottomRightBack = TVec3([ -0.5'f32, 0.5'f32, 0.5'f32]) |
57 BottomLeftBack = Vec3([ 0.5'f32, 0.5'f32, 0.5'f32]) | 57 BottomLeftBack = TVec3([ 0.5'f32, 0.5'f32, 0.5'f32]) |
58 const | 58 const |
59 cube_pos = @[ | 59 cube_pos = @[ |
60 TopLeftFront, TopRightFront, BottomRightFront, BottomLeftFront, # front | 60 TopLeftFront, TopRightFront, BottomRightFront, BottomLeftFront, # front |
61 TopLeftBack, TopRightBack, BottomRightBack, BottomLeftBack, # back | 61 TopLeftBack, TopRightBack, BottomRightBack, BottomLeftBack, # back |
62 TopLeftBack, TopLeftFront, BottomLeftFront, BottomLeftBack, # left | 62 TopLeftBack, TopLeftFront, BottomLeftFront, BottomLeftBack, # left |
95 var myengine = igniteEngine("Hello cube") | 95 var myengine = igniteEngine("Hello cube") |
96 | 96 |
97 # build a mesh | 97 # build a mesh |
98 var trianglemesh = new IndexedMesh[VertexDataA, uint16] | 98 var trianglemesh = new IndexedMesh[VertexDataA, uint16] |
99 trianglemesh.vertexData = VertexDataA( | 99 trianglemesh.vertexData = VertexDataA( |
100 position: PositionAttribute[Vec3[float32]](data: cube_pos), | 100 position: PositionAttribute[TVec3[float32]](data: cube_pos), |
101 color: ColorAttribute[Vec3[float32]](data: cube_color), | 101 color: ColorAttribute[TVec3[float32]](data: cube_color), |
102 ) | 102 ) |
103 trianglemesh.indices = tris | 103 trianglemesh.indices = tris |
104 # build a single-object scene graph | 104 # build a single-object scene graph |
105 var triangle = new Thing | 105 var triangle = new Thing |
106 # add the triangle mesh to the object | 106 # add the triangle mesh to the object |