Added static Create methods for POD types, eliminated warnings, added CMake macros for Kraken public header export

This commit is contained in:
2018-07-27 00:05:59 -07:00
parent fe16af07f1
commit 759b7af066
7 changed files with 66 additions and 19 deletions

View File

@@ -38,3 +38,20 @@ set(SRCS
) )
add_library(hydra STATIC ${SRCS} ${PUBLIC_HEADERS}) add_library(hydra STATIC ${SRCS} ${PUBLIC_HEADERS})
if(COMMAND add_public_header)
add_public_header(include/aabb.h)
add_public_header(include/hitinfo.h)
add_public_header(include/hydra.h)
add_public_header(include/matrix2.h)
add_public_header(include/matrix2x3.h)
add_public_header(include/matrix4.h)
add_public_header(include/quaternion.h)
add_public_header(include/scalar.h)
add_public_header(include/triangle3.h)
add_public_header(include/vector2.h)
add_public_header(include/vector3.h)
add_public_header(include/vector4.h)
add_public_header(include/vector2i.h)
set(KRAKEN_PUBLIC_HEADERS "${KRAKEN_PUBLIC_HEADERS}" PARENT_SCOPE)
endif()

View File

@@ -61,10 +61,11 @@ public:
void init(); void init();
void init(float *pMat); void init(float *pMat);
void init(const Vector3 &new_axis_x, const Vector3 &new_axis_y, const Vector3 &new_axis_z, const Vector3 &new_transform); void init(const Vector3 &new_axis_x, const Vector3 &new_axis_y, const Vector3 &new_axis_z, const Vector3 &new_transform);
void init(const Matrix4 &m); void init(const Matrix4 &m);
static Matrix4 Create(float *pMat);
static Matrix4 Create(const Vector3 &new_axis_x, const Vector3 &new_axis_y, const Vector3 &new_axis_z, const Vector3 &new_transform);
// Overload comparison operator // Overload comparison operator
bool operator==(const Matrix4 &m) const; bool operator==(const Matrix4 &m) const;

View File

@@ -43,6 +43,8 @@ public:
void init(const Triangle3 &tri); void init(const Triangle3 &tri);
void init(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3); void init(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3);
static Triangle3 Create(const Triangle3 &tri);
static Triangle3 Create(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3);
Vector3 calculateNormal() const; Vector3 calculateNormal() const;

View File

@@ -261,7 +261,7 @@ bool AABB::intersectsRay(const Vector3 &v1, const Vector3 &dir) const
maxT.init(); maxT.init();
Vector3 coord; Vector3 coord;
coord.init(); coord.init();
double candidatePlane[3]; float candidatePlane[3];
// Find candidate planes; this loop can be avoided if rays cast all from the eye(assume perpsective view) // Find candidate planes; this loop can be avoided if rays cast all from the eye(assume perpsective view)
for (int i=0; i<3; i++) for (int i=0; i<3; i++)

View File

@@ -63,6 +63,20 @@ void Matrix4::init(const Matrix4 &m) {
memcpy(c, m.c, sizeof(float) * 16); memcpy(c, m.c, sizeof(float) * 16);
} }
Matrix4 Matrix4::Create(float *pMat)
{
Matrix4 r;
r.init(pMat);
return r;
}
Matrix4 Matrix4::Create(const Vector3 &new_axis_x, const Vector3 &new_axis_y, const Vector3 &new_axis_z, const Vector3 &new_transform)
{
Matrix4 r;
r.init(new_axis_x, new_axis_y, new_axis_z, new_transform);
return r;
}
float *Matrix4::getPointer() { float *Matrix4::getPointer() {
return c; return c;
} }
@@ -115,7 +129,7 @@ void Matrix4::perspective(float fov, float aspect, float nearz, float farz) {
memset(c, 0, sizeof(float) * 16); memset(c, 0, sizeof(float) * 16);
float range= tan(fov * 0.5) * nearz; float range= tan(fov * 0.5f) * nearz;
c[0] = (2 * nearz) / ((range * aspect) - (-range * aspect)); c[0] = (2 * nearz) / ((range * aspect) - (-range * aspect));
c[5] = (2 * nearz) / (2 * range); c[5] = (2 * nearz) / (2 * range);
c[10] = -(farz + nearz) / (farz - nearz); c[10] = -(farz + nearz) / (farz - nearz);
@@ -287,7 +301,7 @@ bool Matrix4::invert() {
return false; return false;
} }
det = 1.0 / det; det = 1.0f / det;
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
c[i] = inv[i] * det; c[i] = inv[i] * det;

View File

@@ -139,20 +139,20 @@ Vector3 Quaternion::eulerXYZ() const {
double a2 = 2 * (c[0] * c[2] - c[1] * c[3]); double a2 = 2 * (c[0] * c[2] - c[1] * c[3]);
if(a2 <= -0.99999) { if(a2 <= -0.99999) {
return Vector3::Create( return Vector3::Create(
2.0 * atan2(c[1], c[0]), 2.0f * atan2(c[1], c[0]),
-PI * 0.5f, -PI * 0.5f,
0 0
); );
} else if(a2 >= 0.99999) { } else if(a2 >= 0.99999) {
return Vector3::Create( return Vector3::Create(
2.0 * atan2(c[1], c[0]), 2.0f * atan2(c[1], c[0]),
PI * 0.5f, PI * 0.5f,
0 0
); );
} else { } else {
return Vector3::Create( return Vector3::Create(
atan2(2 * (c[0] * c[1] + c[2] * c[3]), (1 - 2 * (c[1] * c[1] + c[2] * c[2]))), atan2(2 * (c[0] * c[1] + c[2] * c[3]), (1 - 2 * (c[1] * c[1] + c[2] * c[2]))),
asin(a2), asinf(a2),
atan2(2 * (c[0] * c[3] + c[1] * c[2]), (1 - 2 * (c[2] * c[2] + c[3] * c[3]))) atan2(2 * (c[0] * c[3] + c[1] * c[2]), (1 - 2 * (c[2] * c[2] + c[3] * c[3])))
); );
} }
@@ -326,17 +326,17 @@ Matrix4 Quaternion::rotationMatrix() const {
// FINDME - Determine why the more optimal routine commented below wasn't working // FINDME - Determine why the more optimal routine commented below wasn't working
matRotate.c[0] = 1.0 - 2.0 * (c[2] * c[2] + c[3] * c[3]); matRotate.c[0] = 1.0f - 2.0f * (c[2] * c[2] + c[3] * c[3]);
matRotate.c[1] = 2.0 * (c[1] * c[2] - c[0] * c[3]); matRotate.c[1] = 2.0f * (c[1] * c[2] - c[0] * c[3]);
matRotate.c[2] = 2.0 * (c[0] * c[2] + c[1] * c[3]); matRotate.c[2] = 2.0f * (c[0] * c[2] + c[1] * c[3]);
matRotate.c[4] = 2.0 * (c[1] * c[2] + c[0] * c[3]); matRotate.c[4] = 2.0f * (c[1] * c[2] + c[0] * c[3]);
matRotate.c[5] = 1.0 - 2.0 * (c[1] * c[1] + c[3] * c[3]); matRotate.c[5] = 1.0f - 2.0f * (c[1] * c[1] + c[3] * c[3]);
matRotate.c[6] = 2.0 * (c[2] * c[3] - c[0] * c[1]); matRotate.c[6] = 2.0f * (c[2] * c[3] - c[0] * c[1]);
matRotate.c[8] = 2.0 * (c[1] * c[3] - c[0] * c[2]); matRotate.c[8] = 2.0f * (c[1] * c[3] - c[0] * c[2]);
matRotate.c[9] = 2.0 * (c[0] * c[1] + c[2] * c[3]); matRotate.c[9] = 2.0f * (c[0] * c[1] + c[2] * c[3]);
matRotate.c[10] = 1.0 - 2.0 * (c[1] * c[1] + c[2] * c[2]); matRotate.c[10] = 1.0f - 2.0f * (c[1] * c[1] + c[2] * c[2]);
return matRotate; return matRotate;
} }
@@ -367,13 +367,13 @@ Quaternion Quaternion::FromRotationMatrix(const Matrix4 &m)
y = (m[1] + m[4]) / s; y = (m[1] + m[4]) / s;
z = (m[2] + m[8]) / s; z = (m[2] + m[8]) / s;
} else if (m[5] > m[10]) { } else if (m[5] > m[10]) {
const float s = 2.0 * sqrt(1.0f + m[5] - m[0] - m[10]); const float s = 2.0f * sqrt(1.0f + m[5] - m[0] - m[10]);
w = (m[2] - m[8]) / s; w = (m[2] - m[8]) / s;
x = (m[1] + m[4]) / s; x = (m[1] + m[4]) / s;
y = 0.25f * s; y = 0.25f * s;
z = (m[6] + m[9]) / s; z = (m[6] + m[9]) / s;
} else { } else {
const float s = 2.0 * sqrt(1.0f + m[10] - m[0] - m[5]); const float s = 2.0f * sqrt(1.0f + m[10] - m[0] - m[5]);
w = (m[4] - m[1]) / s; w = (m[4] - m[1]) / s;
x = (m[2] + m[8]) / s; x = (m[2] + m[8]) / s;
y = (m[6] + m[9]) / s; y = (m[6] + m[9]) / s;

View File

@@ -112,6 +112,19 @@ void Triangle3::init(const Triangle3 &tri)
vert[2] = tri[2]; vert[2] = tri[2];
} }
Triangle3 Triangle3::Create(const Triangle3 &tri)
{
Triangle3 r;
r.init(tri);
return r;
}
Triangle3 Triangle3::Create(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3)
{
Triangle3 r;
r.init(v1, v2, v3);
return r;
}
bool Triangle3::operator ==(const Triangle3& b) const bool Triangle3::operator ==(const Triangle3& b) const
{ {