From 2c593fa96845d23dddce3107fff66e181d4794e3 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 18 Nov 2010 08:54:29 -0500 Subject: [PATCH] grid picking in place --- anaglymtd.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/anaglymtd.lua b/anaglymtd.lua index 1d4d641..37d2ca9 100644 --- a/anaglymtd.lua +++ b/anaglymtd.lua @@ -1,6 +1,8 @@ ag.import("std") +td = {mx = 0, my = 0, picking = false} + function init_event() ground = std.createPlanePointNormal(0, 0, 0, 0, 0, 1) ground:setColor(0, 1, 0) @@ -11,7 +13,15 @@ function init_event() grid:setTexture(grid_texture) grid:setOffset(1) + grid_selector = ag.createQuad(0, 0, 0, 0.5, 0, 0, 0, 0.5, 0) + grid_selector:setVisible(false) + grid_selector:setColor(0, 0, 1, 0.5) + grid_selector:setBlending(true) + grid_selector:setOffset(2) + ag.setCamera(2, -12, 10) + + ag.setCursorVisible(true) end function key_down_event(k) @@ -19,3 +29,23 @@ function key_down_event(k) ag.exit() end end + +function update_event() + hit = ag.pickOne(td.mx, td.my, ground) + if (hit) then + local px = ground.pick_pos[1] + local py = ground.pick_pos[2] + local x_coord = math.floor(px + 8) + local y_coord = math.floor(py + 8) + td.picking = (x_coord >= 0 and x_coord <= 15 and y_coord >= 0 and y_coord <= 15) + if (td.picking) then + grid_selector:setPosition(x_coord - 7.5, y_coord - 7.5, 0) + end + end + grid_selector:setVisible(td.picking) +end + +function mouse_motion_event(x, y) + td.mx = x + td.my = y +end