diff options
author | joschiwald <joschiwald.trinity@gmail.com> | 2017-05-05 20:48:08 +0200 |
---|---|---|
committer | joschiwald <joschiwald.trinity@gmail.com> | 2017-05-05 21:22:58 +0200 |
commit | 036f67c0c144954827733cad0c5881eba1bd88e7 (patch) | |
tree | 6ebf1797fd5e27ed67049010af18ecb72aea21db /src/common/Collision/Models | |
parent | c1cc0e9949a73e1cbb2640032d5d038cca051954 (diff) |
Core/Collision: Replaced phasemask with proper phases in GameObject collision calculation
Diffstat (limited to 'src/common/Collision/Models')
-rw-r--r-- | src/common/Collision/Models/GameObjectModel.cpp | 14 | ||||
-rw-r--r-- | src/common/Collision/Models/GameObjectModel.h | 17 |
2 files changed, 16 insertions, 15 deletions
diff --git a/src/common/Collision/Models/GameObjectModel.cpp b/src/common/Collision/Models/GameObjectModel.cpp index b111b0de301..f3e5d9f6e64 100644 --- a/src/common/Collision/Models/GameObjectModel.cpp +++ b/src/common/Collision/Models/GameObjectModel.cpp @@ -115,7 +115,6 @@ bool GameObjectModel::initialize(std::unique_ptr<GameObjectModelOwnerBase> model name = it->second.name; iPos = modelOwner->GetPosition(); - phasemask = modelOwner->GetPhaseMask(); iScale = modelOwner->GetScale(); iInvScale = 1.f / iScale; @@ -153,9 +152,12 @@ GameObjectModel* GameObjectModel::Create(std::unique_ptr<GameObjectModelOwnerBas return mdl; } -bool GameObjectModel::intersectRay(const G3D::Ray& ray, float& MaxDist, bool StopAtFirstHit, uint32 ph_mask) const +bool GameObjectModel::intersectRay(G3D::Ray const& ray, float& maxDist, bool stopAtFirstHit, std::set<uint32> const& phases) const { - if (!(phasemask & ph_mask) || !owner->IsSpawned()) + if (!isCollisionEnabled() || !owner->IsSpawned()) + return false; + + if (!owner->IsInPhase(phases)) return false; float time = ray.intersectionTime(iBound); @@ -165,12 +167,12 @@ bool GameObjectModel::intersectRay(const G3D::Ray& ray, float& MaxDist, bool Sto // child bounds are defined in object space: Vector3 p = iInvRot * (ray.origin() - iPos) * iInvScale; Ray modRay(p, iInvRot * ray.direction()); - float distance = MaxDist * iInvScale; - bool hit = iModel->IntersectRay(modRay, distance, StopAtFirstHit); + float distance = maxDist * iInvScale; + bool hit = iModel->IntersectRay(modRay, distance, stopAtFirstHit); if (hit) { distance *= iScale; - MaxDist = distance; + maxDist = distance; } return hit; } diff --git a/src/common/Collision/Models/GameObjectModel.h b/src/common/Collision/Models/GameObjectModel.h index a9fce400146..477d49ccf80 100644 --- a/src/common/Collision/Models/GameObjectModel.h +++ b/src/common/Collision/Models/GameObjectModel.h @@ -26,6 +26,7 @@ #include "Define.h" #include <memory> +#include <set> namespace VMAP { @@ -40,7 +41,7 @@ class TC_COMMON_API GameObjectModelOwnerBase public: virtual bool IsSpawned() const { return false; } virtual uint32 GetDisplayId() const { return 0; } - virtual uint32 GetPhaseMask() const { return 0; } + virtual bool IsInPhase(std::set<uint32> const& phases) const { return false; } virtual G3D::Vector3 GetPosition() const { return G3D::Vector3::zero(); } virtual float GetOrientation() const { return 0.0f; } virtual float GetScale() const { return 1.0f; } @@ -49,7 +50,7 @@ public: class TC_COMMON_API GameObjectModel /*, public Intersectable*/ { - GameObjectModel() : phasemask(0), iInvScale(0), iScale(0), iModel(NULL) { } + GameObjectModel() : _collisionEnabled(false), iInvScale(0), iScale(0), iModel(nullptr) { } public: std::string name; @@ -59,13 +60,11 @@ public: const G3D::Vector3& getPosition() const { return iPos;} - /** Enables\disables collision. */ - void disable() { phasemask = 0;} - void enable(uint32 ph_mask) { phasemask = ph_mask;} + /* Enables/disables collision */ + void enableCollision(bool enable) { _collisionEnabled = enable; } + bool isCollisionEnabled() const { return _collisionEnabled; } - bool isEnabled() const {return phasemask != 0;} - - bool intersectRay(const G3D::Ray& Ray, float& MaxDist, bool StopAtFirstHit, uint32 ph_mask) const; + bool intersectRay(G3D::Ray const& ray, float& maxDist, bool stopAtFirstHit, std::set<uint32> const& phases) const; static GameObjectModel* Create(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string const& dataPath); @@ -74,7 +73,7 @@ public: private: bool initialize(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string const& dataPath); - uint32 phasemask; + bool _collisionEnabled; G3D::AABox iBound; G3D::Matrix3 iInvRot; G3D::Vector3 iPos; |