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

#include <WorldModel.h>

Public Member Functions

 WorldModel ()
 
void setGroupModels (std::vector< GroupModel > &models)
 pass group models to WorldModel and create BIH. Passed vector is swapped with old geometry! More...
 
void setRootWmoID (uint32 id)
 
bool IntersectRay (const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const
 
bool IntersectPoint (const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, AreaInfo &info) const
 
bool GetLocationInfo (const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, LocationInfo &info) const
 
bool writeFile (const std::string &filename)
 
bool readFile (const std::string &filename)
 
void getGroupModels (std::vector< GroupModel > &outGroupModels)
 

Protected Attributes

uint32 RootWMOID
 
std::vector< GroupModelgroupModels
 
BIH groupTree
 

Detailed Description

Holds a model (converted M2 or WMO) in its original coordinate space

Constructor & Destructor Documentation

VMAP::WorldModel::WorldModel ( )
inline
109 : RootWMOID(0) { }
uint32 RootWMOID
Definition: WorldModel.h:121

Member Function Documentation

void VMAP::WorldModel::getGroupModels ( std::vector< GroupModel > &  outGroupModels)
602  {
603  outGroupModels = groupModels;
604  }
std::vector< GroupModel > groupModels
Definition: WorldModel.h:122

+ Here is the caller graph for this function:

bool VMAP::WorldModel::GetLocationInfo ( const G3D::Vector3 p,
const G3D::Vector3 down,
float &  dist,
LocationInfo info 
) const
517  {
518  if (groupModels.empty())
519  return false;
520 
521  WModelAreaCallback callback(groupModels, down);
522  groupTree.intersectPoint(p, callback);
523  if (callback.hit != groupModels.end())
524  {
525  info.hitModel = &(*callback.hit);
526  dist = callback.zDist;
527  return true;
528  }
529  return false;
530  }
std::vector< GroupModel > groupModels
Definition: WorldModel.h:122
BIH groupTree
Definition: WorldModel.h:123
void intersectPoint(const G3D::Vector3 &p, IsectCallback &intersectCallback) const
Definition: BoundingIntervalHierarchy.h:260

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool VMAP::WorldModel::IntersectPoint ( const G3D::Vector3 p,
const G3D::Vector3 down,
float &  dist,
AreaInfo info 
) const
498  {
499  if (groupModels.empty())
500  return false;
501 
502  WModelAreaCallback callback(groupModels, down);
503  groupTree.intersectPoint(p, callback);
504  if (callback.hit != groupModels.end())
505  {
506  info.rootId = RootWMOID;
507  info.groupId = callback.hit->GetWmoID();
508  info.flags = callback.hit->GetMogpFlags();
509  info.result = true;
510  dist = callback.zDist;
511  return true;
512  }
513  return false;
514  }
uint32 RootWMOID
Definition: WorldModel.h:121
std::vector< GroupModel > groupModels
Definition: WorldModel.h:122
BIH groupTree
Definition: WorldModel.h:123
void intersectPoint(const G3D::Vector3 &p, IsectCallback &intersectCallback) const
Definition: BoundingIntervalHierarchy.h:260

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool VMAP::WorldModel::IntersectRay ( const G3D::Ray ray,
float &  distance,
bool  stopAtFirstHit 
) const
449  {
450  // small M2 workaround, maybe better make separate class with virtual intersection funcs
451  // in any case, there's no need to use a bound tree if we only have one submodel
452  if (groupModels.size() == 1)
453  return groupModels[0].IntersectRay(ray, distance, stopAtFirstHit);
454 
455  WModelRayCallBack isc(groupModels);
456  groupTree.intersectRay(ray, isc, distance, stopAtFirstHit);
457  return isc.hit;
458  }
double distance(double x, double y)
Definition: g3dmath.h:731
bool IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const
Definition: WorldModel.cpp:448
std::vector< GroupModel > groupModels
Definition: WorldModel.h:122
BIH groupTree
Definition: WorldModel.h:123
void intersectRay(const G3D::Ray &r, RayCallback &intersectCallback, float &maxDist, bool stopAtFirst=false) const
Definition: BoundingIntervalHierarchy.h:121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool VMAP::WorldModel::readFile ( const std::string &  filename)
566  {
567  FILE* rf = fopen(filename.c_str(), "rb");
568  if (!rf)
569  return false;
570 
571  bool result = true;
572  uint32 chunkSize = 0;
573  uint32 count = 0;
574  char chunk[8]; // Ignore the added magic header
575  if (!readChunk(rf, chunk, VMAP_MAGIC, 8)) result = false;
576 
577  if (result && !readChunk(rf, chunk, "WMOD", 4)) result = false;
578  if (result && fread(&chunkSize, sizeof(uint32), 1, rf) != 1) result = false;
579  if (result && fread(&RootWMOID, sizeof(uint32), 1, rf) != 1) result = false;
580 
581  // read group models
582  if (result && readChunk(rf, chunk, "GMOD", 4))
583  {
584  //if (fread(&chunkSize, sizeof(uint32), 1, rf) != 1) result = false;
585 
586  if (result && fread(&count, sizeof(uint32), 1, rf) != 1) result = false;
587  if (result) groupModels.resize(count);
588  //if (result && fread(&groupModels[0], sizeof(GroupModel), count, rf) != count) result = false;
589  for (uint32 i=0; i<count && result; ++i)
590  result = groupModels[i].readFromFile(rf);
591 
592  // read group BIH
593  if (result && !readChunk(rf, chunk, "GBIH", 4)) result = false;
594  if (result) result = groupTree.readFromFile(rf);
595  }
596 
597  fclose(rf);
598  return result;
599  }
Definition: adtfile.h:57
bool readChunk(FILE *rf, char *dest, const char *compare, uint32 len)
Definition: TileAssembler.cpp:40
uint32 RootWMOID
Definition: WorldModel.h:121
std::vector< GroupModel > groupModels
Definition: WorldModel.h:122
BIH groupTree
Definition: WorldModel.h:123
uint32_t uint32
Definition: Define.h:150
bool readFromFile(FILE *rf)
Definition: BoundingIntervalHierarchy.cpp:261
const char VMAP_MAGIC[]
Definition: VMapDefinitions.h:28

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void VMAP::WorldModel::setGroupModels ( std::vector< GroupModel > &  models)

pass group models to WorldModel and create BIH. Passed vector is swapped with old geometry!

430  {
431  groupModels.swap(models);
433  }
std::vector< GroupModel > groupModels
Definition: WorldModel.h:122
BIH groupTree
Definition: WorldModel.h:123
Definition: BoundsTrait.h:17
void build(const PrimArray &primitives, BoundsFunc &getBounds, uint32 leafSize=3, bool printStats=false)
Definition: BoundingIntervalHierarchy.h:84

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void VMAP::WorldModel::setRootWmoID ( uint32  id)
inline
113 { RootWMOID = id; }
uint32 RootWMOID
Definition: WorldModel.h:121

+ Here is the caller graph for this function:

bool VMAP::WorldModel::writeFile ( const std::string &  filename)
533  {
534  FILE* wf = fopen(filename.c_str(), "wb");
535  if (!wf)
536  return false;
537 
538  uint32 chunkSize, count;
539  bool result = fwrite(VMAP_MAGIC, 1, 8, wf) == 8;
540  if (result && fwrite("WMOD", 1, 4, wf) != 4) result = false;
541  chunkSize = sizeof(uint32) + sizeof(uint32);
542  if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false;
543  if (result && fwrite(&RootWMOID, sizeof(uint32), 1, wf) != 1) result = false;
544 
545  // write group models
546  count=groupModels.size();
547  if (count)
548  {
549  if (result && fwrite("GMOD", 1, 4, wf) != 4) result = false;
550  //chunkSize = sizeof(uint32)+ sizeof(GroupModel)*count;
551  //if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false;
552  if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) result = false;
553  for (uint32 i=0; i<groupModels.size() && result; ++i)
554  result = groupModels[i].writeToFile(wf);
555 
556  // write group BIH
557  if (result && fwrite("GBIH", 1, 4, wf) != 4) result = false;
558  if (result) result = groupTree.writeToFile(wf);
559  }
560 
561  fclose(wf);
562  return result;
563  }
bool writeToFile(FILE *wf) const
Definition: BoundingIntervalHierarchy.cpp:247
uint32 RootWMOID
Definition: WorldModel.h:121
std::vector< GroupModel > groupModels
Definition: WorldModel.h:122
BIH groupTree
Definition: WorldModel.h:123
uint32_t uint32
Definition: Define.h:150
uint32_t uint32
Definition: g3dmath.h:168
const char VMAP_MAGIC[]
Definition: VMapDefinitions.h:28

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

std::vector<GroupModel> VMAP::WorldModel::groupModels
protected
BIH VMAP::WorldModel::groupTree
protected
uint32 VMAP::WorldModel::RootWMOID
protected

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