mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-09 21:42:13 +00:00
Add a method to set/retrieve being on the ground
This commit is contained in:
parent
ebc7bc9427
commit
e577ee2de8
@ -9,6 +9,9 @@
|
||||
#include <OgreCamera.h>
|
||||
#include <OgreTextureManager.h>
|
||||
|
||||
#include <libs/openengine/bullet/trace.h>
|
||||
#include <libs/openengine/bullet/physic.hpp>
|
||||
|
||||
#include <components/nifbullet/bullet_nif_loader.hpp>
|
||||
|
||||
//#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: "<<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))
|
||||
{
|
||||
@ -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;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "worldimp.hpp"
|
||||
|
||||
#include <libs/openengine/bullet/physic.hpp>
|
||||
|
||||
#include <components/bsa/bsa_archive.hpp>
|
||||
#include <components/files/collections.hpp>
|
||||
|
||||
@ -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<bool, Ogre::Vector3> 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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user