remove camera latency
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
# Blender MTL File: 'player.blend'
|
||||||
|
# Material Count: 1
|
||||||
|
|
||||||
|
newmtl entities/player
|
||||||
|
Ns 96.078431
|
||||||
|
Ka 1.000000 1.000000 1.000000
|
||||||
|
Kd 0.640000 0.640000 0.640000
|
||||||
|
Ks 0.000000 0.000000 0.000000
|
||||||
|
Ke 0.000000 0.000000 0.000000
|
||||||
|
Ni 1.000000
|
||||||
|
d 1.000000
|
||||||
|
illum 1
|
||||||
|
map_Kd /home/ubuntu/Projects/Cpp/VoxelEngine-Cpp/res/content/base/textures/entities/player.png
|
||||||
@@ -6,10 +6,10 @@ v 0.125000 -0.900000 -0.125000
|
|||||||
v 0.125000 -0.900000 0.125000
|
v 0.125000 -0.900000 0.125000
|
||||||
v -0.125000 -0.900000 0.125000
|
v -0.125000 -0.900000 0.125000
|
||||||
v -0.125000 -0.900000 -0.125000
|
v -0.125000 -0.900000 -0.125000
|
||||||
v 0.125000 0.700000 -0.125000
|
v 0.125000 0.491919 -0.125000
|
||||||
v 0.125000 0.700000 0.125000
|
v 0.125000 0.491919 0.125000
|
||||||
v -0.125000 0.700000 0.125000
|
v -0.125000 0.491919 0.125000
|
||||||
v -0.125000 0.700000 -0.125000
|
v -0.125000 0.491919 -0.125000
|
||||||
vt 0.783122 0.009685
|
vt 0.783122 0.009685
|
||||||
vt 0.982503 0.009685
|
vt 0.982503 0.009685
|
||||||
vt 0.982503 0.209065
|
vt 0.982503 0.209065
|
||||||
|
|||||||
@@ -163,6 +163,8 @@ void CameraControl::update(const PlayerInput& input, float delta, Chunks* chunks
|
|||||||
auto spCamera = player->spCamera;
|
auto spCamera = player->spCamera;
|
||||||
auto tpCamera = player->tpCamera;
|
auto tpCamera = player->tpCamera;
|
||||||
|
|
||||||
|
refresh();
|
||||||
|
|
||||||
if (player->currentCamera == spCamera) {
|
if (player->currentCamera == spCamera) {
|
||||||
spCamera->position = chunks->rayCastToObstacle(
|
spCamera->position = chunks->rayCastToObstacle(
|
||||||
camera->position, camera->front, 3.0f) - 0.2f * camera->front;
|
camera->position, camera->front, 3.0f) - 0.2f * camera->front;
|
||||||
@@ -256,16 +258,17 @@ void PlayerController::postUpdate(float delta, bool input, bool pause) {
|
|||||||
if (!pause) {
|
if (!pause) {
|
||||||
updateFootsteps(delta);
|
updateFootsteps(delta);
|
||||||
}
|
}
|
||||||
player->postUpdate();
|
|
||||||
camControl.refresh();
|
if (!pause && input) {
|
||||||
if (!pause) {
|
camControl.updateMouse(this->input);
|
||||||
updateCamera(delta, input);
|
|
||||||
}
|
}
|
||||||
if (input) {
|
if (input) {
|
||||||
updateInteraction();
|
updateInteraction();
|
||||||
} else {
|
} else {
|
||||||
player->selection = {};
|
player->selection = {};
|
||||||
}
|
}
|
||||||
|
player->postUpdate();
|
||||||
|
camControl.update(this->input, delta, level->chunks.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerController::updateKeyboard() {
|
void PlayerController::updateKeyboard() {
|
||||||
@@ -283,13 +286,6 @@ void PlayerController::updateKeyboard() {
|
|||||||
input.flight = Events::jactive(BIND_PLAYER_FLIGHT);
|
input.flight = Events::jactive(BIND_PLAYER_FLIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerController::updateCamera(float delta, bool movement) {
|
|
||||||
if (movement) {
|
|
||||||
camControl.updateMouse(input);
|
|
||||||
}
|
|
||||||
camControl.update(input, delta, level->chunks.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerController::resetKeyboard() {
|
void PlayerController::resetKeyboard() {
|
||||||
input.zoom = false;
|
input.zoom = false;
|
||||||
input.moveForward = false;
|
input.moveForward = false;
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ class PlayerController {
|
|||||||
std::vector<on_block_interaction> blockInteractionCallbacks;
|
std::vector<on_block_interaction> blockInteractionCallbacks;
|
||||||
|
|
||||||
void updateKeyboard();
|
void updateKeyboard();
|
||||||
void updateCamera(float delta, bool movement);
|
|
||||||
void resetKeyboard();
|
void resetKeyboard();
|
||||||
void updatePlayer(float delta);
|
void updatePlayer(float delta);
|
||||||
void updateInteraction();
|
void updateInteraction();
|
||||||
|
|||||||
+35
-35
@@ -62,25 +62,11 @@ Hitbox* Player::getHitbox() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Player::updateInput(PlayerInput& input, float delta) {
|
void Player::updateInput(PlayerInput& input, float delta) {
|
||||||
auto entity = level->entities->get(eid);
|
auto hitbox = getHitbox();
|
||||||
if (!entity.has_value()) {
|
if (hitbox == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto& hitbox = entity->getRigidbody().hitbox;
|
bool crouch = input.shift && hitbox->grounded && !input.sprint;
|
||||||
auto& skeleton = entity->getSkeleton();
|
|
||||||
|
|
||||||
skeleton.visible = currentCamera != camera;
|
|
||||||
|
|
||||||
size_t bodyIndex = skeleton.config->find("body")->getIndex();
|
|
||||||
size_t headIndex = skeleton.config->find("head")->getIndex();
|
|
||||||
|
|
||||||
skeleton.pose.matrices[bodyIndex] =
|
|
||||||
glm::rotate(glm::mat4(1.0f), glm::radians(cam.x-90), glm::vec3(0, 1, 0));
|
|
||||||
skeleton.pose.matrices[headIndex] = glm::rotate(glm::rotate(
|
|
||||||
glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.6f, 0.0f)),
|
|
||||||
glm::radians(-cam.y), glm::vec3(0, 0, 1)), glm::radians(90.0f), glm::vec3(0, 1, 0));
|
|
||||||
|
|
||||||
bool crouch = input.shift && hitbox.grounded && !input.sprint;
|
|
||||||
float speed = this->speed;
|
float speed = this->speed;
|
||||||
if (flight){
|
if (flight){
|
||||||
speed *= FLIGHT_SPEED_MUL;
|
speed *= FLIGHT_SPEED_MUL;
|
||||||
@@ -89,7 +75,7 @@ void Player::updateInput(PlayerInput& input, float delta) {
|
|||||||
speed *= CHEAT_SPEED_MUL;
|
speed *= CHEAT_SPEED_MUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
hitbox.crouching = crouch;
|
hitbox->crouching = crouch;
|
||||||
if (crouch) {
|
if (crouch) {
|
||||||
speed *= CROUCH_SPEED_MUL;
|
speed *= CROUCH_SPEED_MUL;
|
||||||
} else if (input.sprint) {
|
} else if (input.sprint) {
|
||||||
@@ -111,37 +97,37 @@ void Player::updateInput(PlayerInput& input, float delta) {
|
|||||||
}
|
}
|
||||||
if (glm::length(dir) > 0.0f){
|
if (glm::length(dir) > 0.0f){
|
||||||
dir = glm::normalize(dir);
|
dir = glm::normalize(dir);
|
||||||
hitbox.velocity += dir * speed * delta * 9.0f;
|
hitbox->velocity += dir * speed * delta * 9.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
hitbox.linearDamping = PLAYER_GROUND_DAMPING;
|
hitbox->linearDamping = PLAYER_GROUND_DAMPING;
|
||||||
hitbox.verticalDamping = flight;
|
hitbox->verticalDamping = flight;
|
||||||
hitbox.gravityScale = flight ? 0.0f : 1.0f;
|
hitbox->gravityScale = flight ? 0.0f : 1.0f;
|
||||||
if (flight){
|
if (flight){
|
||||||
hitbox.linearDamping = PLAYER_AIR_DAMPING;
|
hitbox->linearDamping = PLAYER_AIR_DAMPING;
|
||||||
if (input.jump){
|
if (input.jump){
|
||||||
hitbox.velocity.y += speed * delta * 9;
|
hitbox->velocity.y += speed * delta * 9;
|
||||||
}
|
}
|
||||||
if (input.shift){
|
if (input.shift){
|
||||||
hitbox.velocity.y -= speed * delta * 9;
|
hitbox->velocity.y -= speed * delta * 9;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!hitbox.grounded) {
|
if (!hitbox->grounded) {
|
||||||
hitbox.linearDamping = PLAYER_AIR_DAMPING;
|
hitbox->linearDamping = PLAYER_AIR_DAMPING;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.jump && hitbox.grounded){
|
if (input.jump && hitbox->grounded){
|
||||||
hitbox.velocity.y = JUMP_FORCE;
|
hitbox->velocity.y = JUMP_FORCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((input.flight && !noclip) ||
|
if ((input.flight && !noclip) ||
|
||||||
(input.noclip && flight == noclip)){
|
(input.noclip && flight == noclip)){
|
||||||
flight = !flight;
|
flight = !flight;
|
||||||
if (flight){
|
if (flight){
|
||||||
hitbox.velocity.y += 1.0f;
|
hitbox->velocity.y += 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hitbox.type = noclip ? BodyType::KINEMATIC : BodyType::DYNAMIC;
|
hitbox->type = noclip ? BodyType::KINEMATIC : BodyType::DYNAMIC;
|
||||||
if (input.noclip) {
|
if (input.noclip) {
|
||||||
noclip = !noclip;
|
noclip = !noclip;
|
||||||
}
|
}
|
||||||
@@ -150,18 +136,32 @@ void Player::updateInput(PlayerInput& input, float delta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Player::postUpdate() {
|
void Player::postUpdate() {
|
||||||
auto hitbox = getHitbox();
|
auto entity = level->entities->get(eid);
|
||||||
if (hitbox == nullptr) {
|
if (!entity.has_value()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
position = hitbox->position;
|
auto& hitbox = entity->getRigidbody().hitbox;
|
||||||
|
position = hitbox.position;
|
||||||
|
|
||||||
if (flight && hitbox->grounded) {
|
if (flight && hitbox.grounded) {
|
||||||
flight = false;
|
flight = false;
|
||||||
}
|
}
|
||||||
if (spawnpoint.y <= 0.1) {
|
if (spawnpoint.y <= 0.1) {
|
||||||
attemptToFindSpawnpoint();
|
attemptToFindSpawnpoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto& skeleton = entity->getSkeleton();
|
||||||
|
|
||||||
|
skeleton.visible = currentCamera != camera;
|
||||||
|
|
||||||
|
size_t bodyIndex = skeleton.config->find("body")->getIndex();
|
||||||
|
size_t headIndex = skeleton.config->find("head")->getIndex();
|
||||||
|
|
||||||
|
skeleton.pose.matrices[bodyIndex] =
|
||||||
|
glm::rotate(glm::mat4(1.0f), glm::radians(cam.x-90), glm::vec3(0, 1, 0));
|
||||||
|
skeleton.pose.matrices[headIndex] = glm::rotate(glm::rotate(
|
||||||
|
glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.4f, 0.0f)),
|
||||||
|
glm::radians(-cam.y), glm::vec3(0, 0, 1)), glm::radians(90.0f), glm::vec3(0, 1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::teleport(glm::vec3 position) {
|
void Player::teleport(glm::vec3 position) {
|
||||||
|
|||||||
Reference in New Issue
Block a user