summaryrefslogtreecommitdiff
path: root/main.lua
blob: 2542910bda56e43ba2dbc4380152bf0ce5343efb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
require 'honey.std'

local gl = honey.gl

-- initialize honey
honey.init()


local db = honey.ecs.EntityDb()
local systems = honey.ecs.SystemDb(db)
local space = honey.ode.HashSpaceCreate(honey.ode.Space0)

systems:addSystems(honey.ecs.node.system)
systems:addSystems(honey.ecs.render.system, {drawGeoms=true})
systems:addSystems(honey.ecs.script.system)
systems:addSystems(honey.ecs.collision.system, { space=space })

-- camera
db:createEntityWithComponents{
	node = {
		matrix = Mat4()
			:identity()
			:translate(Vec3{0,0,4}),
	},
	camera = {
		projection = Mat4()
			:perspective(90, 640/480, 0.1, 1000)
	},
}

-- skybox
db:createEntityWithComponents{
	node = {
		matrix = Mat4()
			:identity(),
	},
	renderMesh = {
		mesh = {
			filename = "assets/skybox.obj",
			index = 1,
		},
		uniforms = {
			textures = {
				surface = { filename = "starfield2.png" },
			},
		},
		shader = { vertex = "builtin.basic3d.vert", fragment = "builtin.flat.frag" },
	},
}

-- mesh
db:createEntityWithComponents{
	node = {
		matrix = Mat4()
			:identity(),
	},
	renderMesh = {
		mesh = {
			filename = "builtin.tube",
			index = 1,
		},
		uniforms = {
			textures = {
				ourTexture = { filename = "assets/green-grass.jpg" },
			},
		},
		shader = { vertex="vertex.glsl", fragment="fragment.glsl" },
	},
	collision = {
		class = "capsule",
		radius = 1,
		length = 2,
		lx = 2,
		ly = 2,
		lz = 2,
	},
	script = { script = "scripts.rotate" },
}

honey.loop(function(dt)
	gl.ClearColor(0xa/0xff, 0x10/0xff, 0x1f/0xff, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT + gl.DEPTH_BUFFER_BIT + gl.STENCIL_BUFFER_BIT)
	systems:update(dt)
end)

-- clean up
honey.terminate()