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:
parent
50cb363151
commit
f07e0b69f3
27
ag.cc
27
ag.cc
@ -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
1
ag.h
@ -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);
|
||||||
|
9
ag.lua
9
ag.lua
@ -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,8 +62,9 @@ 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 (amotor ~= nil) then
|
||||||
if (axis0 ~= nil) then
|
if (axis0 ~= nil) then
|
||||||
setAMotorAxis(amotor, 0, axis0)
|
setAMotorAxis(amotor, 0, axis0)
|
||||||
num_axes = 1
|
num_axes = 1
|
||||||
@ -76,8 +77,10 @@ ag.createAMotor = function(obj1, obj2, axis0, axis1, axis2)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
amotor:setNumAxes(num_axes)
|
amotor:setNumAxes(num_axes)
|
||||||
|
else
|
||||||
|
ag.println("Error creating AMotor!")
|
||||||
|
end
|
||||||
|
|
||||||
return amotor
|
return amotor
|
||||||
end
|
end
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user