TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GameObjectModel Class Reference

#include <GameObjectModel.h>

Public Member Functions

const G3D::AABoxgetBounds () const
 
 ~GameObjectModel ()
 
const G3D::Vector3getPosition () const
 
void disable ()
 
void enable (uint32 ph_mask)
 
bool isEnabled () const
 
bool intersectRay (const G3D::Ray &Ray, float &MaxDist, bool StopAtFirstHit, uint32 ph_mask) 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 ()
 
bool initialize (std::unique_ptr< GameObjectModelOwnerBase > modelOwner, std::string const &dataPath)
 

Private Attributes

uint32 phasemask
 
G3D::AABox iBound
 
G3D::Matrix3 iInvRot
 
G3D::Vector3 iPos
 
float iInvScale
 
float iScale
 
VMAP::WorldModeliModel
 
std::unique_ptr
< GameObjectModelOwnerBase
owner
 

Constructor & Destructor Documentation

GameObjectModel::GameObjectModel ( )
inlineprivate
52 : phasemask(0), iInvScale(0), iScale(0), iModel(NULL) { }
uint32 phasemask
Definition: GameObjectModel.h:77
arena_t NULL
Definition: jemalloc_internal.h:624
VMAP::WorldModel * iModel
Definition: GameObjectModel.h:83
float iScale
Definition: GameObjectModel.h:82
float iInvScale
Definition: GameObjectModel.h:81

+ Here is the caller graph for this function:

GameObjectModel::~GameObjectModel ( )
92 {
93  if (iModel)
95 }
Definition: VMapManager2.h:78
VMAP::WorldModel * iModel
Definition: GameObjectModel.h:83
static IVMapManager * createOrGetVMapManager()
Definition: VMapFactory.cpp:28
std::string name
Definition: GameObjectModel.h:54

+ Here is the call graph for this function:

Member Function Documentation

GameObjectModel * GameObjectModel::Create ( std::unique_ptr< GameObjectModelOwnerBase modelOwner,
std::string const dataPath 
)
static
145 {
146  GameObjectModel* mdl = new GameObjectModel();
147  if (!mdl->initialize(std::move(modelOwner), dataPath))
148  {
149  delete mdl;
150  return NULL;
151  }
152 
153  return mdl;
154 }
arena_t NULL
Definition: jemalloc_internal.h:624
GameObjectModel()
Definition: GameObjectModel.h:52
bool initialize(std::unique_ptr< GameObjectModelOwnerBase > modelOwner, std::string const &dataPath)
Definition: GameObjectModel.cpp:97
Definition: GameObjectModel.h:50

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void GameObjectModel::disable ( )
inline

Enables collision.

63 { phasemask = 0;}
uint32 phasemask
Definition: GameObjectModel.h:77
void GameObjectModel::enable ( uint32  ph_mask)
inline
64 { phasemask = ph_mask;}
uint32 phasemask
Definition: GameObjectModel.h:77

+ Here is the caller graph for this function:

const G3D::AABox& GameObjectModel::getBounds ( ) const
inline
56 { return iBound; }
G3D::AABox iBound
Definition: GameObjectModel.h:78

+ Here is the caller graph for this function:

const G3D::Vector3& GameObjectModel::getPosition ( ) const
inline
60 { return iPos;}
G3D::Vector3 iPos
Definition: GameObjectModel.h:80

+ Here is the caller graph for this function:

bool GameObjectModel::initialize ( std::unique_ptr< GameObjectModelOwnerBase modelOwner,
std::string const dataPath 
)
private
98 {
99  ModelList::const_iterator it = model_list.find(modelOwner->GetDisplayId());
100  if (it == model_list.end())
101  return false;
102 
103  G3D::AABox mdl_box(it->second.bound);
104  // ignore models with no bounds
105  if (mdl_box == G3D::AABox::zero())
106  {
107  VMAP_ERROR_LOG("misc", "GameObject model %s has zero bounds, loading skipped", it->second.name.c_str());
108  return false;
109  }
110 
111  iModel = ((VMAP::VMapManager2*)VMAP::VMapFactory::createOrGetVMapManager())->acquireModelInstance(dataPath + "vmaps/", it->second.name);
112 
113  if (!iModel)
114  return false;
115 
116  name = it->second.name;
117  iPos = modelOwner->GetPosition();
118  phasemask = modelOwner->GetPhaseMask();
119  iScale = modelOwner->GetScale();
120  iInvScale = 1.f / iScale;
121 
122  G3D::Matrix3 iRotation = G3D::Matrix3::fromEulerAnglesZYX(modelOwner->GetOrientation(), 0, 0);
123  iInvRot = iRotation.inverse();
124  // transform bounding box:
125  mdl_box = AABox(mdl_box.low() * iScale, mdl_box.high() * iScale);
126  AABox rotated_bounds;
127  for (int i = 0; i < 8; ++i)
128  rotated_bounds.merge(iRotation * mdl_box.corner(i));
129 
130  iBound = rotated_bounds + iPos;
131 #ifdef SPAWN_CORNERS
132  // test:
133  for (int i = 0; i < 8; ++i)
134  {
135  Vector3 pos(iBound.corner(i));
136  modelOwner->DebugVisualizeCorner(pos);
137  }
138 #endif
139 
140  owner = std::move(modelOwner);
141  return true;
142 }
G3D::Matrix3 iInvRot
Definition: GameObjectModel.h:79
uint32 phasemask
Definition: GameObjectModel.h:77
void merge(const AABox &a)
Definition: AABox.h:106
Definition: VMapManager2.h:78
virtual float GetScale() const
Definition: GameObjectModel.h:46
virtual uint32 GetPhaseMask() const
Definition: GameObjectModel.h:43
Definition: Vector3.h:58
G3D::AABox iBound
Definition: GameObjectModel.h:78
virtual float GetOrientation() const
Definition: GameObjectModel.h:45
ModelList model_list
Definition: GameObjectModel.cpp:41
virtual uint32 GetDisplayId() const
Definition: GameObjectModel.h:42
VMAP::WorldModel * iModel
Definition: GameObjectModel.h:83
virtual G3D::Vector3 GetPosition() const
Definition: GameObjectModel.h:44
bool inverse(Matrix3 &rkInverse, float fTolerance=1e-06f) const
Definition: Matrix3.cpp:404
std::unique_ptr< GameObjectModelOwnerBase > owner
Definition: GameObjectModel.h:84
Definition: AABox.h:32
Definition: Matrix3.h:37
G3D::Vector3 iPos
Definition: GameObjectModel.h:80
static const AABox & zero()
Definition: AABox.cpp:87
float iScale
Definition: GameObjectModel.h:82
static IVMapManager * createOrGetVMapManager()
Definition: VMapFactory.cpp:28
#define VMAP_ERROR_LOG(FILTER,...)
Definition: VMapDefinitions.h:38
static Matrix3 fromEulerAnglesZYX(float fYAngle, float fPAngle, float fRAngle)
Definition: Matrix3.cpp:1664
virtual void DebugVisualizeCorner(G3D::Vector3 const &) const
Definition: GameObjectModel.h:47
float iInvScale
Definition: GameObjectModel.h:81
std::string name
Definition: GameObjectModel.h:54
Point3 corner(int index) const
Definition: AABox.cpp:361

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool GameObjectModel::intersectRay ( const G3D::Ray Ray,
float &  MaxDist,
bool  StopAtFirstHit,
uint32  ph_mask 
) const
157 {
158  if (!(phasemask & ph_mask) || !owner->IsSpawned())
159  return false;
160 
161  float time = ray.intersectionTime(iBound);
162  if (time == G3D::finf())
163  return false;
164 
165  // child bounds are defined in object space:
166  Vector3 p = iInvRot * (ray.origin() - iPos) * iInvScale;
167  Ray modRay(p, iInvRot * ray.direction());
168  float distance = MaxDist * iInvScale;
169  bool hit = iModel->IntersectRay(modRay, distance, StopAtFirstHit);
170  if (hit)
171  {
172  distance *= iScale;
173  MaxDist = distance;
174  }
175  return hit;
176 }
float finf()
Definition: g3dmath.cpp:71
G3D::Matrix3 iInvRot
Definition: GameObjectModel.h:79
uint32 phasemask
Definition: GameObjectModel.h:77
double distance(double x, double y)
Definition: g3dmath.h:731
Definition: Vector3.h:58
G3D::AABox iBound
Definition: GameObjectModel.h:78
bool IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const
Definition: WorldModel.cpp:448
VMAP::WorldModel * iModel
Definition: GameObjectModel.h:83
std::unique_ptr< GameObjectModelOwnerBase > owner
Definition: GameObjectModel.h:84
G3D::Vector3 iPos
Definition: GameObjectModel.h:80
float iScale
Definition: GameObjectModel.h:82
float iInvScale
Definition: GameObjectModel.h:81

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool GameObjectModel::isEnabled ( ) const
inline
66 {return phasemask != 0;}
uint32 phasemask
Definition: GameObjectModel.h:77

+ Here is the caller graph for this function:

bool GameObjectModel::UpdatePosition ( )
179 {
180  if (!iModel)
181  return false;
182 
183  ModelList::const_iterator it = model_list.find(owner->GetDisplayId());
184  if (it == model_list.end())
185  return false;
186 
187  G3D::AABox mdl_box(it->second.bound);
188  // ignore models with no bounds
189  if (mdl_box == G3D::AABox::zero())
190  {
191  VMAP_ERROR_LOG("misc", "GameObject model %s has zero bounds, loading skipped", it->second.name.c_str());
192  return false;
193  }
194 
195  iPos = owner->GetPosition();
196 
197  G3D::Matrix3 iRotation = G3D::Matrix3::fromEulerAnglesZYX(owner->GetOrientation(), 0, 0);
198  iInvRot = iRotation.inverse();
199  // transform bounding box:
200  mdl_box = AABox(mdl_box.low() * iScale, mdl_box.high() * iScale);
201  AABox rotated_bounds;
202  for (int i = 0; i < 8; ++i)
203  rotated_bounds.merge(iRotation * mdl_box.corner(i));
204 
205  iBound = rotated_bounds + iPos;
206 #ifdef SPAWN_CORNERS
207  // test:
208  for (int i = 0; i < 8; ++i)
209  {
210  Vector3 pos(iBound.corner(i));
211  owner->DebugVisualizeCorner(pos);
212  }
213 #endif
214 
215  return true;
216 }
G3D::Matrix3 iInvRot
Definition: GameObjectModel.h:79
void merge(const AABox &a)
Definition: AABox.h:106
Definition: Vector3.h:58
G3D::AABox iBound
Definition: GameObjectModel.h:78
ModelList model_list
Definition: GameObjectModel.cpp:41
VMAP::WorldModel * iModel
Definition: GameObjectModel.h:83
bool inverse(Matrix3 &rkInverse, float fTolerance=1e-06f) const
Definition: Matrix3.cpp:404
std::unique_ptr< GameObjectModelOwnerBase > owner
Definition: GameObjectModel.h:84
Definition: AABox.h:32
Definition: Matrix3.h:37
G3D::Vector3 iPos
Definition: GameObjectModel.h:80
static const AABox & zero()
Definition: AABox.cpp:87
float iScale
Definition: GameObjectModel.h:82
#define VMAP_ERROR_LOG(FILTER,...)
Definition: VMapDefinitions.h:38
static Matrix3 fromEulerAnglesZYX(float fYAngle, float fPAngle, float fRAngle)
Definition: Matrix3.cpp:1664
Point3 corner(int index) const
Definition: AABox.cpp:361

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

G3D::AABox GameObjectModel::iBound
private
G3D::Matrix3 GameObjectModel::iInvRot
private
float GameObjectModel::iInvScale
private
VMAP::WorldModel* GameObjectModel::iModel
private
G3D::Vector3 GameObjectModel::iPos
private
float GameObjectModel::iScale
private
std::string GameObjectModel::name
std::unique_ptr<GameObjectModelOwnerBase> GameObjectModel::owner
private
uint32 GameObjectModel::phasemask
private

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