diff --git a/framework2/include/ai/GTAPlayerAIController.hpp b/framework2/include/ai/GTAPlayerAIController.hpp index 7c5fb046..689ced1c 100644 --- a/framework2/include/ai/GTAPlayerAIController.hpp +++ b/framework2/include/ai/GTAPlayerAIController.hpp @@ -31,6 +31,8 @@ public: virtual void update(float dt); virtual glm::vec3 getTargetPosition(); + + void jump(); }; #endif diff --git a/framework2/include/objects/GTACharacter.hpp b/framework2/include/objects/GTACharacter.hpp index 59281161..45ab052a 100644 --- a/framework2/include/objects/GTACharacter.hpp +++ b/framework2/include/objects/GTACharacter.hpp @@ -31,6 +31,9 @@ public: Walk, Run, Crouch, + Jump, + Falling, + Landing, VehicleDrive, VehicleSit, KnockedDown, @@ -81,6 +84,8 @@ public: virtual bool takeDamage(const DamageInfo& damage); + void jump(); + /** * Resets the Actor to the nearest AI Graph node * (taking into account the current vehicle) diff --git a/framework2/src/ai/GTAPlayerAIController.cpp b/framework2/src/ai/GTAPlayerAIController.cpp index c01d0353..915c5483 100644 --- a/framework2/src/ai/GTAPlayerAIController.cpp +++ b/framework2/src/ai/GTAPlayerAIController.cpp @@ -62,26 +62,35 @@ void GTAPlayerAIController::enterNearestVehicle() void GTAPlayerAIController::update(float dt) { - if( glm::length(direction) > 0.001f ) { - character->changeAction(running ? GTACharacter::Run : GTACharacter::Walk); - } - else { - character->changeAction(GTACharacter::Idle); - } + if( character->currentActivity != GTACharacter::Jump ) + { + if( glm::length(direction) > 0.001f ) { + character->changeAction(running ? GTACharacter::Run : GTACharacter::Walk); + } + else { + character->changeAction(GTACharacter::Idle); + } - if( character->getCurrentVehicle() ) { - character->getCurrentVehicle()->setSteeringAngle(-direction.x * 3.131f); + if( character->getCurrentVehicle() ) { + character->getCurrentVehicle()->setSteeringAngle(-direction.x * 3.131f); - // TODO what is handbraking. - character->getCurrentVehicle()->setThrottle(direction.y); + // TODO what is handbraking. + character->getCurrentVehicle()->setThrottle(direction.y); + } + else if( glm::length(direction) > 0.001f ) { + character->rotation = cameraRotation * glm::quat(glm::vec3(0.f, 0.f, -atan2(direction.x, direction.y))); + } } - else if( glm::length(direction) > 0.001f ) { - character->rotation = cameraRotation * glm::quat(glm::vec3(0.f, 0.f, -atan2(direction.x, direction.y))); - } - } glm::vec3 GTAPlayerAIController::getTargetPosition() { return direction; } + +void GTAPlayerAIController::jump() +{ + character->changeAction(GTACharacter::Jump); + character->jump(); +} + diff --git a/framework2/src/objects/GTACharacter.cpp b/framework2/src/objects/GTACharacter.cpp index 7c7d6524..47642857 100644 --- a/framework2/src/objects/GTACharacter.cpp +++ b/framework2/src/objects/GTACharacter.cpp @@ -119,7 +119,6 @@ void GTACharacter::tick(float dt) void GTACharacter::updateCharacter() { if(physCharacter) { - // Check to see if the character should be knocked down. btManifoldArray manifoldArray; btBroadphasePairArray& pairArray = physObject->getOverlappingPairCache()->getOverlappingPairArray(); @@ -163,11 +162,21 @@ void GTACharacter::updateCharacter() } } - glm::vec3 direction = rotation * animator->getRootTranslation(); - physCharacter->setWalkDirection(btVector3(direction.x, direction.y, direction.z)); - - btVector3 Pos = physCharacter->getGhostObject()->getWorldTransform().getOrigin(); - position = glm::vec3(Pos.x(), Pos.y(), Pos.z()); + if(currentActivity == GTACharacter::Jump) + { + if(physCharacter->onGround()) + { + changeAction(GTACharacter::Idle); + } + } + else + { + glm::vec3 direction = rotation * animator->getRootTranslation(); + physCharacter->setWalkDirection(btVector3(direction.x, direction.y, direction.z)); + + btVector3 Pos = physCharacter->getGhostObject()->getWorldTransform().getOrigin(); + position = glm::vec3(Pos.x(), Pos.y(), Pos.z()); + } } } @@ -245,6 +254,12 @@ bool GTACharacter::takeDamage(const GTAObject::DamageInfo& dmg) return true; } +void GTACharacter::jump() +{ + physCharacter->jump(); + changeAction(GTACharacter::Jump); +} + void GTACharacter::resetToAINode() { auto nodes = engine->aigraph.nodes; diff --git a/viewer/main.cpp b/viewer/main.cpp index ec0ca8a9..a298a3ac 100644 --- a/viewer/main.cpp +++ b/viewer/main.cpp @@ -288,9 +288,14 @@ void handleInputEvent(sf::Event &event) switch(event.type) { case sf::Event::KeyPressed: switch (event.key.code) { - case sf::Keyboard::Space: + case sf::Keyboard::LShift: moveSpeed = 60.f; break; + case sf::Keyboard::Space: + if(playerCharacter) { + playerCharacter->jump(); + } + break; case sf::Keyboard::M: mouseGrabbed = ! mouseGrabbed; break; @@ -660,6 +665,7 @@ int main(int argc, char *argv[]) cs.depthBits = 32; window.create(sf::VideoMode(w, h), "GTA3 Viewer", sf::Style::Close, cs); window.setVerticalSyncEnabled(true); + window.setMouseCursorVisible(false); init(argv[optind], loadWorld);