Skip to content

Commit fa0bbbf

Browse files
raymooparamat
authored andcommittedJun 24, 2016
Player: New get_look, set_look API
Deprecate get_look / set_look pitch / yaw
1 parent 04fb109 commit fa0bbbf

File tree

4 files changed

+121
-9
lines changed

4 files changed

+121
-9
lines changed
 

‎doc/lua_api.txt

+14-4
Original file line numberDiff line numberDiff line change
@@ -2679,10 +2679,20 @@ This is basically a reference to a C++ `ServerActiveObject`
26792679
* `get_player_velocity()`: returns `nil` if is not a player, otherwise a
26802680
table {x, y, z} representing the player's instantaneous velocity in nodes/s
26812681
* `get_look_dir()`: get camera direction as a unit vector
2682-
* `get_look_pitch()`: pitch in radians
2683-
* `get_look_yaw()`: yaw in radians (wraps around pretty randomly as of now)
2684-
* `set_look_pitch(radians)`: sets look pitch
2685-
* `set_look_yaw(radians)`: sets look yaw
2682+
* `get_look_vertical()`: pitch in radians
2683+
* Angle ranges between -pi/2 and pi/2, which are straight up and down respectively.
2684+
* `get_look_horizontal()`: yaw in radians
2685+
* Angle is counter-clockwise from the +z direction.
2686+
* `set_look_vertical(radians)`: sets look pitch
2687+
* radians - Angle from looking forward, where positive is downwards.
2688+
* `set_look_horizontal(radians)`: sets look yaw
2689+
* radians - Angle from the +z direction, where positive is counter-clockwise.
2690+
* `get_look_pitch()`: pitch in radians - Deprecated as broken. Use get_look_vertical.
2691+
* Angle ranges between -pi/2 and pi/2, which are straight down and up respectively.
2692+
* `get_look_yaw()`: yaw in radians - Deprecated as broken. Use get_look_horizontal.
2693+
* Angle is counter-clockwise from the +x direction.
2694+
* `set_look_pitch(radians)`: sets look pitch - Deprecated. Use set_look_vertical.
2695+
* `set_look_yaw(radians)`: sets look yaw - Deprecated. Use set_look_horizontal.
26862696
* `get_breath()`: returns players breath
26872697
* `set_breath(value)`: sets players breath
26882698
* values:

‎src/player.h

+14-2
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,28 @@ class Player
188188
m_breath = breath;
189189
}
190190

191-
f32 getRadPitch()
191+
// Deprecated
192+
f32 getRadPitchDep()
192193
{
193194
return -1.0 * m_pitch * core::DEGTORAD;
194195
}
195196

196-
f32 getRadYaw()
197+
// Deprecated
198+
f32 getRadYawDep()
197199
{
198200
return (m_yaw + 90.) * core::DEGTORAD;
199201
}
200202

203+
f32 getRadPitch()
204+
{
205+
return m_pitch * core::DEGTORAD;
206+
}
207+
208+
f32 getRadYaw()
209+
{
210+
return m_yaw * core::DEGTORAD;
211+
}
212+
201213
const char *getName() const
202214
{
203215
return m_name;

‎src/script/lua_api/l_object.cpp

+77-3
Original file line numberDiff line numberDiff line change
@@ -1016,27 +1016,61 @@ int ObjectRef::l_get_look_dir(lua_State *L)
10161016
Player *player = getplayer(ref);
10171017
if (player == NULL) return 0;
10181018
// Do it
1019-
float pitch = player->getRadPitch();
1020-
float yaw = player->getRadYaw();
1019+
float pitch = player->getRadPitchDep();
1020+
float yaw = player->getRadYawDep();
10211021
v3f v(cos(pitch)*cos(yaw), sin(pitch), cos(pitch)*sin(yaw));
10221022
push_v3f(L, v);
10231023
return 1;
10241024
}
10251025

1026+
// DEPRECATED
10261027
// get_look_pitch(self)
10271028
int ObjectRef::l_get_look_pitch(lua_State *L)
10281029
{
10291030
NO_MAP_LOCK_REQUIRED;
1031+
1032+
log_deprecated(L,
1033+
"Deprecated call to get_look_pitch, use get_look_vertical instead");
1034+
10301035
ObjectRef *ref = checkobject(L, 1);
10311036
Player *player = getplayer(ref);
10321037
if (player == NULL) return 0;
10331038
// Do it
1034-
lua_pushnumber(L, player->getRadPitch());
1039+
lua_pushnumber(L, player->getRadPitchDep());
10351040
return 1;
10361041
}
10371042

1043+
// DEPRECATED
10381044
// get_look_yaw(self)
10391045
int ObjectRef::l_get_look_yaw(lua_State *L)
1046+
{
1047+
NO_MAP_LOCK_REQUIRED;
1048+
1049+
log_deprecated(L,
1050+
"Deprecated call to get_look_yaw, use get_look_horizontal instead");
1051+
1052+
ObjectRef *ref = checkobject(L, 1);
1053+
Player *player = getplayer(ref);
1054+
if (player == NULL) return 0;
1055+
// Do it
1056+
lua_pushnumber(L, player->getRadYawDep());
1057+
return 1;
1058+
}
1059+
1060+
// get_look_pitch2(self)
1061+
int ObjectRef::l_get_look_vertical(lua_State *L)
1062+
{
1063+
NO_MAP_LOCK_REQUIRED;
1064+
ObjectRef *ref = checkobject(L, 1);
1065+
Player *player = getplayer(ref);
1066+
if (player == NULL) return 0;
1067+
// Do it
1068+
lua_pushnumber(L, player->getRadPitch());
1069+
return 1;
1070+
}
1071+
1072+
// get_look_yaw2(self)
1073+
int ObjectRef::l_get_look_horizontal(lua_State *L)
10401074
{
10411075
NO_MAP_LOCK_REQUIRED;
10421076
ObjectRef *ref = checkobject(L, 1);
@@ -1047,10 +1081,41 @@ int ObjectRef::l_get_look_yaw(lua_State *L)
10471081
return 1;
10481082
}
10491083

1084+
// set_look_vertical(self, radians)
1085+
int ObjectRef::l_set_look_vertical(lua_State *L)
1086+
{
1087+
NO_MAP_LOCK_REQUIRED;
1088+
ObjectRef *ref = checkobject(L, 1);
1089+
PlayerSAO* co = getplayersao(ref);
1090+
if (co == NULL) return 0;
1091+
float pitch = luaL_checknumber(L, 2) * core::RADTODEG;
1092+
// Do it
1093+
co->setPitch(pitch);
1094+
return 1;
1095+
}
1096+
1097+
// set_look_horizontal(self, radians)
1098+
int ObjectRef::l_set_look_horizontal(lua_State *L)
1099+
{
1100+
NO_MAP_LOCK_REQUIRED;
1101+
ObjectRef *ref = checkobject(L, 1);
1102+
PlayerSAO* co = getplayersao(ref);
1103+
if (co == NULL) return 0;
1104+
float yaw = luaL_checknumber(L, 2) * core::RADTODEG;
1105+
// Do it
1106+
co->setYaw(yaw);
1107+
return 1;
1108+
}
1109+
1110+
// DEPRECATED
10501111
// set_look_pitch(self, radians)
10511112
int ObjectRef::l_set_look_pitch(lua_State *L)
10521113
{
10531114
NO_MAP_LOCK_REQUIRED;
1115+
1116+
log_deprecated(L,
1117+
"Deprecated call to set_look_pitch, use set_look_vertical instead.");
1118+
10541119
ObjectRef *ref = checkobject(L, 1);
10551120
PlayerSAO* co = getplayersao(ref);
10561121
if (co == NULL) return 0;
@@ -1060,10 +1125,15 @@ int ObjectRef::l_set_look_pitch(lua_State *L)
10601125
return 1;
10611126
}
10621127

1128+
// DEPRECATED
10631129
// set_look_yaw(self, radians)
10641130
int ObjectRef::l_set_look_yaw(lua_State *L)
10651131
{
10661132
NO_MAP_LOCK_REQUIRED;
1133+
1134+
log_deprecated(L,
1135+
"Deprecated call to set_look_yaw, use set_look_horizontal instead.");
1136+
10671137
ObjectRef *ref = checkobject(L, 1);
10681138
PlayerSAO* co = getplayersao(ref);
10691139
if (co == NULL) return 0;
@@ -1754,6 +1824,10 @@ const luaL_reg ObjectRef::methods[] = {
17541824
luamethod(ObjectRef, get_look_dir),
17551825
luamethod(ObjectRef, get_look_pitch),
17561826
luamethod(ObjectRef, get_look_yaw),
1827+
luamethod(ObjectRef, get_look_vertical),
1828+
luamethod(ObjectRef, get_look_horizontal),
1829+
luamethod(ObjectRef, set_look_horizontal),
1830+
luamethod(ObjectRef, set_look_vertical),
17571831
luamethod(ObjectRef, set_look_yaw),
17581832
luamethod(ObjectRef, set_look_pitch),
17591833
luamethod(ObjectRef, get_breath),

‎src/script/lua_api/l_object.h

+16
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,31 @@ class ObjectRef : public ModApiBase {
189189
// get_look_dir(self)
190190
static int l_get_look_dir(lua_State *L);
191191

192+
// DEPRECATED
192193
// get_look_pitch(self)
193194
static int l_get_look_pitch(lua_State *L);
194195

196+
// DEPRECATED
195197
// get_look_yaw(self)
196198
static int l_get_look_yaw(lua_State *L);
197199

200+
// get_look_pitch2(self)
201+
static int l_get_look_vertical(lua_State *L);
202+
203+
// get_look_yaw2(self)
204+
static int l_get_look_horizontal(lua_State *L);
205+
206+
// set_look_vertical(self, radians)
207+
static int l_set_look_vertical(lua_State *L);
208+
209+
// set_look_horizontal(self, radians)
210+
static int l_set_look_horizontal(lua_State *L);
211+
212+
// DEPRECATED
198213
// set_look_pitch(self, radians)
199214
static int l_set_look_pitch(lua_State *L);
200215

216+
// DEPRECATED
201217
// set_look_yaw(self, radians)
202218
static int l_set_look_yaw(lua_State *L);
203219

0 commit comments

Comments
 (0)
Please sign in to comment.