From 036f67c0c144954827733cad0c5881eba1bd88e7 Mon Sep 17 00:00:00 2001 From: joschiwald Date: Fri, 5 May 2017 20:48:08 +0200 Subject: Core/Collision: Replaced phasemask with proper phases in GameObject collision calculation --- src/common/Collision/Models/GameObjectModel.cpp | 14 ++++++++------ src/common/Collision/Models/GameObjectModel.h | 17 ++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) (limited to 'src/common/Collision/Models') 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 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 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 +#include 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 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 const& phases) const; static GameObjectModel* Create(std::unique_ptr modelOwner, std::string const& dataPath); @@ -74,7 +73,7 @@ public: private: bool initialize(std::unique_ptr modelOwner, std::string const& dataPath); - uint32 phasemask; + bool _collisionEnabled; G3D::AABox iBound; G3D::Matrix3 iInvRot; G3D::Vector3 iPos; -- cgit v1.2.3