lua methods set_look_pitch and set_look_yaw
authorRealBadAngel <mk@realbadangel.pl>
Sun, 17 Mar 2013 11:16:57 +0000 (12:16 +0100)
committerkwolekr <kwolekr@minetest.net>
Sun, 17 Mar 2013 15:39:35 +0000 (11:39 -0400)
doc/lua_api.txt
src/content_sao.cpp
src/content_sao.h
src/scriptapi_object.cpp
src/scriptapi_object.h

index eb05d117ebbe54309d2905d30b1234948c1b8a20..7d8fa149f9bb48d16c28ce3e8ef5f8b637a5e443 100644 (file)
@@ -1228,6 +1228,8 @@ Player-only: (no-op for other objects)
 - get_look_dir(): get camera direction as a unit vector
 - get_look_pitch(): pitch in radians
 - get_look_yaw(): yaw in radians (wraps around pretty randomly as of now)
+- set_look_pitch(radians): sets look pitch
+- set_look_yaw(radians): sets look yaw
 - set_inventory_formspec(formspec)
   ^ Redefine player's inventory form
   ^ Should usually be called in on_joinplayer
index 1e02ea5a5aa645b160a8c2b482f83e5625496180..d7afc31d80d135154bde34bc79edecbb7fd1bfea 100644 (file)
@@ -1230,6 +1230,20 @@ void PlayerSAO::moveTo(v3f pos, bool continuous)
        m_moved = true;
 }
 
+void PlayerSAO::setYaw(float yaw)
+{
+       m_player->setYaw(yaw);
+       // Force change on client
+       m_moved = true;
+}
+
+void PlayerSAO::setPitch(float pitch)
+{
+       m_player->setPitch(pitch);
+       // Force change on client
+       m_moved = true;
+}
+
 int PlayerSAO::punch(v3f dir,
        const ToolCapabilities *toolcap,
        ServerActiveObject *puncher,
index 2fd1034ebd73a8380c20c14e13ef59129e990101..e5b89d44751e8fdf22b91476600bbfdc8f281702 100644 (file)
@@ -147,6 +147,8 @@ public:
        void setBasePosition(const v3f &position);
        void setPos(v3f pos);
        void moveTo(v3f pos, bool continuous);
+       void setYaw(float);
+       void setPitch(float);
 
        /*
                Interaction interface
index ba72840c00f69515cba43cefd00a068683eb117f..a0f93cbbad33ec0ce5eafe6eb3792c5a668c9926 100644 (file)
@@ -27,7 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "scriptapi_entity.h"
 #include "scriptapi_common.h"
 
-
 /*
        ObjectRef
 */
@@ -582,6 +581,30 @@ int ObjectRef::l_get_look_yaw(lua_State *L)
        return 1;
 }
 
+// set_look_pitch(self, radians)
+int ObjectRef::l_set_look_pitch(lua_State *L)
+{
+       ObjectRef *ref = checkobject(L, 1);
+       PlayerSAO* co = getplayersao(ref);
+       if(co == NULL) return 0;
+       float pitch = luaL_checknumber(L, 2) * core::RADTODEG;
+       // Do it
+       co->setPitch(pitch);
+       return 1;
+}
+
+// set_look_yaw(self, radians)
+int ObjectRef::l_set_look_yaw(lua_State *L)
+{
+       ObjectRef *ref = checkobject(L, 1);
+       PlayerSAO* co = getplayersao(ref);
+       if(co == NULL) return 0;
+       float yaw = luaL_checknumber(L, 2) * core::RADTODEG;
+       // Do it
+       co->setYaw(yaw);
+       return 1;
+}
+
 // set_inventory_formspec(self, formspec)
 int ObjectRef::l_set_inventory_formspec(lua_State *L)
 {
@@ -755,6 +778,8 @@ const luaL_reg ObjectRef::methods[] = {
        luamethod(ObjectRef, get_look_dir),
        luamethod(ObjectRef, get_look_pitch),
        luamethod(ObjectRef, get_look_yaw),
+       luamethod(ObjectRef, set_look_yaw),
+       luamethod(ObjectRef, set_look_pitch),
        luamethod(ObjectRef, set_inventory_formspec),
        luamethod(ObjectRef, get_inventory_formspec),
        luamethod(ObjectRef, get_player_control),
index ba1e7db394d1f2d911a2d86e9350588c8e3819c4..a37abbb781f0545cd1ae95c88d159b8a159fbe2f 100644 (file)
@@ -1,5 +1,5 @@
 /*
-Minetest-c55
+Minetest
 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
 
 This program is free software; you can redistribute it and/or modify
@@ -169,6 +169,12 @@ private:
        // get_look_yaw(self)
        static int l_get_look_yaw(lua_State *L);
 
+       // set_look_pitch(self, radians)
+       static int l_set_look_pitch(lua_State *L);
+
+       // set_look_yaw(self, radians)
+       static int l_set_look_yaw(lua_State *L);
+
        // set_inventory_formspec(self, formspec)
        static int l_set_inventory_formspec(lua_State *L);