AzeorthCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
VMAP::ModelInstance Class Reference

#include "ModelInstance.h"

Inheritance diagram for VMAP::ModelInstance:
VMAP::ModelSpawn

Public Member Functions

 ModelInstance ()
 
 ModelInstance (const ModelSpawn &spawn, WorldModel *model)
 
void setUnloaded ()
 
bool intersectRay (const G3D::Ray &pRay, float &pMaxDist, bool StopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
 
void intersectPoint (const G3D::Vector3 &p, AreaInfo &info) const
 
bool GetLocationInfo (const G3D::Vector3 &p, LocationInfo &info) const
 
bool GetLiquidLevel (const G3D::Vector3 &p, LocationInfo &info, float &liqHeight) const
 
WorldModelgetWorldModel ()
 
- Public Member Functions inherited from VMAP::ModelSpawn
bool operator== (const ModelSpawn &other) const
 
const G3D::AABox & GetBounds () const
 

Protected Attributes

G3D::Matrix3 iInvRot
 
float iInvScale {0.0f}
 
WorldModeliModel {nullptr}
 

Additional Inherited Members

- Static Public Member Functions inherited from VMAP::ModelSpawn
static bool readFromFile (FILE *rf, ModelSpawn &spawn)
 
static bool writeToFile (FILE *rw, const ModelSpawn &spawn)
 
- Public Attributes inherited from VMAP::ModelSpawn
uint32 flags
 
uint16 adtId
 
uint32 ID
 
G3D::Vector3 iPos
 
G3D::Vector3 iRot
 
float iScale
 
G3D::AABox iBound
 
std::string name
 

Detailed Description

Constructor & Destructor Documentation

◆ ModelInstance() [1/2]

VMAP::ModelInstance::ModelInstance ( )
inline
65{ }

◆ ModelInstance() [2/2]

VMAP::ModelInstance::ModelInstance ( const ModelSpawn spawn,
WorldModel model 
)
27 : ModelSpawn(spawn), iModel(model)
28 {
29 iInvRot = G3D::Matrix3::fromEulerAnglesZYX(G3D::pi() * iRot.y / 180.f, G3D::pi() * iRot.x / 180.f, G3D::pi() * iRot.z / 180.f).inverse();
30 iInvScale = 1.f / iScale;
31 }
G3D::Vector3 iRot
Definition: ModelInstance.h:49
float iScale
Definition: ModelInstance.h:50
G3D::Matrix3 iInvRot
Definition: ModelInstance.h:74
WorldModel * iModel
Definition: ModelInstance.h:76
float iInvScale
Definition: ModelInstance.h:75

References iInvRot, iInvScale, VMAP::ModelSpawn::iRot, and VMAP::ModelSpawn::iScale.

Member Function Documentation

◆ GetLiquidLevel()

bool VMAP::ModelInstance::GetLiquidLevel ( const G3D::Vector3 &  p,
LocationInfo info,
float &  liqHeight 
) const
145 {
146 // child bounds are defined in object space:
147 Vector3 pModel = iInvRot * (p - iPos) * iInvScale;
148 //Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
149 float zDist;
150 if (info.hitModel->GetLiquidLevel(pModel, zDist))
151 {
152 // calculate world height (zDist in model coords):
153 // assume WMO not tilted (wouldn't make much sense anyway)
154 liqHeight = zDist * iScale + iPos.z;
155 return true;
156 }
157 return false;
158 }
G3D::Vector3 iPos
Definition: ModelInstance.h:48

References VMAP::GroupModel::GetLiquidLevel(), VMAP::LocationInfo::hitModel, iInvRot, iInvScale, VMAP::ModelSpawn::iPos, and VMAP::ModelSpawn::iScale.

Referenced by VMAP::VMapMgr2::GetAreaAndLiquidData(), and VMAP::VMapMgr2::GetLiquidLevel().

◆ GetLocationInfo()

bool VMAP::ModelInstance::GetLocationInfo ( const G3D::Vector3 &  p,
LocationInfo info 
) const
105 {
106 if (!iModel)
107 {
108#ifdef VMAP_DEBUG
109 std::cout << "<object not loaded>\n";
110#endif
111 return false;
112 }
113
114 // M2 files don't contain area info, only WMO files
115 if (flags & MOD_M2)
116 {
117 return false;
118 }
119 if (!iBound.contains(p))
120 {
121 return false;
122 }
123 // child bounds are defined in object space:
124 Vector3 pModel = iInvRot * (p - iPos) * iInvScale;
125 Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
126 float zDist;
127 if (iModel->GetLocationInfo(pModel, zDirModel, zDist, info))
128 {
129 Vector3 modelGround = pModel + zDist * zDirModel;
130 // Transform back to world space. Note that:
131 // Mat * vec == vec * Mat.transpose()
132 // and for rotation matrices: Mat.inverse() == Mat.transpose()
133 float world_Z = ((modelGround * iInvRot) * iScale + iPos).z;
134 if (info.ground_Z < world_Z) // hm...could it be handled automatically with zDist at intersection?
135 {
136 info.ground_Z = world_Z;
137 info.hitInstance = this;
138 return true;
139 }
140 }
141 return false;
142 }
@ MOD_M2
Definition: ModelInstance.h:36
uint32 flags
Definition: ModelInstance.h:45
G3D::AABox iBound
Definition: ModelInstance.h:51
bool GetLocationInfo(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, LocationInfo &info) const
Definition: WorldModel.cpp:600

References VMAP::ModelSpawn::flags, VMAP::WorldModel::GetLocationInfo(), VMAP::LocationInfo::ground_Z, VMAP::LocationInfo::hitInstance, VMAP::ModelSpawn::iBound, iInvRot, iInvScale, iModel, VMAP::ModelSpawn::iPos, VMAP::ModelSpawn::iScale, and VMAP::MOD_M2.

◆ getWorldModel()

WorldModel * VMAP::ModelInstance::getWorldModel ( )
inline
72{ return iModel; }

References iModel.

Referenced by MMAP::TerrainBuilder::loadVMap().

◆ intersectPoint()

void VMAP::ModelInstance::intersectPoint ( const G3D::Vector3 &  p,
AreaInfo info 
) const
67 {
68 if (!iModel)
69 {
70#ifdef VMAP_DEBUG
71 std::cout << "<object not loaded>\n";
72#endif
73 return;
74 }
75
76 // M2 files don't contain area info, only WMO files
77 if (flags & MOD_M2)
78 {
79 return;
80 }
81 if (!iBound.contains(p))
82 {
83 return;
84 }
85 // child bounds are defined in object space:
86 Vector3 pModel = iInvRot * (p - iPos) * iInvScale;
87 Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
88 float zDist;
89 if (iModel->IntersectPoint(pModel, zDirModel, zDist, info))
90 {
91 Vector3 modelGround = pModel + zDist * zDirModel;
92 // Transform back to world space. Note that:
93 // Mat * vec == vec * Mat.transpose()
94 // and for rotation matrices: Mat.inverse() == Mat.transpose()
95 float world_Z = ((modelGround * iInvRot) * iScale + iPos).z;
96 if (info.ground_Z < world_Z)
97 {
98 info.ground_Z = world_Z;
99 info.adtId = adtId;
100 }
101 }
102 }
uint16 adtId
Definition: ModelInstance.h:46
bool IntersectPoint(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, AreaInfo &info) const
Definition: WorldModel.cpp:579

References VMAP::AreaInfo::adtId, VMAP::ModelSpawn::adtId, VMAP::ModelSpawn::flags, VMAP::AreaInfo::ground_Z, VMAP::ModelSpawn::iBound, iInvRot, iInvScale, iModel, VMAP::WorldModel::IntersectPoint(), VMAP::ModelSpawn::iPos, VMAP::ModelSpawn::iScale, and VMAP::MOD_M2.

Referenced by VMAP::AreaInfoCallback::operator()().

◆ intersectRay()

bool VMAP::ModelInstance::intersectRay ( const G3D::Ray &  pRay,
float &  pMaxDist,
bool  StopAtFirstHit,
ModelIgnoreFlags  ignoreFlags 
) const
34 {
35 if (!iModel)
36 {
37 //std::cout << "<object not loaded>\n";
38 return false;
39 }
40 float time = pRay.intersectionTime(iBound);
41 if (time == G3D::inf())
42 {
43 // std::cout << "Ray does not hit '" << name << "'\n";
44
45 return false;
46 }
47 // std::cout << "Ray crosses bound of '" << name << "'\n";
48 /* std::cout << "ray from:" << pRay.origin().x << ", " << pRay.origin().y << ", " << pRay.origin().z
49 << " dir:" << pRay.direction().x << ", " << pRay.direction().y << ", " << pRay.direction().z
50 << " t/tmax:" << time << '/' << pMaxDist;
51 std::cout << "\nBound lo:" << iBound.low().x << ", " << iBound.low().y << ", " << iBound.low().z << " hi: "
52 << iBound.high().x << ", " << iBound.high().y << ", " << iBound.high().z << std::endl; */
53 // child bounds are defined in object space:
54 Vector3 p = iInvRot * (pRay.origin() - iPos) * iInvScale;
55 Ray modRay(p, iInvRot * pRay.direction());
56 float distance = pMaxDist * iInvScale;
57 bool hit = iModel->IntersectRay(modRay, distance, StopAtFirstHit, ignoreFlags);
58 if (hit)
59 {
60 distance *= iScale;
61 pMaxDist = distance;
62 }
63 return hit;
64 }
bool IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
Definition: WorldModel.cpp:517

References VMAP::ModelSpawn::iBound, iInvRot, iInvScale, iModel, VMAP::WorldModel::IntersectRay(), VMAP::ModelSpawn::iPos, and VMAP::ModelSpawn::iScale.

Referenced by VMAP::MapRayCallback::operator()().

◆ setUnloaded()

void VMAP::ModelInstance::setUnloaded ( )
inline
67{ iModel = nullptr; }

References iModel.

Referenced by VMAP::StaticMapTree::UnloadMap(), and VMAP::StaticMapTree::UnloadMapTile().

Member Data Documentation

◆ iInvRot

G3D::Matrix3 VMAP::ModelInstance::iInvRot
protected

◆ iInvScale

float VMAP::ModelInstance::iInvScale {0.0f}
protected

◆ iModel

WorldModel* VMAP::ModelInstance::iModel {nullptr}
protected