aboutsummaryrefslogtreecommitdiff
path: root/src/common/Collision
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/Collision')
-rw-r--r--src/common/Collision/BoundingIntervalHierarchy.h12
-rw-r--r--src/common/Collision/BoundingIntervalHierarchyWrapper.h8
-rw-r--r--src/common/Collision/DynamicTree.cpp24
-rw-r--r--src/common/Collision/DynamicTree.h6
-rw-r--r--src/common/Collision/Management/IVMapManager.h8
-rw-r--r--src/common/Collision/Management/MMapFactory.cpp6
-rw-r--r--src/common/Collision/Management/MMapManager.cpp13
-rw-r--r--src/common/Collision/Management/VMapFactory.cpp4
-rw-r--r--src/common/Collision/Management/VMapManager2.cpp8
-rw-r--r--src/common/Collision/Management/VMapManager2.h4
-rw-r--r--src/common/Collision/Maps/MapDefines.h17
-rw-r--r--src/common/Collision/Maps/MapTree.cpp22
-rw-r--r--src/common/Collision/Maps/MapTree.h4
-rw-r--r--src/common/Collision/Maps/TileAssembler.cpp23
-rw-r--r--src/common/Collision/Maps/TileAssembler.h2
-rw-r--r--src/common/Collision/Models/GameObjectModel.cpp4
-rw-r--r--src/common/Collision/Models/GameObjectModel.h2
-rw-r--r--src/common/Collision/Models/ModelInstance.cpp6
-rw-r--r--src/common/Collision/Models/ModelInstance.h14
-rw-r--r--src/common/Collision/Models/WorldModel.cpp54
-rw-r--r--src/common/Collision/Models/WorldModel.h20
-rw-r--r--src/common/Collision/RegularGrid.h26
-rw-r--r--src/common/Collision/VMapTools.h148
23 files changed, 164 insertions, 271 deletions
diff --git a/src/common/Collision/BoundingIntervalHierarchy.h b/src/common/Collision/BoundingIntervalHierarchy.h
index a80759f6cf7..539e535fa14 100644
--- a/src/common/Collision/BoundingIntervalHierarchy.h
+++ b/src/common/Collision/BoundingIntervalHierarchy.h
@@ -19,9 +19,9 @@
#ifndef _BIH_H
#define _BIH_H
-#include "G3D/Vector3.h"
-#include "G3D/Ray.h"
-#include "G3D/AABox.h"
+#include <G3D/Vector3.h>
+#include <G3D/Ray.h>
+#include <G3D/AABox.h>
#include "Define.h"
@@ -80,8 +80,8 @@ class TC_COMMON_API BIH
}
public:
BIH() { init_empty(); }
- template< class BoundsFunc, class PrimArray >
- void build(const PrimArray &primitives, BoundsFunc &getBounds, uint32 leafSize = 3, bool printStats=false)
+ template <class BoundsFunc, class PrimArray>
+ void build(PrimArray const& primitives, BoundsFunc& getBounds, uint32 leafSize = 3, bool printStats = false)
{
if (primitives.size() == 0)
{
@@ -118,7 +118,7 @@ class TC_COMMON_API BIH
uint32 primCount() const { return uint32(objects.size()); }
template<typename RayCallback>
- void intersectRay(const G3D::Ray &r, RayCallback& intersectCallback, float &maxDist, bool stopAtFirst=false) const
+ void intersectRay(const G3D::Ray &r, RayCallback& intersectCallback, float &maxDist, bool stopAtFirst = false) const
{
float intervalMin = -1.f;
float intervalMax = -1.f;
diff --git a/src/common/Collision/BoundingIntervalHierarchyWrapper.h b/src/common/Collision/BoundingIntervalHierarchyWrapper.h
index b7f78ea7baf..32c99798768 100644
--- a/src/common/Collision/BoundingIntervalHierarchyWrapper.h
+++ b/src/common/Collision/BoundingIntervalHierarchyWrapper.h
@@ -19,10 +19,10 @@
#ifndef _BIH_WRAP
#define _BIH_WRAP
-#include "G3D/Table.h"
-#include "G3D/Array.h"
-#include "G3D/Set.h"
#include "BoundingIntervalHierarchy.h"
+#include <G3D/Table.h>
+#include <G3D/Array.h>
+#include <G3D/Set.h>
template<class T, class BoundsFunc = BoundsTrait<T> >
@@ -80,7 +80,7 @@ public:
uint32 Idx = 0;
const T * temp;
if (m_obj2Idx.getRemove(&obj, temp, Idx))
- m_objects[Idx] = NULL;
+ m_objects[Idx] = nullptr;
else
m_objects_to_push.remove(&obj);
}
diff --git a/src/common/Collision/DynamicTree.cpp b/src/common/Collision/DynamicTree.cpp
index 38e10318a57..46dfdb1707e 100644
--- a/src/common/Collision/DynamicTree.cpp
+++ b/src/common/Collision/DynamicTree.cpp
@@ -41,20 +41,20 @@ int CHECK_TREE_PERIOD = 200;
} // namespace
template<> struct HashTrait< GameObjectModel>{
- static size_t hashCode(const GameObjectModel& g) { return (size_t)(void*)&g; }
+ static size_t hashCode(GameObjectModel const& g) { return (size_t)(void*)&g; }
};
template<> struct PositionTrait< GameObjectModel> {
- static void getPosition(const GameObjectModel& g, G3D::Vector3& p) { p = g.getPosition(); }
+ static void getPosition(GameObjectModel const& g, G3D::Vector3& p) { p = g.getPosition(); }
};
template<> struct BoundsTrait< GameObjectModel> {
- static void getBounds(const GameObjectModel& g, G3D::AABox& out) { out = g.getBounds();}
- static void getBounds2(const GameObjectModel* g, G3D::AABox& out) { out = g->getBounds();}
+ static void getBounds(GameObjectModel const& g, G3D::AABox& out) { out = g.getBounds();}
+ static void getBounds2(GameObjectModel const* g, G3D::AABox& out) { out = g->getBounds();}
};
/*
-static bool operator == (const GameObjectModel& mdl, const GameObjectModel& mdl2){
+static bool operator==(GameObjectModel const& mdl, GameObjectModel const& mdl2){
return &mdl == &mdl2;
}
*/
@@ -72,13 +72,13 @@ struct DynTreeImpl : public ParentTree/*, public Intersectable*/
{
}
- void insert(const Model& mdl)
+ void insert(Model const& mdl)
{
base::insert(mdl);
++unbalanced_times;
}
- void remove(const Model& mdl)
+ void remove(Model const& mdl)
{
base::remove(mdl);
++unbalanced_times;
@@ -115,17 +115,17 @@ DynamicMapTree::~DynamicMapTree()
delete impl;
}
-void DynamicMapTree::insert(const GameObjectModel& mdl)
+void DynamicMapTree::insert(GameObjectModel const& mdl)
{
impl->insert(mdl);
}
-void DynamicMapTree::remove(const GameObjectModel& mdl)
+void DynamicMapTree::remove(GameObjectModel const& mdl)
{
impl->remove(mdl);
}
-bool DynamicMapTree::contains(const GameObjectModel& mdl) const
+bool DynamicMapTree::contains(GameObjectModel const& mdl) const
{
return impl->contains(mdl);
}
@@ -145,7 +145,7 @@ struct DynamicTreeIntersectionCallback
bool did_hit;
uint32 phase_mask;
DynamicTreeIntersectionCallback(uint32 phasemask) : did_hit(false), phase_mask(phasemask) { }
- bool operator()(const G3D::Ray& r, const GameObjectModel& obj, float& distance)
+ bool operator()(G3D::Ray const& r, GameObjectModel const& obj, float& distance)
{
did_hit = obj.intersectRay(r, distance, true, phase_mask, VMAP::ModelIgnoreFlags::Nothing);
return did_hit;
@@ -161,7 +161,7 @@ struct DynamicTreeIntersectionCallback_WithLogger
{
TC_LOG_DEBUG("maps", "Dynamic Intersection log");
}
- bool operator()(const G3D::Ray& r, const GameObjectModel& obj, float& distance)
+ bool operator()(G3D::Ray const& r, GameObjectModel const& obj, float& distance)
{
TC_LOG_DEBUG("maps", "testing intersection with %s", obj.name.c_str());
bool hit = obj.intersectRay(r, distance, true, phase_mask, VMAP::ModelIgnoreFlags::Nothing);
diff --git a/src/common/Collision/DynamicTree.h b/src/common/Collision/DynamicTree.h
index 49458393906..0e1d1f0342b 100644
--- a/src/common/Collision/DynamicTree.h
+++ b/src/common/Collision/DynamicTree.h
@@ -52,9 +52,9 @@ public:
float getHeight(float x, float y, float z, float maxSearchDist, uint32 phasemask) const;
- void insert(const GameObjectModel&);
- void remove(const GameObjectModel&);
- bool contains(const GameObjectModel&) const;
+ void insert(GameObjectModel const&);
+ void remove(GameObjectModel const&);
+ bool contains(GameObjectModel const&) const;
void balance();
void update(uint32 diff);
diff --git a/src/common/Collision/Management/IVMapManager.h b/src/common/Collision/Management/IVMapManager.h
index e77987a721d..0371135cfa5 100644
--- a/src/common/Collision/Management/IVMapManager.h
+++ b/src/common/Collision/Management/IVMapManager.h
@@ -19,10 +19,10 @@
#ifndef _IVMAPMANAGER_H
#define _IVMAPMANAGER_H
-#include <string>
#include "Define.h"
#include "ModelIgnoreFlags.h"
-#include "Common.h"
+#include "Optional.h"
+#include <string>
//===========================================================
@@ -83,9 +83,9 @@ namespace VMAP
virtual ~IVMapManager(void) { }
- virtual int loadMap(const char* pBasePath, unsigned int pMapId, int x, int y) = 0;
+ virtual int loadMap(char const* pBasePath, unsigned int pMapId, int x, int y) = 0;
- virtual LoadResult existsMap(const char* pBasePath, unsigned int pMapId, int x, int y) = 0;
+ virtual LoadResult existsMap(char const* pBasePath, unsigned int pMapId, int x, int y) = 0;
virtual void unloadMap(unsigned int pMapId, int x, int y) = 0;
virtual void unloadMap(unsigned int pMapId) = 0;
diff --git a/src/common/Collision/Management/MMapFactory.cpp b/src/common/Collision/Management/MMapFactory.cpp
index 1257d852697..02295c2b2db 100644
--- a/src/common/Collision/Management/MMapFactory.cpp
+++ b/src/common/Collision/Management/MMapFactory.cpp
@@ -23,11 +23,11 @@ namespace MMAP
{
// ######################## MMapFactory ########################
// our global singleton copy
- MMapManager* g_MMapManager = NULL;
+ MMapManager* g_MMapManager = nullptr;
MMapManager* MMapFactory::createOrGetMMapManager()
{
- if (g_MMapManager == NULL)
+ if (g_MMapManager == nullptr)
g_MMapManager = new MMapManager();
return g_MMapManager;
@@ -38,7 +38,7 @@ namespace MMAP
if (g_MMapManager)
{
delete g_MMapManager;
- g_MMapManager = NULL;
+ g_MMapManager = nullptr;
}
}
} \ No newline at end of file
diff --git a/src/common/Collision/Management/MMapManager.cpp b/src/common/Collision/Management/MMapManager.cpp
index cec5c0da7f0..ff87ed369cc 100644
--- a/src/common/Collision/Management/MMapManager.cpp
+++ b/src/common/Collision/Management/MMapManager.cpp
@@ -17,6 +17,7 @@
*/
#include "MMapManager.h"
+#include "Errors.h"
#include "Log.h"
#include "Config.h"
#include "MapDefines.h"
@@ -39,7 +40,7 @@ namespace MMAP
void MMapManager::InitializeThreadUnsafe(const std::vector<uint32>& mapIds)
{
// the caller must pass the list of all mapIds that will be used in the VMapManager2 lifetime
- for (const uint32& mapId : mapIds)
+ for (uint32 const& mapId : mapIds)
loadedMMaps.insert(MMapDataSet::value_type(mapId, nullptr));
thread_safe_environment = false;
@@ -222,7 +223,7 @@ namespace MMAP
dtTileRef tileRef = mmap->loadedTileRefs[packedGridPos];
// unload, and mark as non loaded
- if (dtStatusFailed(mmap->navMesh->removeTile(tileRef, NULL, NULL)))
+ if (dtStatusFailed(mmap->navMesh->removeTile(tileRef, nullptr, nullptr)))
{
// this is technically a memory leak
// if the grid is later reloaded, dtNavMesh::addTile will return error but no extra memory is used
@@ -257,7 +258,7 @@ namespace MMAP
{
uint32 x = (i->first >> 16);
uint32 y = (i->first & 0x0000FFFF);
- if (dtStatusFailed(mmap->navMesh->removeTile(i->second, NULL, NULL)))
+ if (dtStatusFailed(mmap->navMesh->removeTile(i->second, nullptr, nullptr)))
TC_LOG_ERROR("maps", "MMAP:unloadMap: Could not unload %03u%02i%02i.mmtile from navmesh", mapId, x, y);
else
{
@@ -304,7 +305,7 @@ namespace MMAP
{
MMapDataSet::const_iterator itr = GetMMapData(mapId);
if (itr == loadedMMaps.end())
- return NULL;
+ return nullptr;
return itr->second->navMesh;
}
@@ -313,7 +314,7 @@ namespace MMAP
{
MMapDataSet::const_iterator itr = GetMMapData(mapId);
if (itr == loadedMMaps.end())
- return NULL;
+ return nullptr;
MMapData* mmap = itr->second;
if (mmap->navMeshQueries.find(instanceId) == mmap->navMeshQueries.end())
@@ -325,7 +326,7 @@ namespace MMAP
{
dtFreeNavMeshQuery(query);
TC_LOG_ERROR("maps", "MMAP:GetNavMeshQuery: Failed to initialize dtNavMeshQuery for mapId %03u instanceId %u", mapId, instanceId);
- return NULL;
+ return nullptr;
}
TC_LOG_DEBUG("maps", "MMAP:GetNavMeshQuery: created dtNavMeshQuery for mapId %03u instanceId %u", mapId, instanceId);
diff --git a/src/common/Collision/Management/VMapFactory.cpp b/src/common/Collision/Management/VMapFactory.cpp
index f36f237c4b2..f8c4be61617 100644
--- a/src/common/Collision/Management/VMapFactory.cpp
+++ b/src/common/Collision/Management/VMapFactory.cpp
@@ -21,7 +21,7 @@
namespace VMAP
{
- IVMapManager* gVMapManager = NULL;
+ IVMapManager* gVMapManager = nullptr;
//===============================================
// just return the instance
@@ -37,6 +37,6 @@ namespace VMAP
void VMapFactory::clear()
{
delete gVMapManager;
- gVMapManager = NULL;
+ gVMapManager = nullptr;
}
}
diff --git a/src/common/Collision/Management/VMapManager2.cpp b/src/common/Collision/Management/VMapManager2.cpp
index 33bf7338616..7c894efa1ca 100644
--- a/src/common/Collision/Management/VMapManager2.cpp
+++ b/src/common/Collision/Management/VMapManager2.cpp
@@ -55,7 +55,7 @@ namespace VMAP
void VMapManager2::InitializeThreadUnsafe(const std::vector<uint32>& mapIds)
{
// the caller must pass the list of all mapIds that will be used in the VMapManager2 lifetime
- for (const uint32& mapId : mapIds)
+ for (uint32 const& mapId : mapIds)
iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId, nullptr));
thread_safe_environment = false;
@@ -82,7 +82,7 @@ namespace VMAP
return fname.str();
}
- int VMapManager2::loadMap(const char* basePath, unsigned int mapId, int x, int y)
+ int VMapManager2::loadMap(char const* basePath, unsigned int mapId, int x, int y)
{
int result = VMAP_LOAD_RESULT_IGNORED;
if (isMapLoadingEnabled())
@@ -323,7 +323,7 @@ namespace VMAP
{
VMAP_ERROR_LOG("misc", "VMapManager2: could not load '%s%s.vmo'", basepath.c_str(), filename.c_str());
delete worldmodel;
- return NULL;
+ return nullptr;
}
VMAP_DEBUG_LOG("maps", "VMapManager2: loading file '%s%s'", basepath.c_str(), filename.c_str());
@@ -355,7 +355,7 @@ namespace VMAP
}
}
- LoadResult VMapManager2::existsMap(const char* basePath, unsigned int mapId, int x, int y)
+ LoadResult VMapManager2::existsMap(char const* basePath, unsigned int mapId, int x, int y)
{
return StaticMapTree::CanLoadMap(std::string(basePath), mapId, x, y);
}
diff --git a/src/common/Collision/Management/VMapManager2.h b/src/common/Collision/Management/VMapManager2.h
index 3fdc427d6eb..b8d59b9c09e 100644
--- a/src/common/Collision/Management/VMapManager2.h
+++ b/src/common/Collision/Management/VMapManager2.h
@@ -102,7 +102,7 @@ namespace VMAP
~VMapManager2(void);
void InitializeThreadUnsafe(const std::vector<uint32>& mapIds);
- int loadMap(const char* pBasePath, unsigned int mapId, int x, int y) override;
+ int loadMap(char const* pBasePath, unsigned int mapId, int x, int y) override;
void unloadMap(unsigned int mapId, int x, int y) override;
void unloadMap(unsigned int mapId) override;
@@ -128,7 +128,7 @@ namespace VMAP
{
return getMapFileName(mapId);
}
- virtual LoadResult existsMap(const char* basePath, unsigned int mapId, int x, int y) override;
+ virtual LoadResult existsMap(char const* basePath, unsigned int mapId, int x, int y) override;
void getInstanceMapTree(InstanceTreeMap &instanceMapTree);
diff --git a/src/common/Collision/Maps/MapDefines.h b/src/common/Collision/Maps/MapDefines.h
index 4b53975237e..3dd19735ff9 100644
--- a/src/common/Collision/Maps/MapDefines.h
+++ b/src/common/Collision/Maps/MapDefines.h
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#ifndef _MAPDEFINES_H
#define _MAPDEFINES_H
diff --git a/src/common/Collision/Maps/MapTree.cpp b/src/common/Collision/Maps/MapTree.cpp
index f3fe8c1f56f..1f2a8a60c73 100644
--- a/src/common/Collision/Maps/MapTree.cpp
+++ b/src/common/Collision/Maps/MapTree.cpp
@@ -37,7 +37,7 @@ namespace VMAP
{
public:
MapRayCallback(ModelInstance* val, ModelIgnoreFlags ignoreFlags): prims(val), hit(false), flags(ignoreFlags) { }
- bool operator()(const G3D::Ray& ray, uint32 entry, float& distance, bool pStopAtFirstHit=true)
+ bool operator()(const G3D::Ray& ray, uint32 entry, float& distance, bool pStopAtFirstHit = true)
{
bool result = prims[entry].intersectRay(ray, distance, pStopAtFirstHit, flags);
if (result)
@@ -55,7 +55,7 @@ namespace VMAP
{
public:
AreaInfoCallback(ModelInstance* val): prims(val) { }
- void operator()(const Vector3& point, uint32 entry)
+ void operator()(Vector3 const& point, uint32 entry)
{
#ifdef VMAP_DEBUG
TC_LOG_DEBUG("maps", "AreaInfoCallback: trying to intersect '%s'", prims[entry].name.c_str());
@@ -71,7 +71,7 @@ namespace VMAP
{
public:
LocationInfoCallback(ModelInstance* val, LocationInfo &info): prims(val), locInfo(info), result(false) { }
- void operator()(const Vector3& point, uint32 entry)
+ void operator()(Vector3 const& point, uint32 entry)
{
#ifdef VMAP_DEBUG
TC_LOG_DEBUG("maps", "LocationInfoCallback: trying to intersect '%s'", prims[entry].name.c_str());
@@ -113,15 +113,15 @@ namespace VMAP
return false;
}
- bool StaticMapTree::GetLocationInfo(const Vector3 &pos, LocationInfo &info) const
+ bool StaticMapTree::GetLocationInfo(Vector3 const& pos, LocationInfo &info) const
{
LocationInfoCallback intersectionCallBack(iTreeValues, info);
iTree.intersectPoint(pos, intersectionCallBack);
return intersectionCallBack.result;
}
- StaticMapTree::StaticMapTree(uint32 mapID, const std::string &basePath) :
- iMapID(mapID), iIsTiled(false), iTreeValues(NULL),
+ StaticMapTree::StaticMapTree(uint32 mapID, std::string const& basePath) :
+ iMapID(mapID), iIsTiled(false), iTreeValues(nullptr),
iNTreeValues(0), iBasePath(basePath)
{
if (iBasePath.length() > 0 && iBasePath[iBasePath.length()-1] != '/' && iBasePath[iBasePath.length()-1] != '\\')
@@ -153,7 +153,7 @@ namespace VMAP
}
//=========================================================
- bool StaticMapTree::isInLineOfSight(const Vector3& pos1, const Vector3& pos2, ModelIgnoreFlags ignoreFlag) const
+ bool StaticMapTree::isInLineOfSight(Vector3 const& pos1, Vector3 const& pos2, ModelIgnoreFlags ignoreFlag) const
{
float maxDist = (pos2 - pos1).magnitude();
// return false if distance is over max float, in case of cheater teleporting to the end of the universe
@@ -178,9 +178,9 @@ namespace VMAP
Return the hit pos or the original dest pos
*/
- bool StaticMapTree::getObjectHitPos(const Vector3& pPos1, const Vector3& pPos2, Vector3& pResultHitPos, float pModifyDist) const
+ bool StaticMapTree::getObjectHitPos(Vector3 const& pPos1, Vector3 const& pPos2, Vector3& pResultHitPos, float pModifyDist) const
{
- bool result=false;
+ bool result = false;
float maxDist = (pPos2 - pPos1).magnitude();
// valid map coords should *never ever* produce float overflow, but this would produce NaNs too
ASSERT(maxDist < std::numeric_limits<float>::max());
@@ -223,7 +223,7 @@ namespace VMAP
//=========================================================
- float StaticMapTree::getHeight(const Vector3& pPos, float maxSearchDist) const
+ float StaticMapTree::getHeight(Vector3 const& pPos, float maxSearchDist) const
{
float height = G3D::finf();
Vector3 dir = Vector3(0, 0, -1);
@@ -438,7 +438,7 @@ namespace VMAP
FILE* tf = fopen(tilefile.c_str(), "rb");
if (tf)
{
- bool result=true;
+ bool result = true;
char chunk[8];
if (!readChunk(tf, chunk, VMAP_MAGIC, 8))
result = false;
diff --git a/src/common/Collision/Maps/MapTree.h b/src/common/Collision/Maps/MapTree.h
index bc18e07789b..6dc32c1241a 100644
--- a/src/common/Collision/Maps/MapTree.h
+++ b/src/common/Collision/Maps/MapTree.h
@@ -36,8 +36,8 @@ namespace VMAP
{
LocationInfo(): hitInstance(nullptr), hitModel(nullptr), ground_Z(-G3D::finf()) { }
int32 rootId;
- const ModelInstance* hitInstance;
- const GroupModel* hitModel;
+ ModelInstance const* hitInstance;
+ GroupModel const* hitModel;
float ground_Z;
};
diff --git a/src/common/Collision/Maps/TileAssembler.cpp b/src/common/Collision/Maps/TileAssembler.cpp
index 2c4d3105050..fe00458cf6d 100644
--- a/src/common/Collision/Maps/TileAssembler.cpp
+++ b/src/common/Collision/Maps/TileAssembler.cpp
@@ -32,7 +32,7 @@ using std::pair;
template<> struct BoundsTrait<VMAP::ModelSpawn*>
{
- static void getBounds(const VMAP::ModelSpawn* const &obj, G3D::AABox& out) { out = obj->getBounds(); }
+ static void getBounds(VMAP::ModelSpawn const* const& obj, G3D::AABox& out) { out = obj->getBounds(); }
};
namespace VMAP
@@ -43,7 +43,7 @@ namespace VMAP
return memcmp(dest, compare, len) == 0;
}
- Vector3 ModelPosition::transform(const Vector3& pIn) const
+ Vector3 ModelPosition::transform(Vector3 const& pIn) const
{
Vector3 out = pIn * iScale;
out = iRotation * out;
@@ -53,7 +53,7 @@ namespace VMAP
//=================================================================
TileAssembler::TileAssembler(const std::string& pSrcDirName, const std::string& pDestDirName)
- : iDestDir(pDestDirName), iSrcDir(pSrcDirName), iFilterMethod(NULL), iCurrentUniqueNameId(0)
+ : iDestDir(pDestDirName), iSrcDir(pSrcDirName), iFilterMethod(nullptr), iCurrentUniqueNameId(0)
{
//mkdir(iDestDir);
//init();
@@ -136,10 +136,8 @@ namespace VMAP
// global map spawns (WDT), if any (most instances)
if (success && fwrite("GOBJ", 4, 1, mapfile) != 1) success = false;
- for (TileMap::iterator glob=globalRange.first; glob != globalRange.second && success; ++glob)
- {
+ for (TileMap::iterator glob = globalRange.first; glob != globalRange.second && success; ++glob)
success = ModelSpawn::writeToFile(mapfile, map_iter->second->UniqueEntries[glob->second]);
- }
fclose(mapfile);
@@ -150,7 +148,7 @@ namespace VMAP
TileMap::iterator tile;
for (tile = tileEntries.begin(); tile != tileEntries.end(); ++tile)
{
- const ModelSpawn &spawn = map_iter->second->UniqueEntries[tile->second];
+ ModelSpawn const& spawn = map_iter->second->UniqueEntries[tile->second];
if (spawn.flags & MOD_WORLDSPAWN) // WDT spawn, saved as tile 65/65 currently...
continue;
uint32 nSpawns = tileEntries.count(tile->first);
@@ -171,7 +169,7 @@ namespace VMAP
{
if (s)
++tile;
- const ModelSpawn &spawn2 = map_iter->second->UniqueEntries[tile->second];
+ ModelSpawn const& spawn2 = map_iter->second->UniqueEntries[tile->second];
success = success && ModelSpawn::writeToFile(tilefile, spawn2);
// MapTree nodes to update when loading tile:
std::map<uint32, uint32>::iterator nIdx = modelNodeIdx.find(spawn2.ID);
@@ -266,9 +264,9 @@ namespace VMAP
printf("Warning: '%s' does not seem to be a M2 model!\n", modelFilename.c_str());
AABox modelBound;
- bool boundEmpty=true;
+ bool boundEmpty = true;
- for (uint32 g=0; g<groups; ++g) // should be only one for M2 files...
+ for (uint32 g = 0; g < groups; ++g) // should be only one for M2 files...
{
std::vector<Vector3>& vertices = raw_model.groupsArray[g].vertexArray;
@@ -284,7 +282,10 @@ namespace VMAP
Vector3 v = modelPosition.transform(vertices[i]);
if (boundEmpty)
- modelBound = AABox(v, v), boundEmpty=false;
+ {
+ modelBound = AABox(v, v);
+ boundEmpty = false;
+ }
else
modelBound.merge(v);
}
diff --git a/src/common/Collision/Maps/TileAssembler.h b/src/common/Collision/Maps/TileAssembler.h
index ae0585dbd57..f11f2682a0d 100644
--- a/src/common/Collision/Maps/TileAssembler.h
+++ b/src/common/Collision/Maps/TileAssembler.h
@@ -76,7 +76,7 @@ namespace VMAP
class WmoLiquid* liquid;
GroupModel_Raw() : mogpflags(0), GroupWMOID(0), liquidflags(0),
- liquid(NULL) { }
+ liquid(nullptr) { }
~GroupModel_Raw();
bool Read(FILE* f);
diff --git a/src/common/Collision/Models/GameObjectModel.cpp b/src/common/Collision/Models/GameObjectModel.cpp
index 2950a48c21b..992ec59e1af 100644
--- a/src/common/Collision/Models/GameObjectModel.cpp
+++ b/src/common/Collision/Models/GameObjectModel.cpp
@@ -30,7 +30,7 @@ using G3D::AABox;
struct GameobjectModelData
{
- GameobjectModelData(const std::string& name_, const AABox& box) :
+ GameobjectModelData(std::string const& name_, AABox const& box) :
bound(box), name(name_) { }
AABox bound;
@@ -147,7 +147,7 @@ GameObjectModel* GameObjectModel::Create(std::unique_ptr<GameObjectModelOwnerBas
if (!mdl->initialize(std::move(modelOwner), dataPath))
{
delete mdl;
- return NULL;
+ return nullptr;
}
return mdl;
diff --git a/src/common/Collision/Models/GameObjectModel.h b/src/common/Collision/Models/GameObjectModel.h
index c121e421e6d..72fee944380 100644
--- a/src/common/Collision/Models/GameObjectModel.h
+++ b/src/common/Collision/Models/GameObjectModel.h
@@ -50,7 +50,7 @@ public:
class TC_COMMON_API GameObjectModel /*, public Intersectable*/
{
- GameObjectModel() : phasemask(0), iInvScale(0), iScale(0), iModel(NULL) { }
+ GameObjectModel() : phasemask(0), iInvScale(0), iScale(0), iModel(nullptr) { }
public:
std::string name;
diff --git a/src/common/Collision/Models/ModelInstance.cpp b/src/common/Collision/Models/ModelInstance.cpp
index 3390b233c82..3eeb0e8c669 100644
--- a/src/common/Collision/Models/ModelInstance.cpp
+++ b/src/common/Collision/Models/ModelInstance.cpp
@@ -25,13 +25,13 @@ using G3D::Ray;
namespace VMAP
{
- ModelInstance::ModelInstance(const ModelSpawn &spawn, WorldModel* model): ModelSpawn(spawn), iModel(model)
+ ModelInstance::ModelInstance(ModelSpawn const& spawn, WorldModel* model): ModelSpawn(spawn), iModel(model)
{
iInvRot = G3D::Matrix3::fromEulerAnglesZYX(G3D::pif()*iRot.y/180.f, G3D::pif()*iRot.x/180.f, G3D::pif()*iRot.z/180.f).inverse();
iInvScale = 1.f/iScale;
}
- bool ModelInstance::intersectRay(const G3D::Ray& pRay, float& pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
+ bool ModelInstance::intersectRay(G3D::Ray const& pRay, float& pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
{
if (!iModel)
{
@@ -196,7 +196,7 @@ namespace VMAP
return true;
}
- bool ModelSpawn::writeToFile(FILE* wf, const ModelSpawn &spawn)
+ bool ModelSpawn::writeToFile(FILE* wf, ModelSpawn const& spawn)
{
uint32 check=0;
check += fwrite(&spawn.flags, sizeof(uint32), 1, wf);
diff --git a/src/common/Collision/Models/ModelInstance.h b/src/common/Collision/Models/ModelInstance.h
index 3036ac10117..fa53ceab70d 100644
--- a/src/common/Collision/Models/ModelInstance.h
+++ b/src/common/Collision/Models/ModelInstance.h
@@ -52,25 +52,25 @@ namespace VMAP
float iScale;
G3D::AABox iBound;
std::string name;
- bool operator==(const ModelSpawn &other) const { return ID == other.ID; }
+ bool operator==(ModelSpawn const& other) const { return ID == other.ID; }
//uint32 hashCode() const { return ID; }
// temp?
const G3D::AABox& getBounds() const { return iBound; }
static bool readFromFile(FILE* rf, ModelSpawn &spawn);
- static bool writeToFile(FILE* rw, const ModelSpawn &spawn);
+ static bool writeToFile(FILE* rw, ModelSpawn const& spawn);
};
class TC_COMMON_API ModelInstance: public ModelSpawn
{
public:
ModelInstance(): iInvScale(0.0f), iModel(nullptr) { }
- ModelInstance(const ModelSpawn &spawn, WorldModel* model);
+ ModelInstance(ModelSpawn const& spawn, WorldModel* model);
void setUnloaded() { iModel = nullptr; }
- bool intersectRay(const G3D::Ray& pRay, float& pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) 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;
+ bool intersectRay(G3D::Ray const& pRay, float& pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const;
+ void intersectPoint(G3D::Vector3 const& p, AreaInfo &info) const;
+ bool GetLocationInfo(G3D::Vector3 const& p, LocationInfo &info) const;
+ bool GetLiquidLevel(G3D::Vector3 const& p, LocationInfo &info, float &liqHeight) const;
WorldModel* getWorldModel() { return iModel; }
protected:
G3D::Matrix3 iInvRot;
diff --git a/src/common/Collision/Models/WorldModel.cpp b/src/common/Collision/Models/WorldModel.cpp
index d04bcf4d241..7a40ba215cf 100644
--- a/src/common/Collision/Models/WorldModel.cpp
+++ b/src/common/Collision/Models/WorldModel.cpp
@@ -32,7 +32,7 @@ template<> struct BoundsTrait<VMAP::GroupModel>
namespace VMAP
{
- bool IntersectTriangle(const MeshTriangle &tri, std::vector<Vector3>::const_iterator points, const G3D::Ray &ray, float &distance)
+ bool IntersectTriangle(MeshTriangle const& tri, std::vector<Vector3>::const_iterator points, G3D::Ray const& ray, float& distance)
{
static const float EPS = 1e-5f;
@@ -85,8 +85,8 @@ namespace VMAP
class TriBoundFunc
{
public:
- TriBoundFunc(std::vector<Vector3> &vert): vertices(vert.begin()) { }
- void operator()(const MeshTriangle &tri, G3D::AABox &out) const
+ TriBoundFunc(std::vector<Vector3>& vert): vertices(vert.begin()) { }
+ void operator()(MeshTriangle const& tri, G3D::AABox& out) const
{
G3D::Vector3 lo = vertices[tri.idx0];
G3D::Vector3 hi = lo;
@@ -102,14 +102,14 @@ namespace VMAP
// ===================== WmoLiquid ==================================
- WmoLiquid::WmoLiquid(uint32 width, uint32 height, const Vector3 &corner, uint32 type):
+ WmoLiquid::WmoLiquid(uint32 width, uint32 height, Vector3 const& corner, uint32 type) :
iTilesX(width), iTilesY(height), iCorner(corner), iType(type)
{
- iHeight = new float[(width+1)*(height+1)];
+ iHeight = new float[(width + 1) * (height + 1)];
iFlags = new uint8[width*height];
}
- WmoLiquid::WmoLiquid(const WmoLiquid &other): iHeight(nullptr), iFlags(nullptr)
+ WmoLiquid::WmoLiquid(WmoLiquid const& other): iHeight(nullptr), iFlags(nullptr)
{
*this = other; // use assignment operator...
}
@@ -120,7 +120,7 @@ namespace VMAP
delete[] iFlags;
}
- WmoLiquid& WmoLiquid::operator=(const WmoLiquid &other)
+ WmoLiquid& WmoLiquid::operator=(WmoLiquid const& other)
{
if (this == &other)
return *this;
@@ -147,7 +147,7 @@ namespace VMAP
return *this;
}
- bool WmoLiquid::GetLiquidHeight(const Vector3 &pos, float &liqHeight) const
+ bool WmoLiquid::GetLiquidHeight(Vector3 const& pos, float &liqHeight) const
{
float tx_f = (pos.x - iCorner.x)/LIQUID_TILE_SIZE;
uint32 tx = uint32(tx_f);
@@ -180,7 +180,7 @@ namespace VMAP
0 1
*/
- const uint32 rowOffset = iTilesX + 1;
+ uint32 const rowOffset = iTilesX + 1;
if (dx > dy) // case (a)
{
float sx = iHeight[tx+1 + ty * rowOffset] - iHeight[tx + ty * rowOffset];
@@ -260,7 +260,7 @@ namespace VMAP
// ===================== GroupModel ==================================
- GroupModel::GroupModel(const GroupModel &other):
+ GroupModel::GroupModel(GroupModel const& other):
iBound(other.iBound), iMogpFlags(other.iMogpFlags), iGroupWMOID(other.iGroupWMOID),
vertices(other.vertices), triangles(other.triangles), meshTree(other.meshTree), iLiquid(nullptr)
{
@@ -331,7 +331,7 @@ namespace VMAP
triangles.clear();
vertices.clear();
delete iLiquid;
- iLiquid = NULL;
+ iLiquid = nullptr;
if (result && fread(&iBound, sizeof(G3D::AABox), 1, rf) != 1) result = false;
if (result && fread(&iMogpFlags, sizeof(uint32), 1, rf) != 1) result = false;
@@ -367,12 +367,13 @@ namespace VMAP
struct GModelRayCallback
{
- GModelRayCallback(const std::vector<MeshTriangle> &tris, const std::vector<Vector3> &vert):
+ GModelRayCallback(std::vector<MeshTriangle> const& tris, const std::vector<Vector3> &vert):
vertices(vert.begin()), triangles(tris.begin()), hit(false) { }
- bool operator()(const G3D::Ray& ray, uint32 entry, float& distance, bool /*pStopAtFirstHit*/)
+ bool operator()(G3D::Ray const& ray, uint32 entry, float& distance, bool /*pStopAtFirstHit*/)
{
bool result = IntersectTriangle(triangles[entry], vertices, ray, distance);
- if (result) hit=true;
+ if (result)
+ hit = true;
return hit;
}
std::vector<Vector3>::const_iterator vertices;
@@ -380,7 +381,7 @@ namespace VMAP
bool hit;
};
- bool GroupModel::IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const
+ bool GroupModel::IntersectRay(G3D::Ray const& ray, float& distance, bool stopAtFirstHit) const
{
if (triangles.empty())
return false;
@@ -390,7 +391,7 @@ namespace VMAP
return callback.hit;
}
- bool GroupModel::IsInsideObject(const Vector3 &pos, const Vector3 &down, float &z_dist) const
+ bool GroupModel::IsInsideObject(Vector3 const& pos, Vector3 const& down, float& z_dist) const
{
if (triangles.empty() || !iBound.contains(pos))
return false;
@@ -404,7 +405,7 @@ namespace VMAP
return hit;
}
- bool GroupModel::GetLiquidLevel(const Vector3 &pos, float &liqHeight) const
+ bool GroupModel::GetLiquidLevel(Vector3 const& pos, float& liqHeight) const
{
if (iLiquid)
return iLiquid->GetLiquidHeight(pos, liqHeight);
@@ -427,7 +428,7 @@ namespace VMAP
// ===================== WorldModel ==================================
- void WorldModel::setGroupModels(std::vector<GroupModel> &models)
+ void WorldModel::setGroupModels(std::vector<GroupModel>& models)
{
groupModels.swap(models);
groupTree.build(groupModels, BoundsTrait<GroupModel>::getBounds, 1);
@@ -435,18 +436,19 @@ namespace VMAP
struct WModelRayCallBack
{
- WModelRayCallBack(const std::vector<GroupModel> &mod): models(mod.begin()), hit(false) { }
- bool operator()(const G3D::Ray& ray, uint32 entry, float& distance, bool pStopAtFirstHit)
+ WModelRayCallBack(std::vector<GroupModel> const& mod): models(mod.begin()), hit(false) { }
+ bool operator()(G3D::Ray const& ray, uint32 entry, float& distance, bool pStopAtFirstHit)
{
bool result = models[entry].IntersectRay(ray, distance, pStopAtFirstHit);
- if (result) hit=true;
+ if (result)
+ hit = true;
return hit;
}
std::vector<GroupModel>::const_iterator models;
bool hit;
};
- bool WorldModel::IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
+ bool WorldModel::IntersectRay(G3D::Ray const& ray, float& distance, bool stopAtFirstHit, ModelIgnoreFlags ignoreFlags) const
{
// If the caller asked us to ignore certain objects we should check flags
if ((ignoreFlags & ModelIgnoreFlags::M2) != ModelIgnoreFlags::Nothing)
@@ -468,14 +470,14 @@ namespace VMAP
class WModelAreaCallback {
public:
- WModelAreaCallback(const std::vector<GroupModel> &vals, const Vector3 &down):
+ WModelAreaCallback(std::vector<GroupModel> const& vals, Vector3 const& down) :
prims(vals.begin()), hit(vals.end()), minVol(G3D::finf()), zDist(G3D::finf()), zVec(down) { }
std::vector<GroupModel>::const_iterator prims;
std::vector<GroupModel>::const_iterator hit;
float minVol;
float zDist;
Vector3 zVec;
- void operator()(const Vector3& point, uint32 entry)
+ void operator()(Vector3 const& point, uint32 entry)
{
float group_Z;
//float pVol = prims[entry].GetBound().volume();
@@ -492,7 +494,7 @@ namespace VMAP
hit = prims + entry;
}
#ifdef VMAP_DEBUG
- const GroupModel &gm = prims[entry];
+ GroupModel const& gm = prims[entry];
printf("%10u %8X %7.3f, %7.3f, %7.3f | %7.3f, %7.3f, %7.3f | z=%f, p_z=%f\n", gm.GetWmoID(), gm.GetMogpFlags(),
gm.GetBound().low().x, gm.GetBound().low().y, gm.GetBound().low().z,
gm.GetBound().high().x, gm.GetBound().high().y, gm.GetBound().high().z, group_Z, point.z);
@@ -553,7 +555,7 @@ namespace VMAP
if (result && fwrite(&RootWMOID, sizeof(uint32), 1, wf) != 1) result = false;
// write group models
- count=groupModels.size();
+ count = groupModels.size();
if (count)
{
if (result && fwrite("GMOD", 1, 4, wf) != 4) result = false;
diff --git a/src/common/Collision/Models/WorldModel.h b/src/common/Collision/Models/WorldModel.h
index df472708209..935598d3941 100644
--- a/src/common/Collision/Models/WorldModel.h
+++ b/src/common/Collision/Models/WorldModel.h
@@ -48,11 +48,11 @@ namespace VMAP
class TC_COMMON_API WmoLiquid
{
public:
- WmoLiquid(uint32 width, uint32 height, const G3D::Vector3 &corner, uint32 type);
- WmoLiquid(const WmoLiquid &other);
+ WmoLiquid(uint32 width, uint32 height, G3D::Vector3 const& corner, uint32 type);
+ WmoLiquid(WmoLiquid const& other);
~WmoLiquid();
- WmoLiquid& operator=(const WmoLiquid &other);
- bool GetLiquidHeight(const G3D::Vector3 &pos, float &liqHeight) const;
+ WmoLiquid& operator=(WmoLiquid const& other);
+ bool GetLiquidHeight(G3D::Vector3 const& pos, float& liqHeight) const;
uint32 GetType() const { return iType; }
float *GetHeightStorage() { return iHeight; }
uint8 *GetFlagsStorage() { return iFlags; }
@@ -61,7 +61,7 @@ namespace VMAP
static bool readFromFile(FILE* rf, WmoLiquid* &liquid);
void getPosInfo(uint32 &tilesX, uint32 &tilesY, G3D::Vector3 &corner) const;
private:
- WmoLiquid() : iTilesX(0), iTilesY(0), iCorner(), iType(0), iHeight(NULL), iFlags(NULL) { }
+ WmoLiquid() : iTilesX(0), iTilesY(0), iCorner(), iType(0), iHeight(nullptr), iFlags(nullptr) { }
uint32 iTilesX; //!< number of tiles in x direction, each
uint32 iTilesY;
G3D::Vector3 iCorner; //!< the lower corner
@@ -74,15 +74,15 @@ namespace VMAP
class TC_COMMON_API GroupModel
{
public:
- GroupModel() : iBound(), iMogpFlags(0), iGroupWMOID(0), iLiquid(NULL) { }
- GroupModel(const GroupModel &other);
- GroupModel(uint32 mogpFlags, uint32 groupWMOID, const G3D::AABox &bound):
- iBound(bound), iMogpFlags(mogpFlags), iGroupWMOID(groupWMOID), iLiquid(NULL) { }
+ GroupModel() : iBound(), iMogpFlags(0), iGroupWMOID(0), iLiquid(nullptr) { }
+ GroupModel(GroupModel const& other);
+ GroupModel(uint32 mogpFlags, uint32 groupWMOID, G3D::AABox const& bound):
+ iBound(bound), iMogpFlags(mogpFlags), iGroupWMOID(groupWMOID), iLiquid(nullptr) { }
~GroupModel() { delete iLiquid; }
//! pass mesh data to object and create BIH. Passed vectors get get swapped with old geometry!
void setMeshData(std::vector<G3D::Vector3> &vert, std::vector<MeshTriangle> &tri);
- void setLiquidData(WmoLiquid*& liquid) { iLiquid = liquid; liquid = NULL; }
+ void setLiquidData(WmoLiquid*& liquid) { iLiquid = liquid; liquid = nullptr; }
bool IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const;
bool IsInsideObject(const G3D::Vector3 &pos, const G3D::Vector3 &down, float &z_dist) const;
bool GetLiquidLevel(const G3D::Vector3 &pos, float &liqHeight) const;
diff --git a/src/common/Collision/RegularGrid.h b/src/common/Collision/RegularGrid.h
index 4d045179290..0800276f065 100644
--- a/src/common/Collision/RegularGrid.h
+++ b/src/common/Collision/RegularGrid.h
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#ifndef _REGULAR_GRID_H
#define _REGULAR_GRID_H
@@ -86,15 +103,18 @@ public:
struct Cell
{
int x, y;
- bool operator == (const Cell& c2) const { return x == c2.x && y == c2.y;}
+ bool operator==(Cell const& c2) const
+ {
+ return x == c2.x && y == c2.y;
+ }
static Cell ComputeCell(float fx, float fy)
{
- Cell c = { int(fx * (1.f/CELL_SIZE) + (CELL_NUMBER/2)), int(fy * (1.f/CELL_SIZE) + (CELL_NUMBER/2)) };
+ Cell c = { int(fx * (1.f / CELL_SIZE) + (CELL_NUMBER / 2)), int(fy * (1.f / CELL_SIZE) + (CELL_NUMBER / 2)) };
return c;
}
- bool isValid() const { return x >= 0 && x < CELL_NUMBER && y >= 0 && y < CELL_NUMBER;}
+ bool isValid() const { return x >= 0 && x < CELL_NUMBER && y >= 0 && y < CELL_NUMBER; }
};
Node& getGrid(int x, int y)
diff --git a/src/common/Collision/VMapTools.h b/src/common/Collision/VMapTools.h
deleted file mode 100644
index b73e524ce5a..00000000000
--- a/src/common/Collision/VMapTools.h
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
- * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef _VMAPTOOLS_H
-#define _VMAPTOOLS_H
-
-#include <G3D/CollisionDetection.h>
-#include <G3D/AABox.h>
-
-/**
-The Class is mainly taken from G3D/AABSPTree.h but modified to be able to use our internal data structure.
-This is an iterator that helps us analysing the BSP-Trees.
-The collision detection is modified to return true, if we are inside an object.
-*/
-
-namespace VMAP
-{
- template<class TValue>
- class IntersectionCallBack {
- public:
- TValue* closestEntity;
- G3D::Vector3 hitLocation;
- G3D::Vector3 hitNormal;
-
- void operator()(const G3D::Ray& ray, const TValue* entity, bool pStopAtFirstHit, float& distance) {
- entity->intersect(ray, distance, pStopAtFirstHit, hitLocation, hitNormal);
- }
- };
-
- //==============================================================
- //==============================================================
- //==============================================================
-
- class TC_COMMON_API MyCollisionDetection
- {
- private:
- public:
-
- static bool collisionLocationForMovingPointFixedAABox(
- const G3D::Vector3& origin,
- const G3D::Vector3& dir,
- const G3D::AABox& box,
- G3D::Vector3& location,
- bool& Inside)
- {
-
- // Integer representation of a floating-point value.
-#define IR(x) (reinterpret_cast<G3D::uint32 const&>(x))
-
- Inside = true;
- const G3D::Vector3& MinB = box.low();
- const G3D::Vector3& MaxB = box.high();
- G3D::Vector3 MaxT(-1.0f, -1.0f, -1.0f);
-
- // Find candidate planes.
- for (int i = 0; i < 3; ++i)
- {
- if (origin[i] < MinB[i])
- {
- location[i] = MinB[i];
- Inside = false;
-
- // Calculate T distances to candidate planes
- if (IR(dir[i]))
- {
- MaxT[i] = (MinB[i] - origin[i]) / dir[i];
- }
- }
- else if (origin[i] > MaxB[i])
- {
- location[i] = MaxB[i];
- Inside = false;
-
- // Calculate T distances to candidate planes
- if (IR(dir[i]))
- {
- MaxT[i] = (MaxB[i] - origin[i]) / dir[i];
- }
- }
- }
-
- if (Inside)
- {
- // definite hit
- location = origin;
- return true;
- }
-
- // Get largest of the maxT's for final choice of intersection
- int WhichPlane = 0;
- if (MaxT[1] > MaxT[WhichPlane])
- {
- WhichPlane = 1;
- }
-
- if (MaxT[2] > MaxT[WhichPlane])
- {
- WhichPlane = 2;
- }
-
- // Check final candidate actually inside box
- if (IR(MaxT[WhichPlane]) & 0x80000000)
- {
- // Miss the box
- return false;
- }
-
- for (int i = 0; i < 3; ++i)
- {
- if (i != WhichPlane)
- {
- location[i] = origin[i] + MaxT[WhichPlane] * dir[i];
- if ((location[i] < MinB[i]) ||
- (location[i] > MaxB[i]))
- {
- // On this plane we're outside the box extents, so
- // we miss the box
- return false;
- }
- }
- }
- /*
- // Choose the normal to be the plane normal facing into the ray
- normal = G3D::Vector3::zero();
- normal[WhichPlane] = (dir[WhichPlane] > 0) ? -1.0 : 1.0;
- */
- return true;
-
-#undef IR
- }
- };
-}
-#endif