1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 06:52:34 +02: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 glm::vec3 getTargetPosition();
void jump();
};
#endif

View File

@ -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)

View File

@ -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();
}

View File

@ -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;

View File

@ -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);