2019-02-13 11:30:16 +04:00
|
|
|
#ifndef OPENMW_MWPHYSICS_PROJECTILE_H
|
|
|
|
#define OPENMW_MWPHYSICS_PROJECTILE_H
|
|
|
|
|
2020-10-23 20:27:07 +02:00
|
|
|
#include <atomic>
|
2019-02-13 11:30:16 +04:00
|
|
|
#include <memory>
|
2020-10-23 20:27:07 +02:00
|
|
|
#include <mutex>
|
2019-02-13 11:30:16 +04:00
|
|
|
|
2021-07-17 08:56:43 +02:00
|
|
|
#include <LinearMath/btVector3.h>
|
|
|
|
|
2020-10-23 20:27:07 +02:00
|
|
|
#include "ptrholder.hpp"
|
2019-02-13 11:30:16 +04:00
|
|
|
|
|
|
|
class btCollisionObject;
|
2020-10-23 20:27:07 +02:00
|
|
|
class btCollisionShape;
|
2019-02-13 11:30:16 +04:00
|
|
|
class btConvexShape;
|
2020-10-23 20:27:07 +02:00
|
|
|
|
|
|
|
namespace osg
|
|
|
|
{
|
|
|
|
class Vec3f;
|
|
|
|
}
|
2019-02-13 11:30:16 +04:00
|
|
|
|
|
|
|
namespace MWPhysics
|
|
|
|
{
|
2020-10-23 20:27:07 +02:00
|
|
|
class PhysicsTaskScheduler;
|
|
|
|
class PhysicsSystem;
|
|
|
|
|
|
|
|
class Projectile final : public PtrHolder
|
2019-02-13 11:30:16 +04:00
|
|
|
{
|
|
|
|
public:
|
2022-09-22 21:26:05 +03:00
|
|
|
Projectile(const MWWorld::Ptr& caster, const osg::Vec3f& position, float radius,
|
|
|
|
PhysicsTaskScheduler* scheduler, PhysicsSystem* physicssystem);
|
2020-10-23 20:27:07 +02:00
|
|
|
~Projectile() override;
|
2019-02-13 11:30:16 +04:00
|
|
|
|
|
|
|
btConvexShape* getConvexShape() const { return mConvexShape; }
|
|
|
|
|
2021-10-09 18:13:54 +02:00
|
|
|
void updateCollisionObjectPosition();
|
2019-02-13 11:30:16 +04:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
bool isActive() const { return mActive.load(std::memory_order_acquire); }
|
2020-10-23 20:27:07 +02:00
|
|
|
|
2021-08-05 10:55:19 +02:00
|
|
|
MWWorld::Ptr getTarget() const;
|
2020-10-23 20:27:07 +02:00
|
|
|
|
2020-12-14 22:23:01 +01:00
|
|
|
MWWorld::Ptr getCaster() const;
|
2021-06-23 23:13:59 +02:00
|
|
|
void setCaster(const MWWorld::Ptr& caster);
|
2022-09-22 21:26:05 +03:00
|
|
|
const btCollisionObject* getCasterCollisionObject() const { return mCasterColObj; }
|
2020-11-21 16:26:45 +01:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
void setHitWater() { mHitWater = true; }
|
2021-08-31 16:25:45 +02:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
bool getHitWater() const { return mHitWater; }
|
2020-10-23 20:27:07 +02:00
|
|
|
|
2021-08-05 10:55:19 +02:00
|
|
|
void hit(const btCollisionObject* target, btVector3 pos, btVector3 normal);
|
2020-10-23 20:27:07 +02:00
|
|
|
|
2020-12-14 22:23:01 +01:00
|
|
|
void setValidTargets(const std::vector<MWWorld::Ptr>& targets);
|
2021-08-05 10:55:19 +02:00
|
|
|
bool isValidTarget(const btCollisionObject* target) const;
|
2020-12-14 22:23:01 +01:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
btVector3 getHitPosition() const { return mHitPosition; }
|
2021-01-07 11:02:53 +01:00
|
|
|
|
2019-02-13 11:30:16 +04:00
|
|
|
private:
|
|
|
|
std::unique_ptr<btCollisionShape> mShape;
|
|
|
|
btConvexShape* mConvexShape;
|
|
|
|
|
2021-08-31 16:25:45 +02:00
|
|
|
bool mHitWater;
|
2020-10-23 20:27:07 +02:00
|
|
|
std::atomic<bool> mActive;
|
2020-11-21 16:26:45 +01:00
|
|
|
MWWorld::Ptr mCaster;
|
2021-08-05 10:55:19 +02:00
|
|
|
const btCollisionObject* mCasterColObj;
|
|
|
|
const btCollisionObject* mHitTarget;
|
2020-10-31 14:01:14 +01:00
|
|
|
btVector3 mHitPosition;
|
|
|
|
btVector3 mHitNormal;
|
2020-10-23 20:27:07 +02:00
|
|
|
|
2021-08-05 10:55:19 +02:00
|
|
|
std::vector<const btCollisionObject*> mValidTargets;
|
2020-12-14 22:23:01 +01:00
|
|
|
|
|
|
|
mutable std::mutex mMutex;
|
2019-02-13 11:30:16 +04:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
PhysicsSystem* mPhysics;
|
|
|
|
PhysicsTaskScheduler* mTaskScheduler;
|
2019-02-13 11:30:16 +04:00
|
|
|
|
|
|
|
Projectile(const Projectile&);
|
|
|
|
Projectile& operator=(const Projectile&);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|