summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_camera.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2020-05-14 21:16:45 +0200
committerGitHub <noreply@github.com>2020-05-14 21:16:45 +0200
commit36d35f2fe31a429c1510df680801940472416d45 (patch)
treef36be46515b7631ccbc581451c134e8d9c9a9265 /src/script/lua_api/l_camera.cpp
parent6ef7ad09bbed9176d0d15f53b5cb14ef6e18a3b2 (diff)
downloadminetest-36d35f2fe31a429c1510df680801940472416d45.tar.gz
minetest-36d35f2fe31a429c1510df680801940472416d45.tar.bz2
minetest-36d35f2fe31a429c1510df680801940472416d45.zip
CSM: Bugfixes to camera:get_pos() and camera:get_fov()
closes #9857
Diffstat (limited to 'src/script/lua_api/l_camera.cpp')
-rw-r--r--src/script/lua_api/l_camera.cpp59
1 files changed, 36 insertions, 23 deletions
diff --git a/src/script/lua_api/l_camera.cpp b/src/script/lua_api/l_camera.cpp
index 9c1470284..bfa60be67 100644
--- a/src/script/lua_api/l_camera.cpp
+++ b/src/script/lua_api/l_camera.cpp
@@ -51,6 +51,7 @@ void LuaCamera::create(lua_State *L, Camera *m)
lua_setfield(L, objectstable, "camera");
}
+// set_camera_mode(self, mode)
int LuaCamera::l_set_camera_mode(lua_State *L)
{
Camera *camera = getobject(L, 1);
@@ -67,17 +68,19 @@ int LuaCamera::l_set_camera_mode(lua_State *L)
return 0;
}
+// get_camera_mode(self)
int LuaCamera::l_get_camera_mode(lua_State *L)
{
Camera *camera = getobject(L, 1);
if (!camera)
return 0;
- lua_pushnumber(L, (int)camera->getCameraMode());
+ lua_pushinteger(L, (int)camera->getCameraMode());
return 1;
}
+// get_fov(self)
int LuaCamera::l_get_fov(lua_State *L)
{
Camera *camera = getobject(L, 1);
@@ -85,9 +88,9 @@ int LuaCamera::l_get_fov(lua_State *L)
return 0;
lua_newtable(L);
- lua_pushnumber(L, camera->getFovX() * core::DEGTORAD);
+ lua_pushnumber(L, camera->getFovX() * core::RADTODEG);
lua_setfield(L, -2, "x");
- lua_pushnumber(L, camera->getFovY() * core::DEGTORAD);
+ lua_pushnumber(L, camera->getFovY() * core::RADTODEG);
lua_setfield(L, -2, "y");
lua_pushnumber(L, camera->getCameraNode()->getFOV() * core::RADTODEG);
lua_setfield(L, -2, "actual");
@@ -96,16 +99,18 @@ int LuaCamera::l_get_fov(lua_State *L)
return 1;
}
+// get_pos(self)
int LuaCamera::l_get_pos(lua_State *L)
{
Camera *camera = getobject(L, 1);
if (!camera)
return 0;
- push_v3f(L, camera->getPosition());
+ push_v3f(L, camera->getPosition() / BS);
return 1;
}
+// get_offset(self)
int LuaCamera::l_get_offset(lua_State *L)
{
LocalPlayer *player = getClient(L)->getEnv().getLocalPlayer();
@@ -115,38 +120,40 @@ int LuaCamera::l_get_offset(lua_State *L)
return 1;
}
+// get_look_dir(self)
int LuaCamera::l_get_look_dir(lua_State *L)
{
- LocalPlayer *player = getClient(L)->getEnv().getLocalPlayer();
- sanity_check(player);
-
- float pitch = -1.0 * player->getPitch() * core::DEGTORAD;
- float yaw = (player->getYaw() + 90.) * core::DEGTORAD;
- v3f v(std::cos(pitch) * std::cos(yaw), std::sin(pitch),
- std::cos(pitch) * std::sin(yaw));
+ Camera *camera = getobject(L, 1);
+ if (!camera)
+ return 0;
- push_v3f(L, v);
+ push_v3f(L, camera->getDirection());
return 1;
}
+// get_look_horizontal(self)
+// FIXME: wouldn't localplayer be a better place for this?
int LuaCamera::l_get_look_horizontal(lua_State *L)
{
LocalPlayer *player = getClient(L)->getEnv().getLocalPlayer();
sanity_check(player);
- lua_pushnumber(L, (player->getYaw() + 90.) * core::DEGTORAD);
+ lua_pushnumber(L, (player->getYaw() + 90.f) * core::DEGTORAD);
return 1;
}
+// get_look_vertical(self)
+// FIXME: wouldn't localplayer be a better place for this?
int LuaCamera::l_get_look_vertical(lua_State *L)
{
LocalPlayer *player = getClient(L)->getEnv().getLocalPlayer();
sanity_check(player);
- lua_pushnumber(L, -1.0 * player->getPitch() * core::DEGTORAD);
+ lua_pushnumber(L, -1.0f * player->getPitch() * core::DEGTORAD);
return 1;
}
+// get_aspect_ratio(self)
int LuaCamera::l_get_aspect_ratio(lua_State *L)
{
Camera *camera = getobject(L, 1);
@@ -215,13 +222,19 @@ void LuaCamera::Register(lua_State *L)
lua_pop(L, 1);
}
+// clang-format off
const char LuaCamera::className[] = "Camera";
-const luaL_Reg LuaCamera::methods[] = {luamethod(LuaCamera, set_camera_mode),
- luamethod(LuaCamera, get_camera_mode), luamethod(LuaCamera, get_fov),
- luamethod(LuaCamera, get_pos), luamethod(LuaCamera, get_offset),
- luamethod(LuaCamera, get_look_dir),
- luamethod(LuaCamera, get_look_vertical),
- luamethod(LuaCamera, get_look_horizontal),
- luamethod(LuaCamera, get_aspect_ratio),
-
- {0, 0}};
+const luaL_Reg LuaCamera::methods[] = {
+ luamethod(LuaCamera, set_camera_mode),
+ luamethod(LuaCamera, get_camera_mode),
+ luamethod(LuaCamera, get_fov),
+ luamethod(LuaCamera, get_pos),
+ luamethod(LuaCamera, get_offset),
+ luamethod(LuaCamera, get_look_dir),
+ luamethod(LuaCamera, get_look_vertical),
+ luamethod(LuaCamera, get_look_horizontal),
+ luamethod(LuaCamera, get_aspect_ratio),
+
+ {0, 0}
+};
+// clang-format on