From 724622e094e97f7621b2359a14ff69f72766cc26 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 19 Oct 2009 02:53:58 +0000 Subject: [PATCH] add absolute/relative force/torque addition functions git-svn-id: svn://anubis/anaglym/trunk@102 99a6e188-d820-4881-8870-2d33a10e2619 --- Engine.h | 16 +++++++++ ag.cc | 84 ++++++++++++++++++++++++++++++++++++++++++++ ag.h | 4 +++ tests/ballstairs.lua | 2 ++ 4 files changed, 106 insertions(+) diff --git a/Engine.h b/Engine.h index 032c4f4..0f26103 100644 --- a/Engine.h +++ b/Engine.h @@ -35,6 +35,22 @@ class Engine } void setVisible(bool visible) { m_is_visible = visible; } bool getVisible() { return m_is_visible; } + void addForce(dReal fx, dReal fy, dReal fz) + { + m_ode_object->addForce(fx, fy, fz); + } + void addRelForce(dReal fx, dReal fy, dReal fz) + { + m_ode_object->addRelForce(fx, fy, fz); + } + void addTorque(dReal fx, dReal fy, dReal fz) + { + m_ode_object->addTorque(fx, fy, fz); + } + void addRelTorque(dReal fx, dReal fy, dReal fz) + { + m_ode_object->addRelTorque(fx, fy, fz); + } void draw(); diff --git a/ag.cc b/ag.cc index 13d1a72..32401b4 100644 --- a/ag.cc +++ b/ag.cc @@ -123,6 +123,14 @@ namespace ag lua_setfield(L, -2, "destroy"); lua_pushcfunction(L, object::setVisible); lua_setfield(L, -2, "setVisible"); + lua_pushcfunction(L, object::addForce); + lua_setfield(L, -2, "addForce"); + lua_pushcfunction(L, object::addRelForce); + lua_setfield(L, -2, "addRelForce"); + lua_pushcfunction(L, object::addTorque); + lua_setfield(L, -2, "addTorque"); + lua_pushcfunction(L, object::addRelTorque); + lua_setfield(L, -2, "addRelTorque"); } static int loadModelSpecify(lua_State * L, bool static_data) @@ -393,5 +401,81 @@ namespace ag } return 0; } + + int addForce(lua_State * L) + { + int argc = lua_gettop(L); + if (argc == 4) + { + Engine::Object * obj = getObject(L, 1); + if (obj != NULL && + lua_isnumber(L, 2) && + lua_isnumber(L, 3) && + lua_isnumber(L, 4)) + { + obj->addForce(lua_tonumber(L, 2), + lua_tonumber(L, 3), + lua_tonumber(L, 4)); + } + } + return 0; + } + + int addRelForce(lua_State * L) + { + int argc = lua_gettop(L); + if (argc == 4) + { + Engine::Object * obj = getObject(L, 1); + if (obj != NULL && + lua_isnumber(L, 2) && + lua_isnumber(L, 3) && + lua_isnumber(L, 4)) + { + obj->addRelForce(lua_tonumber(L, 2), + lua_tonumber(L, 3), + lua_tonumber(L, 4)); + } + } + return 0; + } + + int addTorque(lua_State * L) + { + int argc = lua_gettop(L); + if (argc == 4) + { + Engine::Object * obj = getObject(L, 1); + if (obj != NULL && + lua_isnumber(L, 2) && + lua_isnumber(L, 3) && + lua_isnumber(L, 4)) + { + obj->addTorque(lua_tonumber(L, 2), + lua_tonumber(L, 3), + lua_tonumber(L, 4)); + } + } + return 0; + } + + int addRelTorque(lua_State * L) + { + int argc = lua_gettop(L); + if (argc == 4) + { + Engine::Object * obj = getObject(L, 1); + if (obj != NULL && + lua_isnumber(L, 2) && + lua_isnumber(L, 3) && + lua_isnumber(L, 4)) + { + obj->addRelTorque(lua_tonumber(L, 2), + lua_tonumber(L, 3), + lua_tonumber(L, 4)); + } + } + return 0; + } } } diff --git a/ag.h b/ag.h index 557f395..f7a36d3 100644 --- a/ag.h +++ b/ag.h @@ -32,6 +32,10 @@ namespace ag int clone(lua_State * L); int destroy(lua_State * L); int setVisible(lua_State * L); + int addForce(lua_State * L); + int addRelForce(lua_State * L); + int addTorque(lua_State * L); + int addRelTorque(lua_State * L); } } diff --git a/tests/ballstairs.lua b/tests/ballstairs.lua index b64ff4e..65fce3d 100755 --- a/tests/ballstairs.lua +++ b/tests/ballstairs.lua @@ -10,6 +10,8 @@ end function key_pressed_event(key) if (key == "d") then ball2:destroy() + elseif (key == "p") then + ball:addForce(-10000, 0, 0) end end