add cameras.look_at, player.set_camera, base:cinematic camera
This commit is contained in:
parent
ce7037e9d0
commit
247acb3687
@ -2,6 +2,7 @@
|
||||
"camera": [
|
||||
"first-person",
|
||||
"third-person-front",
|
||||
"third-person-back"
|
||||
"third-person-back",
|
||||
"cinematic"
|
||||
]
|
||||
}
|
||||
|
||||
@ -173,7 +173,11 @@ void CameraControl::update(const PlayerInput& input, float delta, Chunks* chunks
|
||||
tpCamera->dir = camera->dir;
|
||||
tpCamera->front = camera->front;
|
||||
}
|
||||
player->currentCamera->setFov(glm::radians(settings.fov.get()));
|
||||
if (player->currentCamera == spCamera ||
|
||||
player->currentCamera == tpCamera ||
|
||||
player->currentCamera == camera) {
|
||||
player->currentCamera->setFov(glm::radians(settings.fov.get()));
|
||||
}
|
||||
}
|
||||
|
||||
PlayerController::PlayerController(
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
#include "../../../world/Level.hpp"
|
||||
#include "../../../window/Camera.hpp"
|
||||
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
template<int(*getterfunc)(lua::State*, const Camera&)>
|
||||
@ -86,6 +88,15 @@ static int getter_up(lua::State* L, const Camera& camera) {
|
||||
return lua::pushvec3_arr(L, camera.up);
|
||||
}
|
||||
|
||||
static int l_look_at(lua::State* L) {
|
||||
size_t index = static_cast<size_t>(lua::tointeger(L, 1));
|
||||
auto& camera = *level->cameras.at(index);
|
||||
auto center = lua::tovec<3>(L, 2);
|
||||
camera.rotation = glm::inverse(glm::lookAt(glm::vec3(), center-camera.position, glm::vec3(0, 1, 0)));
|
||||
camera.updateVectors();
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg cameralib [] = {
|
||||
{"index", lua::wrap<l_index>},
|
||||
{"name", lua::wrap<l_name>},
|
||||
@ -104,5 +115,6 @@ const luaL_Reg cameralib [] = {
|
||||
{"get_front", lua::wrap<l_camera_getter<getter_front>>},
|
||||
{"get_right", lua::wrap<l_camera_getter<getter_right>>},
|
||||
{"get_up", lua::wrap<l_camera_getter<getter_up>>},
|
||||
{"look_at", lua::wrap<l_look_at>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@ -181,6 +181,16 @@ static int l_player_set_entity(lua::State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_player_set_camera(lua::State* L) {
|
||||
auto player = get_player(L, 1);
|
||||
if (player == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
size_t index = lua::tointeger(L, 2);
|
||||
player->currentCamera = level->cameras.at(index);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg playerlib [] = {
|
||||
{"get_pos", lua::wrap<l_player_get_pos>},
|
||||
{"set_pos", lua::wrap<l_player_set_pos>},
|
||||
@ -199,5 +209,6 @@ const luaL_Reg playerlib [] = {
|
||||
{"get_spawnpoint", lua::wrap<l_player_get_spawnpoint>},
|
||||
{"get_entity", lua::wrap<l_player_get_entity>},
|
||||
{"set_entity", lua::wrap<l_player_set_entity>},
|
||||
{"set_camera", lua::wrap<l_player_set_camera>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user