adding AMotors works! added test to managed_objects.lua

git-svn-id: svn://anubis/anaglym/trunk@236 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2010-01-31 02:19:37 +00:00
parent 50cb363151
commit f07e0b69f3
4 changed files with 47 additions and 14 deletions

27
ag.cc
View File

@ -62,6 +62,8 @@ namespace ag
{ "type", type }, { "type", type },
{ "clearWorld", clearWorld }, { "clearWorld", clearWorld },
{ "_createAMotor", _createAMotor },
/* managed object functions */ /* managed object functions */
{ "createBox", createBox }, { "createBox", createBox },
{ "createBoxStatic", createBoxStatic }, { "createBoxStatic", createBoxStatic },
@ -277,6 +279,8 @@ namespace ag
lua_setfield(L, -2, "setBounce"); lua_setfield(L, -2, "setBounce");
lua_pushcfunction(L, joint::setAMotorAxis); lua_pushcfunction(L, joint::setAMotorAxis);
lua_setfield(L, -2, "setAxis"); lua_setfield(L, -2, "setAxis");
lua_pushcfunction(L, joint::setAMotorNumAxes);
lua_setfield(L, -2, "setNumAxes");
} }
int _createAMotor(lua_State * L) int _createAMotor(lua_State * L)
@ -286,9 +290,12 @@ namespace ag
{ {
Engine::Object * o1 = object::getObject(L, 1); Engine::Object * o1 = object::getObject(L, 1);
Engine::Object * o2 = object::getObject(L, 2); Engine::Object * o2 = object::getObject(L, 2);
if (o1 != NULL && o2 != NULL) /* it is ok if o1 or o2 are NULL, this means that the motor
* is connected to the global environment */
int jid = g_engine->addAMotor(o1, o2);
if (jid != 0)
{ {
lua_pushinteger(L, g_engine->addAMotor(o1, o2)); createLuaAMotor(L, jid);
return 1; return 1;
} }
} }
@ -1291,6 +1298,22 @@ namespace ag
return 0; return 0;
} }
int setAMotorNumAxes(lua_State * L)
{
int argc = lua_gettop(L);
if (argc == 2 && lua_istable(L, 1) && lua_isnumber(L, 2))
{
lua_getfield(L, 1, "id");
if (lua_isnumber(L, -1))
{
int jid = lua_tointeger(L, -1);
g_engine->setAMotorNumAxes(jid, lua_tointeger(L, 2));
}
lua_pop(L, 1);
}
return 0;
}
int setAMotorLoStop(lua_State * L) int setAMotorLoStop(lua_State * L)
{ {
int argc = lua_gettop(L); int argc = lua_gettop(L);

1
ag.h
View File

@ -92,6 +92,7 @@ namespace ag
namespace joint namespace joint
{ {
int setAMotorAxis(lua_State * L); int setAMotorAxis(lua_State * L);
int setAMotorNumAxes(lua_State * L);
int setAMotorLoStop(lua_State * L); int setAMotorLoStop(lua_State * L);
int setAMotorHiStop(lua_State * L); int setAMotorHiStop(lua_State * L);
int setAMotorVel(lua_State * L); int setAMotorVel(lua_State * L);

27
ag.lua
View File

@ -43,7 +43,7 @@ ag.createAMotor = function(obj1, obj2, axis0, axis1, axis2)
amotor:setBounce(v) amotor:setBounce(v)
end end
end end
amotor:setAxis(rel, x, y, z) amotor:setAxis(anum, rel, x, y, z)
end end
local o1 = obj1 local o1 = obj1
@ -62,23 +62,26 @@ ag.createAMotor = function(obj1, obj2, axis0, axis1, axis2)
end end
end end
local amotor = ag._createAMotor(obj1, obj2) local amotor = ag._createAMotor(o1, o2)
if (axis0 ~= nil) then if (amotor ~= nil) then
setAMotorAxis(amotor, 0, axis0) if (axis0 ~= nil) then
num_axes = 1 setAMotorAxis(amotor, 0, axis0)
if (axis1 ~= nil) then
setAMotorAxis(amotor, 1, axis1)
num_axes = 1 num_axes = 1
if (axis2 ~= nil) then if (axis1 ~= nil) then
setAMotorAxis(amotor, 2, axis2) setAMotorAxis(amotor, 1, axis1)
num_axes = 2 num_axes = 1
if (axis2 ~= nil) then
setAMotorAxis(amotor, 2, axis2)
num_axes = 2
end
end end
end end
amotor:setNumAxes(num_axes)
else
ag.println("Error creating AMotor!")
end end
amotor:setNumAxes(num_axes)
return amotor return amotor
end end

View File

@ -37,5 +37,11 @@ function key_down_event(key)
init_obj(sphere) init_obj(sphere)
elseif (key == "q") then elseif (key == "q") then
ag.exit() ag.exit()
elseif (key == "r") then
-- creating a rotating cube
local box = ag.createBox(1, 1, 1)
init_obj(box)
ag.createAMotor(0, box,
{ x = 0, y = 0, z = 1, vel = 10, fmax = 10 })
end end
end end