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

#include "GameObjectModel.h"

Public Member Functions

G3D::AABox const & GetBounds () const
 
 ~GameObjectModel ()=default
 
G3D::Vector3 const & GetPosition () const
 
void disable ()
 
void enable (uint32 ph_mask)
 
bool isEnabled () const
 
bool IsMapObject () const
 
bool intersectRay (G3D::Ray const &Ray, float &MaxDist, bool StopAtFirstHit, uint32 ph_mask, VMAP::ModelIgnoreFlags ignoreFlags) 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}
 
std::shared_ptr< VMAP::WorldModeliModel
 
std::unique_ptr< GameObjectModelOwnerBaseowner
 
bool isWmo {false}
 

Detailed Description

Constructor & Destructor Documentation

◆ GameObjectModel()

GameObjectModel::GameObjectModel ( )
privatedefault

Referenced by Create().

◆ ~GameObjectModel()

GameObjectModel::~GameObjectModel ( )
default

Member Function Documentation

◆ Create()

GameObjectModel * GameObjectModel::Create ( std::unique_ptr< GameObjectModelOwnerBase modelOwner,
std::string const &  dataPath 
)
static
162{
163 GameObjectModel* mdl = new GameObjectModel();
164 if (!mdl->initialize(std::move(modelOwner), dataPath))
165 {
166 delete mdl;
167 return nullptr;
168 }
169
170 return mdl;
171}
Definition GameObjectModel.h:55
GameObjectModel()=default
bool initialize(std::unique_ptr< GameObjectModelOwnerBase > modelOwner, std::string const &dataPath)
Definition GameObjectModel.cpp:105

References GameObjectModel(), and initialize().

Referenced by GameObject::CreateModel().

◆ disable()

void GameObjectModel::disable ( )
inline

Enables\disables collision.

68{ phasemask = 0; }
uint32 phasemask
Definition GameObjectModel.h:85

References phasemask.

◆ enable()

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

References phasemask.

Referenced by GameObject::EnableCollision().

◆ GetBounds()

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

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
231{
232 // child bounds are defined in object space:
233 Vector3 pModel = iInvRot * (point - iPos) * iInvScale;
234 //Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
235 float zDist;
236 if (info.hitModel->GetLiquidLevel(pModel, zDist))
237 {
238 // calculate world height (zDist in model coords):
239 // assume WMO not tilted (wouldn't make much sense anyway)
240 liqHeight = zDist * iScale + iPos.z;
241 return true;
242 }
243 return false;
244}
G3D::Vector3 iPos
Definition GameObjectModel.h:88
G3D::Matrix3 iInvRot
Definition GameObjectModel.h:87
float iScale
Definition GameObjectModel.h:90
float iInvScale
Definition GameObjectModel.h:89
bool GetLiquidLevel(G3D::Vector3 const &pos, float &liqHeight) const
Definition WorldModel.cpp:496
GroupModel const * hitModel
Definition MapTree.h:43

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
200{
201 // transports provide inaccurate area info while moving (e.g. Booty Bay - Ratchet boat, see #7335)
202 if (!(phasemask & ph_mask) || !owner->IsSpawned() || !IsMapObject() || owner->IsTransport())
203 return false;
204
205 if (!iBound.contains(point))
206 return false;
207
208 // child bounds are defined in object space:
209 Vector3 pModel = iInvRot * (point - iPos) * iInvScale;
210 Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
211 float zDist;
212
213 VMAP::GroupLocationInfo groupInfo;
214 if (iModel->GetLocationInfo(pModel, zDirModel, zDist, groupInfo))
215 {
216 Vector3 modelGround = pModel + zDist * zDirModel;
217 float world_Z = ((modelGround * iInvRot) * iScale + iPos).z;
218 if (info.ground_Z < world_Z)
219 {
220 info.rootId = groupInfo.rootId;
221 info.hitModel = groupInfo.hitModel;
222 info.ground_Z = world_Z;
223 return true;
224 }
225 }
226
227 return false;
228}
std::shared_ptr< VMAP::WorldModel > iModel
Definition GameObjectModel.h:91
std::unique_ptr< GameObjectModelOwnerBase > owner
Definition GameObjectModel.h:92
bool IsMapObject() const
Definition GameObjectModel.h:72
Definition MapTree.h:34
GroupModel const * hitModel
Definition MapTree.h:35
int32 rootId
Definition MapTree.h:36
float ground_Z
Definition MapTree.h:44
int32 rootId
Definition MapTree.h:45

References VMAP::LocationInfo::ground_Z, VMAP::GroupLocationInfo::hitModel, VMAP::LocationInfo::hitModel, iBound, iInvRot, iInvScale, iModel, iPos, iScale, IsMapObject(), owner, phasemask, VMAP::GroupLocationInfo::rootId, and VMAP::LocationInfo::rootId.

Referenced by DynamicTreeLocationInfoCallback::operator()().

◆ GetPosition()

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

References iPos.

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

◆ initialize()

bool GameObjectModel::initialize ( std::unique_ptr< GameObjectModelOwnerBase modelOwner,
std::string const &  dataPath 
)
private
106{
107 ModelList::const_iterator it = model_list.find(modelOwner->GetDisplayId());
108 if (it == model_list.end())
109 {
110 return false;
111 }
112
113 G3D::AABox mdl_box(it->second.bound);
114 // ignore models with no bounds
115 if (mdl_box == G3D::AABox::zero())
116 {
117 LOG_ERROR("maps", "GameObject model {} has zero bounds, loading skipped", it->second.name);
118 return false;
119 }
120
121 iModel = sWorldModelStore->AcquireModelInstance(dataPath + "vmaps/", it->second.name,
123
124 if (!iModel)
125 {
126 return false;
127 }
128
129 name = it->second.name;
130 iPos = modelOwner->GetPosition();
131 phasemask = modelOwner->GetPhaseMask();
132 iScale = modelOwner->GetScale();
133 iInvScale = 1.f / iScale;
134
135 G3D::Matrix3 iRotation = G3D::Matrix3::fromEulerAnglesZYX(modelOwner->GetOrientation(), 0, 0);
136 iInvRot = iRotation.inverse();
137 // transform bounding box:
138 mdl_box = AABox(mdl_box.low() * iScale, mdl_box.high() * iScale);
139 AABox rotated_bounds;
140 for (int i = 0; i < 8; ++i)
141 {
142 rotated_bounds.merge(iRotation * mdl_box.corner(i));
143 }
144
145 iBound = rotated_bounds + iPos;
146
147#ifdef SPAWN_CORNERS
148 // test:
149 for (int i = 0; i < 8; ++i)
150 {
151 Vector3 pos(iBound.corner(i));
152 modelOwner->DebugVisualizeCorner(pos);
153 }
154#endif
155
156 owner = std::move(modelOwner);
157 isWmo = it->second.isWmo;
158 return true;
159}
ModelList model_list
Definition GameObjectModel.cpp:44
#define LOG_ERROR(filterType__,...)
Definition Log.h:145
#define sWorldModelStore
Definition WorldModelStore.h:44
bool isWmo
Definition GameObjectModel.h:93
std::string name
Definition GameObjectModel.h:59
Definition DynamicTree.h:31
@ MOD_WORLDSPAWN
Definition ModelInstance.h:38
ModelFlags
Definition vmapexport.h:32
@ MOD_M2
Definition vmapexport.h:33

References iBound, iInvRot, iInvScale, iModel, iPos, iScale, isWmo, LOG_ERROR, VMAP::MOD_M2, VMAP::MOD_WORLDSPAWN, model_list, name, owner, phasemask, and sWorldModelStore.

Referenced by Create().

◆ intersectRay()

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

References iBound, iInvRot, iInvScale, iModel, iPos, iScale, owner, and phasemask.

Referenced by DynamicTreeIntersectionCallback::operator()().

◆ isEnabled()

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

References phasemask.

Referenced by GameObject::SetPhaseMask().

◆ IsMapObject()

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

References isWmo.

Referenced by GetLocationInfo().

◆ UpdatePosition()

bool GameObjectModel::UpdatePosition ( )
247{
248 if (!iModel)
249 {
250 return false;
251 }
252
253 ModelList::const_iterator it = model_list.find(owner->GetDisplayId());
254 if (it == model_list.end())
255 {
256 return false;
257 }
258
259 G3D::AABox mdl_box(it->second.bound);
260
261 // ignore models with no bounds
262 if (mdl_box == G3D::AABox::zero())
263 {
264 //VMAP_ERROR_LOG("misc", "GameObject model %s has zero bounds, loading skipped", it->second.name.c_str());
265 return false;
266 }
267
268 iPos = owner->GetPosition();
269 G3D::Matrix3 iRotation = G3D::Matrix3::fromEulerAnglesZYX(owner->GetOrientation(), 0, 0);
270 iInvRot = iRotation.inverse();
271
272 // transform bounding box:
273 mdl_box = AABox(mdl_box.low() * iScale, mdl_box.high() * iScale);
274 AABox rotated_bounds;
275
276 for (int i = 0; i < 8; ++i)
277 {
278 rotated_bounds.merge(iRotation * mdl_box.corner(i));
279 }
280
281 iBound = rotated_bounds + iPos;
282#ifdef SPAWN_CORNERS
283 // test:
284 for (int i = 0; i < 8; ++i)
285 {
286 Vector3 pos(iBound.corner(i));
287 owner->DebugVisualizeCorner(pos);
288 }
289#endif
290
291 return true;
292}

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

std::shared_ptr<VMAP::WorldModel> GameObjectModel::iModel
private

◆ iPos

G3D::Vector3 GameObjectModel::iPos
private

◆ iScale

float GameObjectModel::iScale {0}
private

◆ isWmo

bool GameObjectModel::isWmo {false}
private
93{false};

Referenced by initialize(), and IsMapObject().

◆ name

std::string GameObjectModel::name

Referenced by initialize().

◆ owner

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

◆ phasemask

uint32 GameObjectModel::phasemask {0}
private

The documentation for this class was generated from the following files: