summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-05-18 22:23:42 -0500
committersanine <sanine.not@pm.me>2023-05-18 22:23:42 -0500
commiteafff1e04eb7f6a63818db035d2c6a277c5c364c (patch)
treec32d7bb4fde9408539d13ce43dc0ff4824765412
parent4b2507b2f30d50c8673f33179c2b537ac83da3bf (diff)
visualize collisionsrefactor
-rw-r--r--honey/ecs/collision.lua6
-rw-r--r--honey/ecs/render.lua1
-rw-r--r--main.lua34
-rw-r--r--scripts/collide.lua3
-rw-r--r--scripts/update.lua6
5 files changed, 43 insertions, 7 deletions
diff --git a/honey/ecs/collision.lua b/honey/ecs/collision.lua
index b385e76..54598cb 100644
--- a/honey/ecs/collision.lua
+++ b/honey/ecs/collision.lua
@@ -59,7 +59,7 @@ local function updateGeom(collision)
elseif class == "cylinder" then
ode.GeomCylinderSetParams(geom, collision.radius, collision.length)
elseif class == "ray" then
- GeomRaySetLength(geom, collision.length)
+ ode.GeomRaySetLength(geom, collision.length)
end
end
@@ -121,8 +121,8 @@ local updateTransform = ecs.System("collisionTransform", function(db, dt, p)
local collisions = ode.Collide(geomA, geomB, p.maxPoints or 1)
if #collisions > 0 then
-- get entity ids
- local idA = ode.GetData(geomA)
- local idB = ode.GetData(geomB)
+ local idA = ode.GeomGetData(geomA)
+ local idB = ode.GeomGetData(geomB)
-- run handlers, if any
runCollisionScript(db, idA, idB, collisions)
diff --git a/honey/ecs/render.lua b/honey/ecs/render.lua
index 1c38692..8ee6e8f 100644
--- a/honey/ecs/render.lua
+++ b/honey/ecs/render.lua
@@ -123,6 +123,7 @@ local function drawGeoms(db, view, projection)
drawMesh(program, uniforms, matrices, vao, count)
elseif tbl.class == "ray" then
m:scale(Vec3{0.001, 0.001, tbl.length})
+ :translate(Vec3{0, 0, 1/2})
local vao, count = mesh.get("builtin.cube", 1)
drawMesh(program, uniforms, matrices, vao, count)
end
diff --git a/main.lua b/main.lua
index 2542910..f5237a5 100644
--- a/main.lua
+++ b/main.lua
@@ -48,11 +48,23 @@ db:createEntityWithComponents{
},
}
+
+local parent = db:createEntityWithComponents{
+ node = {
+ matrix = Mat4()
+ :identity()
+ },
+ script = { script = "scripts.update" },
+}
+
-- mesh
db:createEntityWithComponents{
node = {
+ parent = parent,
matrix = Mat4()
- :identity(),
+ :identity()
+ :rotateX(0.5*math.pi)
+ :rotateZ(0.5*math.pi)
},
renderMesh = {
mesh = {
@@ -67,14 +79,28 @@ db:createEntityWithComponents{
shader = { vertex="vertex.glsl", fragment="fragment.glsl" },
},
collision = {
- class = "capsule",
+ class = "ray",
radius = 1,
- length = 2,
+ length = 4,
lx = 2,
ly = 2,
lz = 2,
},
- script = { script = "scripts.rotate" },
+ onCollision = { script = "scripts.collide" },
+}
+
+
+-- box?
+db:createEntityWithComponents{
+ node = {
+ matrix = Mat4()
+ :identity()
+ :translate(Vec3{0,-3,0})
+ },
+ collision = {
+ class = "box",
+ lx = 1, ly=1, lz=1,
+ },
}
honey.loop(function(dt)
diff --git a/scripts/collide.lua b/scripts/collide.lua
new file mode 100644
index 0000000..382f5d7
--- /dev/null
+++ b/scripts/collide.lua
@@ -0,0 +1,3 @@
+return function(db, id, other, collisions)
+ print(honey.glfw.GetTime(), "collide with: ", other)
+end
diff --git a/scripts/update.lua b/scripts/update.lua
new file mode 100644
index 0000000..906fc17
--- /dev/null
+++ b/scripts/update.lua
@@ -0,0 +1,6 @@
+return function(db, id, dt)
+ local node = db:getComponent(id, "node")
+ --local t = honey.glfw.GetTime()
+ --node.matrix[2][4] = 2*math.sin(2*t)
+ node.matrix:rotateZ(math.pi*dt)
+end