aboutsummaryrefslogtreecommitdiff
path: root/src/common/Collision/Models
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/Collision/Models')
-rw-r--r--src/common/Collision/Models/ModelInstance.cpp20
-rw-r--r--src/common/Collision/Models/ModelInstance.h22
-rw-r--r--src/common/Collision/Models/WorldModel.cpp78
-rw-r--r--src/common/Collision/Models/WorldModel.h12
4 files changed, 67 insertions, 65 deletions
diff --git a/src/common/Collision/Models/ModelInstance.cpp b/src/common/Collision/Models/ModelInstance.cpp
index 3689824e50b..385702a25ad 100644
--- a/src/common/Collision/Models/ModelInstance.cpp
+++ b/src/common/Collision/Models/ModelInstance.cpp
@@ -24,13 +24,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;
+ 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)
{
@@ -63,7 +63,7 @@ namespace VMAP
return hit;
}
- void ModelInstance::intersectPoint(const G3D::Vector3& p, AreaInfo &info) const
+ void ModelInstance::intersectPoint(const G3D::Vector3& p, AreaInfo& info) const
{
if (!iModel)
{
@@ -97,7 +97,7 @@ namespace VMAP
}
}
- bool ModelInstance::GetLocationInfo(const G3D::Vector3& p, LocationInfo &info) const
+ bool ModelInstance::GetLocationInfo(const G3D::Vector3& p, LocationInfo& info) const
{
if (!iModel)
{
@@ -133,7 +133,7 @@ namespace VMAP
return false;
}
- bool ModelInstance::GetLiquidLevel(const G3D::Vector3& p, LocationInfo &info, float &liqHeight) const
+ bool ModelInstance::GetLiquidLevel(const G3D::Vector3& p, LocationInfo& info, float& liqHeight) const
{
// child bounds are defined in object space:
Vector3 pModel = iInvRot * (p - iPos) * iInvScale;
@@ -149,7 +149,7 @@ namespace VMAP
return false;
}
- bool ModelSpawn::readFromFile(FILE* rf, ModelSpawn &spawn)
+ bool ModelSpawn::readFromFile(FILE* rf, ModelSpawn& spawn)
{
uint32 check = 0, nameLen;
check += fread(&spawn.flags, sizeof(uint32), 1, rf);
@@ -195,9 +195,9 @@ namespace VMAP
return true;
}
- bool ModelSpawn::writeToFile(FILE* wf, const ModelSpawn &spawn)
+ bool ModelSpawn::writeToFile(FILE* wf, ModelSpawn const& spawn)
{
- uint32 check=0;
+ uint32 check = 0;
check += fwrite(&spawn.flags, sizeof(uint32), 1, wf);
check += fwrite(&spawn.adtId, sizeof(uint16), 1, wf);
check += fwrite(&spawn.ID, sizeof(uint32), 1, wf);
diff --git a/src/common/Collision/Models/ModelInstance.h b/src/common/Collision/Models/ModelInstance.h
index c5caf9599be..b342a14fdc6 100644
--- a/src/common/Collision/Models/ModelInstance.h
+++ b/src/common/Collision/Models/ModelInstance.h
@@ -51,25 +51,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; }
+ G3D::AABox const& getBounds() const { return iBound; }
- static bool readFromFile(FILE* rf, ModelSpawn &spawn);
- static bool writeToFile(FILE* rw, const ModelSpawn &spawn);
+ static bool readFromFile(FILE* rf, ModelSpawn& spawn);
+ static bool writeToFile(FILE* rw, ModelSpawn const& spawn);
};
- class TC_COMMON_API ModelInstance: public ModelSpawn
+ class TC_COMMON_API ModelInstance : public ModelSpawn
{
public:
- ModelInstance(): iInvScale(0.0f), iModel(nullptr) { }
- ModelInstance(const ModelSpawn &spawn, WorldModel* model);
+ ModelInstance() : iInvScale(0.0f), iModel(nullptr) { }
+ 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 a547a402b9d..9bbb6278950 100644
--- a/src/common/Collision/Models/WorldModel.cpp
+++ b/src/common/Collision/Models/WorldModel.cpp
@@ -31,7 +31,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;
@@ -84,8 +84,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;
@@ -101,7 +101,7 @@ 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)
{
if (width && height)
@@ -116,7 +116,7 @@ namespace VMAP
}
}
- WmoLiquid::WmoLiquid(const WmoLiquid &other): iHeight(nullptr), iFlags(nullptr)
+ WmoLiquid::WmoLiquid(WmoLiquid const& other) : iHeight(nullptr), iFlags(nullptr)
{
*this = other; // use assignment operator...
}
@@ -127,7 +127,7 @@ namespace VMAP
delete[] iFlags;
}
- WmoLiquid& WmoLiquid::operator=(const WmoLiquid &other)
+ WmoLiquid& WmoLiquid::operator=(WmoLiquid const& other)
{
if (this == &other)
return *this;
@@ -154,7 +154,7 @@ namespace VMAP
return *this;
}
- bool WmoLiquid::GetLiquidHeight(const Vector3 &pos, float &liqHeight) const
+ bool WmoLiquid::GetLiquidHeight(Vector3 const& pos, float& liqHeight) const
{
// simple case
if (!iFlags)
@@ -163,18 +163,18 @@ namespace VMAP
return true;
}
- float tx_f = (pos.x - iCorner.x)/LIQUID_TILE_SIZE;
+ float tx_f = (pos.x - iCorner.x) / LIQUID_TILE_SIZE;
uint32 tx = uint32(tx_f);
if (tx_f < 0.0f || tx >= iTilesX)
return false;
- float ty_f = (pos.y - iCorner.y)/LIQUID_TILE_SIZE;
+ float ty_f = (pos.y - iCorner.y) / LIQUID_TILE_SIZE;
uint32 ty = uint32(ty_f);
if (ty_f < 0.0f || ty >= iTilesY)
return false;
// check if tile shall be used for liquid level
// checking for 0x08 *might* be enough, but disabled tiles always are 0x?F:
- if ((iFlags[tx + ty*iTilesX] & 0x0F) == 0x0F)
+ if ((iFlags[tx + ty * iTilesX] & 0x0F) == 0x0F)
return false;
// (dx, dy) coordinates inside tile, in [0, 1]^2
@@ -194,7 +194,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];
@@ -242,7 +242,7 @@ namespace VMAP
return result;
}
- bool WmoLiquid::readFromFile(FILE* rf, WmoLiquid* &out)
+ bool WmoLiquid::readFromFile(FILE* rf, WmoLiquid*& out)
{
bool result = false;
WmoLiquid* liquid = new WmoLiquid();
@@ -278,7 +278,7 @@ namespace VMAP
return result;
}
- void WmoLiquid::getPosInfo(uint32 &tilesX, uint32 &tilesY, G3D::Vector3 &corner) const
+ void WmoLiquid::getPosInfo(uint32& tilesX, uint32& tilesY, G3D::Vector3& corner) const
{
tilesX = iTilesX;
tilesY = iTilesY;
@@ -287,7 +287,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)
{
@@ -295,7 +295,7 @@ namespace VMAP
iLiquid = new WmoLiquid(*other.iLiquid);
}
- void GroupModel::setMeshData(std::vector<Vector3> &vert, std::vector<MeshTriangle> &tri)
+ void GroupModel::setMeshData(std::vector<Vector3>& vert, std::vector<MeshTriangle>& tri)
{
vertices.swap(vert);
triangles.swap(tri);
@@ -315,7 +315,7 @@ namespace VMAP
// write vertices
if (result && fwrite("VERT", 1, 4, wf) != 4) result = false;
count = vertices.size();
- chunkSize = sizeof(uint32)+ sizeof(Vector3)*count;
+ chunkSize = sizeof(uint32) + sizeof(Vector3) * count;
if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false;
if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) result = false;
if (!count) // models without (collision) geometry end here, unsure if they are useful
@@ -325,7 +325,7 @@ namespace VMAP
// write triangle mesh
if (result && fwrite("TRIM", 1, 4, wf) != 4) result = false;
count = triangles.size();
- chunkSize = sizeof(uint32)+ sizeof(MeshTriangle)*count;
+ chunkSize = sizeof(uint32) + sizeof(MeshTriangle) * count;
if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false;
if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) result = false;
if (result && fwrite(&triangles[0], sizeof(MeshTriangle), count, wf) != count) result = false;
@@ -394,12 +394,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;
@@ -407,7 +408,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;
@@ -417,7 +418,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;
@@ -431,7 +432,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);
@@ -454,7 +455,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);
@@ -462,18 +463,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)
@@ -495,14 +497,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();
@@ -519,7 +521,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);
@@ -530,7 +532,7 @@ namespace VMAP
}
};
- bool WorldModel::IntersectPoint(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, AreaInfo &info) const
+ bool WorldModel::IntersectPoint(const G3D::Vector3& p, const G3D::Vector3& down, float& dist, AreaInfo& info) const
{
if (groupModels.empty())
return false;
@@ -549,7 +551,7 @@ namespace VMAP
return false;
}
- bool WorldModel::GetLocationInfo(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, LocationInfo &info) const
+ bool WorldModel::GetLocationInfo(const G3D::Vector3& p, const G3D::Vector3& down, float& dist, LocationInfo& info) const
{
if (groupModels.empty())
return false;
@@ -566,7 +568,7 @@ namespace VMAP
return false;
}
- bool WorldModel::writeFile(const std::string &filename)
+ bool WorldModel::writeFile(const std::string& filename)
{
FILE* wf = fopen(filename.c_str(), "wb");
if (!wf)
@@ -580,14 +582,14 @@ 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;
//chunkSize = sizeof(uint32)+ sizeof(GroupModel)*count;
//if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false;
if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) result = false;
- for (uint32 i=0; i<groupModels.size() && result; ++i)
+ for (uint32 i = 0; i < groupModels.size() && result; ++i)
result = groupModels[i].writeToFile(wf);
// write group BIH
@@ -599,7 +601,7 @@ namespace VMAP
return result;
}
- bool WorldModel::readFile(const std::string &filename)
+ bool WorldModel::readFile(const std::string& filename)
{
FILE* rf = fopen(filename.c_str(), "rb");
if (!rf)
@@ -623,7 +625,7 @@ namespace VMAP
if (result && fread(&count, sizeof(uint32), 1, rf) != 1) result = false;
if (result) groupModels.resize(count);
//if (result && fread(&groupModels[0], sizeof(GroupModel), count, rf) != count) result = false;
- for (uint32 i=0; i<count && result; ++i)
+ for (uint32 i = 0; i < count && result; ++i)
result = groupModels[i].readFromFile(rf);
// read group BIH
diff --git a/src/common/Collision/Models/WorldModel.h b/src/common/Collision/Models/WorldModel.h
index 4392f9b194f..093a4ea84ed 100644
--- a/src/common/Collision/Models/WorldModel.h
+++ b/src/common/Collision/Models/WorldModel.h
@@ -47,11 +47,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; }
@@ -74,8 +74,8 @@ namespace VMAP
{
public:
GroupModel() : iBound(), iMogpFlags(0), iGroupWMOID(0), iLiquid(nullptr) { }
- GroupModel(const GroupModel &other);
- GroupModel(uint32 mogpFlags, uint32 groupWMOID, const G3D::AABox &bound):
+ GroupModel(GroupModel const& other);
+ GroupModel(uint32 mogpFlags, uint32 groupWMOID, G3D::AABox const& bound):
iBound(bound), iMogpFlags(mogpFlags), iGroupWMOID(groupWMOID), iLiquid(nullptr) { }
~GroupModel() { delete iLiquid; }