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 ()=default
 
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
 
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:54
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.

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

References phasemask.

◆ enable()

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

References phasemask.

Referenced by GameObject::EnableCollision().

◆ GetBounds()

const G3D::AABox & GameObjectModel::GetBounds ( ) const
inline
60{ 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
228{
229 // child bounds are defined in object space:
230 Vector3 pModel = iInvRot * (point - iPos) * iInvScale;
231 //Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
232 float zDist;
233 if (info.hitModel->GetLiquidLevel(pModel, zDist))
234 {
235 // calculate world height (zDist in model coords):
236 // assume WMO not tilted (wouldn't make much sense anyway)
237 liqHeight = zDist * iScale + iPos.z;
238 return true;
239 }
240 return false;
241}
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:496
const GroupModel * 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 if (!(phasemask & ph_mask) || !owner->IsSpawned() || !IsMapObject())
202 return false;
203
204 if (!iBound.contains(point))
205 return false;
206
207 // child bounds are defined in object space:
208 Vector3 pModel = iInvRot * (point - iPos) * iInvScale;
209 Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
210 float zDist;
211
212 VMAP::GroupLocationInfo groupInfo;
213 if (iModel->GetLocationInfo(pModel, zDirModel, zDist, groupInfo))
214 {
215 Vector3 modelGround = pModel + zDist * zDirModel;
216 float world_Z = ((modelGround * iInvRot) * iScale + iPos).z;
217 if (info.ground_Z < world_Z)
218 {
219 info.ground_Z = world_Z;
220 return true;
221 }
222 }
223
224 return false;
225}
std::shared_ptr< VMAP::WorldModel > iModel
Definition GameObjectModel.h:90
std::unique_ptr< GameObjectModelOwnerBase > owner
Definition GameObjectModel.h:91
bool IsMapObject() const
Definition GameObjectModel.h:71
Definition MapTree.h:34
float ground_Z
Definition MapTree.h:44

References 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
64{ 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:158
#define sWorldModelStore
Definition WorldModelStore.h:44
bool isWmo
Definition GameObjectModel.h:92
std::string name
Definition GameObjectModel.h:58
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 ( const G3D::Ray &  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
70{ return phasemask != 0; }

References phasemask.

Referenced by GameObject::SetPhaseMask().

◆ IsMapObject()

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

References isWmo.

Referenced by GetLocationInfo().

◆ UpdatePosition()

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

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
92{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: