1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-05 17:45:34 +00:00

Add a method to set/retrieve being on the ground

This commit is contained in:
Chris Robinson 2013-02-06 21:44:58 -08:00
parent ebc7bc9427
commit e577ee2de8
4 changed files with 31 additions and 16 deletions

View file

@ -9,6 +9,9 @@
#include <OgreCamera.h> #include <OgreCamera.h>
#include <OgreTextureManager.h> #include <OgreTextureManager.h>
#include <libs/openengine/bullet/trace.h>
#include <libs/openengine/bullet/physic.hpp>
#include <components/nifbullet/bullet_nif_loader.hpp> #include <components/nifbullet/bullet_nif_loader.hpp>
//#include "../mwbase/world.hpp" // FIXME //#include "../mwbase/world.hpp" // FIXME
@ -129,6 +132,7 @@ namespace MWWorld
Ogre::Vector3 up(0.0f, 0.0f, 1.0f); Ogre::Vector3 up(0.0f, 0.0f, 1.0f);
Ogre::Vector3 newPosition = position; Ogre::Vector3 newPosition = position;
bool onground = false;
if(gravity) if(gravity)
{ {
newtrace(&trace, position, position+Ogre::Vector3(0,0,-10), halfExtents, verticalRotation, isInterior, engine); 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); remainingTime = remainingTime * (1.0f-trace.fraction);
// check for obstructions // check for obstructions
if(trace.fraction != 1.0f) if(trace.fraction < 1.0f)
{ {
//std::cout<<"angle: "<<getSlope(trace.planenormal)<<"\n"; //std::cout<<"angle: "<<getSlope(trace.planenormal)<<"\n";
if(getSlope(currentNormal) > sMaxSlope || currentNormal == lastNormal) onground = getSlope(currentNormal) <= sMaxSlope;
if(!onground || currentNormal == lastNormal)
{ {
if(!stepMove(newPosition, velocity, remainingTime, verticalRotation, halfExtents, isInterior, engine)) if(!stepMove(newPosition, velocity, remainingTime, verticalRotation, halfExtents, isInterior, engine))
{ {
@ -184,8 +189,8 @@ namespace MWWorld
} while(iterations < maxIterations && remainingTime != 0.0f); } while(iterations < maxIterations && remainingTime != 0.0f);
verticalVelocity = clippedVelocity.z; verticalVelocity = clippedVelocity.z;
verticalVelocity -= time*400; physicActor->setVerticalForce(verticalVelocity - time*400.0f);
physicActor->setVerticalForce(verticalVelocity); physicActor->setOnGround(onground);
return newPosition; return newPosition;
} }

View file

@ -1,5 +1,7 @@
#include "worldimp.hpp" #include "worldimp.hpp"
#include <libs/openengine/bullet/physic.hpp>
#include <components/bsa/bsa_archive.hpp> #include <components/bsa/bsa_archive.hpp>
#include <components/files/collections.hpp> #include <components/files/collections.hpp>
@ -1366,20 +1368,14 @@ namespace MWWorld
{ {
Ptr::CellStore *currentCell = mWorldScene->getCurrentCell(); Ptr::CellStore *currentCell = mWorldScene->getCurrentCell();
Ogre::Vector3 playerPos; RefData &refdata = mPlayer->getPlayer().getRefData();
float* pos = mPlayer->getPlayer ().getRefData ().getPosition ().pos; const OEngine::Physic::PhysicActor *physact = mPhysEngine->getCharacter(refdata.getHandle());
playerPos.x = pos[0]; Ogre::Vector3 playerPos(refdata.getPosition().pos);
playerPos.y = pos[1];
playerPos.z = pos[2];
std::pair<bool, Ogre::Vector3> hit = if(!physact->getOnGround() || isUnderwater(*currentCell->mCell, playerPos))
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))
return 2; return 2;
if (currentCell->mCell->mData.mFlags & ESM::Cell::NoSleep) if((currentCell->mCell->mData.mFlags&ESM::Cell::NoSleep))
return 1; return 1;
return 0; return 0;

View file

@ -28,7 +28,7 @@ namespace Physic
}; };
PhysicActor::PhysicActor(std::string name, std::string mesh, PhysicEngine* engine, Ogre::Vector3 position, Ogre::Quaternion rotation, float scale): 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); mBody = mEngine->createAndAdjustRigidBody(mMesh, mName, scale, position, rotation, &mBoxScaledTranslation, &mBoxRotation);
Ogre::Quaternion inverse = mBoxRotation.Inverse(); Ogre::Quaternion inverse = mBoxRotation.Inverse();
@ -180,6 +180,15 @@ namespace Physic
return verticalForce; return verticalForce;
} }
void PhysicActor::setOnGround(bool grounded)
{
onGround = grounded;
}
bool PhysicActor::getOnGround() const
{
return collisionMode && onGround;
}
void PhysicActor::runPmove(){ void PhysicActor::runPmove(){
Pmove(pmove); Pmove(pmove);

View file

@ -132,6 +132,10 @@ namespace Physic
*/ */
float getVerticalForce() const; float getVerticalForce() const;
void setOnGround(bool grounded);
bool getOnGround() const;
/** /**
* Runs pmove for this PhysicActor * Runs pmove for this PhysicActor
*/ */
@ -152,6 +156,7 @@ namespace Physic
btQuaternion mBoxRotationInverse; btQuaternion mBoxRotationInverse;
Ogre::Quaternion mBoxRotation; Ogre::Quaternion mBoxRotation;
float verticalForce; float verticalForce;
bool onGround;
bool collisionMode; bool collisionMode;
std::string mMesh; std::string mMesh;
PhysicEngine* mEngine; PhysicEngine* mEngine;