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

#include <ModelInstance.h>

Public Member Functions

 ModelInstance ()
 
 ModelInstance (const ModelSpawn &spawn, WorldModel *model)
 
void setUnloaded ()
 
bool intersectRay (const G3D::Ray &pRay, float &pMaxDist, bool pStopAtFirstHit) 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::AABoxgetBounds () const
 

Protected Attributes

G3D::Matrix3 iInvRot
 
float iInvScale
 
WorldModeliModel
 

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
 

Constructor & Destructor Documentation

VMAP::ModelInstance::ModelInstance ( )
inline
66 : iInvScale(0.0f), iModel(nullptr) { }
float iInvScale
Definition: ModelInstance.h:76
WorldModel * iModel
Definition: ModelInstance.h:77
ModelInstance::ModelInstance ( const ModelSpawn spawn,
WorldModel model 
)
29  : ModelSpawn(spawn), iModel(model)
30  {
32  iInvScale = 1.f/iScale;
33  }
float x
Definition: Vector3.h:62
float iInvScale
Definition: ModelInstance.h:76
float y
Definition: Vector3.h:62
float iScale
Definition: ModelInstance.h:51
bool inverse(Matrix3 &rkInverse, float fTolerance=1e-06f) const
Definition: Matrix3.cpp:404
float z
Definition: Vector3.h:62
WorldModel * iModel
Definition: ModelInstance.h:77
float pif()
Definition: g3dmath.h:151
static Matrix3 fromEulerAnglesZYX(float fYAngle, float fPAngle, float fRAngle)
Definition: Matrix3.cpp:1664
G3D::Vector3 iRot
Definition: ModelInstance.h:50
G3D::Matrix3 iInvRot
Definition: ModelInstance.h:75

+ Here is the call graph for this function:

Member Function Documentation

bool ModelInstance::GetLiquidLevel ( const G3D::Vector3 p,
LocationInfo info,
float &  liqHeight 
) const
139  {
140  // child bounds are defined in object space:
141  Vector3 pModel = iInvRot * (p - iPos) * iInvScale;
142  //Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
143  float zDist;
144  if (info.hitModel->GetLiquidLevel(pModel, zDist))
145  {
146  // calculate world height (zDist in model coords):
147  // assume WMO not tilted (wouldn't make much sense anyway)
148  liqHeight = zDist * iScale + iPos.z;
149  return true;
150  }
151  return false;
152  }
G3D::Vector3 iPos
Definition: ModelInstance.h:49
float iInvScale
Definition: ModelInstance.h:76
float iScale
Definition: ModelInstance.h:51
Definition: Vector3.h:58
float z
Definition: Vector3.h:62
G3D::Matrix3 iInvRot
Definition: ModelInstance.h:75

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

+ Here is the call graph for this function:

WorldModel* VMAP::ModelInstance::getWorldModel ( )
inline
73 { return iModel; }
WorldModel * iModel
Definition: ModelInstance.h:77

+ Here is the caller graph for this function:

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ModelInstance::intersectRay ( const G3D::Ray pRay,
float &  pMaxDist,
bool  pStopAtFirstHit 
) const
36  {
37  if (!iModel)
38  {
39  //std::cout << "<object not loaded>\n";
40  return false;
41  }
42  float time = pRay.intersectionTime(iBound);
43  if (time == G3D::finf())
44  {
45 // std::cout << "Ray does not hit '" << name << "'\n";
46 
47  return false;
48  }
49 // std::cout << "Ray crosses bound of '" << name << "'\n";
50 /* std::cout << "ray from:" << pRay.origin().x << ", " << pRay.origin().y << ", " << pRay.origin().z
51  << " dir:" << pRay.direction().x << ", " << pRay.direction().y << ", " << pRay.direction().z
52  << " t/tmax:" << time << '/' << pMaxDist;
53  std::cout << "\nBound lo:" << iBound.low().x << ", " << iBound.low().y << ", " << iBound.low().z << " hi: "
54  << iBound.high().x << ", " << iBound.high().y << ", " << iBound.high().z << std::endl; */
55  // child bounds are defined in object space:
56  Vector3 p = iInvRot * (pRay.origin() - iPos) * iInvScale;
57  Ray modRay(p, iInvRot * pRay.direction());
58  float distance = pMaxDist * iInvScale;
59  bool hit = iModel->IntersectRay(modRay, distance, pStopAtFirstHit);
60  if (hit)
61  {
62  distance *= iScale;
63  pMaxDist = distance;
64  }
65  return hit;
66  }
float finf()
Definition: g3dmath.cpp:71
G3D::Vector3 iPos
Definition: ModelInstance.h:49
float iInvScale
Definition: ModelInstance.h:76
double distance(double x, double y)
Definition: g3dmath.h:731
float iScale
Definition: ModelInstance.h:51
Definition: Vector3.h:58
bool IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const
Definition: WorldModel.cpp:448
G3D::AABox iBound
Definition: ModelInstance.h:52
Definition: Ray.h:24
const Point3 & origin() const
Definition: Ray.h:56
WorldModel * iModel
Definition: ModelInstance.h:77
const Vector3 & direction() const
Definition: Ray.h:61
float intersectionTime(const class Sphere &sphere, bool solid=false) const
Definition: Ray.cpp:179
G3D::Matrix3 iInvRot
Definition: ModelInstance.h:75

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void VMAP::ModelInstance::setUnloaded ( )
inline
68 { iModel = nullptr; }
WorldModel * iModel
Definition: ModelInstance.h:77

+ Here is the caller graph for this function:

Member Data Documentation

G3D::Matrix3 VMAP::ModelInstance::iInvRot
protected
float VMAP::ModelInstance::iInvScale
protected
WorldModel* VMAP::ModelInstance::iModel
protected

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