From 2c98e88daee38b71bb26373d47d1be3e9fae7d36 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 23 Sep 2010 17:09:35 +0000 Subject: [PATCH] updated checkerpick.lua test script, moved it into lib/demo git-svn-id: svn://anubis/anaglym/trunk@322 99a6e188-d820-4881-8870-2d33a10e2619 --- lib/demo/checkerpick.lua | 42 ++++++++++++++++++++++++++++++++++++++++ tests/checkerpick.lua | 25 ------------------------ 2 files changed, 42 insertions(+), 25 deletions(-) create mode 100644 lib/demo/checkerpick.lua delete mode 100644 tests/checkerpick.lua diff --git a/lib/demo/checkerpick.lua b/lib/demo/checkerpick.lua new file mode 100644 index 0000000..6b91c5f --- /dev/null +++ b/lib/demo/checkerpick.lua @@ -0,0 +1,42 @@ +function init_event() + local checker_texture = ag.loadTexture("checker.jpg") + + checker_box = ag.createBox(8, 8, 0.1, {static = true}) + checker_box:setPosition(0, 0, 0.1/2) + checker_box:setTexture(checker_texture) + checker_box:setTextureScale(2) + + hilite = ag.createBox(1, 1, 0.1, {static = true, enable_blending = true}) + hilite:setColor(0.3, 0.5, 1) + hilite:setPosition(1.5, 1.5, 0.15) + hilite:setTransparency(0.4) + + ag.setCamera(4, -8, 8, 0, 0, 0) + ag.setCursorVisible(true) +end + +function mouse_motion_event(x, y, xrel, yrel) + local hit = ag.pickOne(x, y, checker_box) + if hit then + local cx, cy = checker_box:getPosition() + local sx, sy = checker_box:getSize() + local px = checker_box.pick_pos[1] + local py = checker_box.pick_pos[2] + local x_coord = math.floor((px - cx + sx / 2) * 8 / sx) + local y_coord = math.floor((py - cy + sy / 2) * 8 / sy) + if x_coord >= 0 and x_coord <= 7 and y_coord >= 0 and y_coord <= 7 then + hilite:setPosition((x_coord - 3.5) * sx / 8 + cx, + (y_coord - 3.5) * sy / 8 + cy, 0.15) + end + end +end + +function mousebutton_down_event(button, x, y) + if (button == 1) then + local spawnSphere = ag.createSphere(0.45) + spawnSphere:setColor(math.random(), math.random(), math.random()) + local hlx, hly = hilite:getPosition() + spawnSphere:setPosition(hlx, hly, 0.6) + spawnSphere:addForce(0, 0, 100) + end +end diff --git a/tests/checkerpick.lua b/tests/checkerpick.lua deleted file mode 100644 index 927cc7d..0000000 --- a/tests/checkerpick.lua +++ /dev/null @@ -1,25 +0,0 @@ -function init_event() - local checker_texture = ag.loadTexture("checker.jpg") - ground = ag.createBox(8, 8, 0.1, {static = true}) - ground:setTexture(checker_texture) - ag.setCamera(10, -10, 10, 0, 0, 0) - hilite = ag.createBox(2, 2, 0.1, {static = true, enable_blending = true}) - hilite:setColor(0.3, 0.5, 1) - hilite:setPosition(1, 1, 0.1) - hilite:setTransparency(0.4) - - ag.setCursorVisible(true) -end - -function mouse_motion_event(x, y, xrel, yrel) - local hit = ag.pickOne(x, y, ground) - if hit then - x = ground.pick_pos[1] - y = ground.pick_pos[2] - xp = 2 * math.floor(x / 2) + 1 - yp = 2 * math.floor(y / 2) + 1 - if xp >= -3 and xp <= 3 and yp >= -3 and yp <= 3 then - hilite:setPosition(xp, yp, 0.1) - end - end -end