diff --git a/ag.cc b/ag.cc index 7aa7e33..471f704 100644 --- a/ag.cc +++ b/ag.cc @@ -260,6 +260,23 @@ namespace ag lua_setfield(L, -2, "getSize"); } + static void createLuaJoint(lua_State * L, int id) + { + lua_newtable(L); + lua_pushinteger(L, id); + lua_setfield(L, -2, "id"); + lua_pushcfunction(L, joint::setLoStop); + lua_setfield(L, -2, "setLoStop"); + lua_pushcfunction(L, joint::setHiStop); + lua_setfield(L, -2, "setHiStop"); + lua_pushcfunction(L, joint::setVel); + lua_setfield(L, -2, "setVel"); + lua_pushcfunction(L, joint::setFMax); + lua_setfield(L, -2, "setFMax"); + lua_pushcfunction(L, joint::setBounce); + lua_setfield(L, -2, "setBounce"); + } + static int loadModelSpecify(lua_State * L, bool static_data) { bool added = false; @@ -1225,4 +1242,27 @@ namespace ag return 1; } } + + namespace joint + { + int setLoStop(lua_State * L) + { + } + + int setHiStop(lua_State * L) + { + } + + int setVel(lua_State * L) + { + } + + int setFMax(lua_State * L) + { + } + + int setBounce(lua_State * L) + { + } + } } diff --git a/ag.h b/ag.h index ac63c55..9454709 100644 --- a/ag.h +++ b/ag.h @@ -83,6 +83,15 @@ namespace ag int getAABB(lua_State * L); int getSize(lua_State * L); } + + namespace joint + { + int setLoStop(lua_State * L); + int setHiStop(lua_State * L); + int setVel(lua_State * L); + int setFMax(lua_State * L); + int setBounce(lua_State * L); + } } #endif diff --git a/ag.lua b/ag.lua index e1308d2..0a80775 100644 --- a/ag.lua +++ b/ag.lua @@ -1,5 +1,4 @@ next = ag.next - type = ag.type pairs = function(table) @@ -20,33 +19,65 @@ end ag.createAMotor = function(obj1, obj2, axis0, axis1, axis2) local function setAMotorAxis(amotor, anum, axis) + local rel, x, y, z, angle = 0, 1, 0, 0, 0 + for k, v in pairs(axis) do + if (k == "rel") then + rel = v + elseif (k == "x") then + x = v + elseif (k == "y") then + y = v + elseif (k == "z") then + z = v + elseif (k == "angle") then + angle = v + elseif (k == "lo_stop") then + amotor:setLoStop(v) + elseif (k == "hi_stop") then + amotor:setHiStop(v) + elseif (k == "vel") then + amotor:setVel(v) + elseif (k == "fmax") then + amotor:setFMax(v) + elseif (k == "bounce") then + amotor:setBounce(v) + end + end end + local o1 = obj1 local o2 = obj2 - local num_axes = 1 + local num_axes = 0 + if (type(obj1) == "number") then if (obj1 == 0) then o1 = { id = 0 } end end + if (type(obj2) == "number") then if (obj2 == 0) then o2 = { id = 0 } end end - local num_axes = 0 + + local amotor = ag._createAMotor(obj1, obj2) + if (axis0 ~= nil) then - setAMotorAxis(0, axis0) + setAMotorAxis(amotor, 0, axis0) num_axes = 1 if (axis1 ~= nil) then - setAMotorAxis(1, axis1) + setAMotorAxis(amotor, 1, axis1) num_axes = 1 if (axis2 ~= nil) then - setAMotorAxis(2, axis2) + setAMotorAxis(amotor, 2, axis2) num_axes = 2 end end end - ag.setAMotorNumAxes(num_axes) + + amotor:setNumAxes(num_axes) + + return amotor end