anaglym/ag.lua
Josh Holtrop 50cb363151 added setAMotorAxis
git-svn-id: svn://anubis/anaglym/trunk@235 99a6e188-d820-4881-8870-2d33a10e2619
2010-01-31 01:48:33 +00:00

85 lines
1.9 KiB
Lua

next = ag.next
type = ag.type
pairs = function(table)
return next, table, nil
end
ipairs = function(table)
local iter_func = function(t, i)
i = i + 1
if t[i] == nil then
return nil
else
return i, t[i]
end
end
return iter_func, table, 0
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
amotor:setAxis(rel, x, y, z)
end
local o1 = obj1
local o2 = obj2
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 amotor = ag._createAMotor(obj1, obj2)
if (axis0 ~= nil) then
setAMotorAxis(amotor, 0, axis0)
num_axes = 1
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)
return amotor
end