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:
parent
2ec38be58c
commit
dec24f3af5
3
Engine.h
3
Engine.h
@ -68,8 +68,9 @@ class Engine
|
||||
render();
|
||||
}
|
||||
void setTexture(GLuint tex);
|
||||
|
||||
void draw();
|
||||
dReal getMass() { return m_ode_object->getMass(); }
|
||||
void setMass(dReal mass) { m_ode_object->setMass(mass); }
|
||||
|
||||
protected:
|
||||
void createManagedObject();
|
||||
|
34
ag.cc
34
ag.cc
@ -158,6 +158,10 @@ namespace ag
|
||||
lua_setfield(L, -2, "setColor");
|
||||
lua_pushcfunction(L, object::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)
|
||||
@ -807,5 +811,35 @@ namespace ag
|
||||
}
|
||||
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
2
ag.h
@ -59,6 +59,8 @@ namespace ag
|
||||
int addRelTorque(lua_State * L);
|
||||
int setColor(lua_State * L);
|
||||
int setTexture(lua_State * L);
|
||||
int getMass(lua_State * L);
|
||||
int setMass(lua_State * L);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,20 +15,21 @@ function init()
|
||||
local ground = ag.createPlane(0, 0, 1, 0)
|
||||
ground:setColor(0.8, 0.5, 0.0)
|
||||
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()
|
||||
|
||||
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:setColor(0.2, 0.2, 0.9)
|
||||
ball:setPosition(2*camx - cx, 2*camy - cy, 2*camz - cz)
|
||||
end
|
||||
|
||||
function mousebutton_down_event(button)
|
||||
local function button1()
|
||||
local newball = ball:clone()
|
||||
newball:setPosition(camx, camy, 1)
|
||||
force = 800
|
||||
force = 4000
|
||||
newball:addForce(force * (cx-camx),
|
||||
force * (cy-camy),
|
||||
force * (cz-camz))
|
||||
|
Loading…
x
Reference in New Issue
Block a user