comparison examples/E04_input.nim @ 763:a4c757f5d17f

did: change API for ECS
author Sam <sam@basx.dev>
date Tue, 27 Jun 2023 00:17:40 +0700
parents dcc12ab20a91
children 754835bf175e
comparison
equal deleted inserted replaced
762:4f991bc3613a 763:a4c757f5d17f
133 indices= @[[0'u16, 1'u16, 2'u16], [2'u16, 3'u16, 0'u16]], 133 indices= @[[0'u16, 1'u16, 2'u16], [2'u16, 3'u16, 0'u16]],
134 ) 134 )
135 135
136 # define mesh objects 136 # define mesh objects
137 scene = newScene("scene", newEntity("scene")) 137 scene = newScene("scene", newEntity("scene"))
138 scene.root.add newEntity("background", backgroundmesh) 138 scene.root.add newEntity("background", {"mesh": Component(backgroundmesh)})
139 let keyboard = newEntity("keyboard", keyboardmesh) 139 let keyboard = newEntity("keyboard", {"mesh": Component(keyboardmesh)})
140 keyboard.transform = translate3d( 140 keyboard.transform = translate3d(
141 -float32(rowWidth) / 2'f32, 141 -float32(rowWidth) / 2'f32,
142 -float32(tupleLen(keyRows) * (keyDimension + keyGap) - keyGap) / 2'f32, 142 -float32(tupleLen(keyRows) * (keyDimension + keyGap) - keyGap) / 2'f32,
143 0'f32 143 0'f32
144 ) 144 )
145 scene.root.add newEntity("keyboard-center", keyboard) 145 scene.root.add newEntity("keyboard-center", [], keyboard)
146 scene.root.add newEntity("cursor", cursormesh) 146 scene.root.add newEntity("cursor", {"mesh": Component(cursormesh)})
147 147
148 # shaders 148 # shaders
149 const 149 const
150 vertexInput = @[ 150 vertexInput = @[
151 attr[Vec3f]("position"), 151 attr[Vec3f]("position"),
192 scene.root.firstWithName("background").transform = scale3d(float32(winsize[0]), float32(winsize[1]), 1'f32) 192 scene.root.firstWithName("background").transform = scale3d(float32(winsize[0]), float32(winsize[1]), 1'f32)
193 193
194 let mousePos = translate3d(myengine.mousePosition().x + 20, myengine.mousePosition().y + 20, 0'f32) 194 let mousePos = translate3d(myengine.mousePosition().x + 20, myengine.mousePosition().y + 20, 0'f32)
195 scene.root.firstWithName("cursor").transform = mousePos 195 scene.root.firstWithName("cursor").transform = mousePos
196 196
197 var mesh = Mesh(scene.root.firstWithName("keyboard").components[0]) 197 var mesh = Mesh(scene.root.firstWithName("keyboard")["mesh"])
198 for (index, key) in enumerate(keyIndices): 198 for (index, key) in enumerate(keyIndices):
199 if myengine.keyWasPressed(key): 199 if myengine.keyWasPressed(key):
200 let baseIndex = uint32(index * 4) 200 let baseIndex = uint32(index * 4)
201 mesh.updateMeshData("color", baseIndex + 0, activeColor) 201 mesh.updateMeshData("color", baseIndex + 0, activeColor)
202 mesh.updateMeshData("color", baseIndex + 1, activeColor) 202 mesh.updateMeshData("color", baseIndex + 1, activeColor)