From e577ee2de815d9880ab66cf208c03c6c259cec0f Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 6 Feb 2013 21:44:58 -0800 Subject: [PATCH] Add a method to set/retrieve being on the ground --- apps/openmw/mwworld/physicssystem.cpp | 13 +++++++++---- apps/openmw/mwworld/worldimp.cpp | 18 +++++++----------- libs/openengine/bullet/physic.cpp | 11 ++++++++++- libs/openengine/bullet/physic.hpp | 5 +++++ 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index c42214fb20..c5c634d79d 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -9,6 +9,9 @@ #include #include +#include +#include + #include //#include "../mwbase/world.hpp" // FIXME @@ -129,6 +132,7 @@ namespace MWWorld Ogre::Vector3 up(0.0f, 0.0f, 1.0f); Ogre::Vector3 newPosition = position; + bool onground = false; if(gravity) { newtrace(&trace, position, position+Ogre::Vector3(0,0,-10), halfExtents, verticalRotation, isInterior, engine); @@ -155,10 +159,11 @@ namespace MWWorld remainingTime = remainingTime * (1.0f-trace.fraction); // check for obstructions - if(trace.fraction != 1.0f) + if(trace.fraction < 1.0f) { //std::cout<<"angle: "< sMaxSlope || currentNormal == lastNormal) + onground = getSlope(currentNormal) <= sMaxSlope; + if(!onground || currentNormal == lastNormal) { if(!stepMove(newPosition, velocity, remainingTime, verticalRotation, halfExtents, isInterior, engine)) { @@ -184,8 +189,8 @@ namespace MWWorld } while(iterations < maxIterations && remainingTime != 0.0f); verticalVelocity = clippedVelocity.z; - verticalVelocity -= time*400; - physicActor->setVerticalForce(verticalVelocity); + physicActor->setVerticalForce(verticalVelocity - time*400.0f); + physicActor->setOnGround(onground); return newPosition; } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 55270280d1..085add7c9e 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1,5 +1,7 @@ #include "worldimp.hpp" +#include + #include #include @@ -1366,20 +1368,14 @@ namespace MWWorld { Ptr::CellStore *currentCell = mWorldScene->getCurrentCell(); - Ogre::Vector3 playerPos; - float* pos = mPlayer->getPlayer ().getRefData ().getPosition ().pos; - playerPos.x = pos[0]; - playerPos.y = pos[1]; - playerPos.z = pos[2]; + RefData &refdata = mPlayer->getPlayer().getRefData(); + const OEngine::Physic::PhysicActor *physact = mPhysEngine->getCharacter(refdata.getHandle()); + Ogre::Vector3 playerPos(refdata.getPosition().pos); - std::pair hit = - mPhysics->castRay(playerPos, Ogre::Vector3(0,0,-1), 50); - bool isOnGround = (hit.first ? (hit.second.distance (playerPos) < 25) : false); - - if (!isOnGround || isUnderwater (*currentCell->mCell, playerPos)) + if(!physact->getOnGround() || isUnderwater(*currentCell->mCell, playerPos)) return 2; - if (currentCell->mCell->mData.mFlags & ESM::Cell::NoSleep) + if((currentCell->mCell->mData.mFlags&ESM::Cell::NoSleep)) return 1; return 0; diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index 1ae916f81c..95313cdba4 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -28,7 +28,7 @@ namespace Physic }; PhysicActor::PhysicActor(std::string name, std::string mesh, PhysicEngine* engine, Ogre::Vector3 position, Ogre::Quaternion rotation, float scale): - mName(name), mEngine(engine), mMesh(mesh), mBoxScaledTranslation(0,0,0), mBoxRotationInverse(0,0,0,0), mBody(0), collisionMode(false), mBoxRotation(0,0,0,0), verticalForce(0.0f) + mName(name), mEngine(engine), mMesh(mesh), mBoxScaledTranslation(0,0,0), mBoxRotationInverse(0,0,0,0), mBody(0), onGround(false), collisionMode(false), mBoxRotation(0,0,0,0), verticalForce(0.0f) { mBody = mEngine->createAndAdjustRigidBody(mMesh, mName, scale, position, rotation, &mBoxScaledTranslation, &mBoxRotation); Ogre::Quaternion inverse = mBoxRotation.Inverse(); @@ -180,6 +180,15 @@ namespace Physic return verticalForce; } + void PhysicActor::setOnGround(bool grounded) + { + onGround = grounded; + } + + bool PhysicActor::getOnGround() const + { + return collisionMode && onGround; + } void PhysicActor::runPmove(){ Pmove(pmove); diff --git a/libs/openengine/bullet/physic.hpp b/libs/openengine/bullet/physic.hpp index daf1c09f2b..4bc926b8ab 100644 --- a/libs/openengine/bullet/physic.hpp +++ b/libs/openengine/bullet/physic.hpp @@ -132,6 +132,10 @@ namespace Physic */ float getVerticalForce() const; + void setOnGround(bool grounded); + + bool getOnGround() const; + /** * Runs pmove for this PhysicActor */ @@ -152,6 +156,7 @@ namespace Physic btQuaternion mBoxRotationInverse; Ogre::Quaternion mBoxRotation; float verticalForce; + bool onGround; bool collisionMode; std::string mMesh; PhysicEngine* mEngine;