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
88
89
90
91
92
93
94
95
96
97
|
require 'honey.std'
return function(db)
local capsule = db:createEntityWithComponents{
node = {
matrix = Mat4()
:identity()
:translate(Vec3{0,10,0})
:rotateX(0.5*math.pi)
},
collision = {
class = "capsule",
radius = 1,
length = 2,
category = 2,
collide = bit.bxor(0xffffffff, 2)
},
physics = {
mass = {
class = "capsule",
mass = 10,
direction = 3,
radius = 1,
length = 2,
},
surface = true,
maxAngularSpeed = 0,
},
renderMesh = {
mesh = { filename="assets/capsule.obj", index=1 },
shader = { vertex="vertex.glsl", fragment="fragment.glsl" },
textures = {
ourTexture = { filename = "assets/green-grass.jpg" },
},
},
script = { script = "scripts.capsuleMove" },
}
local spring = db:createEntityWithComponents{
node = {
name = "spring",
parent = capsule,
matrix = Mat4():identity()
:translate(Vec3{0,-1,0})
},
collision = {
class = "ray",
length = 4,
category = 2,
collide = bit.bxor(0xffffffff, 2)
},
onCollision = {
script = "scripts.character.spring",
},
spring = {
F = 0,
}
}
local pivotPivot = db:createEntityWithComponents{
node = {
name = "p",
parent = capsule,
matrix = Mat4():identity():rotateX(-0.5*math.pi),
},
}
local capcamPivot = db:createEntityWithComponents{
node = {
name = "pivot",
parent = pivotPivot,
matrix = Mat4():identity(),
},
pitchyaw = {
pitch = 0,
yaw = 0,
},
onCursorPos = { script = "scripts.cameraPivot" },
}
local capcam = db:createEntityWithComponents{
camera = {
projection = Mat4():perspective(math.rad(45), 640/480, 0.1, 1000),
render="screen",
},
node = {
parent = capcamPivot,
matrix = Mat4():identity():translate(Vec3{0,0,20}),
},
onScroll = { script = "scripts.character.cameraDistance" },
onFramebufferSize = { script = "scripts.cameraHandleResize" },
}
end
|