1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-11-04 16:35:03 -05:00

Add ObjectRef:getvelocity(), ObjectRef:setyaw() and ObjectRef:getyaw()

This commit is contained in:
Perttu Ahola 2012-01-02 16:19:52 +02:00
parent 2445cbbbdc
commit 56f55ab1af
4 changed files with 61 additions and 0 deletions

View File

@ -200,8 +200,11 @@
-- - set_hp(hp): set number of hitpoints (2 * number of hearts) -- - set_hp(hp): set number of hitpoints (2 * number of hearts)
-- LuaEntitySAO-only: (no-op for other objects) -- LuaEntitySAO-only: (no-op for other objects)
-- - setvelocity({x=num, y=num, z=num}) -- - setvelocity({x=num, y=num, z=num})
-- - getvelocity() -> {x=num, y=num, z=num}
-- - setacceleration({x=num, y=num, z=num}) -- - setacceleration({x=num, y=num, z=num})
-- - getacceleration() -> {x=num, y=num, z=num} -- - getacceleration() -> {x=num, y=num, z=num}
-- - setyaw(radians)
-- - getyaw() -> radians
-- - settexturemod(mod) -- - settexturemod(mod)
-- - setsprite(p={x=0,y=0}, num_frames=1, framelength=0.2, -- - setsprite(p={x=0,y=0}, num_frames=1, framelength=0.2,
-- - select_horiz_by_yawpitch=false) -- - select_horiz_by_yawpitch=false)

View File

@ -1698,6 +1698,11 @@ void LuaEntitySAO::setVelocity(v3f velocity)
m_velocity = velocity; m_velocity = velocity;
} }
v3f LuaEntitySAO::getVelocity()
{
return m_velocity;
}
void LuaEntitySAO::setAcceleration(v3f acceleration) void LuaEntitySAO::setAcceleration(v3f acceleration)
{ {
m_acceleration = acceleration; m_acceleration = acceleration;
@ -1708,6 +1713,16 @@ v3f LuaEntitySAO::getAcceleration()
return m_acceleration; return m_acceleration;
} }
void LuaEntitySAO::setYaw(float yaw)
{
m_yaw = yaw;
}
float LuaEntitySAO::getYaw()
{
return m_yaw;
}
void LuaEntitySAO::setTextureMod(const std::string &mod) void LuaEntitySAO::setTextureMod(const std::string &mod)
{ {
std::ostringstream os(std::ios::binary); std::ostringstream os(std::ios::binary);

View File

@ -213,8 +213,11 @@ public:
float getMinimumSavedMovement(); float getMinimumSavedMovement();
/* LuaEntitySAO-specific */ /* LuaEntitySAO-specific */
void setVelocity(v3f velocity); void setVelocity(v3f velocity);
v3f getVelocity();
void setAcceleration(v3f acceleration); void setAcceleration(v3f acceleration);
v3f getAcceleration(); v3f getAcceleration();
void setYaw(float yaw);
float getYaw();
void setTextureMod(const std::string &mod); void setTextureMod(const std::string &mod);
void setSprite(v2s16 p, int num_frames, float framelength, void setSprite(v2s16 p, int num_frames, float framelength,
bool select_horiz_by_yawpitch); bool select_horiz_by_yawpitch);

View File

@ -1928,6 +1928,18 @@ private:
return 0; return 0;
} }
// getvelocity(self)
static int l_getvelocity(lua_State *L)
{
ObjectRef *ref = checkobject(L, 1);
LuaEntitySAO *co = getluaobject(ref);
if(co == NULL) return 0;
// Do it
v3f v = co->getVelocity();
pushFloatPos(L, v);
return 1;
}
// setacceleration(self, {x=num, y=num, z=num}) // setacceleration(self, {x=num, y=num, z=num})
static int l_setacceleration(lua_State *L) static int l_setacceleration(lua_State *L)
{ {
@ -1953,6 +1965,31 @@ private:
return 1; return 1;
} }
// setyaw(self, radians)
static int l_setyaw(lua_State *L)
{
ObjectRef *ref = checkobject(L, 1);
LuaEntitySAO *co = getluaobject(ref);
if(co == NULL) return 0;
// pos
float yaw = luaL_checknumber(L, 2) * core::RADTODEG;
// Do it
co->setYaw(yaw);
return 0;
}
// getyaw(self)
static int l_getyaw(lua_State *L)
{
ObjectRef *ref = checkobject(L, 1);
LuaEntitySAO *co = getluaobject(ref);
if(co == NULL) return 0;
// Do it
float yaw = co->getYaw() * core::DEGTORAD;
lua_pushnumber(L, yaw);
return 1;
}
// settexturemod(self, mod) // settexturemod(self, mod)
static int l_settexturemod(lua_State *L) static int l_settexturemod(lua_State *L)
{ {
@ -2209,8 +2246,11 @@ const luaL_reg ObjectRef::methods[] = {
method(ObjectRef, get_hp), method(ObjectRef, get_hp),
// LuaEntitySAO-only // LuaEntitySAO-only
method(ObjectRef, setvelocity), method(ObjectRef, setvelocity),
method(ObjectRef, getvelocity),
method(ObjectRef, setacceleration), method(ObjectRef, setacceleration),
method(ObjectRef, getacceleration), method(ObjectRef, getacceleration),
method(ObjectRef, setyaw),
method(ObjectRef, getyaw),
method(ObjectRef, settexturemod), method(ObjectRef, settexturemod),
method(ObjectRef, setsprite), method(ObjectRef, setsprite),
method(ObjectRef, get_entity_name), method(ObjectRef, get_entity_name),