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 },
{ "clearWorld", clearWorld },
{ "_createAMotor", _createAMotor },
/* managed object functions */
{ "createBox", createBox },
{ "createBoxStatic", createBoxStatic },
@ -277,6 +279,8 @@ namespace ag
lua_setfield(L, -2, "setBounce");
lua_pushcfunction(L, joint::setAMotorAxis);
lua_setfield(L, -2, "setAxis");
lua_pushcfunction(L, joint::setAMotorNumAxes);
lua_setfield(L, -2, "setNumAxes");
}
int _createAMotor(lua_State * L)
@ -286,9 +290,12 @@ namespace ag
{
Engine::Object * o1 = object::getObject(L, 1);
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;
}
}
@ -1291,6 +1298,22 @@ namespace ag
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 argc = lua_gettop(L);

1
ag.h
View File

@ -92,6 +92,7 @@ namespace ag
namespace joint
{
int setAMotorAxis(lua_State * L);
int setAMotorNumAxes(lua_State * L);
int setAMotorLoStop(lua_State * L);
int setAMotorHiStop(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)
end
end
amotor:setAxis(rel, x, y, z)
amotor:setAxis(anum, rel, x, y, z)
end
local o1 = obj1
@ -62,23 +62,26 @@ ag.createAMotor = function(obj1, obj2, axis0, axis1, axis2)
end
end
local amotor = ag._createAMotor(obj1, obj2)
local amotor = ag._createAMotor(o1, o2)
if (axis0 ~= nil) then
setAMotorAxis(amotor, 0, axis0)
num_axes = 1
if (axis1 ~= nil) then
setAMotorAxis(amotor, 1, axis1)
if (amotor ~= nil) then
if (axis0 ~= nil) then
setAMotorAxis(amotor, 0, axis0)
num_axes = 1
if (axis2 ~= nil) then
setAMotorAxis(amotor, 2, axis2)
num_axes = 2
if (axis1 ~= nil) then
setAMotorAxis(amotor, 1, axis1)
num_axes = 1
if (axis2 ~= nil) then
setAMotorAxis(amotor, 2, axis2)
num_axes = 2
end
end
end
amotor:setNumAxes(num_axes)
else
ag.println("Error creating AMotor!")
end
amotor:setNumAxes(num_axes)
return amotor
end

View File

@ -37,5 +37,11 @@ function key_down_event(key)
init_obj(sphere)
elseif (key == "q") then
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