Merge internal branch.
This commit is contained in:
parent
18c452a2a6
commit
98b2377a11
@ -17,6 +17,7 @@ SET(CORE_SRCS
|
|||||||
TextReader.h
|
TextReader.h
|
||||||
TextReader.cpp
|
TextReader.cpp
|
||||||
TextWriter.h
|
TextWriter.h
|
||||||
|
TextWriter.cpp
|
||||||
Tokenizer.h
|
Tokenizer.h
|
||||||
Tokenizer.cpp
|
Tokenizer.cpp
|
||||||
Radix.h
|
Radix.h
|
||||||
|
@ -23,12 +23,6 @@ Do not use memmove in insert & remove, use copy ctors instead.
|
|||||||
#include <string.h> // memmove
|
#include <string.h> // memmove
|
||||||
#include <new> // for placement new
|
#include <new> // for placement new
|
||||||
|
|
||||||
#ifndef USE_TU_CONTAINERS
|
|
||||||
#define USE_TU_CONTAINERS 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if USE_TU_CONTAINERS
|
|
||||||
|
|
||||||
#if NV_CC_GNUC // If typeof is available:
|
#if NV_CC_GNUC // If typeof is available:
|
||||||
|
|
||||||
@ -57,7 +51,7 @@ struct PseudoIndexWrapper {
|
|||||||
return *reinterpret_cast<const typename T::PseudoIndex *>(memory);
|
return *reinterpret_cast<const typename T::PseudoIndex *>(memory);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 memory[8]; // Increase the size if we have bigger enumerators.
|
uint8 memory[4]; // Increase the size if we have bigger enumerators.
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NV_FOREACH(i, container) \
|
#define NV_FOREACH(i, container) \
|
||||||
@ -70,7 +64,6 @@ struct PseudoIndexWrapper {
|
|||||||
# define foreach NV_FOREACH
|
# define foreach NV_FOREACH
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // USE_TU_CONTAINERS
|
|
||||||
|
|
||||||
|
|
||||||
namespace nv
|
namespace nv
|
||||||
@ -193,7 +186,6 @@ namespace nv
|
|||||||
virtual T current();
|
virtual T current();
|
||||||
};
|
};
|
||||||
|
|
||||||
#if USE_TU_CONTAINERS
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replacement for std::vector that is easier to debug and provides
|
* Replacement for std::vector that is easier to debug and provides
|
||||||
@ -1060,7 +1052,7 @@ namespace nv
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // USE_TU_CONTAINERS
|
|
||||||
|
|
||||||
} // nv namespace
|
} // nv namespace
|
||||||
|
|
||||||
|
@ -315,6 +315,11 @@ public:
|
|||||||
return m_s->isError();
|
return m_s->isError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void clearError()
|
||||||
|
{
|
||||||
|
m_s->clearError();
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool isAtEnd() const
|
virtual bool isAtEnd() const
|
||||||
{
|
{
|
||||||
return m_s->isAtEnd();
|
return m_s->isAtEnd();
|
||||||
|
45
src/nvcore/TextWriter.cpp
Normal file
45
src/nvcore/TextWriter.cpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
// This code is in the public domain -- castanyo@yahoo.es
|
||||||
|
|
||||||
|
#include <nvcore/TextWriter.h>
|
||||||
|
|
||||||
|
using namespace nv;
|
||||||
|
|
||||||
|
|
||||||
|
/// Constructor
|
||||||
|
TextWriter::TextWriter(Stream * s) :
|
||||||
|
s(s),
|
||||||
|
str(1024)
|
||||||
|
{
|
||||||
|
nvCheck(s != NULL);
|
||||||
|
nvCheck(s->isSaving());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextWriter::writeString(const char * str)
|
||||||
|
{
|
||||||
|
nvDebugCheck(s != NULL);
|
||||||
|
s->serialize(const_cast<char *>(str), strlen(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextWriter::writeString(const char * str, uint len)
|
||||||
|
{
|
||||||
|
nvDebugCheck(s != NULL);
|
||||||
|
s->serialize(const_cast<char *>(str), len);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextWriter::write(const char * format, ...)
|
||||||
|
{
|
||||||
|
va_list arg;
|
||||||
|
va_start(arg,format);
|
||||||
|
str.format(format, arg);
|
||||||
|
writeString(str.str(), str.length());
|
||||||
|
va_end(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextWriter::write(const char * format, va_list arg)
|
||||||
|
{
|
||||||
|
va_list tmp;
|
||||||
|
va_copy(tmp, arg);
|
||||||
|
str.format(format, arg);
|
||||||
|
writeString(str.str(), str.length());
|
||||||
|
va_end(tmp);
|
||||||
|
}
|
@ -7,9 +7,6 @@
|
|||||||
#include <nvcore/Stream.h>
|
#include <nvcore/Stream.h>
|
||||||
#include <nvcore/StrLib.h>
|
#include <nvcore/StrLib.h>
|
||||||
|
|
||||||
// @@ NOT IMPLEMENTED !!!
|
|
||||||
|
|
||||||
|
|
||||||
namespace nv
|
namespace nv
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -18,16 +15,12 @@ namespace nv
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Ctor.
|
TextWriter(Stream * s);
|
||||||
TextWriter(Stream * s) : s(s), str(1024) {
|
|
||||||
nvDebugCheck(s != NULL);
|
|
||||||
nvCheck(s->IsSaving());
|
|
||||||
}
|
|
||||||
|
|
||||||
void write( const char * str, uint len );
|
|
||||||
void write( const char * format, ... ) __attribute__((format (printf, 2, 3)));
|
|
||||||
void write( const char * format, va_list arg );
|
|
||||||
|
|
||||||
|
void writeString(const char * str);
|
||||||
|
void writeString(const char * str, uint len);
|
||||||
|
void write(const char * format, ...) __attribute__((format (printf, 2, 3)));
|
||||||
|
void write(const char * format, va_list arg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -38,7 +31,35 @@ namespace nv
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline TextWriter & operator<<( TextWriter & tw, int i)
|
||||||
|
{
|
||||||
|
tw.write("%d", i);
|
||||||
|
return tw;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline TextWriter & operator<<( TextWriter & tw, uint i)
|
||||||
|
{
|
||||||
|
tw.write("%u", i);
|
||||||
|
return tw;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline TextWriter & operator<<( TextWriter & tw, float f)
|
||||||
|
{
|
||||||
|
tw.write("%f", f);
|
||||||
|
return tw;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline TextWriter & operator<<( TextWriter & tw, const char * str)
|
||||||
|
{
|
||||||
|
tw.writeString(str);
|
||||||
|
return tw;
|
||||||
|
}
|
||||||
|
|
||||||
} // nv namespace
|
} // nv namespace
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // NVCORE_TEXTWRITER_H
|
#endif // NVCORE_TEXTWRITER_H
|
||||||
|
@ -363,7 +363,25 @@ inline Matrix inverse(Matrix::Arg m)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Matrix isometryInverse(Matrix::Arg m);
|
inline Matrix isometryInverse(Matrix::Arg m)
|
||||||
|
{
|
||||||
|
Matrix r(identity);
|
||||||
|
|
||||||
|
// transposed 3x3 upper left matrix
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
|
r(i, j) = m(j, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// translate by the negative offsets
|
||||||
|
r.translate(-Vector3(m.data(12), m.data(13), m.data(14)));
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
//Matrix affineInverse(Matrix::Arg m);
|
//Matrix affineInverse(Matrix::Arg m);
|
||||||
|
|
||||||
/// Transform the given 3d point with the given matrix.
|
/// Transform the given 3d point with the given matrix.
|
||||||
@ -394,6 +412,13 @@ inline Vector4 transform(Matrix::Arg m, Vector4::Arg p)
|
|||||||
p.x() * m(3,0) + p.y() * m(3,1) + p.z() * m(3,2) + p.w() * m(3,3));
|
p.x() * m(3,0) + p.y() * m(3,1) + p.z() * m(3,2) + p.w() * m(3,3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Matrix mul(Matrix::Arg a, Matrix::Arg b)
|
||||||
|
{
|
||||||
|
// @@ Is this the right order? mul(a, b) = b * a
|
||||||
|
Matrix m = a;
|
||||||
|
m.apply(b);
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
} // nv namespace
|
} // nv namespace
|
||||||
|
|
||||||
|
@ -76,18 +76,18 @@ namespace nv
|
|||||||
{
|
{
|
||||||
return scale(q.asVector(), s);
|
return scale(q.asVector(), s);
|
||||||
}
|
}
|
||||||
inline Quaternion operator *(Quaternion::Arg q, Vector4::Arg s)
|
/*inline Quaternion operator *(Quaternion::Arg q, Vector4::Arg s)
|
||||||
{
|
{
|
||||||
return scale(q, s);
|
return scale(q, s);
|
||||||
}
|
}
|
||||||
inline Quaternion operator *(Vector4::Arg s, Quaternion::Arg q)
|
inline Quaternion operator *(Vector4::Arg s, Quaternion::Arg q)
|
||||||
{
|
{
|
||||||
return scale(q, s);
|
return scale(q, s);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
inline Quaternion conjugate(Quaternion::Arg q)
|
inline Quaternion conjugate(Quaternion::Arg q)
|
||||||
{
|
{
|
||||||
return q * Vector4(-1, -1, -1, 1);
|
return scale(q, Vector4(-1, -1, -1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float length(Quaternion::Arg q)
|
inline float length(Quaternion::Arg q)
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
/********************************************************/
|
/********************************************************/
|
||||||
|
|
||||||
#include <nvmath/Vector.h>
|
#include <nvmath/Vector.h>
|
||||||
//#include <nvmath/Triangle.h>
|
#include <nvmath/Triangle.h>
|
||||||
|
|
||||||
using namespace nv;
|
using namespace nv;
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ static bool planeBoxOverlap(Vector3::Arg normal, Vector3::Arg vert, Vector3::Arg
|
|||||||
if(min>rad || max<-rad) return false;
|
if(min>rad || max<-rad) return false;
|
||||||
|
|
||||||
|
|
||||||
bool triBoxOverlap(Vector3::Arg boxcenter, Vector3::Arg boxhalfsize, const Vector3 * triverts)
|
bool triBoxOverlap(Vector3::Arg boxcenter, Vector3::Arg boxhalfsize, const Triangle & tri)
|
||||||
{
|
{
|
||||||
// use separating axis theorem to test overlap between triangle and box
|
// use separating axis theorem to test overlap between triangle and box
|
||||||
// need to test for overlap in these directions:
|
// need to test for overlap in these directions:
|
||||||
@ -111,9 +111,9 @@ bool triBoxOverlap(Vector3::Arg boxcenter, Vector3::Arg boxhalfsize, const Vecto
|
|||||||
|
|
||||||
// This is the fastest branch on Sun.
|
// This is the fastest branch on Sun.
|
||||||
// move everything so that the boxcenter is in (0,0,0)
|
// move everything so that the boxcenter is in (0,0,0)
|
||||||
v0 = triverts[0] - boxcenter;
|
v0 = tri.v[0] - boxcenter;
|
||||||
v1 = triverts[1] - boxcenter;
|
v1 = tri.v[1] - boxcenter;
|
||||||
v2 = triverts[2] - boxcenter;
|
v2 = tri.v[2] - boxcenter;
|
||||||
|
|
||||||
// Compute triangle edges.
|
// Compute triangle edges.
|
||||||
e0 = v1 - v0; // tri edge 0
|
e0 = v1 - v0; // tri edge 0
|
||||||
@ -170,7 +170,7 @@ bool triBoxOverlap(Vector3::Arg boxcenter, Vector3::Arg boxhalfsize, const Vecto
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool triBoxOverlapNoBounds(Vector3::Arg boxcenter, Vector3::Arg boxhalfsize, const Vector3 * triverts)
|
bool triBoxOverlapNoBounds(Vector3::Arg boxcenter, Vector3::Arg boxhalfsize, const Triangle & tri)
|
||||||
{
|
{
|
||||||
// use separating axis theorem to test overlap between triangle and box
|
// use separating axis theorem to test overlap between triangle and box
|
||||||
// need to test for overlap in these directions:
|
// need to test for overlap in these directions:
|
||||||
@ -185,9 +185,9 @@ bool triBoxOverlapNoBounds(Vector3::Arg boxcenter, Vector3::Arg boxhalfsize, con
|
|||||||
|
|
||||||
// This is the fastest branch on Sun.
|
// This is the fastest branch on Sun.
|
||||||
// move everything so that the boxcenter is in (0,0,0)
|
// move everything so that the boxcenter is in (0,0,0)
|
||||||
v0 = triverts[0] - boxcenter;
|
v0 = tri.v[0] - boxcenter;
|
||||||
v1 = triverts[1] - boxcenter;
|
v1 = tri.v[1] - boxcenter;
|
||||||
v2 = triverts[2] - boxcenter;
|
v2 = tri.v[2] - boxcenter;
|
||||||
|
|
||||||
// Compute triangle edges.
|
// Compute triangle edges.
|
||||||
e0 = v1 - v0; // tri edge 0
|
e0 = v1 - v0; // tri edge 0
|
||||||
|
@ -6,26 +6,23 @@ using namespace nv;
|
|||||||
|
|
||||||
|
|
||||||
/// Tomas Möller, barycentric ray-triangle test.
|
/// Tomas Möller, barycentric ray-triangle test.
|
||||||
bool Triangle::TestRay_Moller(Vector3::Arg orig, Vector3::Arg dir, float * out_t, float * out_u, float * out_v)
|
bool rayTest_Moller(const Triangle & t, Vector3::Arg orig, Vector3::Arg dir, float * out_t, float * out_u, float * out_v)
|
||||||
{
|
{
|
||||||
Vector3 e1, e2, tvec, pvec, qvec;
|
|
||||||
float det, inv_det;
|
|
||||||
|
|
||||||
// find vectors for two edges sharing vert0
|
// find vectors for two edges sharing vert0
|
||||||
e1 = v[1] - v[0];
|
Vector3 e1 = t.v[1] - t.v[0];
|
||||||
e2 = v[2] - v[0];
|
Vector3 e2 = t.v[2] - t.v[0];
|
||||||
|
|
||||||
// begin calculating determinant - also used to calculate U parameter
|
// begin calculating determinant - also used to calculate U parameter
|
||||||
pvec = cross(dir, e2);
|
Vector3 pvec = cross(dir, e2);
|
||||||
|
|
||||||
// if determinant is near zero, ray lies in plane of triangle
|
// if determinant is near zero, ray lies in plane of triangle
|
||||||
det = dot(e1, pvec);
|
float det = dot(e1, pvec);
|
||||||
if (det < -NV_EPSILON) {
|
if (det < -NV_EPSILON) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate distance from vert0 to ray origin
|
// calculate distance from vert0 to ray origin
|
||||||
tvec = orig - v[0];
|
Vector3 tvec = orig - t.v[0];
|
||||||
|
|
||||||
// calculate U parameter and test bounds
|
// calculate U parameter and test bounds
|
||||||
float u = dot(tvec, pvec);
|
float u = dot(tvec, pvec);
|
||||||
@ -34,7 +31,7 @@ bool Triangle::TestRay_Moller(Vector3::Arg orig, Vector3::Arg dir, float * out_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
// prepare to test V parameter
|
// prepare to test V parameter
|
||||||
qvec = cross(tvec, e1);
|
Vector3 qvec = cross(tvec, e1);
|
||||||
|
|
||||||
// calculate V parameter and test bounds
|
// calculate V parameter and test bounds
|
||||||
float v = dot(dir, qvec);
|
float v = dot(dir, qvec);
|
||||||
@ -43,7 +40,7 @@ bool Triangle::TestRay_Moller(Vector3::Arg orig, Vector3::Arg dir, float * out_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
// calculate t, scale parameters, ray intersects triangle
|
// calculate t, scale parameters, ray intersects triangle
|
||||||
inv_det = 1.0f / det;
|
float inv_det = 1.0f / det;
|
||||||
*out_t = dot(e2, qvec) * inv_det;
|
*out_t = dot(e2, qvec) * inv_det;
|
||||||
*out_u = u * inv_det; // v
|
*out_u = u * inv_det; // v
|
||||||
*out_v = v * inv_det; // 1-(u+v)
|
*out_v = v * inv_det; // 1-(u+v)
|
||||||
|
@ -3,146 +3,78 @@
|
|||||||
#ifndef NV_MATH_TRIANGLE_H
|
#ifndef NV_MATH_TRIANGLE_H
|
||||||
#define NV_MATH_TRIANGLE_H
|
#define NV_MATH_TRIANGLE_H
|
||||||
|
|
||||||
|
|
||||||
#include <nvmath/nvmath.h>
|
#include <nvmath/nvmath.h>
|
||||||
#include <nvmath/Vector.h>
|
#include <nvmath/Vector.h>
|
||||||
#include <nvmath/Box.h>
|
#include <nvmath/Box.h>
|
||||||
//#include <nvmath/Plane.h>
|
|
||||||
|
|
||||||
namespace nv
|
namespace nv
|
||||||
{
|
{
|
||||||
|
|
||||||
// Tomas Akenine-Möller box-triangle test.
|
/// Triangle class with three vertices.
|
||||||
NVMATH_API bool triBoxOverlap(Vector3::Arg boxcenter, Vector3::Arg boxhalfsize, const Vector3 * restrict triverts);
|
class Triangle
|
||||||
NVMATH_API bool triBoxOverlapNoBounds(Vector3::Arg boxcenter, Vector3::Arg boxhalfsize, const Vector3 * restrict triverts);
|
|
||||||
|
|
||||||
|
|
||||||
/// Triangle class with three vertices.
|
|
||||||
class Triangle
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Triangle() {};
|
|
||||||
|
|
||||||
Triangle(const Vector3 & v0, const Vector3 & v1, const Vector3 & v2)
|
|
||||||
{
|
{
|
||||||
v[0] = v0;
|
public:
|
||||||
v[1] = v1;
|
Triangle() {};
|
||||||
v[2] = v2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the bounds of the triangle.
|
Triangle(Vector3::Arg v0, Vector3::Arg v1, Vector3::Arg v2)
|
||||||
Box bounds() const {
|
{
|
||||||
Box bounds;
|
v[0] = v0;
|
||||||
bounds.clearBounds();
|
v[1] = v1;
|
||||||
bounds.addPointToBounds(v[0]);
|
v[2] = v2;
|
||||||
bounds.addPointToBounds(v[1]);
|
|
||||||
bounds.addPointToBounds(v[2]);
|
|
||||||
return bounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
/// Get barycentric coordinates of the given point in this triangle.
|
|
||||||
Vector3 barycentricCoordinates(Vector3::Arg p)
|
|
||||||
{
|
|
||||||
Vector3 bar;
|
|
||||||
|
|
||||||
// p must lie in the triangle plane.
|
|
||||||
Plane plane;
|
|
||||||
plane.set(v[0], v[1], v[2]);
|
|
||||||
nvCheck( equalf(plane.Distance(p), 0.0f) );
|
|
||||||
|
|
||||||
Vector3 n;
|
|
||||||
|
|
||||||
// Compute signed area of triangle <v0, v1, p>
|
|
||||||
n = cross(v[1] - v[0], p - v[0]);
|
|
||||||
bar.x = length(n);
|
|
||||||
if (dot(n, plane.vector) < 0) {
|
|
||||||
bar->x = -bar->x;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute signed area of triangle <v1, v2, p>
|
/// Get the bounds of the triangle.
|
||||||
n = cross(v[2] - v[1], p - v[1]);
|
Box bounds() const
|
||||||
bar->y = length(cross(e, d));
|
{
|
||||||
if (dot(n, plane.vector) < 0) {
|
Box bounds;
|
||||||
bar->y = -bar->y;
|
bounds.clearBounds();
|
||||||
|
bounds.addPointToBounds(v[0]);
|
||||||
|
bounds.addPointToBounds(v[1]);
|
||||||
|
bounds.addPointToBounds(v[2]);
|
||||||
|
return bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute signed area of triangle <v2, v0, p>
|
Vector4 plane() const
|
||||||
n = cross(v[0] - v[2], p - v[2]);
|
{
|
||||||
bar->z = length(n);
|
Vector3 n = cross(v[1]-v[0], v[2]-v[0]);
|
||||||
if (dot(n, plane.vector) < 0) {
|
return Vector4(n, dot(n, v[0]));
|
||||||
bar->z = -bar->z;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We cannot just do this because we need the signed areas.
|
Vector3 v[3];
|
||||||
// bar->x = Vector3Area(e0, d0);
|
};
|
||||||
// bar->y = Vector3Area(e1, d1);
|
|
||||||
// bar->z = Vector3Area(e2, d2);
|
|
||||||
|
|
||||||
// bar->x = Vector3TripleProduct(v[1], v[2], p);
|
|
||||||
// bar->y = Vector3TripleProduct(v[2], v[0], p);
|
|
||||||
// bar->z = Vector3TripleProduct(v[0], v[1], p);
|
|
||||||
|
|
||||||
}
|
// Tomas Akenine-Möller box-triangle test.
|
||||||
*/
|
NVMATH_API bool triBoxOverlap(Vector3::Arg boxcenter, Vector3::Arg boxhalfsize, const Triangle & triangle);
|
||||||
|
NVMATH_API bool triBoxOverlapNoBounds(Vector3::Arg boxcenter, Vector3::Arg boxhalfsize, const Triangle & triangle);
|
||||||
|
|
||||||
|
|
||||||
// Moller ray triangle test.
|
// Moller ray triangle test.
|
||||||
bool TestRay_Moller(const Vector3 & orig, const Vector3 & dir, float * out_t, float * out_u, float * out_v);
|
NVMATH_API bool rayTest_Moller(const Triangle & t, Vector3::Arg orig, Vector3::Arg dir, float * out_t, float * out_u, float * out_v);
|
||||||
|
|
||||||
Vector3 v[3];
|
inline bool rayTest(const Triangle & t, Vector3::Arg orig, Vector3::Arg dir, float * out_t, float * out_u, float * out_v)
|
||||||
};
|
{
|
||||||
|
rayTest_Moller(t, orig, dir, out_t, out_u, out_v);
|
||||||
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
/** A planar triangle. */
|
|
||||||
class Triangle2 {
|
|
||||||
public:
|
|
||||||
|
|
||||||
Triangle2() {};
|
|
||||||
Triangle2(const Vec2 & v0, const Vec2 & v1, const Vec2 & v2) {
|
|
||||||
v[0] = v0;
|
|
||||||
v[1] = v1;
|
|
||||||
v[2] = v2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the barycentric coordinates of the given point for this triangle.
|
inline bool overlap(const Triangle & t, const Box & b)
|
||||||
* http://stevehollasch.com/cgindex/math/barycentric.html
|
{
|
||||||
*/
|
Vector3 center = b.center();
|
||||||
void GetBarycentricCoordinates(const Vec2 & p, Vector3 * bar) const {
|
Vector3 extents = b.extents();
|
||||||
float denom = 1.0f / (v[1].x - v[0].x) * (v[2].y - v[0].y) - (v[2].x - v[0].x) * (v[1].y - v[0].y);
|
return triBoxOverlap(center, extents, t);
|
||||||
bar->x = ((v[1].x - p.x) * (v[2].y - p.y) - (v[2].x - p.x) * (v[1].y - p.y)) * denom;
|
|
||||||
bar->y = ((v[2].x - p.x) * (v[0].y - p.y) - (v[0].x - p.x) * (v[2].y - p.y)) * denom;
|
|
||||||
//bar->z = ((v[0].x - p.x) * (v[1].y - p.y) - (v[1].x - p.x) * (v[0].y - p.y)) * denom;
|
|
||||||
bar->z = 1 - bar->x - bar->y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool overlap(const Box & b, const Triangle & t)
|
||||||
|
{
|
||||||
|
return overlap(t, b);
|
||||||
|
}
|
||||||
|
|
||||||
Vec2 v[3];
|
inline bool overlapNoBounds(const Triangle & t, const Box & b)
|
||||||
};
|
{
|
||||||
|
Vector3 center = b.center();
|
||||||
#endif // 0
|
Vector3 extents = b.extents();
|
||||||
|
return triBoxOverlapNoBounds(center, extents, t);
|
||||||
|
}
|
||||||
inline bool overlap(const Triangle & t, const Box & b)
|
|
||||||
{
|
|
||||||
Vector3 center = b.center();
|
|
||||||
Vector3 extents = b.extents();
|
|
||||||
return triBoxOverlap(center, extents, t.v);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Overlap(const Box & b, const Triangle & t)
|
|
||||||
{
|
|
||||||
return overlap(t, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline bool overlapNoBounds(const Triangle & t, const Box & b)
|
|
||||||
{
|
|
||||||
Vector3 center = b.center();
|
|
||||||
Vector3 extents = b.extents();
|
|
||||||
return triBoxOverlapNoBounds(center, extents, t.v);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // nv namespace
|
} // nv namespace
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user