diff options
author | Shauren <shauren.trinity@gmail.com> | 2020-06-28 12:26:39 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2020-06-28 12:26:39 +0200 |
commit | 6040f8eb3167ee84cac9de5e6e1a97aeb6a8c569 (patch) | |
tree | a9002f771fa0bb64c555b56341a412c728a629f0 | |
parent | 623413d08886c74c5a72b55479136b62793f080a (diff) |
Core/Collision: Port new parts for retrieving area/liquid data from gameobjects added when porting 42f9deb21ec68e169f7ed1c8cf14092f144b22da to 3.3.5
-rw-r--r-- | src/common/Collision/DynamicTree.cpp | 43 | ||||
-rw-r--r-- | src/common/Collision/DynamicTree.h | 6 | ||||
-rw-r--r-- | src/common/Collision/Models/GameObjectModel.cpp | 45 | ||||
-rw-r--r-- | src/common/Collision/Models/GameObjectModel.h | 4 |
4 files changed, 98 insertions, 0 deletions
diff --git a/src/common/Collision/DynamicTree.cpp b/src/common/Collision/DynamicTree.cpp index aac78545524..ae215e0db4f 100644 --- a/src/common/Collision/DynamicTree.cpp +++ b/src/common/Collision/DynamicTree.cpp @@ -24,6 +24,9 @@ #include "ModelInstance.h" #include "RegularGrid.h" #include "Timer.h" +#include "VMapFactory.h" +#include "VMapManager2.h" +#include "WorldModel.h" #include <G3D/AABox.h> #include <G3D/Ray.h> #include <G3D/Vector3.h> @@ -169,6 +172,25 @@ private: VMAP::AreaInfo _areaInfo; }; +struct DynamicTreeLocationInfoCallback +{ + DynamicTreeLocationInfoCallback(PhaseShift const& phaseShift) : _phaseShift(phaseShift), _hitModel(nullptr) {} + + void operator()(G3D::Vector3 const& p, GameObjectModel const& obj) + { + if (obj.GetLocationInfo(p, _locationInfo, _phaseShift)) + _hitModel = &obj; + } + + VMAP::LocationInfo& GetLocationInfo() { return _locationInfo; } + GameObjectModel const* GetHitModel() const { return _hitModel; } + +private: + PhaseShift const& _phaseShift; + VMAP::LocationInfo _locationInfo; + GameObjectModel const* _hitModel; +}; + bool DynamicMapTree::getIntersectionTime(G3D::Ray const& ray, G3D::Vector3 const& endPos, PhaseShift const& phaseShift, float& maxDist) const { float distance = maxDist; @@ -260,3 +282,24 @@ bool DynamicMapTree::getAreaInfo(float x, float y, float& z, PhaseShift const& p } return false; } + +void DynamicMapTree::getAreaAndLiquidData(float x, float y, float z, PhaseShift const& phaseShift, uint8 /*reqLiquidType*/, VMAP::AreaAndLiquidData& /*data*/) const +{ + G3D::Vector3 v(x, y, z + 0.5f); + DynamicTreeLocationInfoCallback intersectionCallBack(phaseShift); + impl->intersectPoint(v, intersectionCallBack); + if (intersectionCallBack.GetLocationInfo().hitModel) + {/* For future use (needs cherry-pick f6c849729b27b77228704b595de3adaf24da2c10) + data.floorZ = intersectionCallBack.GetLocationInfo().ground_Z; + uint32 liquidType = intersectionCallBack.GetLocationInfo().hitModel->GetLiquidType(); + float liquidLevel; + if (!reqLiquidType || (dynamic_cast<VMAP::VMapManager2*>(VMAP::VMapFactory::createOrGetVMapManager())->GetLiquidFlagsPtr(liquidType) & reqLiquidType)) + if (intersectionCallBack.GetHitModel()->GetLiquidLevel(v, intersectionCallBack.GetLocationInfo(), liquidLevel)) + data.liquidInfo = boost::in_place(liquidType, liquidLevel); + + data.areaInfo = boost::in_place(intersectionCallBack.GetHitModel()->GetNameSetId(), + intersectionCallBack.GetLocationInfo().rootId, + intersectionCallBack.GetLocationInfo().hitModel->GetWmoID(), + intersectionCallBack.GetLocationInfo().hitModel->GetMogpFlags()); + */} +} diff --git a/src/common/Collision/DynamicTree.h b/src/common/Collision/DynamicTree.h index 75cbf8466f4..5581702a504 100644 --- a/src/common/Collision/DynamicTree.h +++ b/src/common/Collision/DynamicTree.h @@ -31,6 +31,11 @@ class GameObjectModel; class PhaseShift; struct DynTreeImpl; +namespace VMAP +{ + struct AreaAndLiquidData; +} + class TC_COMMON_API DynamicMapTree { DynTreeImpl *impl; @@ -46,6 +51,7 @@ public: float getHeight(float x, float y, float z, float maxSearchDist, PhaseShift const& phaseShift) const; bool getAreaInfo(float x, float y, float& z, PhaseShift const& phaseShift, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const; + void getAreaAndLiquidData(float x, float y, float z, PhaseShift const& phaseShift, uint8 reqLiquidType, VMAP::AreaAndLiquidData& data) const; void insert(const GameObjectModel&); void remove(const GameObjectModel&); diff --git a/src/common/Collision/Models/GameObjectModel.cpp b/src/common/Collision/Models/GameObjectModel.cpp index c1f7f9e1bb1..d81ccee9c5a 100644 --- a/src/common/Collision/Models/GameObjectModel.cpp +++ b/src/common/Collision/Models/GameObjectModel.cpp @@ -212,6 +212,51 @@ void GameObjectModel::intersectPoint(G3D::Vector3 const& point, VMAP::AreaInfo& } } +bool GameObjectModel::GetLocationInfo(G3D::Vector3 const& point, VMAP::LocationInfo& info, PhaseShift const& phaseShift) const +{ + if (!isCollisionEnabled() || !owner->IsSpawned() || !isMapObject()) + return false; + + if (!owner->IsInPhase(phaseShift)) + return false; + + if (!iBound.contains(point)) + return false; + + // child bounds are defined in object space: + Vector3 pModel = iInvRot * (point - iPos) * iInvScale; + Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f); + float zDist; + if (iModel->GetLocationInfo(pModel, zDirModel, zDist, info)) + { + Vector3 modelGround = pModel + zDist * zDirModel; + float world_Z = ((modelGround * iInvRot) * iScale + iPos).z; + if (info.ground_Z < world_Z) + { + info.ground_Z = world_Z; + return true; + } + } + + return false; +} + +bool GameObjectModel::GetLiquidLevel(G3D::Vector3 const& point, VMAP::LocationInfo& info, float& liqHeight) const +{ + // child bounds are defined in object space: + Vector3 pModel = iInvRot * (point - iPos) * iInvScale; + //Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f); + float zDist; + if (info.hitModel->GetLiquidLevel(pModel, zDist)) + { + // calculate world height (zDist in model coords): + // assume WMO not tilted (wouldn't make much sense anyway) + liqHeight = zDist * iScale + iPos.z; + return true; + } + return false; +} + bool GameObjectModel::UpdatePosition() { if (!iModel) diff --git a/src/common/Collision/Models/GameObjectModel.h b/src/common/Collision/Models/GameObjectModel.h index 54453f6987f..38406b12701 100644 --- a/src/common/Collision/Models/GameObjectModel.h +++ b/src/common/Collision/Models/GameObjectModel.h @@ -30,6 +30,7 @@ namespace VMAP { class WorldModel; struct AreaInfo; + struct LocationInfo; enum class ModelIgnoreFlags : uint32; } @@ -68,9 +69,12 @@ public: void enableCollision(bool enable) { _collisionEnabled = enable; } bool isCollisionEnabled() const { return _collisionEnabled; } bool isMapObject() const { return isWmo; } + uint8 GetNameSetId() const { return owner->GetNameSetId(); } bool intersectRay(G3D::Ray const& ray, float& maxDist, bool stopAtFirstHit, PhaseShift const& phaseShift, VMAP::ModelIgnoreFlags ignoreFlags) const; void intersectPoint(G3D::Vector3 const& point, VMAP::AreaInfo& info, PhaseShift const& phaseShift) const; + bool GetLocationInfo(G3D::Vector3 const& point, VMAP::LocationInfo& info, PhaseShift const& phaseShift) const; + bool GetLiquidLevel(G3D::Vector3 const& point, VMAP::LocationInfo& info, float& liqHeight) const; static GameObjectModel* Create(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string const& dataPath); |