/s/KRTriangle3/Triangle3/g
This commit is contained in:
@@ -1104,7 +1104,7 @@ KRMesh::model_format_t KRMesh::getModelFormat() const
|
||||
return f;
|
||||
}
|
||||
|
||||
bool KRMesh::rayCast(const Vector3 &start, const Vector3 &dir, const KRTriangle3 &tri, const Vector3 &tri_n0, const Vector3 &tri_n1, const Vector3 &tri_n2, KRHitInfo &hitinfo)
|
||||
bool KRMesh::rayCast(const Vector3 &start, const Vector3 &dir, const Triangle3 &tri, const Vector3 &tri_n0, const Vector3 &tri_n1, const Vector3 &tri_n2, KRHitInfo &hitinfo)
|
||||
{
|
||||
Vector3 hit_point;
|
||||
if(tri.rayCast(start, dir, hit_point)) {
|
||||
@@ -1154,7 +1154,7 @@ bool KRMesh::rayCast(const Vector3 &start, const Vector3 &dir, KRHitInfo &hitinf
|
||||
tri_vert_index[1] = getTriangleVertexIndex(submesh_index, triangle_index*3 + 1);
|
||||
tri_vert_index[2] = getTriangleVertexIndex(submesh_index, triangle_index*3 + 2);
|
||||
|
||||
KRTriangle3 tri = KRTriangle3(getVertexPosition(tri_vert_index[0]), getVertexPosition(tri_vert_index[1]), getVertexPosition(tri_vert_index[2]));
|
||||
Triangle3 tri = Triangle3(getVertexPosition(tri_vert_index[0]), getVertexPosition(tri_vert_index[1]), getVertexPosition(tri_vert_index[2]));
|
||||
|
||||
if(rayCast(start, dir, tri, getVertexNormal(tri_vert_index[0]), getVertexNormal(tri_vert_index[1]), getVertexNormal(tri_vert_index[2]), hitinfo)) hit_found = true;
|
||||
}
|
||||
@@ -1200,12 +1200,12 @@ bool KRMesh::sphereCast(const Matrix4 &model_to_world, const Vector3 &v0, const
|
||||
tri_vert_index[1] = getTriangleVertexIndex(submesh_index, triangle_index*3 + 1);
|
||||
tri_vert_index[2] = getTriangleVertexIndex(submesh_index, triangle_index*3 + 2);
|
||||
|
||||
KRTriangle3 tri = KRTriangle3(getVertexPosition(tri_vert_index[0]), getVertexPosition(tri_vert_index[1]), getVertexPosition(tri_vert_index[2]));
|
||||
Triangle3 tri = Triangle3(getVertexPosition(tri_vert_index[0]), getVertexPosition(tri_vert_index[1]), getVertexPosition(tri_vert_index[2]));
|
||||
|
||||
if(sphereCast(model_to_world, v0, v1, radius, tri, hitinfo)) hit_found = true;
|
||||
|
||||
/*
|
||||
KRTriangle3 tri2 = KRTriangle3(getVertexPosition(tri_vert_index[1]), getVertexPosition(tri_vert_index[0]), getVertexPosition(tri_vert_index[2]));
|
||||
Triangle3 tri2 = Triangle3(getVertexPosition(tri_vert_index[1]), getVertexPosition(tri_vert_index[0]), getVertexPosition(tri_vert_index[2]));
|
||||
|
||||
if(sphereCast(model_to_world, v0, v1, radius, tri2, new_hitinfo)) hit_found = true;
|
||||
*/
|
||||
@@ -1236,7 +1236,7 @@ bool KRMesh::sphereCast(const Matrix4 &model_to_world, const Vector3 &v0, const
|
||||
return hit_found;
|
||||
}
|
||||
|
||||
bool KRMesh::sphereCast(const Matrix4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, const KRTriangle3 &tri, KRHitInfo &hitinfo)
|
||||
bool KRMesh::sphereCast(const Matrix4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, const Triangle3 &tri, KRHitInfo &hitinfo)
|
||||
{
|
||||
|
||||
Vector3 dir = Vector3::Normalize(v1 - v0);
|
||||
@@ -1245,7 +1245,7 @@ bool KRMesh::sphereCast(const Matrix4 &model_to_world, const Vector3 &v0, const
|
||||
Vector3 new_hit_point;
|
||||
float new_hit_distance;
|
||||
|
||||
KRTriangle3 world_tri = KRTriangle3(Matrix4::Dot(model_to_world, tri[0]), Matrix4::Dot(model_to_world, tri[1]), Matrix4::Dot(model_to_world, tri[2]));
|
||||
Triangle3 world_tri = Triangle3(Matrix4::Dot(model_to_world, tri[0]), Matrix4::Dot(model_to_world, tri[1]), Matrix4::Dot(model_to_world, tri[2]));
|
||||
|
||||
if(world_tri.sphereCast(start, dir, radius, new_hit_point, new_hit_distance)) {
|
||||
if((!hitinfo.didHit() || hitinfo.getDistance() > new_hit_distance) && new_hit_distance <= (v1 - v0).magnitude()) {
|
||||
|
||||
@@ -230,8 +230,8 @@ private:
|
||||
void getSubmeshes();
|
||||
void getMaterials();
|
||||
|
||||
static bool rayCast(const Vector3 &start, const Vector3 &dir, const KRTriangle3 &tri, const Vector3 &tri_n0, const Vector3 &tri_n1, const Vector3 &tri_n2, KRHitInfo &hitinfo);
|
||||
static bool sphereCast(const Matrix4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, const KRTriangle3 &tri, KRHitInfo &hitinfo);
|
||||
static bool rayCast(const Vector3 &start, const Vector3 &dir, const Triangle3 &tri, const Vector3 &tri_n0, const Vector3 &tri_n1, const Vector3 &tri_n2, KRHitInfo &hitinfo);
|
||||
static bool sphereCast(const Matrix4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, const Triangle3 &tri, KRHitInfo &hitinfo);
|
||||
|
||||
int m_lodCoverage; // This LOD level is activated when the bounding box of the model will cover less than this percent of the screen (100 = highest detail model)
|
||||
vector<KRMaterial *> m_materials;
|
||||
|
||||
@@ -8,6 +8,6 @@
|
||||
#include "matrix4.h"
|
||||
#include "quaternion.h"
|
||||
#include "KRAABB.h"
|
||||
#include "KRTriangle3.h"
|
||||
#include "triangle3.h"
|
||||
|
||||
#endif // KRAKEN_H
|
||||
|
||||
@@ -32,24 +32,24 @@
|
||||
#ifndef KRAKEN_TRIANGLE3_H
|
||||
#define KRAKEN_TRIANGLE3_H
|
||||
|
||||
#include "Vector3.h"
|
||||
#include "vector3.h"
|
||||
|
||||
namespace kraken {
|
||||
|
||||
class KRTriangle3
|
||||
class Triangle3
|
||||
{
|
||||
public:
|
||||
Vector3 vert[3];
|
||||
|
||||
KRTriangle3(const KRTriangle3 &tri);
|
||||
KRTriangle3(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3);
|
||||
~KRTriangle3();
|
||||
Triangle3(const Triangle3 &tri);
|
||||
Triangle3(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3);
|
||||
~Triangle3();
|
||||
|
||||
Vector3 calculateNormal() const;
|
||||
|
||||
bool operator ==(const KRTriangle3& b) const;
|
||||
bool operator !=(const KRTriangle3& b) const;
|
||||
KRTriangle3& operator =(const KRTriangle3& b);
|
||||
bool operator ==(const Triangle3& b) const;
|
||||
bool operator !=(const Triangle3& b) const;
|
||||
Triangle3& operator =(const Triangle3& b);
|
||||
Vector3& operator[](unsigned int i);
|
||||
Vector3 operator[](unsigned int i) const;
|
||||
|
||||
@@ -62,4 +62,18 @@ public:
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<kraken::Triangle3> {
|
||||
public:
|
||||
size_t operator()(const kraken::Triangle3 &s) const
|
||||
{
|
||||
size_t h1 = hash<kraken::Vector3>()(s.vert[0]);
|
||||
size_t h2 = hash<kraken::Vector3>()(s.vert[1]);
|
||||
size_t h3 = hash<kraken::Vector3>()(s.vert[2]);
|
||||
return h1 ^ (h2 << 1) ^ (h3 << 2);
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
#endif // KRAKEN_TRIANGLE3_H
|
||||
@@ -34,8 +34,8 @@
|
||||
|
||||
#include <functional> // for hash<>
|
||||
|
||||
#include "Vector2.h"
|
||||
#include "Vector4.h"
|
||||
#include "vector2.h"
|
||||
#include "vector4.h"
|
||||
|
||||
namespace kraken {
|
||||
|
||||
|
||||
26
kraken/KRTriangle3.cpp → kraken/triangle3.cpp
Executable file → Normal file
26
kraken/KRTriangle3.cpp → kraken/triangle3.cpp
Executable file → Normal file
@@ -75,14 +75,14 @@ namespace {
|
||||
|
||||
namespace kraken {
|
||||
|
||||
KRTriangle3::KRTriangle3(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3)
|
||||
Triangle3::Triangle3(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3)
|
||||
{
|
||||
vert[0] = v1;
|
||||
vert[1] = v2;
|
||||
vert[2] = v3;
|
||||
}
|
||||
|
||||
KRTriangle3::KRTriangle3(const KRTriangle3 &tri)
|
||||
Triangle3::Triangle3(const Triangle3 &tri)
|
||||
{
|
||||
vert[0] = tri[0];
|
||||
vert[1] = tri[1];
|
||||
@@ -90,22 +90,22 @@ KRTriangle3::KRTriangle3(const KRTriangle3 &tri)
|
||||
}
|
||||
|
||||
|
||||
KRTriangle3::~KRTriangle3()
|
||||
Triangle3::~Triangle3()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool KRTriangle3::operator ==(const KRTriangle3& b) const
|
||||
bool Triangle3::operator ==(const Triangle3& b) const
|
||||
{
|
||||
return vert[0] == b[0] && vert[1] == b[1] && vert[2] == b[2];
|
||||
}
|
||||
|
||||
bool KRTriangle3::operator !=(const KRTriangle3& b) const
|
||||
bool Triangle3::operator !=(const Triangle3& b) const
|
||||
{
|
||||
return vert[0] != b[0] || vert[1] != b[1] || vert[2] != b[2];
|
||||
}
|
||||
|
||||
KRTriangle3& KRTriangle3::operator =(const KRTriangle3& b)
|
||||
Triangle3& Triangle3::operator =(const Triangle3& b)
|
||||
{
|
||||
|
||||
vert[0] = b[0];
|
||||
@@ -114,18 +114,18 @@ KRTriangle3& KRTriangle3::operator =(const KRTriangle3& b)
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector3& KRTriangle3::operator[](unsigned int i)
|
||||
Vector3& Triangle3::operator[](unsigned int i)
|
||||
{
|
||||
return vert[i];
|
||||
}
|
||||
|
||||
Vector3 KRTriangle3::operator[](unsigned int i) const
|
||||
Vector3 Triangle3::operator[](unsigned int i) const
|
||||
{
|
||||
return vert[i];
|
||||
}
|
||||
|
||||
|
||||
bool KRTriangle3::rayCast(const Vector3 &start, const Vector3 &dir, Vector3 &hit_point) const
|
||||
bool Triangle3::rayCast(const Vector3 &start, const Vector3 &dir, Vector3 &hit_point) const
|
||||
{
|
||||
// algorithm based on Dan Sunday's implementation at http://geomalgorithms.com/a06-_intersect-2.html
|
||||
const float SMALL_NUM = 0.00000001; // anything that avoids division overflow
|
||||
@@ -184,7 +184,7 @@ bool KRTriangle3::rayCast(const Vector3 &start, const Vector3 &dir, Vector3 &hit
|
||||
return true;
|
||||
}
|
||||
|
||||
Vector3 KRTriangle3::calculateNormal() const
|
||||
Vector3 Triangle3::calculateNormal() const
|
||||
{
|
||||
Vector3 v1 = vert[1] - vert[0];
|
||||
Vector3 v2 = vert[2] - vert[0];
|
||||
@@ -192,7 +192,7 @@ Vector3 KRTriangle3::calculateNormal() const
|
||||
return Vector3::Normalize(Vector3::Cross(v1, v2));
|
||||
}
|
||||
|
||||
Vector3 KRTriangle3::closestPointOnTriangle(const Vector3 &p) const
|
||||
Vector3 Triangle3::closestPointOnTriangle(const Vector3 &p) const
|
||||
{
|
||||
Vector3 a = vert[0];
|
||||
Vector3 b = vert[1];
|
||||
@@ -216,7 +216,7 @@ Vector3 KRTriangle3::closestPointOnTriangle(const Vector3 &p) const
|
||||
}
|
||||
}
|
||||
|
||||
bool KRTriangle3::sphereCast(const Vector3 &start, const Vector3 &dir, float radius, Vector3 &hit_point, float &hit_distance) const
|
||||
bool Triangle3::sphereCast(const Vector3 &start, const Vector3 &dir, float radius, Vector3 &hit_point, float &hit_distance) const
|
||||
{
|
||||
// Dir must be normalized
|
||||
const float SMALL_NUM = 0.001f; // anything that avoids division overflow
|
||||
@@ -276,7 +276,7 @@ bool KRTriangle3::sphereCast(const Vector3 &start, const Vector3 &dir, float rad
|
||||
}
|
||||
|
||||
|
||||
bool KRTriangle3::containsPoint(const Vector3 &p) const
|
||||
bool Triangle3::containsPoint(const Vector3 &p) const
|
||||
{
|
||||
/*
|
||||
// From: http://stackoverflow.com/questions/995445/determine-if-a-3d-point-is-within-a-triangle
|
||||
@@ -192,7 +192,7 @@
|
||||
<ClCompile Include="..\kraken\KRTextureManager.cpp" />
|
||||
<ClCompile Include="..\kraken\KRTexturePVR.cpp" />
|
||||
<ClCompile Include="..\kraken\KRTextureTGA.cpp" />
|
||||
<ClCompile Include="..\kraken\KRTriangle3.cpp" />
|
||||
<ClCompile Include="..\kraken\triangle3.cpp" />
|
||||
<ClCompile Include="..\kraken\KRUnknown.cpp" />
|
||||
<ClCompile Include="..\kraken\KRUnknownManager.cpp" />
|
||||
<ClCompile Include="..\kraken\vector2.cpp" />
|
||||
@@ -276,7 +276,7 @@
|
||||
<ClInclude Include="..\kraken\public\scalar.h" />
|
||||
<ClInclude Include="..\kraken\public\matrix4.h" />
|
||||
<ClInclude Include="..\kraken\public\quaternion.h" />
|
||||
<ClInclude Include="..\kraken\public\KRTriangle3.h" />
|
||||
<ClInclude Include="..\kraken\public\triangle3.h" />
|
||||
<ClInclude Include="..\kraken\public\vector2.h" />
|
||||
<ClInclude Include="..\kraken\public\vector3.h" />
|
||||
<ClInclude Include="..\kraken\public\vector4.h" />
|
||||
|
||||
@@ -33,9 +33,6 @@
|
||||
<ClCompile Include="..\kraken\KRFloat.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\kraken\KRTriangle3.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\kraken\KRAABB.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@@ -252,6 +249,9 @@
|
||||
<ClCompile Include="..\kraken\quaternion.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\kraken\triangle3.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\3rdparty\tinyxml2\tinyxml2.h">
|
||||
@@ -479,9 +479,6 @@
|
||||
<ClInclude Include="..\kraken\public\KRAABB.h">
|
||||
<Filter>Header Files\public</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\kraken\public\KRTriangle3.h">
|
||||
<Filter>Header Files\public</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\kraken\public\vector2.h">
|
||||
<Filter>Header Files\public</Filter>
|
||||
</ClInclude>
|
||||
@@ -500,5 +497,8 @@
|
||||
<ClInclude Include="..\kraken\public\quaternion.h">
|
||||
<Filter>Header Files\public</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\kraken\public\triangle3.h">
|
||||
<Filter>Header Files\public</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user