Better boat handling
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <Jolt/Physics/Collision/Shape/Shape.h>
|
||||
#include <Jolt/Physics/Collision/Shape/StaticCompoundShape.h>
|
||||
#include <Jolt/Physics/Collision/ObjectLayer.h>
|
||||
#include <Jolt/Physics/Collision/ContactListener.h>
|
||||
#include <Jolt/Physics/Collision/BroadPhase/BroadPhaseLayer.h>
|
||||
#include <Jolt/Physics/Body/BodyCreationSettings.h>
|
||||
#include <Jolt/Physics/EActivation.h>
|
||||
@@ -13,6 +14,9 @@ void physics();
|
||||
namespace JPH
|
||||
{
|
||||
class CharacterBase;
|
||||
class ContactManifold;
|
||||
class ContactSettings;
|
||||
class SubShapeIDPair;
|
||||
}
|
||||
// Layer that objects can be in, determines which other objects it can collide with
|
||||
// Typically you at least want to have 1 layer for moving bodies and 1 layer for static bodies, but you can have more
|
||||
@@ -50,10 +54,58 @@ struct CompoundShapeBuilder {
|
||||
const Ogre::Quaternion &rotation);
|
||||
JPH::ShapeRefC build();
|
||||
};
|
||||
class ContactListener : public JPH::ContactListener {
|
||||
public:
|
||||
struct ContactReport {
|
||||
bool entered;
|
||||
JPH::BodyID id1, id2;
|
||||
JPH::ContactManifold manifold;
|
||||
JPH::ContactSettings settings;
|
||||
};
|
||||
|
||||
private:
|
||||
std::list<ContactReport> reports;
|
||||
std::function<void(const ContactReport &report)> dispatch;
|
||||
std::map<JPH::BodyID, std::function<void(const ContactReport &report)> >
|
||||
listeners;
|
||||
|
||||
public:
|
||||
ContactListener();
|
||||
JPH::ValidateResult OnContactValidate(
|
||||
const JPH::Body &inBody1, const JPH::Body &inBody2,
|
||||
JPH::RVec3Arg inBaseOffset,
|
||||
const JPH::CollideShapeResult &inCollisionResult) override;
|
||||
void OnContactAdded(const JPH::Body &inBody1, const JPH::Body &inBody2,
|
||||
const JPH::ContactManifold &inManifold,
|
||||
JPH::ContactSettings &ioSettings) override;
|
||||
void OnContactPersisted(const JPH::Body &inBody1,
|
||||
const JPH::Body &inBody2,
|
||||
const JPH::ContactManifold &inManifold,
|
||||
JPH::ContactSettings &ioSettings) override;
|
||||
void
|
||||
OnContactRemoved(const JPH::SubShapeIDPair &inSubShapePair) override;
|
||||
void setDispatch(const std::function<void(const ContactReport &report)>
|
||||
dispatcher)
|
||||
{
|
||||
dispatch = dispatcher;
|
||||
}
|
||||
void addListener(
|
||||
const JPH::BodyID &id,
|
||||
const std::function<void(const ContactReport &report)> listener)
|
||||
{
|
||||
listeners[id] = listener;
|
||||
}
|
||||
void removeListener(const JPH::BodyID &id)
|
||||
{
|
||||
listeners.erase(id);
|
||||
}
|
||||
void update();
|
||||
};
|
||||
}
|
||||
|
||||
class JoltPhysicsWrapper : public Ogre::Singleton<JoltPhysicsWrapper> {
|
||||
public:
|
||||
JoltPhysics::ContactListener contacts;
|
||||
JoltPhysicsWrapper(Ogre::SceneManager *scnMgr,
|
||||
Ogre::SceneNode *cameraNode);
|
||||
~JoltPhysicsWrapper();
|
||||
@@ -128,6 +180,7 @@ public:
|
||||
Ogre::Vector3 getPosition(JPH::BodyID id);
|
||||
void setPosition(JPH::BodyID id, const Ogre::Vector3 &position,
|
||||
bool activate = true);
|
||||
Ogre::Quaternion getRotation(JPH::BodyID id);
|
||||
void setRotation(JPH::BodyID id, const Ogre::Quaternion &rotation,
|
||||
bool activate = true);
|
||||
void getPositionAndRotation(JPH::BodyID id, Ogre::Vector3 &position,
|
||||
@@ -137,7 +190,19 @@ public:
|
||||
const Ogre::Quaternion &rotation,
|
||||
bool activate = true);
|
||||
Ogre::Vector3 getLinearVelocity(JPH::BodyID id);
|
||||
Ogre::Vector3 getAngularVelocity(JPH::BodyID id);
|
||||
float getFriction(JPH::BodyID id);
|
||||
void setFriction(JPH::BodyID id, float friction);
|
||||
void addAngularImpulse(const JPH::BodyID &id,
|
||||
const Ogre::Vector3 &impulse);
|
||||
void setDispatch(std::function<void(const JoltPhysics::ContactListener::
|
||||
ContactReport &report)>
|
||||
dispatcher);
|
||||
void addContactListener(
|
||||
const JPH::BodyID &id,
|
||||
const std::function<void(const JoltPhysics::ContactListener::
|
||||
ContactReport &report)>
|
||||
listener);
|
||||
void removeContactListener(const JPH::BodyID &id);
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user