Skip to content

Commit

Permalink
Merge pull request #196 from ucsd-cse125-sp24/fix/animation-speed
Browse files Browse the repository at this point in the history
Scale animation speed off frame rate + fix player y positioning
  • Loading branch information
Tyler-Lentz authored Jun 4, 2024
2 parents 6d57293 + 7bdbc37 commit 3d587c6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/client/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,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 @@ -666,6 +666,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 @@ -693,6 +697,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 @@ -714,7 +719,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 @@ -724,6 +729,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

0 comments on commit 3d587c6

Please sign in to comment.