2019-02-13 07:30:16 +00:00
|
|
|
#ifndef OPENMW_MWPHYSICS_PROJECTILE_H
|
|
|
|
#define OPENMW_MWPHYSICS_PROJECTILE_H
|
|
|
|
|
2020-10-23 18:27:07 +00:00
|
|
|
#include <atomic>
|
2019-02-13 07:30:16 +00:00
|
|
|
#include <memory>
|
2020-10-23 18:27:07 +00:00
|
|
|
#include <mutex>
|
2021-01-07 10:02:53 +00:00
|
|
|
#include <optional>
|
2019-02-13 07:30:16 +00:00
|
|
|
|
2020-10-23 18:27:07 +00:00
|
|
|
#include "ptrholder.hpp"
|
2019-02-13 07:30:16 +00:00
|
|
|
|
|
|
|
class btCollisionObject;
|
2020-10-23 18:27:07 +00:00
|
|
|
class btCollisionShape;
|
2019-02-13 07:30:16 +00:00
|
|
|
class btConvexShape;
|
2020-10-23 18:27:07 +00:00
|
|
|
class btVector3;
|
|
|
|
|
|
|
|
namespace osg
|
|
|
|
{
|
|
|
|
class Vec3f;
|
|
|
|
}
|
2019-02-13 07:30:16 +00:00
|
|
|
|
|
|
|
namespace Resource
|
|
|
|
{
|
|
|
|
class BulletShape;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace MWPhysics
|
|
|
|
{
|
2020-10-23 18:27:07 +00:00
|
|
|
class PhysicsTaskScheduler;
|
|
|
|
class PhysicsSystem;
|
|
|
|
|
|
|
|
class Projectile final : public PtrHolder
|
2019-02-13 07:30:16 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-01-07 10:02:53 +00:00
|
|
|
Projectile(const MWWorld::Ptr& caster, const osg::Vec3f& position, float radius, bool canCrossWaterSurface, PhysicsTaskScheduler* scheduler, PhysicsSystem* physicssystem);
|
2020-10-23 18:27:07 +00:00
|
|
|
~Projectile() override;
|
2019-02-13 07:30:16 +00:00
|
|
|
|
|
|
|
btConvexShape* getConvexShape() const { return mConvexShape; }
|
|
|
|
|
2020-10-23 18:27:07 +00:00
|
|
|
void commitPositionChange();
|
2019-02-13 07:30:16 +00:00
|
|
|
|
|
|
|
void setPosition(const osg::Vec3f& position);
|
2021-01-07 10:02:53 +00:00
|
|
|
osg::Vec3f getPosition() const;
|
2019-02-13 07:30:16 +00:00
|
|
|
|
|
|
|
btCollisionObject* getCollisionObject() const
|
|
|
|
{
|
|
|
|
return mCollisionObject.get();
|
|
|
|
}
|
|
|
|
|
2020-10-23 18:27:07 +00:00
|
|
|
bool isActive() const
|
|
|
|
{
|
|
|
|
return mActive.load(std::memory_order_acquire);
|
|
|
|
}
|
|
|
|
|
|
|
|
MWWorld::Ptr getTarget() const
|
|
|
|
{
|
|
|
|
assert(!mActive);
|
|
|
|
return mHitTarget;
|
|
|
|
}
|
|
|
|
|
2020-12-14 21:23:01 +00:00
|
|
|
MWWorld::Ptr getCaster() const;
|
2021-06-23 21:13:59 +00:00
|
|
|
void setCaster(const MWWorld::Ptr& caster);
|
2020-11-21 15:26:45 +00:00
|
|
|
|
2021-01-07 10:02:53 +00:00
|
|
|
bool canTraverseWater() const;
|
2020-10-23 18:27:07 +00:00
|
|
|
|
2021-06-23 21:13:59 +00:00
|
|
|
void hit(const MWWorld::Ptr& target, btVector3 pos, btVector3 normal);
|
2020-10-23 18:27:07 +00:00
|
|
|
|
2020-12-14 21:23:01 +00:00
|
|
|
void setValidTargets(const std::vector<MWWorld::Ptr>& targets);
|
|
|
|
bool isValidTarget(const MWWorld::Ptr& target) const;
|
|
|
|
|
2021-01-07 10:02:53 +00:00
|
|
|
std::optional<btVector3> getWaterHitPosition();
|
|
|
|
void setWaterHitPosition(btVector3 pos);
|
|
|
|
|
2019-02-13 07:30:16 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
std::unique_ptr<btCollisionShape> mShape;
|
|
|
|
btConvexShape* mConvexShape;
|
|
|
|
|
|
|
|
std::unique_ptr<btCollisionObject> mCollisionObject;
|
2020-10-23 18:27:07 +00:00
|
|
|
btTransform mLocalTransform;
|
|
|
|
bool mTransformUpdatePending;
|
2021-01-07 10:02:53 +00:00
|
|
|
bool mCanCrossWaterSurface;
|
|
|
|
bool mCrossedWaterSurface;
|
2020-10-23 18:27:07 +00:00
|
|
|
std::atomic<bool> mActive;
|
2020-11-21 15:26:45 +00:00
|
|
|
MWWorld::Ptr mCaster;
|
2020-10-23 18:27:07 +00:00
|
|
|
MWWorld::Ptr mHitTarget;
|
2021-01-07 10:02:53 +00:00
|
|
|
std::optional<btVector3> mWaterHitPosition;
|
2020-10-31 13:01:14 +00:00
|
|
|
btVector3 mHitPosition;
|
|
|
|
btVector3 mHitNormal;
|
2020-10-23 18:27:07 +00:00
|
|
|
|
2020-12-14 21:23:01 +00:00
|
|
|
std::vector<MWWorld::Ptr> mValidTargets;
|
|
|
|
|
|
|
|
mutable std::mutex mMutex;
|
2019-02-13 07:30:16 +00:00
|
|
|
|
2020-10-31 13:01:14 +00:00
|
|
|
PhysicsSystem *mPhysics;
|
2020-10-23 18:27:07 +00:00
|
|
|
PhysicsTaskScheduler *mTaskScheduler;
|
2019-02-13 07:30:16 +00:00
|
|
|
|
|
|
|
Projectile(const Projectile&);
|
|
|
|
Projectile& operator=(const Projectile&);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|