diff --git a/Engine.h b/Engine.h index 8f6001d..5e2722a 100644 --- a/Engine.h +++ b/Engine.h @@ -68,8 +68,9 @@ class Engine render(); } void setTexture(GLuint tex); - void draw(); + dReal getMass() { return m_ode_object->getMass(); } + void setMass(dReal mass) { m_ode_object->setMass(mass); } protected: void createManagedObject(); diff --git a/ag.cc b/ag.cc index 70f9000..8b79c5d 100644 --- a/ag.cc +++ b/ag.cc @@ -158,6 +158,10 @@ namespace ag lua_setfield(L, -2, "setColor"); lua_pushcfunction(L, object::setTexture); lua_setfield(L, -2, "setTexture"); + lua_pushcfunction(L, object::setMass); + lua_setfield(L, -2, "setMass"); + lua_pushcfunction(L, object::getMass); + lua_setfield(L, -2, "getMass"); } static int loadModelSpecify(lua_State * L, bool static_data) @@ -807,5 +811,35 @@ namespace ag } return 0; } + + int getMass(lua_State * L) + { + int argc = lua_gettop(L); + if (argc == 1 && lua_istable(L, 1)) + { + Engine::Object * obj = getObject(L, 1); + if (obj != NULL) + { + lua_pushnumber(L, obj->getMass()); + return 1; + } + } + lua_pushnumber(L, 0); + return 1; + } + + int setMass(lua_State * L) + { + int argc = lua_gettop(L); + if (argc == 2 && lua_istable(L, 1) && lua_isnumber(L, 2)) + { + Engine::Object * obj = getObject(L, 1); + if (obj != NULL) + { + obj->setMass(lua_tonumber(L, 2)); + } + } + return 0; + } } } diff --git a/ag.h b/ag.h index ffb1207..5ad7f51 100644 --- a/ag.h +++ b/ag.h @@ -59,6 +59,8 @@ namespace ag int addRelTorque(lua_State * L); int setColor(lua_State * L); int setTexture(lua_State * L); + int getMass(lua_State * L); + int setMass(lua_State * L); } } diff --git a/tests/bowling.lua b/tests/bowling.lua index bda689d..16dc1ea 100644 --- a/tests/bowling.lua +++ b/tests/bowling.lua @@ -15,20 +15,21 @@ function init() local ground = ag.createPlane(0, 0, 1, 0) ground:setColor(0.8, 0.5, 0.0) ground:setPosition(0, 0, -10) - ag.setCamera(0, -25, 10, 0, 0, 1, 0, 0, 1) + ag.setCamera(0.3, -25, 10, 0, 0, 1, 0, 0, 1) camx, camy, camz, cx, cy, cz = ag.getCamera() ball = ag.loadModel("checkerball", 0.5) + ball:setPosition(2*camx - cx, 2*camy - cy, 2*camz - cz) + ball:setMass(5) --ball = ag.createSphere(0.4) --ball:setColor(0.2, 0.2, 0.9) - ball:setPosition(2*camx - cx, 2*camy - cy, 2*camz - cz) end function mousebutton_down_event(button) local function button1() local newball = ball:clone() newball:setPosition(camx, camy, 1) - force = 800 + force = 4000 newball:addForce(force * (cx-camx), force * (cy-camy), force * (cz-camz))