added player camera rotation z axis
This commit is contained in:
@@ -47,13 +47,15 @@ void CameraControl::refresh() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CameraControl::updateMouse(PlayerInput& input) {
|
void CameraControl::updateMouse(PlayerInput& input) {
|
||||||
glm::vec2& cam = player->cam;
|
glm::vec3& cam = player->cam;
|
||||||
|
|
||||||
float sensitivity = (input.zoom
|
float sensitivity = (input.zoom
|
||||||
? settings.sensitivity.get() / 4.f
|
? settings.sensitivity.get() / 4.f
|
||||||
: settings.sensitivity.get());
|
: settings.sensitivity.get());
|
||||||
|
|
||||||
cam -= glm::degrees(Events::delta / (float)Window::height * sensitivity);
|
auto d = glm::degrees(Events::delta / (float)Window::height * sensitivity);
|
||||||
|
cam.x -= d.x;
|
||||||
|
cam.y -= d.y;
|
||||||
|
|
||||||
if (cam.y < -89.9f) {
|
if (cam.y < -89.9f) {
|
||||||
cam.y = -89.9f;
|
cam.y = -89.9f;
|
||||||
@@ -69,7 +71,7 @@ void CameraControl::updateMouse(PlayerInput& input) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
camera->rotation = glm::mat4(1.0f);
|
camera->rotation = glm::mat4(1.0f);
|
||||||
camera->rotate(glm::radians(cam.y), glm::radians(cam.x), 0);
|
camera->rotate(glm::radians(cam.y), glm::radians(cam.x), glm::radians(cam.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 CameraControl::updateCameraShaking(float delta) {
|
glm::vec3 CameraControl::updateCameraShaking(float delta) {
|
||||||
|
|||||||
@@ -66,10 +66,11 @@ static int l_player_get_rot(lua_State* L) {
|
|||||||
if (!player) {
|
if (!player) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
glm::vec2 rot = player->cam;
|
const glm::vec3& rot = player->cam;
|
||||||
lua_pushnumber(L, rot.x);
|
lua_pushnumber(L, rot.x);
|
||||||
lua_pushnumber(L, rot.y);
|
lua_pushnumber(L, rot.y);
|
||||||
return 2;
|
lua_pushnumber(L, rot.z);
|
||||||
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_player_set_rot(lua_State* L) {
|
static int l_player_set_rot(lua_State* L) {
|
||||||
@@ -77,11 +78,17 @@ static int l_player_set_rot(lua_State* L) {
|
|||||||
if (!player) {
|
if (!player) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
auto x = lua_tonumber(L, 2);
|
glm::vec3& cam = player->cam;
|
||||||
auto y = lua_tonumber(L, 3);
|
|
||||||
glm::vec2& cam = player->cam;
|
lua_Number x = lua_tonumber(L, 2);
|
||||||
|
lua_Number y = lua_tonumber(L, 3);
|
||||||
|
lua_Number z = cam.z;
|
||||||
|
if (lua_isnumber(L, 4)) {
|
||||||
|
z = lua_tonumber(L, 4);
|
||||||
|
}
|
||||||
cam.x = x;
|
cam.x = x;
|
||||||
cam.y = y;
|
cam.y = y;
|
||||||
|
cam.z = z;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -206,6 +206,7 @@ std::unique_ptr<dynamic::Map> Player::serialize() const {
|
|||||||
auto& rotarr = root->putList("rotation");
|
auto& rotarr = root->putList("rotation");
|
||||||
rotarr.put(cam.x);
|
rotarr.put(cam.x);
|
||||||
rotarr.put(cam.y);
|
rotarr.put(cam.y);
|
||||||
|
rotarr.put(cam.z);
|
||||||
|
|
||||||
auto& sparr = root->putList("spawnpoint");
|
auto& sparr = root->putList("spawnpoint");
|
||||||
sparr.put(spawnpoint.x);
|
sparr.put(spawnpoint.x);
|
||||||
@@ -230,6 +231,9 @@ void Player::deserialize(dynamic::Map *src) {
|
|||||||
auto rotarr = src->list("rotation");
|
auto rotarr = src->list("rotation");
|
||||||
cam.x = rotarr->num(0);
|
cam.x = rotarr->num(0);
|
||||||
cam.y = rotarr->num(1);
|
cam.y = rotarr->num(1);
|
||||||
|
if (rotarr->size() > 2) {
|
||||||
|
cam.z = rotarr->num(2);
|
||||||
|
}
|
||||||
|
|
||||||
if (src->has("spawnpoint")) {
|
if (src->has("spawnpoint")) {
|
||||||
auto sparr = src->list("spawnpoint");
|
auto sparr = src->list("spawnpoint");
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public:
|
|||||||
std::unique_ptr<Hitbox> hitbox;
|
std::unique_ptr<Hitbox> hitbox;
|
||||||
bool debug = false;
|
bool debug = false;
|
||||||
voxel selectedVoxel {0, 0};
|
voxel selectedVoxel {0, 0};
|
||||||
glm::vec2 cam {};
|
glm::vec3 cam {};
|
||||||
|
|
||||||
Player(glm::vec3 position, float speed, std::shared_ptr<Inventory> inv);
|
Player(glm::vec3 position, float speed, std::shared_ptr<Inventory> inv);
|
||||||
~Player();
|
~Player();
|
||||||
|
|||||||
Reference in New Issue
Block a user