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
|
local module = {}
setmetatable(module, {__index=_G}
setfenv(1, module)
--===== collision =====--
Geom = {}
Geom.__index = Geom
function Geom.new(_, type, params)
local self = {}
self.type = type
self.params = params
setmetatable(self, Geom)
return self
end
setmetatable(Geom, {__call=Geom.new})
function Geom.renew(geom)
return ode.GeomGetData(geom)
end
local function instantiateSphere(space, params)
local geom = ode.CreateSphere(space, params.radius)
return geom
end
local function instantiatePlane(space, params)
local geom = ode.CreatePlane(space, params.a, params.b, params.c, params.d)
return geom
end
function Geom.instantiate(self, space)
if self.type == "sphere" then
self.geom = instantiateSphere(space, self.params)
elseif self.type == "plane" then
self.geom = instantiatePlane(space, self.params)
else
error(string.format("bad geom type: %s", self.type))
end
ode.GeomSetData(self.geom, self)
return self
end
function Geom.setBody(self, body)
ode.GeomSetBody(self.geom, body.body)
return self
end
|