diff options
Diffstat (limited to 'src/common/Collision/DynamicTree.cpp')
-rw-r--r-- | src/common/Collision/DynamicTree.cpp | 86 |
1 files changed, 79 insertions, 7 deletions
diff --git a/src/common/Collision/DynamicTree.cpp b/src/common/Collision/DynamicTree.cpp index 40acfb6c49b..bae8ab38dc1 100644 --- a/src/common/Collision/DynamicTree.cpp +++ b/src/common/Collision/DynamicTree.cpp @@ -16,17 +16,16 @@ */ #include "DynamicTree.h" -//#include "QuadTree.h" -//#include "RegularGrid.h" #include "BoundingIntervalHierarchyWrapper.h" - +#include "GameObjectModel.h" #include "Log.h" +#include "MapTree.h" +#include "ModelIgnoreFlags.h" +#include "ModelInstance.h" #include "RegularGrid.h" #include "Timer.h" -#include "GameObjectModel.h" -#include "ModelInstance.h" -#include "ModelIgnoreFlags.h" - +#include "VMapFactory.h" +#include "VMapManager2.h" #include <G3D/AABox.h> #include <G3D/Ray.h> #include <G3D/Vector3.h> @@ -174,6 +173,41 @@ struct DynamicTreeIntersectionCallback_WithLogger bool didHit() const { return did_hit;} }; +struct DynamicTreeAreaInfoCallback +{ + DynamicTreeAreaInfoCallback(uint32 phaseMask) : _phaseMask(phaseMask) {} + + void operator()(G3D::Vector3 const& p, GameObjectModel const& obj) + { + obj.intersectPoint(p, _areaInfo, _phaseMask); + } + + VMAP::AreaInfo const& GetAreaInfo() const { return _areaInfo; } + +private: + uint32 _phaseMask; + VMAP::AreaInfo _areaInfo; +}; + +struct DynamicTreeLocationInfoCallback +{ + DynamicTreeLocationInfoCallback(uint32 phaseMask) : _phaseMask(phaseMask), _hitModel(nullptr) {} + + void operator()(G3D::Vector3 const& p, GameObjectModel const& obj) + { + if (obj.GetLocationInfo(p, _locationInfo, _phaseMask)) + _hitModel = &obj; + } + + VMAP::LocationInfo& GetLocationInfo() { return _locationInfo; } + GameObjectModel const* GetHitModel() const { return _hitModel; } + +private: + uint32 _phaseMask; + VMAP::LocationInfo _locationInfo; + GameObjectModel const* _hitModel; +}; + bool DynamicMapTree::getIntersectionTime(const uint32 phasemask, const G3D::Ray& ray, const G3D::Vector3& endPos, float& maxDist) const { @@ -253,3 +287,41 @@ float DynamicMapTree::getHeight(float x, float y, float z, float maxSearchDist, else return -G3D::finf(); } + +bool DynamicMapTree::getAreaInfo(float x, float y, float& z, uint32 phasemask, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const +{ + G3D::Vector3 v(x, y, z + 0.5f); + DynamicTreeAreaInfoCallback intersectionCallBack(phasemask); + impl->intersectPoint(v, intersectionCallBack); + if (intersectionCallBack.GetAreaInfo().result) + { + flags = intersectionCallBack.GetAreaInfo().flags; + adtId = intersectionCallBack.GetAreaInfo().adtId; + rootId = intersectionCallBack.GetAreaInfo().rootId; + groupId = intersectionCallBack.GetAreaInfo().groupId; + z = intersectionCallBack.GetAreaInfo().ground_Z; + return true; + } + return false; +} + +void DynamicMapTree::getAreaAndLiquidData(float x, float y, float z, uint32 phasemask, uint8 reqLiquidType, VMAP::AreaAndLiquidData& data) const +{ + G3D::Vector3 v(x, y, z + 0.5f); + DynamicTreeLocationInfoCallback intersectionCallBack(phasemask); + impl->intersectPoint(v, intersectionCallBack); + if (intersectionCallBack.GetLocationInfo().hitModel) + { + 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(0, + intersectionCallBack.GetLocationInfo().rootId, + intersectionCallBack.GetLocationInfo().hitModel->GetWmoID(), + intersectionCallBack.GetLocationInfo().hitModel->GetMogpFlags()); + } +} |