Skip to content

Commit 225a1bb

Browse files
mdX7Lordron
authored andcommitted
Core/Vmaps: Fix inconsistency of hitInstance and hitModel to cause wrong area ids (#28632)
Closes #19761 Closes #28326 Co-authored-by: Gosha <[email protected]> (cherry picked from commit 6ce66659929cbd680a91dd5caa1a5957f30b0716)
1 parent cf27f1c commit 225a1bb

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

src/common/Collision/Maps/MapTree.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ namespace VMAP
3030
enum class LoadResult : uint8;
3131
enum class ModelIgnoreFlags : uint32;
3232

33+
struct GroupLocationInfo
34+
{
35+
const GroupModel* hitModel = nullptr;
36+
int32 rootId = -1;
37+
};
38+
3339
struct TC_COMMON_API LocationInfo
3440
{
3541
LocationInfo(): rootId(-1), hitInstance(nullptr), hitModel(nullptr), ground_Z(-G3D::finf()) { }

src/common/Collision/Models/GameObjectModel.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ bool GameObjectModel::GetLocationInfo(G3D::Vector3 const& point, VMAP::LocationI
216216
Vector3 pModel = iInvRot * (point - iPos) * iInvScale;
217217
Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
218218
float zDist;
219-
if (iModel->GetLocationInfo(pModel, zDirModel, zDist, info))
219+
220+
VMAP::GroupLocationInfo groupInfo;
221+
if (iModel->GetLocationInfo(pModel, zDirModel, zDist, groupInfo))
220222
{
221223
Vector3 modelGround = pModel + zDist * zDirModel;
222224
float world_Z = ((modelGround * iInvRot) * iScale + iPos).z;

src/common/Collision/Models/ModelInstance.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ namespace VMAP
116116
Vector3 pModel = iInvRot * (p - iPos) * iInvScale;
117117
Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
118118
float zDist;
119-
if (iModel->GetLocationInfo(pModel, zDirModel, zDist, info))
119+
120+
GroupLocationInfo groupInfo;
121+
if (iModel->GetLocationInfo(pModel, zDirModel, zDist, groupInfo))
120122
{
121123
Vector3 modelGround = pModel + zDist * zDirModel;
122124
// Transform back to world space. Note that:
@@ -125,6 +127,8 @@ namespace VMAP
125127
float world_Z = ((modelGround * iInvRot) * iScale + iPos).z;
126128
if (info.ground_Z < world_Z) // hm...could it be handled automatically with zDist at intersection?
127129
{
130+
info.rootId = groupInfo.rootId;
131+
info.hitModel = groupInfo.hitModel;
128132
info.ground_Z = world_Z;
129133
info.hitInstance = this;
130134
return true;

src/common/Collision/Models/WorldModel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ namespace VMAP
548548
return false;
549549
}
550550

551-
bool WorldModel::GetLocationInfo(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, LocationInfo &info) const
551+
bool WorldModel::GetLocationInfo(const G3D::Vector3& p, const G3D::Vector3& down, float& dist, GroupLocationInfo& info) const
552552
{
553553
if (groupModels.empty())
554554
return false;

src/common/Collision/Models/WorldModel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace VMAP
3131
class TreeNode;
3232
struct AreaInfo;
3333
struct LocationInfo;
34+
struct GroupLocationInfo;
3435
enum class ModelIgnoreFlags : uint32;
3536

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

0 commit comments

Comments
 (0)