1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-26 04:12:41 +01:00

Jump test

This commit is contained in:
Daniel Evans 2013-12-24 19:47:04 +00:00
parent dc32c9c6ce
commit 7cbebb89dd
5 changed files with 58 additions and 21 deletions

View File

@ -31,6 +31,8 @@ public:
virtual void update(float dt); virtual void update(float dt);
virtual glm::vec3 getTargetPosition(); virtual glm::vec3 getTargetPosition();
void jump();
}; };
#endif #endif

View File

@ -31,6 +31,9 @@ public:
Walk, Walk,
Run, Run,
Crouch, Crouch,
Jump,
Falling,
Landing,
VehicleDrive, VehicleDrive,
VehicleSit, VehicleSit,
KnockedDown, KnockedDown,
@ -81,6 +84,8 @@ public:
virtual bool takeDamage(const DamageInfo& damage); virtual bool takeDamage(const DamageInfo& damage);
void jump();
/** /**
* Resets the Actor to the nearest AI Graph node * Resets the Actor to the nearest AI Graph node
* (taking into account the current vehicle) * (taking into account the current vehicle)

View File

@ -62,26 +62,35 @@ void GTAPlayerAIController::enterNearestVehicle()
void GTAPlayerAIController::update(float dt) void GTAPlayerAIController::update(float dt)
{ {
if( glm::length(direction) > 0.001f ) { if( character->currentActivity != GTACharacter::Jump )
character->changeAction(running ? GTACharacter::Run : GTACharacter::Walk); {
} if( glm::length(direction) > 0.001f ) {
else { character->changeAction(running ? GTACharacter::Run : GTACharacter::Walk);
character->changeAction(GTACharacter::Idle); }
} else {
character->changeAction(GTACharacter::Idle);
}
if( character->getCurrentVehicle() ) { if( character->getCurrentVehicle() ) {
character->getCurrentVehicle()->setSteeringAngle(-direction.x * 3.131f); character->getCurrentVehicle()->setSteeringAngle(-direction.x * 3.131f);
// TODO what is handbraking. // TODO what is handbraking.
character->getCurrentVehicle()->setThrottle(direction.y); 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() glm::vec3 GTAPlayerAIController::getTargetPosition()
{ {
return direction; return direction;
} }
void GTAPlayerAIController::jump()
{
character->changeAction(GTACharacter::Jump);
character->jump();
}

View File

@ -119,7 +119,6 @@ void GTACharacter::tick(float dt)
void GTACharacter::updateCharacter() void GTACharacter::updateCharacter()
{ {
if(physCharacter) { if(physCharacter) {
// Check to see if the character should be knocked down. // Check to see if the character should be knocked down.
btManifoldArray manifoldArray; btManifoldArray manifoldArray;
btBroadphasePairArray& pairArray = physObject->getOverlappingPairCache()->getOverlappingPairArray(); btBroadphasePairArray& pairArray = physObject->getOverlappingPairCache()->getOverlappingPairArray();
@ -163,11 +162,21 @@ void GTACharacter::updateCharacter()
} }
} }
glm::vec3 direction = rotation * animator->getRootTranslation(); if(currentActivity == GTACharacter::Jump)
physCharacter->setWalkDirection(btVector3(direction.x, direction.y, direction.z)); {
if(physCharacter->onGround())
btVector3 Pos = physCharacter->getGhostObject()->getWorldTransform().getOrigin(); {
position = glm::vec3(Pos.x(), Pos.y(), Pos.z()); 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; return true;
} }
void GTACharacter::jump()
{
physCharacter->jump();
changeAction(GTACharacter::Jump);
}
void GTACharacter::resetToAINode() void GTACharacter::resetToAINode()
{ {
auto nodes = engine->aigraph.nodes; auto nodes = engine->aigraph.nodes;

View File

@ -288,9 +288,14 @@ void handleInputEvent(sf::Event &event)
switch(event.type) { switch(event.type) {
case sf::Event::KeyPressed: case sf::Event::KeyPressed:
switch (event.key.code) { switch (event.key.code) {
case sf::Keyboard::Space: case sf::Keyboard::LShift:
moveSpeed = 60.f; moveSpeed = 60.f;
break; break;
case sf::Keyboard::Space:
if(playerCharacter) {
playerCharacter->jump();
}
break;
case sf::Keyboard::M: case sf::Keyboard::M:
mouseGrabbed = ! mouseGrabbed; mouseGrabbed = ! mouseGrabbed;
break; break;
@ -660,6 +665,7 @@ int main(int argc, char *argv[])
cs.depthBits = 32; cs.depthBits = 32;
window.create(sf::VideoMode(w, h), "GTA3 Viewer", sf::Style::Close, cs); window.create(sf::VideoMode(w, h), "GTA3 Viewer", sf::Style::Close, cs);
window.setVerticalSyncEnabled(true); window.setVerticalSyncEnabled(true);
window.setMouseCursorVisible(false);
init(argv[optind], loadWorld); init(argv[optind], loadWorld);