Skip to content

Commit

Permalink
Core/Vmaps: Fix inconsistency of hitInstance and hitModel to cause wr…
Browse files Browse the repository at this point in the history
…ong area ids (TrinityCore#28632)

Closes TrinityCore#19761
Closes TrinityCore#28326

Co-authored-by: Gosha <[email protected]>
(cherry picked from commit 6ce6665)
  • Loading branch information
mdX7 authored and Shauren committed Nov 18, 2024
1 parent cf27f1c commit 225a1bb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/common/Collision/Maps/MapTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ namespace VMAP
enum class LoadResult : uint8;
enum class ModelIgnoreFlags : uint32;

struct GroupLocationInfo
{
const GroupModel* hitModel = nullptr;
int32 rootId = -1;
};

struct TC_COMMON_API LocationInfo
{
LocationInfo(): rootId(-1), hitInstance(nullptr), hitModel(nullptr), ground_Z(-G3D::finf()) { }
Expand Down
4 changes: 3 additions & 1 deletion src/common/Collision/Models/GameObjectModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ bool GameObjectModel::GetLocationInfo(G3D::Vector3 const& point, VMAP::LocationI
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))

VMAP::GroupLocationInfo groupInfo;
if (iModel->GetLocationInfo(pModel, zDirModel, zDist, groupInfo))
{
Vector3 modelGround = pModel + zDist * zDirModel;
float world_Z = ((modelGround * iInvRot) * iScale + iPos).z;
Expand Down
6 changes: 5 additions & 1 deletion src/common/Collision/Models/ModelInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ namespace VMAP
Vector3 pModel = iInvRot * (p - iPos) * iInvScale;
Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
float zDist;
if (iModel->GetLocationInfo(pModel, zDirModel, zDist, info))

GroupLocationInfo groupInfo;
if (iModel->GetLocationInfo(pModel, zDirModel, zDist, groupInfo))
{
Vector3 modelGround = pModel + zDist * zDirModel;
// Transform back to world space. Note that:
Expand All @@ -125,6 +127,8 @@ namespace VMAP
float world_Z = ((modelGround * iInvRot) * iScale + iPos).z;
if (info.ground_Z < world_Z) // hm...could it be handled automatically with zDist at intersection?
{
info.rootId = groupInfo.rootId;
info.hitModel = groupInfo.hitModel;
info.ground_Z = world_Z;
info.hitInstance = this;
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/common/Collision/Models/WorldModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ namespace VMAP
return false;
}

bool WorldModel::GetLocationInfo(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, LocationInfo &info) const
bool WorldModel::GetLocationInfo(const G3D::Vector3& p, const G3D::Vector3& down, float& dist, GroupLocationInfo& info) const
{
if (groupModels.empty())
return false;
Expand Down
3 changes: 2 additions & 1 deletion src/common/Collision/Models/WorldModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace VMAP
class TreeNode;
struct AreaInfo;
struct LocationInfo;
struct GroupLocationInfo;
enum class ModelIgnoreFlags : uint32;

class TC_COMMON_API MeshTriangle
Expand Down Expand Up @@ -113,7 +114,7 @@ namespace VMAP
void setRootWmoID(uint32 id) { RootWMOID = id; }
bool IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit, ModelIgnoreFlags ignoreFlags) const;
bool IntersectPoint(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, AreaInfo &info) const;
bool GetLocationInfo(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, LocationInfo &info) const;
bool GetLocationInfo(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, GroupLocationInfo& info) const;
bool writeFile(const std::string &filename);
bool readFile(const std::string &filename);
void getGroupModels(std::vector<GroupModel>& outGroupModels);
Expand Down

0 comments on commit 225a1bb

Please sign in to comment.