added ag::object::getMass() and ag::object::setMass()

git-svn-id: svn://anubis/anaglym/trunk@179 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2009-11-17 00:44:47 +00:00
parent 2ec38be58c
commit dec24f3af5
4 changed files with 42 additions and 4 deletions

View File

@ -68,8 +68,9 @@ class Engine
render(); render();
} }
void setTexture(GLuint tex); void setTexture(GLuint tex);
void draw(); void draw();
dReal getMass() { return m_ode_object->getMass(); }
void setMass(dReal mass) { m_ode_object->setMass(mass); }
protected: protected:
void createManagedObject(); void createManagedObject();

34
ag.cc
View File

@ -158,6 +158,10 @@ namespace ag
lua_setfield(L, -2, "setColor"); lua_setfield(L, -2, "setColor");
lua_pushcfunction(L, object::setTexture); lua_pushcfunction(L, object::setTexture);
lua_setfield(L, -2, "setTexture"); lua_setfield(L, -2, "setTexture");
lua_pushcfunction(L, object::setMass);
lua_setfield(L, -2, "setMass");
lua_pushcfunction(L, object::getMass);
lua_setfield(L, -2, "getMass");
} }
static int loadModelSpecify(lua_State * L, bool static_data) static int loadModelSpecify(lua_State * L, bool static_data)
@ -807,5 +811,35 @@ namespace ag
} }
return 0; return 0;
} }
int getMass(lua_State * L)
{
int argc = lua_gettop(L);
if (argc == 1 && lua_istable(L, 1))
{
Engine::Object * obj = getObject(L, 1);
if (obj != NULL)
{
lua_pushnumber(L, obj->getMass());
return 1;
}
}
lua_pushnumber(L, 0);
return 1;
}
int setMass(lua_State * L)
{
int argc = lua_gettop(L);
if (argc == 2 && lua_istable(L, 1) && lua_isnumber(L, 2))
{
Engine::Object * obj = getObject(L, 1);
if (obj != NULL)
{
obj->setMass(lua_tonumber(L, 2));
}
}
return 0;
}
} }
} }

2
ag.h
View File

@ -59,6 +59,8 @@ namespace ag
int addRelTorque(lua_State * L); int addRelTorque(lua_State * L);
int setColor(lua_State * L); int setColor(lua_State * L);
int setTexture(lua_State * L); int setTexture(lua_State * L);
int getMass(lua_State * L);
int setMass(lua_State * L);
} }
} }

View File

@ -15,20 +15,21 @@ function init()
local ground = ag.createPlane(0, 0, 1, 0) local ground = ag.createPlane(0, 0, 1, 0)
ground:setColor(0.8, 0.5, 0.0) ground:setColor(0.8, 0.5, 0.0)
ground:setPosition(0, 0, -10) ground:setPosition(0, 0, -10)
ag.setCamera(0, -25, 10, 0, 0, 1, 0, 0, 1) ag.setCamera(0.3, -25, 10, 0, 0, 1, 0, 0, 1)
camx, camy, camz, cx, cy, cz = ag.getCamera() camx, camy, camz, cx, cy, cz = ag.getCamera()
ball = ag.loadModel("checkerball", 0.5) ball = ag.loadModel("checkerball", 0.5)
ball:setPosition(2*camx - cx, 2*camy - cy, 2*camz - cz)
ball:setMass(5)
--ball = ag.createSphere(0.4) --ball = ag.createSphere(0.4)
--ball:setColor(0.2, 0.2, 0.9) --ball:setColor(0.2, 0.2, 0.9)
ball:setPosition(2*camx - cx, 2*camy - cy, 2*camz - cz)
end end
function mousebutton_down_event(button) function mousebutton_down_event(button)
local function button1() local function button1()
local newball = ball:clone() local newball = ball:clone()
newball:setPosition(camx, camy, 1) newball:setPosition(camx, camy, 1)
force = 800 force = 4000
newball:addForce(force * (cx-camx), newball:addForce(force * (cx-camx),
force * (cy-camy), force * (cy-camy),
force * (cz-camz)) force * (cz-camz))