compiling again after adding AMotor functions

git-svn-id: svn://anubis/anaglym/trunk@234 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2010-01-31 01:29:19 +00:00
parent f8db43ff2e
commit 4ce1891cd1
4 changed files with 155 additions and 19 deletions

View File

@ -306,12 +306,60 @@ int Engine::addAMotor(Object * o1, Object * o2)
b1 = o1->getBody(); b1 = o1->getBody();
if (o2 != NULL) if (o2 != NULL)
b2 = o2->getBody(); b2 = o2->getBody();
dJointID j = dJointCreateAMotor(m_world.getWorldID(), 0); dJointID jid = m_world.createAMotor(b1, b2);
int id = m_next_joint_index++; int id = m_next_joint_index++;
m_joints[id] = j; m_joints[id] = jid;
return id; return id;
} }
void Engine::setAMotorNumAxes(int jid, int num_axes)
{
if (m_joints.find(jid) != m_joints.end())
{
m_world.setAMotorNumAxes(m_joints[jid], num_axes);
}
}
void Engine::setAMotorLoStop(int jid, dReal val)
{
if (m_joints.find(jid) != m_joints.end())
{
m_world.setAMotorLoStop(m_joints[jid], val);
}
}
void Engine::setAMotorHiStop(int jid, dReal val)
{
if (m_joints.find(jid) != m_joints.end())
{
m_world.setAMotorHiStop(m_joints[jid], val);
}
}
void Engine::setAMotorVel(int jid, dReal val)
{
if (m_joints.find(jid) != m_joints.end())
{
m_world.setAMotorVel(m_joints[jid], val);
}
}
void Engine::setAMotorFMax(int jid, dReal val)
{
if (m_joints.find(jid) != m_joints.end())
{
m_world.setAMotorFMax(m_joints[jid], val);
}
}
void Engine::setAMotorBounce(int jid, dReal val)
{
if (m_joints.find(jid) != m_joints.end())
{
m_world.setAMotorBounce(m_joints[jid], val);
}
}
void Engine::removeObject(int id) void Engine::removeObject(int id)
{ {
Object * obj = getObject(id); Object * obj = getObject(id);

View File

@ -125,6 +125,12 @@ class Engine
int addObject(bool is_static, OdeWorld::GeomType geom_type, int addObject(bool is_static, OdeWorld::GeomType geom_type,
refptr< std::vector<float> > args); refptr< std::vector<float> > args);
int addAMotor(Object * o1, Object * o2); int addAMotor(Object * o1, Object * o2);
void setAMotorNumAxes(int jid, int num_axes);
void setAMotorLoStop(int jid, dReal val);
void setAMotorHiStop(int jid, dReal val);
void setAMotorVel(int jid, dReal val);
void setAMotorFMax(int jid, dReal val);
void setAMotorBounce(int jid, dReal val);
void removeObject(int id); void removeObject(int id);
int cloneObject(const Object * obj); int cloneObject(const Object * obj);
Object * getObject(int id); Object * getObject(int id);

101
ag.cc
View File

@ -260,23 +260,40 @@ namespace ag
lua_setfield(L, -2, "getSize"); lua_setfield(L, -2, "getSize");
} }
static void createLuaJoint(lua_State * L, int id) static void createLuaAMotor(lua_State * L, int id)
{ {
lua_newtable(L); lua_newtable(L);
lua_pushinteger(L, id); lua_pushinteger(L, id);
lua_setfield(L, -2, "id"); lua_setfield(L, -2, "id");
lua_pushcfunction(L, joint::setLoStop); lua_pushcfunction(L, joint::setAMotorLoStop);
lua_setfield(L, -2, "setLoStop"); lua_setfield(L, -2, "setLoStop");
lua_pushcfunction(L, joint::setHiStop); lua_pushcfunction(L, joint::setAMotorHiStop);
lua_setfield(L, -2, "setHiStop"); lua_setfield(L, -2, "setHiStop");
lua_pushcfunction(L, joint::setVel); lua_pushcfunction(L, joint::setAMotorVel);
lua_setfield(L, -2, "setVel"); lua_setfield(L, -2, "setVel");
lua_pushcfunction(L, joint::setFMax); lua_pushcfunction(L, joint::setAMotorFMax);
lua_setfield(L, -2, "setFMax"); lua_setfield(L, -2, "setFMax");
lua_pushcfunction(L, joint::setBounce); lua_pushcfunction(L, joint::setAMotorBounce);
lua_setfield(L, -2, "setBounce"); lua_setfield(L, -2, "setBounce");
} }
int _createAMotor(lua_State * L)
{
int argc = lua_gettop(L);
if (argc == 2)
{
Engine::Object * o1 = object::getObject(L, 1);
Engine::Object * o2 = object::getObject(L, 2);
if (o1 != NULL && o2 != NULL)
{
lua_pushinteger(L, g_engine->addAMotor(o1, o2));
return 1;
}
}
lua_pushnil(L);
return 1;
}
static int loadModelSpecify(lua_State * L, bool static_data) static int loadModelSpecify(lua_State * L, bool static_data)
{ {
bool added = false; bool added = false;
@ -885,7 +902,7 @@ namespace ag
namespace object namespace object
{ {
static Engine::Object * getObject(lua_State * L, int index) Engine::Object * getObject(lua_State * L, int index)
{ {
Engine::Object * ret = NULL; Engine::Object * ret = NULL;
@ -1245,24 +1262,84 @@ namespace ag
namespace joint namespace joint
{ {
int setLoStop(lua_State * L) int setAMotorLoStop(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->setAMotorLoStop(jid, lua_tonumber(L, 2));
}
lua_pop(L, 1);
}
return 0;
} }
int setHiStop(lua_State * L) int setAMotorHiStop(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->setAMotorHiStop(jid, lua_tonumber(L, 2));
}
lua_pop(L, 1);
}
return 0;
} }
int setVel(lua_State * L) int setAMotorVel(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->setAMotorVel(jid, lua_tonumber(L, 2));
}
lua_pop(L, 1);
}
return 0;
} }
int setFMax(lua_State * L) int setAMotorFMax(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->setAMotorFMax(jid, lua_tonumber(L, 2));
}
lua_pop(L, 1);
}
return 0;
} }
int setBounce(lua_State * L) int setAMotorBounce(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->setAMotorBounce(jid, lua_tonumber(L, 2));
}
lua_pop(L, 1);
}
return 0;
} }
} }
} }

15
ag.h
View File

@ -3,6 +3,7 @@
#define AG_H #define AG_H
#include <lua.hpp> #include <lua.hpp>
#include "Engine.h"
namespace ag namespace ag
{ {
@ -40,6 +41,8 @@ namespace ag
int type(lua_State * L); int type(lua_State * L);
int clearWorld(lua_State * L); int clearWorld(lua_State * L);
int _createAMotor(lua_State * L);
/* 2D overlay functions */ /* 2D overlay functions */
int drawArc(lua_State * L); int drawArc(lua_State * L);
int drawCircle(lua_State * L); int drawCircle(lua_State * L);
@ -64,6 +67,8 @@ namespace ag
namespace object namespace object
{ {
Engine::Object * getObject(lua_State * L, int index);
int draw(lua_State * L); int draw(lua_State * L);
int setPosition(lua_State * L); int setPosition(lua_State * L);
int getPosition(lua_State * L); int getPosition(lua_State * L);
@ -86,11 +91,11 @@ namespace ag
namespace joint namespace joint
{ {
int setLoStop(lua_State * L); int setAMotorLoStop(lua_State * L);
int setHiStop(lua_State * L); int setAMotorHiStop(lua_State * L);
int setVel(lua_State * L); int setAMotorVel(lua_State * L);
int setFMax(lua_State * L); int setAMotorFMax(lua_State * L);
int setBounce(lua_State * L); int setAMotorBounce(lua_State * L);
} }
} }