summaryrefslogtreecommitdiff
path: root/honey/ecs/collision.lua
diff options
context:
space:
mode:
Diffstat (limited to 'honey/ecs/collision.lua')
-rw-r--r--honey/ecs/collision.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/honey/ecs/collision.lua b/honey/ecs/collision.lua
index 5c0452b..4c8af5b 100644
--- a/honey/ecs/collision.lua
+++ b/honey/ecs/collision.lua
@@ -25,8 +25,12 @@ local function createGeom(self, id, collision)
local d = normal:dot(position)
print(normal, d)
geom = ode.CreatePlane(self.space, normal[1], normal[2], normal[3], d)
+ elseif collision.class == "ray" then
+ geom = ode.CreateRay(self.space, collision.length)
end
+ ode.GeomSetCategoryBits(geom, collision.category or 1)
+ ode.GeomSetCollideBits(geom, collision.collide or 0xffffffff)
ode.GeomSetData(geom, id)
collision._geom = geom
@@ -36,6 +40,15 @@ local function createGeom(self, id, collision)
end)
end
+
+local function isPlaceable(collision)
+ if collision.class == "ray" then
+ return true
+ end
+ return false
+end
+
+
system = function(params)
local db = params.db
local space = params.space
@@ -50,6 +63,28 @@ system = function(params)
createGeom(self, id, collision)
print(id, collision._geom)
end
+ if
+ not self.db:getComponent(id, "physics") and
+ isPlaceable(collision)
+ then
+ -- no attached physics body, update position & orientation
+ -- from node transform
+ local node = self.db:getComponent(id, "node")
+ local m = node._matrix or node.matrix
+ local geom = collision._geom
+ ode.GeomSetPosition(
+ geom,
+ m[1][4],
+ m[2][4],
+ m[3][4]
+ )
+ ode.GeomSetRotation(
+ geom,
+ m[1][1], m[1][2], m[1][3],
+ m[2][1], m[2][2], m[2][3],
+ m[3][1], m[3][2], m[3][3]
+ )
+ end
end
end
}