Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale animation speed off frame rate + fix player y positioning #196

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/client/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ class Client {
float mouse_xpos = 0.0f;
float mouse_ypos = 0.0f;

double lastTime = 0.0;

GameConfig config;
tcp::resolver resolver;
tcp::socket socket;
Expand Down
9 changes: 8 additions & 1 deletion src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,10 @@ void Client::geometryPass() {
bool is_dm = this->session->getInfo().is_dungeon_master.value();
glm::vec3 my_pos = this->gameState.objects[eid]->physics.corner;

double currentTime = glfwGetTime();
double timeElapsed = currentTime - lastTime;
lastTime = currentTime;

// draw all objects to g-buffer
for (auto& [id, sharedObject] : this->gameState.objects) {
if (!sharedObject.has_value()) {
Expand Down Expand Up @@ -627,6 +631,7 @@ void Client::geometryPass() {
// TODO: Update the player eye level to an acceptable level

glm::vec3 pos = sharedObject->physics.getCenterPosition();
pos.y -= (sharedObject->physics.dimensions.y / 2.0f);
pos.y += PLAYER_EYE_LEVEL;
cam->updatePos(pos);

Expand All @@ -648,7 +653,7 @@ void Client::geometryPass() {
animManager->setAnimation(sharedObject->globalID, sharedObject->type, sharedObject->animState);

/* Update model animation */
animManager->updateAnimation(0.025f);
animManager->updateAnimation(timeElapsed);
auto transforms = animManager->getFinalBoneMatrices();

for (int i = 0; i < (transforms.size() < 100 ? transforms.size() : 100); ++i) {
Expand All @@ -658,6 +663,8 @@ void Client::geometryPass() {
if (!sharedObject->playerInfo->render) { break; } // dont render while invisible

auto player_pos = sharedObject->physics.getCenterPosition();
player_pos.y -= (sharedObject->physics.dimensions.y / 2.0f);

auto player_dir = sharedObject->physics.facing;

if (player_dir == glm::vec3(0.0f)) {
Expand Down
Loading