AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
GameObjectModel Class Reference

#include "GameObjectModel.h"

Public Member Functions

const G3D::AABox & GetBounds () const
 
 ~GameObjectModel ()
 
const G3D::Vector3 & GetPosition () const
 
void disable ()
 
void enable (uint32 ph_mask)
 
bool isEnabled () const
 
bool IsMapObject () const
 
bool intersectRay (const G3D::Ray &Ray, float &MaxDist, bool StopAtFirstHit, uint32 ph_mask, VMAP::ModelIgnoreFlags ignoreFlags) const
 
void IntersectPoint (G3D::Vector3 const &point, VMAP::AreaInfo &info, uint32 ph_mask) const
 
bool GetLocationInfo (G3D::Vector3 const &point, VMAP::LocationInfo &info, uint32 ph_mask) const
 
bool GetLiquidLevel (G3D::Vector3 const &point, VMAP::LocationInfo &info, float &liqHeight) const
 
bool UpdatePosition ()
 

Static Public Member Functions

static GameObjectModelCreate (std::unique_ptr< GameObjectModelOwnerBase > modelOwner, std::string const &dataPath)
 

Public Attributes

std::string name
 

Private Member Functions

 GameObjectModel ()=default
 
bool initialize (std::unique_ptr< GameObjectModelOwnerBase > modelOwner, std::string const &dataPath)
 

Private Attributes

uint32 phasemask {0}
 
G3D::AABox iBound
 
G3D::Matrix3 iInvRot
 
G3D::Vector3 iPos
 
float iInvScale {0}
 
float iScale {0}
 
VMAP::WorldModeliModel {nullptr}
 
std::unique_ptr< GameObjectModelOwnerBaseowner
 
bool isWmo {false}
 

Detailed Description

Constructor & Destructor Documentation

◆ GameObjectModel()

GameObjectModel::GameObjectModel ( )
privatedefault

Referenced by Create().

◆ ~GameObjectModel()

GameObjectModel::~GameObjectModel ( )
105{
106 if (iModel)
107 {
109 }
110}
static VMapMgr2 * createOrGetVMapMgr()
Definition: VMapFactory.cpp:27
void releaseModelInstance(const std::string &filename)
Definition: VMapMgr2.cpp:366
VMAP::WorldModel * iModel
Definition: GameObjectModel.h:90
std::string name
Definition: GameObjectModel.h:57

References VMAP::VMapFactory::createOrGetVMapMgr(), iModel, name, and VMAP::VMapMgr2::releaseModelInstance().

Member Function Documentation

◆ Create()

GameObjectModel * GameObjectModel::Create ( std::unique_ptr< GameObjectModelOwnerBase modelOwner,
std::string const &  dataPath 
)
static
169{
170 GameObjectModel* mdl = new GameObjectModel();
171 if (!mdl->initialize(std::move(modelOwner), dataPath))
172 {
173 delete mdl;
174 return nullptr;
175 }
176
177 return mdl;
178}
Definition: GameObjectModel.h:53
GameObjectModel()=default
bool initialize(std::unique_ptr< GameObjectModelOwnerBase > modelOwner, std::string const &dataPath)
Definition: GameObjectModel.cpp:112

References GameObjectModel(), and initialize().

Referenced by GameObject::CreateModel().

◆ disable()

void GameObjectModel::disable ( )
inline

Enables\disables collision.

66{ phasemask = 0; }
uint32 phasemask
Definition: GameObjectModel.h:84

References phasemask.

◆ enable()

void GameObjectModel::enable ( uint32  ph_mask)
inline
67{ phasemask = ph_mask; }

References phasemask.

Referenced by GameObject::EnableCollision().

◆ GetBounds()

const G3D::AABox & GameObjectModel::GetBounds ( ) const
inline
59{ return iBound; }
G3D::AABox iBound
Definition: GameObjectModel.h:85

References iBound.

Referenced by BoundsTrait< GameObjectModel >::GetBounds(), and BoundsTrait< GameObjectModel >::GetBounds2().

◆ GetLiquidLevel()

bool GameObjectModel::GetLiquidLevel ( G3D::Vector3 const &  point,
VMAP::LocationInfo info,
float &  liqHeight 
) const
254{
255 // child bounds are defined in object space:
256 Vector3 pModel = iInvRot * (point - iPos) * iInvScale;
257 //Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
258 float zDist;
259 if (info.hitModel->GetLiquidLevel(pModel, zDist))
260 {
261 // calculate world height (zDist in model coords):
262 // assume WMO not tilted (wouldn't make much sense anyway)
263 liqHeight = zDist * iScale + iPos.z;
264 return true;
265 }
266 return false;
267}
const GroupModel * hitModel
Definition: MapTree.h:37
G3D::Vector3 iPos
Definition: GameObjectModel.h:87
G3D::Matrix3 iInvRot
Definition: GameObjectModel.h:86
float iScale
Definition: GameObjectModel.h:89
float iInvScale
Definition: GameObjectModel.h:88
bool GetLiquidLevel(const G3D::Vector3 &pos, float &liqHeight) const
Definition: WorldModel.cpp:471

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

Referenced by DynamicMapTree::GetAreaAndLiquidData().

◆ GetLocationInfo()

bool GameObjectModel::GetLocationInfo ( G3D::Vector3 const &  point,
VMAP::LocationInfo info,
uint32  ph_mask 
) const
228{
229 if (!(phasemask & ph_mask) || !owner->IsSpawned() || !IsMapObject())
230 return false;
231
232 if (!iBound.contains(point))
233 return false;
234
235 // child bounds are defined in object space:
236 Vector3 pModel = iInvRot * (point - iPos) * iInvScale;
237 Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
238 float zDist;
239 if (iModel->GetLocationInfo(pModel, zDirModel, zDist, info))
240 {
241 Vector3 modelGround = pModel + zDist * zDirModel;
242 float world_Z = ((modelGround * iInvRot) * iScale + iPos).z;
243 if (info.ground_Z < world_Z)
244 {
245 info.ground_Z = world_Z;
246 return true;
247 }
248 }
249
250 return false;
251}
float ground_Z
Definition: MapTree.h:38
std::unique_ptr< GameObjectModelOwnerBase > owner
Definition: GameObjectModel.h:91
bool IsMapObject() const
Definition: GameObjectModel.h:70
bool GetLocationInfo(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, LocationInfo &info) const
Definition: WorldModel.cpp:600

References VMAP::WorldModel::GetLocationInfo(), VMAP::LocationInfo::ground_Z, iBound, iInvRot, iInvScale, iModel, iPos, iScale, IsMapObject(), owner, and phasemask.

Referenced by DynamicTreeLocationInfoCallback::operator()().

◆ GetPosition()

const G3D::Vector3 & GameObjectModel::GetPosition ( ) const
inline
63{ return iPos; }

References iPos.

Referenced by PositionTrait< GameObjectModel >::GetPosition().

◆ initialize()

bool GameObjectModel::initialize ( std::unique_ptr< GameObjectModelOwnerBase modelOwner,
std::string const &  dataPath 
)
private
113{
114 ModelList::const_iterator it = model_list.find(modelOwner->GetDisplayId());
115 if (it == model_list.end())
116 {
117 return false;
118 }
119
120 G3D::AABox mdl_box(it->second.bound);
121 // ignore models with no bounds
122 if (mdl_box == G3D::AABox::zero())
123 {
124 LOG_ERROR("maps", "GameObject model {} has zero bounds, loading skipped", it->second.name);
125 return false;
126 }
127
128 iModel = VMAP::VMapFactory::createOrGetVMapMgr()->acquireModelInstance(dataPath + "vmaps/", it->second.name,
130
131 if (!iModel)
132 {
133 return false;
134 }
135
136 name = it->second.name;
137 iPos = modelOwner->GetPosition();
138 phasemask = modelOwner->GetPhaseMask();
139 iScale = modelOwner->GetScale();
140 iInvScale = 1.f / iScale;
141
142 G3D::Matrix3 iRotation = G3D::Matrix3::fromEulerAnglesZYX(modelOwner->GetOrientation(), 0, 0);
143 iInvRot = iRotation.inverse();
144 // transform bounding box:
145 mdl_box = AABox(mdl_box.low() * iScale, mdl_box.high() * iScale);
146 AABox rotated_bounds;
147 for (int i = 0; i < 8; ++i)
148 {
149 rotated_bounds.merge(iRotation * mdl_box.corner(i));
150 }
151
152 iBound = rotated_bounds + iPos;
153
154#ifdef SPAWN_CORNERS
155 // test:
156 for (int i = 0; i < 8; ++i)
157 {
158 Vector3 pos(iBound.corner(i));
159 modelOwner->DebugVisualizeCorner(pos);
160 }
161#endif
162
163 owner = std::move(modelOwner);
164 isWmo = it->second.isWmo;
165 return true;
166}
ModelList model_list
Definition: GameObjectModel.cpp:43
#define LOG_ERROR(filterType__,...)
Definition: Log.h:159
@ MOD_WORLDSPAWN
Definition: ModelInstance.h:37
@ MOD_M2
Definition: ModelInstance.h:36
WorldModel * acquireModelInstance(const std::string &basepath, const std::string &filename, uint32 flags)
Definition: VMapMgr2.cpp:340
bool isWmo
Definition: GameObjectModel.h:92

References VMAP::VMapMgr2::acquireModelInstance(), VMAP::VMapFactory::createOrGetVMapMgr(), iBound, iInvRot, iInvScale, iModel, iPos, iScale, isWmo, LOG_ERROR, VMAP::MOD_M2, VMAP::MOD_WORLDSPAWN, model_list, name, owner, and phasemask.

Referenced by Create().

◆ IntersectPoint()

void GameObjectModel::IntersectPoint ( G3D::Vector3 const &  point,
VMAP::AreaInfo info,
uint32  ph_mask 
) const
207{
208 if (!(phasemask & ph_mask) || !owner->IsSpawned() || !IsMapObject())
209 return;
210
211 if (!iBound.contains(point))
212 return;
213
214 // child bounds are defined in object space:
215 Vector3 pModel = iInvRot * (point - iPos) * iInvScale;
216 Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
217 float zDist;
218 if (iModel->IntersectPoint(pModel, zDirModel, zDist, info))
219 {
220 Vector3 modelGround = pModel + zDist * zDirModel;
221 float world_Z = ((modelGround * iInvRot) * iScale + iPos).z;
222 if (info.ground_Z < world_Z)
223 info.ground_Z = world_Z;
224 }
225}
float ground_Z
Definition: MapTree.h:92
bool IntersectPoint(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, AreaInfo &info) const
Definition: WorldModel.cpp:579

References VMAP::AreaInfo::ground_Z, iBound, iInvRot, iInvScale, iModel, VMAP::WorldModel::IntersectPoint(), iPos, iScale, IsMapObject(), owner, and phasemask.

Referenced by DynamicTreeAreaInfoCallback::operator()().

◆ intersectRay()

bool GameObjectModel::intersectRay ( const G3D::Ray &  Ray,
float &  MaxDist,
bool  StopAtFirstHit,
uint32  ph_mask,
VMAP::ModelIgnoreFlags  ignoreFlags 
) const
181{
182 if (!(phasemask & ph_mask) || !owner->IsSpawned())
183 {
184 return false;
185 }
186
187 float time = ray.intersectionTime(iBound);
188 if (time == G3D::inf())
189 {
190 return false;
191 }
192
193 // child bounds are defined in object space:
194 Vector3 p = iInvRot * (ray.origin() - iPos) * iInvScale;
195 Ray modRay(p, iInvRot * ray.direction());
196 float distance = MaxDist * iInvScale;
197 bool hit = iModel->IntersectRay(modRay, distance, StopAtFirstHit, ignoreFlags);
198 if (hit)
199 {
200 distance *= iScale;
201 MaxDist = distance;
202 }
203 return hit;
204}
bool IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
Definition: WorldModel.cpp:517

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

Referenced by DynamicTreeIntersectionCallback::operator()().

◆ isEnabled()

bool GameObjectModel::isEnabled ( ) const
inline
69{ return phasemask != 0; }

References phasemask.

Referenced by GameObject::SetPhaseMask().

◆ IsMapObject()

bool GameObjectModel::IsMapObject ( ) const
inline
70{ return isWmo; }

References isWmo.

Referenced by GetLocationInfo(), and IntersectPoint().

◆ UpdatePosition()

bool GameObjectModel::UpdatePosition ( )
270{
271 if (!iModel)
272 {
273 return false;
274 }
275
276 ModelList::const_iterator it = model_list.find(owner->GetDisplayId());
277 if (it == model_list.end())
278 {
279 return false;
280 }
281
282 G3D::AABox mdl_box(it->second.bound);
283
284 // ignore models with no bounds
285 if (mdl_box == G3D::AABox::zero())
286 {
287 //VMAP_ERROR_LOG("misc", "GameObject model %s has zero bounds, loading skipped", it->second.name.c_str());
288 return false;
289 }
290
291 iPos = owner->GetPosition();
292 G3D::Matrix3 iRotation = G3D::Matrix3::fromEulerAnglesZYX(owner->GetOrientation(), 0, 0);
293 iInvRot = iRotation.inverse();
294
295 // transform bounding box:
296 mdl_box = AABox(mdl_box.low() * iScale, mdl_box.high() * iScale);
297 AABox rotated_bounds;
298
299 for (int i = 0; i < 8; ++i)
300 {
301 rotated_bounds.merge(iRotation * mdl_box.corner(i));
302 }
303
304 iBound = rotated_bounds + iPos;
305#ifdef SPAWN_CORNERS
306 // test:
307 for (int i = 0; i < 8; ++i)
308 {
309 Vector3 pos(iBound.corner(i));
310 owner->DebugVisualizeCorner(pos);
311 }
312#endif
313
314 return true;
315}

References iBound, iInvRot, iModel, iPos, iScale, model_list, and owner.

Referenced by GameObject::AddToWorld(), and GameObject::UpdateModelPosition().

Member Data Documentation

◆ iBound

G3D::AABox GameObjectModel::iBound
private

◆ iInvRot

G3D::Matrix3 GameObjectModel::iInvRot
private

◆ iInvScale

float GameObjectModel::iInvScale {0}
private

◆ iModel

VMAP::WorldModel* GameObjectModel::iModel {nullptr}
private

◆ iPos

G3D::Vector3 GameObjectModel::iPos
private

◆ iScale

float GameObjectModel::iScale {0}
private

◆ isWmo

bool GameObjectModel::isWmo {false}
private

Referenced by initialize(), and IsMapObject().

◆ name

std::string GameObjectModel::name

Referenced by initialize(), and ~GameObjectModel().

◆ owner

std::unique_ptr<GameObjectModelOwnerBase> GameObjectModel::owner
private

◆ phasemask

uint32 GameObjectModel::phasemask {0}
private