mirror of
https://github.com/ZDoom/ZDRay.git
synced 2025-02-03 13:11:04 +00:00
- remove kex prefix from classes
This commit is contained in:
parent
9a84d487dc
commit
4ceab7cec7
25 changed files with 1218 additions and 1240 deletions
|
@ -38,14 +38,14 @@ typedef union
|
|||
float f;
|
||||
} fint_t;
|
||||
|
||||
uint8_t kexBinFile::Read8()
|
||||
uint8_t BinFile::Read8()
|
||||
{
|
||||
uint8_t result;
|
||||
result = buffer[bufferOffset++];
|
||||
return result;
|
||||
}
|
||||
|
||||
short kexBinFile::Read16()
|
||||
short BinFile::Read16()
|
||||
{
|
||||
int result;
|
||||
result = Read8();
|
||||
|
@ -53,7 +53,7 @@ short kexBinFile::Read16()
|
|||
return result;
|
||||
}
|
||||
|
||||
int kexBinFile::Read32()
|
||||
int BinFile::Read32()
|
||||
{
|
||||
int result;
|
||||
result = Read8();
|
||||
|
@ -63,16 +63,16 @@ int kexBinFile::Read32()
|
|||
return result;
|
||||
}
|
||||
|
||||
float kexBinFile::ReadFloat()
|
||||
float BinFile::ReadFloat()
|
||||
{
|
||||
fint_t fi;
|
||||
fi.i = Read32();
|
||||
return fi.f;
|
||||
}
|
||||
|
||||
kexVec3 kexBinFile::ReadVector()
|
||||
Vec3 BinFile::ReadVector()
|
||||
{
|
||||
kexVec3 vec;
|
||||
Vec3 vec;
|
||||
|
||||
vec.x = ReadFloat();
|
||||
vec.y = ReadFloat();
|
||||
|
@ -81,7 +81,7 @@ kexVec3 kexBinFile::ReadVector()
|
|||
return vec;
|
||||
}
|
||||
|
||||
std::string kexBinFile::ReadString()
|
||||
std::string BinFile::ReadString()
|
||||
{
|
||||
std::string str;
|
||||
char c = 0;
|
||||
|
@ -99,19 +99,19 @@ std::string kexBinFile::ReadString()
|
|||
return str;
|
||||
}
|
||||
|
||||
void kexBinFile::Write8(const uint8_t val)
|
||||
void BinFile::Write8(const uint8_t val)
|
||||
{
|
||||
buffer[bufferOffset] = val;
|
||||
bufferOffset++;
|
||||
}
|
||||
|
||||
void kexBinFile::Write16(const short val)
|
||||
void BinFile::Write16(const short val)
|
||||
{
|
||||
Write8(val & 0xff);
|
||||
Write8((val >> 8) & 0xff);
|
||||
}
|
||||
|
||||
void kexBinFile::Write32(const int val)
|
||||
void BinFile::Write32(const int val)
|
||||
{
|
||||
Write8(val & 0xff);
|
||||
Write8((val >> 8) & 0xff);
|
||||
|
@ -119,21 +119,21 @@ void kexBinFile::Write32(const int val)
|
|||
Write8((val >> 24) & 0xff);
|
||||
}
|
||||
|
||||
void kexBinFile::WriteFloat(const float val)
|
||||
void BinFile::WriteFloat(const float val)
|
||||
{
|
||||
fint_t fi;
|
||||
fi.f = val;
|
||||
Write32(fi.i);
|
||||
}
|
||||
|
||||
void kexBinFile::WriteVector(const kexVec3 &val)
|
||||
void BinFile::WriteVector(const Vec3 &val)
|
||||
{
|
||||
WriteFloat(val.x);
|
||||
WriteFloat(val.y);
|
||||
WriteFloat(val.z);
|
||||
}
|
||||
|
||||
void kexBinFile::WriteString(const std::string &val)
|
||||
void BinFile::WriteString(const std::string &val)
|
||||
{
|
||||
const char *c = val.c_str();
|
||||
|
||||
|
@ -145,12 +145,12 @@ void kexBinFile::WriteString(const std::string &val)
|
|||
Write8(0);
|
||||
}
|
||||
|
||||
int kexBinFile::GetOffsetValue(int id)
|
||||
int BinFile::GetOffsetValue(int id)
|
||||
{
|
||||
return *(int*)(buffer + (id << 2));
|
||||
}
|
||||
|
||||
uint8_t *kexBinFile::GetOffset(int id, uint8_t *subdata, int *count)
|
||||
uint8_t *BinFile::GetOffset(int id, uint8_t *subdata, int *count)
|
||||
{
|
||||
uint8_t *data = (subdata == nullptr) ? buffer : subdata;
|
||||
|
||||
|
|
|
@ -30,21 +30,21 @@
|
|||
#include "math/mathlib.h"
|
||||
#include <string>
|
||||
|
||||
class kexBinFile
|
||||
class BinFile
|
||||
{
|
||||
public:
|
||||
uint8_t Read8();
|
||||
short Read16();
|
||||
int Read32();
|
||||
float ReadFloat();
|
||||
kexVec3 ReadVector();
|
||||
Vec3 ReadVector();
|
||||
std::string ReadString();
|
||||
|
||||
void Write8(const uint8_t val);
|
||||
void Write16(const short val);
|
||||
void Write32(const int val);
|
||||
void WriteFloat(const float val);
|
||||
void WriteVector(const kexVec3 &val);
|
||||
void WriteVector(const Vec3 &val);
|
||||
void WriteString(const std::string &val);
|
||||
|
||||
int GetOffsetValue(int id);
|
||||
|
|
|
@ -109,8 +109,8 @@ struct IntSector
|
|||
// empty is enough
|
||||
MapSector data;
|
||||
|
||||
kexPlane ceilingplane;
|
||||
kexPlane floorplane;
|
||||
Plane ceilingplane;
|
||||
Plane floorplane;
|
||||
|
||||
int floorlightdef;
|
||||
int ceilinglightdef;
|
||||
|
@ -242,10 +242,9 @@ struct IntVertex
|
|||
TArray<UDMFKey> props;
|
||||
};
|
||||
|
||||
class kexBBox;
|
||||
class kexVec3;
|
||||
class kexVec2;
|
||||
class kexLightSurface;
|
||||
class BBox;
|
||||
class Vec3;
|
||||
class Vec2;
|
||||
struct vertex_t;
|
||||
struct surface_t;
|
||||
struct thingLight_t;
|
||||
|
@ -264,22 +263,22 @@ struct lightDef_t
|
|||
float intensity;
|
||||
float falloff;
|
||||
bool bCeiling;
|
||||
kexVec3 rgb;
|
||||
Vec3 rgb;
|
||||
};
|
||||
|
||||
struct mapDef_t
|
||||
{
|
||||
int map;
|
||||
int sunIgnoreTag;
|
||||
kexVec3 sunDir;
|
||||
kexVec3 sunColor;
|
||||
Vec3 sunDir;
|
||||
Vec3 sunColor;
|
||||
};
|
||||
|
||||
struct thingLight_t
|
||||
{
|
||||
IntThing *mapThing;
|
||||
kexVec2 origin;
|
||||
kexVec3 rgb;
|
||||
Vec2 origin;
|
||||
Vec3 rgb;
|
||||
float intensity;
|
||||
float innerAngleCos;
|
||||
float outerAngleCos;
|
||||
|
@ -294,7 +293,7 @@ struct surfaceLightDef
|
|||
{
|
||||
float distance;
|
||||
float intensity;
|
||||
kexVec3 rgb;
|
||||
Vec3 rgb;
|
||||
};
|
||||
|
||||
enum mapFlags_t
|
||||
|
@ -358,8 +357,8 @@ struct FLevel
|
|||
void SetupDlight();
|
||||
void CreateLights();
|
||||
|
||||
const kexVec3 &GetSunColor() const;
|
||||
const kexVec3 &GetSunDirection() const;
|
||||
const Vec3 &GetSunColor() const;
|
||||
const Vec3 &GetSunDirection() const;
|
||||
IntSector *GetFrontSector(const IntSideDef *side);
|
||||
IntSector *GetBackSector(const IntSideDef *side);
|
||||
IntSector *GetSectorFromSubSector(const MapSubsectorEx *sub);
|
||||
|
|
|
@ -129,5 +129,5 @@ private:
|
|||
|
||||
bool NodesBuilt = false;
|
||||
bool LightmapsBuilt = false;
|
||||
kexLightmapBuilder LMBuilder;
|
||||
LightmapBuilder LMBuilder;
|
||||
};
|
||||
|
|
|
@ -41,8 +41,8 @@
|
|||
#pragma warning(disable: 4244) // warning C4244: '=': conversion from '__int64' to 'int', possible loss of data
|
||||
#endif
|
||||
|
||||
static const kexVec3 defaultSunColor(1, 1, 1);
|
||||
static const kexVec3 defaultSunDirection(0.45f, 0.3f, 0.9f);
|
||||
static const Vec3 defaultSunColor(1, 1, 1);
|
||||
static const Vec3 defaultSunDirection(0.45f, 0.3f, 0.9f);
|
||||
|
||||
void FLevel::SetupDlight()
|
||||
{
|
||||
|
@ -107,12 +107,12 @@ void FLevel::CheckSkySectors()
|
|||
}
|
||||
}
|
||||
|
||||
const kexVec3 &FLevel::GetSunColor() const
|
||||
const Vec3 &FLevel::GetSunColor() const
|
||||
{
|
||||
return defaultSunColor;
|
||||
}
|
||||
|
||||
const kexVec3 &FLevel::GetSunDirection() const
|
||||
const Vec3 &FLevel::GetSunDirection() const
|
||||
{
|
||||
return defaultSunDirection;
|
||||
}
|
||||
|
@ -159,8 +159,8 @@ MapSubsectorEx *FLevel::PointInSubSector(const int x, const int y)
|
|||
MapNodeEx *node;
|
||||
int side;
|
||||
int nodenum;
|
||||
kexVec3 dp1;
|
||||
kexVec3 dp2;
|
||||
Vec3 dp1;
|
||||
Vec3 dp2;
|
||||
float d;
|
||||
|
||||
// single subsector is a special case
|
||||
|
@ -175,11 +175,11 @@ MapSubsectorEx *FLevel::PointInSubSector(const int x, const int y)
|
|||
{
|
||||
node = &GLNodes[nodenum];
|
||||
|
||||
kexVec3 pt1(F(node->x), F(node->y), 0);
|
||||
kexVec3 pt2(F(node->dx), F(node->dy), 0);
|
||||
//kexVec3 pt1(F(node->x << 16), F(node->y << 16), 0);
|
||||
//kexVec3 pt2(F(node->dx << 16), F(node->dy << 16), 0);
|
||||
kexVec3 pos(F(x << 16), F(y << 16), 0);
|
||||
Vec3 pt1(F(node->x), F(node->y), 0);
|
||||
Vec3 pt2(F(node->dx), F(node->dy), 0);
|
||||
//Vec3 pt1(F(node->x << 16), F(node->y << 16), 0);
|
||||
//Vec3 pt2(F(node->dx << 16), F(node->dy << 16), 0);
|
||||
Vec3 pos(F(x << 16), F(y << 16), 0);
|
||||
|
||||
dp1 = pt1 - pos;
|
||||
dp2 = (pt2 + pt1) - pos;
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <immintrin.h>
|
||||
#endif
|
||||
|
||||
TriangleMeshShape::TriangleMeshShape(const kexVec3 *vertices, int num_vertices, const unsigned int *elements, int num_elements)
|
||||
TriangleMeshShape::TriangleMeshShape(const Vec3 *vertices, int num_vertices, const unsigned int *elements, int num_elements)
|
||||
: vertices(vertices), num_vertices(num_vertices), elements(elements), num_elements(num_elements)
|
||||
{
|
||||
int num_triangles = num_elements / 3;
|
||||
|
@ -35,7 +35,7 @@ TriangleMeshShape::TriangleMeshShape(const kexVec3 *vertices, int num_vertices,
|
|||
return;
|
||||
|
||||
std::vector<int> triangles;
|
||||
std::vector<kexVec3> centroids;
|
||||
std::vector<Vec3> centroids;
|
||||
triangles.reserve(num_triangles);
|
||||
centroids.reserve(num_triangles);
|
||||
for (int i = 0; i < num_triangles; i++)
|
||||
|
@ -43,7 +43,7 @@ TriangleMeshShape::TriangleMeshShape(const kexVec3 *vertices, int num_vertices,
|
|||
triangles.push_back(i);
|
||||
|
||||
int element_index = i * 3;
|
||||
kexVec3 centroid = (vertices[elements[element_index + 0]] + vertices[elements[element_index + 1]] + vertices[elements[element_index + 2]]) * (1.0f / 3.0f);
|
||||
Vec3 centroid = (vertices[elements[element_index + 0]] + vertices[elements[element_index + 1]] + vertices[elements[element_index + 2]]) * (1.0f / 3.0f);
|
||||
centroids.push_back(centroid);
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ TriangleMeshShape::TriangleMeshShape(const kexVec3 *vertices, int num_vertices,
|
|||
root = subdivide(&triangles[0], (int)triangles.size(), ¢roids[0], &work_buffer[0]);
|
||||
}
|
||||
|
||||
float TriangleMeshShape::sweep(TriangleMeshShape *shape1, SphereShape *shape2, const kexVec3 &target)
|
||||
float TriangleMeshShape::sweep(TriangleMeshShape *shape1, SphereShape *shape2, const Vec3 &target)
|
||||
{
|
||||
return sweep(shape1, shape2, shape1->root, target);
|
||||
}
|
||||
|
@ -67,18 +67,18 @@ bool TriangleMeshShape::find_any_hit(TriangleMeshShape *shape1, SphereShape *sha
|
|||
return find_any_hit(shape1, shape2, shape1->root);
|
||||
}
|
||||
|
||||
bool TriangleMeshShape::find_any_hit(TriangleMeshShape *shape, const kexVec3 &ray_start, const kexVec3 &ray_end)
|
||||
bool TriangleMeshShape::find_any_hit(TriangleMeshShape *shape, const Vec3 &ray_start, const Vec3 &ray_end)
|
||||
{
|
||||
return find_any_hit(shape, RayBBox(ray_start, ray_end), shape->root);
|
||||
}
|
||||
|
||||
TraceHit TriangleMeshShape::find_first_hit(TriangleMeshShape *shape, const kexVec3 &ray_start, const kexVec3 &ray_end)
|
||||
TraceHit TriangleMeshShape::find_first_hit(TriangleMeshShape *shape, const Vec3 &ray_start, const Vec3 &ray_end)
|
||||
{
|
||||
TraceHit hit;
|
||||
|
||||
// Perform segmented tracing to keep the ray AABB box smaller
|
||||
|
||||
kexVec3 ray_dir = ray_end - ray_start;
|
||||
Vec3 ray_dir = ray_end - ray_start;
|
||||
float tracedist = ray_dir.Length();
|
||||
float segmentlen = std::max(100.0f, tracedist / 20.0f);
|
||||
for (float t = 0.0f; t < tracedist; t += segmentlen)
|
||||
|
@ -97,7 +97,7 @@ TraceHit TriangleMeshShape::find_first_hit(TriangleMeshShape *shape, const kexVe
|
|||
return hit;
|
||||
}
|
||||
|
||||
float TriangleMeshShape::sweep(TriangleMeshShape *shape1, SphereShape *shape2, int a, const kexVec3 &target)
|
||||
float TriangleMeshShape::sweep(TriangleMeshShape *shape1, SphereShape *shape2, int a, const Vec3 &target)
|
||||
{
|
||||
if (sweep_overlap_bv_sphere(shape1, shape2, a, target))
|
||||
{
|
||||
|
@ -238,7 +238,7 @@ float TriangleMeshShape::intersect_triangle_ray(TriangleMeshShape *shape, const
|
|||
{
|
||||
const int start_element = shape->nodes[a].element_index;
|
||||
|
||||
kexVec3 p[3] =
|
||||
Vec3 p[3] =
|
||||
{
|
||||
shape->vertices[shape->elements[start_element]],
|
||||
shape->vertices[shape->elements[start_element + 1]],
|
||||
|
@ -247,15 +247,15 @@ float TriangleMeshShape::intersect_triangle_ray(TriangleMeshShape *shape, const
|
|||
|
||||
// Moeller–Trumbore ray-triangle intersection algorithm:
|
||||
|
||||
kexVec3 D = ray.end - ray.start;
|
||||
Vec3 D = ray.end - ray.start;
|
||||
|
||||
// Find vectors for two edges sharing p[0]
|
||||
kexVec3 e1 = p[1] - p[0];
|
||||
kexVec3 e2 = p[2] - p[0];
|
||||
Vec3 e1 = p[1] - p[0];
|
||||
Vec3 e2 = p[2] - p[0];
|
||||
|
||||
// Begin calculating determinant - also used to calculate u parameter
|
||||
kexVec3 P = kexVec3::Cross(D, e2);
|
||||
float det = kexVec3::Dot(e1, P);
|
||||
Vec3 P = Vec3::Cross(D, e2);
|
||||
float det = Vec3::Dot(e1, P);
|
||||
|
||||
// Backface check
|
||||
//if (det < 0.0f)
|
||||
|
@ -268,26 +268,26 @@ float TriangleMeshShape::intersect_triangle_ray(TriangleMeshShape *shape, const
|
|||
float inv_det = 1.0f / det;
|
||||
|
||||
// Calculate distance from p[0] to ray origin
|
||||
kexVec3 T = ray.start - p[0];
|
||||
Vec3 T = ray.start - p[0];
|
||||
|
||||
// Calculate u parameter and test bound
|
||||
float u = kexVec3::Dot(T, P) * inv_det;
|
||||
float u = Vec3::Dot(T, P) * inv_det;
|
||||
|
||||
// Check if the intersection lies outside of the triangle
|
||||
if (u < 0.f || u > 1.f)
|
||||
return 1.0f;
|
||||
|
||||
// Prepare to test v parameter
|
||||
kexVec3 Q = kexVec3::Cross(T, e1);
|
||||
Vec3 Q = Vec3::Cross(T, e1);
|
||||
|
||||
// Calculate V parameter and test bound
|
||||
float v = kexVec3::Dot(D, Q) * inv_det;
|
||||
float v = Vec3::Dot(D, Q) * inv_det;
|
||||
|
||||
// The intersection lies outside of the triangle
|
||||
if (v < 0.f || u + v > 1.f)
|
||||
return 1.0f;
|
||||
|
||||
float t = kexVec3::Dot(e2, Q) * inv_det;
|
||||
float t = Vec3::Dot(e2, Q) * inv_det;
|
||||
if (t <= FLT_EPSILON)
|
||||
return 1.0f;
|
||||
|
||||
|
@ -298,7 +298,7 @@ float TriangleMeshShape::intersect_triangle_ray(TriangleMeshShape *shape, const
|
|||
return t;
|
||||
}
|
||||
|
||||
bool TriangleMeshShape::sweep_overlap_bv_sphere(TriangleMeshShape *shape1, SphereShape *shape2, int a, const kexVec3 &target)
|
||||
bool TriangleMeshShape::sweep_overlap_bv_sphere(TriangleMeshShape *shape1, SphereShape *shape2, int a, const Vec3 &target)
|
||||
{
|
||||
// Convert to ray test by expanding the AABB:
|
||||
|
||||
|
@ -308,30 +308,30 @@ bool TriangleMeshShape::sweep_overlap_bv_sphere(TriangleMeshShape *shape1, Spher
|
|||
return IntersectionTest::ray_aabb(RayBBox(shape2->center, target), aabb) == IntersectionTest::overlap;
|
||||
}
|
||||
|
||||
float TriangleMeshShape::sweep_intersect_triangle_sphere(TriangleMeshShape *shape1, SphereShape *shape2, int a, const kexVec3 &target)
|
||||
float TriangleMeshShape::sweep_intersect_triangle_sphere(TriangleMeshShape *shape1, SphereShape *shape2, int a, const Vec3 &target)
|
||||
{
|
||||
const int start_element = shape1->nodes[a].element_index;
|
||||
|
||||
kexVec3 p[3] =
|
||||
Vec3 p[3] =
|
||||
{
|
||||
shape1->vertices[shape1->elements[start_element]],
|
||||
shape1->vertices[shape1->elements[start_element + 1]],
|
||||
shape1->vertices[shape1->elements[start_element + 2]]
|
||||
};
|
||||
|
||||
kexVec3 c = shape2->center;
|
||||
kexVec3 e = target;
|
||||
Vec3 c = shape2->center;
|
||||
Vec3 e = target;
|
||||
float r = shape2->radius;
|
||||
|
||||
// Dynamic intersection test between a ray and the minkowski sum of the sphere and polygon:
|
||||
|
||||
kexVec3 n = kexVec3::Normalize(kexVec3::Cross(p[1] - p[0], p[2] - p[0]));
|
||||
kexVec4 plane(n, -kexVec3::Dot(n, p[0]));
|
||||
Vec3 n = Vec3::Normalize(Vec3::Cross(p[1] - p[0], p[2] - p[0]));
|
||||
Vec4 plane(n, -Vec3::Dot(n, p[0]));
|
||||
|
||||
// Step 1: Plane intersect test
|
||||
|
||||
float sc = kexVec4::Dot(plane, kexVec4(c, 1.0f));
|
||||
float se = kexVec4::Dot(plane, kexVec4(e, 1.0f));
|
||||
float sc = Vec4::Dot(plane, Vec4(c, 1.0f));
|
||||
float se = Vec4::Dot(plane, Vec4(e, 1.0f));
|
||||
bool same_side = sc * se > 0.0f;
|
||||
|
||||
if (same_side && std::abs(sc) > r && std::abs(se) > r)
|
||||
|
@ -341,26 +341,26 @@ float TriangleMeshShape::sweep_intersect_triangle_sphere(TriangleMeshShape *shap
|
|||
{
|
||||
float t = (sc - r) / (sc - se);
|
||||
|
||||
kexVec3 vt = c + (e - c) * t;
|
||||
Vec3 vt = c + (e - c) * t;
|
||||
|
||||
kexVec3 u0 = p[1] - p[0];
|
||||
kexVec3 u1 = p[2] - p[0];
|
||||
Vec3 u0 = p[1] - p[0];
|
||||
Vec3 u1 = p[2] - p[0];
|
||||
|
||||
kexVec2 v_2d[3] =
|
||||
Vec2 v_2d[3] =
|
||||
{
|
||||
kexVec2(0.0f, 0.0f),
|
||||
kexVec2(kexVec3::Dot(u0, u0), 0.0f),
|
||||
kexVec2(0.0f, kexVec3::Dot(u1, u1))
|
||||
Vec2(0.0f, 0.0f),
|
||||
Vec2(Vec3::Dot(u0, u0), 0.0f),
|
||||
Vec2(0.0f, Vec3::Dot(u1, u1))
|
||||
};
|
||||
|
||||
kexVec2 point(kexVec3::Dot(u0, vt), kexVec3::Dot(u1, vt));
|
||||
Vec2 point(Vec3::Dot(u0, vt), Vec3::Dot(u1, vt));
|
||||
|
||||
bool inside = false;
|
||||
kexVec2 e0 = v_2d[2];
|
||||
Vec2 e0 = v_2d[2];
|
||||
bool y0 = e0.y >= point.y;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
kexVec2 e1 = v_2d[i];
|
||||
Vec2 e1 = v_2d[i];
|
||||
bool y1 = e1.y >= point.y;
|
||||
|
||||
if (y0 != y1 && ((e1.y - point.y) * (e0.x - e1.x) >= (e1.x - point.x) * (e0.y - e1.y)) == y1)
|
||||
|
@ -376,21 +376,21 @@ float TriangleMeshShape::sweep_intersect_triangle_sphere(TriangleMeshShape *shap
|
|||
|
||||
// Step 2: Edge intersect test
|
||||
|
||||
kexVec3 ke[3] =
|
||||
Vec3 ke[3] =
|
||||
{
|
||||
p[1] - p[0],
|
||||
p[2] - p[1],
|
||||
p[0] - p[2],
|
||||
};
|
||||
|
||||
kexVec3 kg[3] =
|
||||
Vec3 kg[3] =
|
||||
{
|
||||
p[0] - c,
|
||||
p[1] - c,
|
||||
p[2] - c,
|
||||
};
|
||||
|
||||
kexVec3 ks = e - c;
|
||||
Vec3 ks = e - c;
|
||||
|
||||
float kgg[3];
|
||||
float kgs[3];
|
||||
|
@ -398,12 +398,12 @@ float TriangleMeshShape::sweep_intersect_triangle_sphere(TriangleMeshShape *shap
|
|||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
float kee = kexVec3::Dot(ke[i], ke[i]);
|
||||
float keg = kexVec3::Dot(ke[i], kg[i]);
|
||||
float kes = kexVec3::Dot(ke[i], ks);
|
||||
kgg[i] = kexVec3::Dot(kg[i], kg[i]);
|
||||
kgs[i] = kexVec3::Dot(kg[i], ks);
|
||||
kss[i] = kexVec3::Dot(ks, ks);
|
||||
float kee = Vec3::Dot(ke[i], ke[i]);
|
||||
float keg = Vec3::Dot(ke[i], kg[i]);
|
||||
float kes = Vec3::Dot(ke[i], ks);
|
||||
kgg[i] = Vec3::Dot(kg[i], kg[i]);
|
||||
kgs[i] = Vec3::Dot(kg[i], ks);
|
||||
kss[i] = Vec3::Dot(ks, ks);
|
||||
|
||||
float aa = kee * kss[i] - kes * kes;
|
||||
float bb = 2 * (keg * kes - kee * kgs[i]);
|
||||
|
@ -424,8 +424,8 @@ float TriangleMeshShape::sweep_intersect_triangle_sphere(TriangleMeshShape *shap
|
|||
|
||||
if (t >= 0.0f && t <= 1.0f)
|
||||
{
|
||||
kexVec3 ct = c + ks * t;
|
||||
float d = kexVec3::Dot(ct - p[i], ke[i]);
|
||||
Vec3 ct = c + ks * t;
|
||||
float d = Vec3::Dot(ct - p[i], ke[i]);
|
||||
if (d >= 0.0f && d <= kee)
|
||||
return t;
|
||||
}
|
||||
|
@ -485,49 +485,49 @@ bool TriangleMeshShape::overlap_triangle_sphere(TriangleMeshShape *shape1, Spher
|
|||
|
||||
int element_index = shape1->nodes[shape1_node_index].element_index;
|
||||
|
||||
kexVec3 P = shape2->center;
|
||||
kexVec3 A = shape1->vertices[shape1->elements[element_index]] - P;
|
||||
kexVec3 B = shape1->vertices[shape1->elements[element_index + 1]] - P;
|
||||
kexVec3 C = shape1->vertices[shape1->elements[element_index + 2]] - P;
|
||||
Vec3 P = shape2->center;
|
||||
Vec3 A = shape1->vertices[shape1->elements[element_index]] - P;
|
||||
Vec3 B = shape1->vertices[shape1->elements[element_index + 1]] - P;
|
||||
Vec3 C = shape1->vertices[shape1->elements[element_index + 2]] - P;
|
||||
float r = shape2->radius;
|
||||
float rr = r * r;
|
||||
|
||||
// Testing if sphere lies outside the triangle plane
|
||||
kexVec3 V = kexVec3::Cross(B - A, C - A);
|
||||
float d = kexVec3::Dot(A, V);
|
||||
float e = kexVec3::Dot(V, V);
|
||||
Vec3 V = Vec3::Cross(B - A, C - A);
|
||||
float d = Vec3::Dot(A, V);
|
||||
float e = Vec3::Dot(V, V);
|
||||
bool sep1 = d * d > rr * e;
|
||||
|
||||
// Testing if sphere lies outside a triangle vertex
|
||||
float aa = kexVec3::Dot(A, A);
|
||||
float ab = kexVec3::Dot(A, B);
|
||||
float ac = kexVec3::Dot(A, C);
|
||||
float bb = kexVec3::Dot(B, B);
|
||||
float bc = kexVec3::Dot(B, C);
|
||||
float cc = kexVec3::Dot(C, C);
|
||||
float aa = Vec3::Dot(A, A);
|
||||
float ab = Vec3::Dot(A, B);
|
||||
float ac = Vec3::Dot(A, C);
|
||||
float bb = Vec3::Dot(B, B);
|
||||
float bc = Vec3::Dot(B, C);
|
||||
float cc = Vec3::Dot(C, C);
|
||||
bool sep2 = (aa > rr) && (ab > aa) && (ac > aa);
|
||||
bool sep3 = (bb > rr) && (ab > bb) && (bc > bb);
|
||||
bool sep4 = (cc > rr) && (ac > cc) && (bc > cc);
|
||||
|
||||
// Testing if sphere lies outside a triangle edge
|
||||
kexVec3 AB = B - A;
|
||||
kexVec3 BC = C - B;
|
||||
kexVec3 CA = A - C;
|
||||
Vec3 AB = B - A;
|
||||
Vec3 BC = C - B;
|
||||
Vec3 CA = A - C;
|
||||
float d1 = ab - aa;
|
||||
float d2 = bc - bb;
|
||||
float d3 = ac - cc;
|
||||
float e1 = kexVec3::Dot(AB, AB);
|
||||
float e2 = kexVec3::Dot(BC, BC);
|
||||
float e3 = kexVec3::Dot(CA, CA);
|
||||
kexVec3 Q1 = A * e1 - AB * d1;
|
||||
kexVec3 Q2 = B * e2 - BC * d2;
|
||||
kexVec3 Q3 = C * e3 - CA * d3;
|
||||
kexVec3 QC = C * e1 - Q1;
|
||||
kexVec3 QA = A * e2 - Q2;
|
||||
kexVec3 QB = B * e3 - Q3;
|
||||
bool sep5 = (kexVec3::Dot(Q1, Q1) > rr * e1 * e1) && (kexVec3::Dot(Q1, QC) > 0.0f);
|
||||
bool sep6 = (kexVec3::Dot(Q2, Q2) > rr * e2 * e2) && (kexVec3::Dot(Q2, QA) > 0.0f);
|
||||
bool sep7 = (kexVec3::Dot(Q3, Q3) > rr * e3 * e3) && (kexVec3::Dot(Q3, QB) > 0.0f);
|
||||
float e1 = Vec3::Dot(AB, AB);
|
||||
float e2 = Vec3::Dot(BC, BC);
|
||||
float e3 = Vec3::Dot(CA, CA);
|
||||
Vec3 Q1 = A * e1 - AB * d1;
|
||||
Vec3 Q2 = B * e2 - BC * d2;
|
||||
Vec3 Q3 = C * e3 - CA * d3;
|
||||
Vec3 QC = C * e1 - Q1;
|
||||
Vec3 QA = A * e2 - Q2;
|
||||
Vec3 QB = B * e3 - Q3;
|
||||
bool sep5 = (Vec3::Dot(Q1, Q1) > rr * e1 * e1) && (Vec3::Dot(Q1, QC) > 0.0f);
|
||||
bool sep6 = (Vec3::Dot(Q2, Q2) > rr * e2 * e2) && (Vec3::Dot(Q2, QA) > 0.0f);
|
||||
bool sep7 = (Vec3::Dot(Q3, Q3) > rr * e3 * e3) && (Vec3::Dot(Q3, QB) > 0.0f);
|
||||
|
||||
bool separated = sep1 || sep2 || sep3 || sep4 || sep5 || sep6 || sep7;
|
||||
return (!separated);
|
||||
|
@ -540,7 +540,7 @@ bool TriangleMeshShape::is_leaf(int node_index)
|
|||
|
||||
float TriangleMeshShape::volume(int node_index)
|
||||
{
|
||||
const kexVec3 &extents = nodes[node_index].aabb.Extents;
|
||||
const Vec3 &extents = nodes[node_index].aabb.Extents;
|
||||
return extents.x * extents.y * extents.z;
|
||||
}
|
||||
|
||||
|
@ -590,14 +590,14 @@ float TriangleMeshShape::get_balanced_depth() const
|
|||
return std::log2((float)(num_elements / 3));
|
||||
}
|
||||
|
||||
int TriangleMeshShape::subdivide(int *triangles, int num_triangles, const kexVec3 *centroids, int *work_buffer)
|
||||
int TriangleMeshShape::subdivide(int *triangles, int num_triangles, const Vec3 *centroids, int *work_buffer)
|
||||
{
|
||||
if (num_triangles == 0)
|
||||
return -1;
|
||||
|
||||
// Find bounding box and median of the triangle centroids
|
||||
kexVec3 median;
|
||||
kexVec3 min, max;
|
||||
Vec3 median;
|
||||
Vec3 min, max;
|
||||
min = vertices[elements[triangles[0] * 3]];
|
||||
max = min;
|
||||
for (int i = 0; i < num_triangles; i++)
|
||||
|
@ -605,7 +605,7 @@ int TriangleMeshShape::subdivide(int *triangles, int num_triangles, const kexVec
|
|||
int element_index = triangles[i] * 3;
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
const kexVec3 &vertex = vertices[elements[element_index + j]];
|
||||
const Vec3 &vertex = vertices[elements[element_index + j]];
|
||||
|
||||
min.x = std::min(min.x, vertex.x);
|
||||
min.y = std::min(min.y, vertex.y);
|
||||
|
@ -639,18 +639,18 @@ int TriangleMeshShape::subdivide(int *triangles, int num_triangles, const kexVec
|
|||
|
||||
// Try split at longest axis, then if that fails the next longest, and then the remaining one
|
||||
int left_count, right_count;
|
||||
kexVec3 axis;
|
||||
Vec3 axis;
|
||||
for (int attempt = 0; attempt < 3; attempt++)
|
||||
{
|
||||
// Find the split plane for axis
|
||||
switch (axis_order[attempt])
|
||||
{
|
||||
default:
|
||||
case 0: axis = kexVec3(1.0f, 0.0f, 0.0f); break;
|
||||
case 1: axis = kexVec3(0.0f, 1.0f, 0.0f); break;
|
||||
case 2: axis = kexVec3(0.0f, 0.0f, 1.0f); break;
|
||||
case 0: axis = Vec3(1.0f, 0.0f, 0.0f); break;
|
||||
case 1: axis = Vec3(0.0f, 1.0f, 0.0f); break;
|
||||
case 2: axis = Vec3(0.0f, 0.0f, 1.0f); break;
|
||||
}
|
||||
kexVec4 plane(axis, -kexVec3::Dot(median, axis));
|
||||
Vec4 plane(axis, -Vec3::Dot(median, axis));
|
||||
|
||||
// Split triangles into two
|
||||
left_count = 0;
|
||||
|
@ -660,7 +660,7 @@ int TriangleMeshShape::subdivide(int *triangles, int num_triangles, const kexVec
|
|||
int triangle = triangles[i];
|
||||
int element_index = triangle * 3;
|
||||
|
||||
float side = kexVec4::Dot(kexVec4(centroids[triangles[i]], 1.0f), plane);
|
||||
float side = Vec4::Dot(Vec4(centroids[triangles[i]], 1.0f), plane);
|
||||
if (side >= 0.0f)
|
||||
{
|
||||
work_buffer[left_count] = triangle;
|
||||
|
@ -706,10 +706,10 @@ int TriangleMeshShape::subdivide(int *triangles, int num_triangles, const kexVec
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
IntersectionTest::Result IntersectionTest::plane_aabb(const kexVec4 &plane, const kexBBox &aabb)
|
||||
IntersectionTest::Result IntersectionTest::plane_aabb(const Vec4 &plane, const BBox &aabb)
|
||||
{
|
||||
kexVec3 center = aabb.Center();
|
||||
kexVec3 extents = aabb.Extents();
|
||||
Vec3 center = aabb.Center();
|
||||
Vec3 extents = aabb.Extents();
|
||||
float e = extents.x * std::abs(plane.x) + extents.y * std::abs(plane.y) + extents.z * std::abs(plane.z);
|
||||
float s = center.x * plane.x + center.y * plane.y + center.z * plane.z + plane.w;
|
||||
if (s - e > 0)
|
||||
|
@ -720,12 +720,12 @@ IntersectionTest::Result IntersectionTest::plane_aabb(const kexVec4 &plane, cons
|
|||
return intersecting;
|
||||
}
|
||||
|
||||
IntersectionTest::Result IntersectionTest::plane_obb(const kexVec4 &plane, const kexOrientedBBox &obb)
|
||||
IntersectionTest::Result IntersectionTest::plane_obb(const Vec4 &plane, const OrientedBBox &obb)
|
||||
{
|
||||
kexVec3 n = plane.ToVec3();
|
||||
Vec3 n = plane.ToVec3();
|
||||
float d = plane.w;
|
||||
float e = obb.Extents.x * std::abs(kexVec3::Dot(obb.axis_x, n)) + obb.Extents.y * std::abs(kexVec3::Dot(obb.axis_y, n)) + obb.Extents.z * std::abs(kexVec3::Dot(obb.axis_z, n));
|
||||
float s = kexVec3::Dot(obb.Center, n) + d;
|
||||
float e = obb.Extents.x * std::abs(Vec3::Dot(obb.axis_x, n)) + obb.Extents.y * std::abs(Vec3::Dot(obb.axis_y, n)) + obb.Extents.z * std::abs(Vec3::Dot(obb.axis_z, n));
|
||||
float s = Vec3::Dot(obb.Center, n) + d;
|
||||
if (s - e > 0)
|
||||
return inside;
|
||||
else if (s + e < 0)
|
||||
|
@ -734,10 +734,10 @@ IntersectionTest::Result IntersectionTest::plane_obb(const kexVec4 &plane, const
|
|||
return intersecting;
|
||||
}
|
||||
|
||||
IntersectionTest::OverlapResult IntersectionTest::sphere(const kexVec3 ¢er1, float radius1, const kexVec3 ¢er2, float radius2)
|
||||
IntersectionTest::OverlapResult IntersectionTest::sphere(const Vec3 ¢er1, float radius1, const Vec3 ¢er2, float radius2)
|
||||
{
|
||||
kexVec3 h = center1 - center2;
|
||||
float square_distance = kexVec3::Dot(h, h);
|
||||
Vec3 h = center1 - center2;
|
||||
float square_distance = Vec3::Dot(h, h);
|
||||
float radius_sum = radius1 + radius2;
|
||||
if (square_distance > radius_sum * radius_sum)
|
||||
return disjoint;
|
||||
|
@ -745,25 +745,25 @@ IntersectionTest::OverlapResult IntersectionTest::sphere(const kexVec3 ¢er1,
|
|||
return overlap;
|
||||
}
|
||||
|
||||
IntersectionTest::OverlapResult IntersectionTest::sphere_aabb(const kexVec3 ¢er, float radius, const kexBBox &aabb)
|
||||
IntersectionTest::OverlapResult IntersectionTest::sphere_aabb(const Vec3 ¢er, float radius, const BBox &aabb)
|
||||
{
|
||||
kexVec3 a = aabb.min - center;
|
||||
kexVec3 b = center - aabb.max;
|
||||
Vec3 a = aabb.min - center;
|
||||
Vec3 b = center - aabb.max;
|
||||
a.x = std::max(a.x, 0.0f);
|
||||
a.y = std::max(a.y, 0.0f);
|
||||
a.z = std::max(a.z, 0.0f);
|
||||
b.x = std::max(b.x, 0.0f);
|
||||
b.y = std::max(b.y, 0.0f);
|
||||
b.z = std::max(b.z, 0.0f);
|
||||
kexVec3 e = a + b;
|
||||
float d = kexVec3::Dot(e, e);
|
||||
Vec3 e = a + b;
|
||||
float d = Vec3::Dot(e, e);
|
||||
if (d > radius * radius)
|
||||
return disjoint;
|
||||
else
|
||||
return overlap;
|
||||
}
|
||||
|
||||
IntersectionTest::OverlapResult IntersectionTest::aabb(const kexBBox &a, const kexBBox &b)
|
||||
IntersectionTest::OverlapResult IntersectionTest::aabb(const BBox &a, const BBox &b)
|
||||
{
|
||||
if (a.min.x > b.max.x || b.min.x > a.max.x ||
|
||||
a.min.y > b.max.y || b.min.y > a.max.y ||
|
||||
|
@ -777,7 +777,7 @@ IntersectionTest::OverlapResult IntersectionTest::aabb(const kexBBox &a, const k
|
|||
}
|
||||
}
|
||||
|
||||
IntersectionTest::Result IntersectionTest::frustum_aabb(const FrustumPlanes &frustum, const kexBBox &box)
|
||||
IntersectionTest::Result IntersectionTest::frustum_aabb(const FrustumPlanes &frustum, const BBox &box)
|
||||
{
|
||||
bool is_intersecting = false;
|
||||
for (int i = 0; i < 6; i++)
|
||||
|
@ -795,7 +795,7 @@ IntersectionTest::Result IntersectionTest::frustum_aabb(const FrustumPlanes &fru
|
|||
return inside;
|
||||
}
|
||||
|
||||
IntersectionTest::Result IntersectionTest::frustum_obb(const FrustumPlanes &frustum, const kexOrientedBBox &box)
|
||||
IntersectionTest::Result IntersectionTest::frustum_obb(const FrustumPlanes &frustum, const OrientedBBox &box)
|
||||
{
|
||||
bool is_intersecting = false;
|
||||
for (int i = 0; i < 6; i++)
|
||||
|
@ -846,9 +846,9 @@ IntersectionTest::OverlapResult IntersectionTest::ray_aabb(const RayBBox &ray, c
|
|||
return (mask & 7) ? disjoint : overlap;
|
||||
|
||||
#else
|
||||
const kexVec3 &v = ray.v;
|
||||
const kexVec3 &w = ray.w;
|
||||
const kexVec3 &h = aabb.Extents;
|
||||
const Vec3 &v = ray.v;
|
||||
const Vec3 &w = ray.w;
|
||||
const Vec3 &h = aabb.Extents;
|
||||
auto c = ray.c - aabb.Center;
|
||||
|
||||
if (std::abs(c.x) > v.x + h.x || std::abs(c.y) > v.y + h.y || std::abs(c.z) > v.z + h.z)
|
||||
|
@ -869,7 +869,7 @@ FrustumPlanes::FrustumPlanes()
|
|||
{
|
||||
}
|
||||
|
||||
FrustumPlanes::FrustumPlanes(const kexMatrix &world_to_projection)
|
||||
FrustumPlanes::FrustumPlanes(const Mat4 &world_to_projection)
|
||||
{
|
||||
planes[0] = near_frustum_plane(world_to_projection);
|
||||
planes[1] = far_frustum_plane(world_to_projection);
|
||||
|
@ -879,9 +879,9 @@ FrustumPlanes::FrustumPlanes(const kexMatrix &world_to_projection)
|
|||
planes[5] = bottom_frustum_plane(world_to_projection);
|
||||
}
|
||||
|
||||
kexVec4 FrustumPlanes::left_frustum_plane(const kexMatrix &matrix)
|
||||
Vec4 FrustumPlanes::left_frustum_plane(const Mat4 &matrix)
|
||||
{
|
||||
kexVec4 plane(
|
||||
Vec4 plane(
|
||||
matrix[3 + 0 * 4] + matrix[0 + 0 * 4],
|
||||
matrix[3 + 1 * 4] + matrix[0 + 1 * 4],
|
||||
matrix[3 + 2 * 4] + matrix[0 + 2 * 4],
|
||||
|
@ -890,9 +890,9 @@ kexVec4 FrustumPlanes::left_frustum_plane(const kexMatrix &matrix)
|
|||
return plane;
|
||||
}
|
||||
|
||||
kexVec4 FrustumPlanes::right_frustum_plane(const kexMatrix &matrix)
|
||||
Vec4 FrustumPlanes::right_frustum_plane(const Mat4 &matrix)
|
||||
{
|
||||
kexVec4 plane(
|
||||
Vec4 plane(
|
||||
matrix[3 + 0 * 4] - matrix[0 + 0 * 4],
|
||||
matrix[3 + 1 * 4] - matrix[0 + 1 * 4],
|
||||
matrix[3 + 2 * 4] - matrix[0 + 2 * 4],
|
||||
|
@ -901,9 +901,9 @@ kexVec4 FrustumPlanes::right_frustum_plane(const kexMatrix &matrix)
|
|||
return plane;
|
||||
}
|
||||
|
||||
kexVec4 FrustumPlanes::top_frustum_plane(const kexMatrix &matrix)
|
||||
Vec4 FrustumPlanes::top_frustum_plane(const Mat4 &matrix)
|
||||
{
|
||||
kexVec4 plane(
|
||||
Vec4 plane(
|
||||
matrix[3 + 0 * 4] - matrix[1 + 0 * 4],
|
||||
matrix[3 + 1 * 4] - matrix[1 + 1 * 4],
|
||||
matrix[3 + 2 * 4] - matrix[1 + 2 * 4],
|
||||
|
@ -912,9 +912,9 @@ kexVec4 FrustumPlanes::top_frustum_plane(const kexMatrix &matrix)
|
|||
return plane;
|
||||
}
|
||||
|
||||
kexVec4 FrustumPlanes::bottom_frustum_plane(const kexMatrix &matrix)
|
||||
Vec4 FrustumPlanes::bottom_frustum_plane(const Mat4 &matrix)
|
||||
{
|
||||
kexVec4 plane(
|
||||
Vec4 plane(
|
||||
matrix[3 + 0 * 4] + matrix[1 + 0 * 4],
|
||||
matrix[3 + 1 * 4] + matrix[1 + 1 * 4],
|
||||
matrix[3 + 2 * 4] + matrix[1 + 2 * 4],
|
||||
|
@ -923,9 +923,9 @@ kexVec4 FrustumPlanes::bottom_frustum_plane(const kexMatrix &matrix)
|
|||
return plane;
|
||||
}
|
||||
|
||||
kexVec4 FrustumPlanes::near_frustum_plane(const kexMatrix &matrix)
|
||||
Vec4 FrustumPlanes::near_frustum_plane(const Mat4 &matrix)
|
||||
{
|
||||
kexVec4 plane(
|
||||
Vec4 plane(
|
||||
matrix[3 + 0 * 4] + matrix[2 + 0 * 4],
|
||||
matrix[3 + 1 * 4] + matrix[2 + 1 * 4],
|
||||
matrix[3 + 2 * 4] + matrix[2 + 2 * 4],
|
||||
|
@ -934,9 +934,9 @@ kexVec4 FrustumPlanes::near_frustum_plane(const kexMatrix &matrix)
|
|||
return plane;
|
||||
}
|
||||
|
||||
kexVec4 FrustumPlanes::far_frustum_plane(const kexMatrix &matrix)
|
||||
Vec4 FrustumPlanes::far_frustum_plane(const Mat4 &matrix)
|
||||
{
|
||||
kexVec4 plane(
|
||||
Vec4 plane(
|
||||
matrix[3 + 0 * 4] - matrix[2 + 0 * 4],
|
||||
matrix[3 + 1 * 4] - matrix[2 + 1 * 4],
|
||||
matrix[3 + 2 * 4] - matrix[2 + 2 * 4],
|
||||
|
|
|
@ -30,9 +30,9 @@ class SphereShape
|
|||
{
|
||||
public:
|
||||
SphereShape() { }
|
||||
SphereShape(const kexVec3 ¢er, float radius) : center(center), radius(radius) { }
|
||||
SphereShape(const Vec3 ¢er, float radius) : center(center), radius(radius) { }
|
||||
|
||||
kexVec3 center;
|
||||
Vec3 center;
|
||||
float radius = 0.0f;
|
||||
};
|
||||
|
||||
|
@ -44,12 +44,12 @@ struct TraceHit
|
|||
float c = 0.0f;
|
||||
};
|
||||
|
||||
class CollisionBBox : public kexBBox
|
||||
class CollisionBBox : public BBox
|
||||
{
|
||||
public:
|
||||
CollisionBBox() = default;
|
||||
|
||||
CollisionBBox(const kexVec3 &aabb_min, const kexVec3 &aabb_max) : kexBBox(aabb_min, aabb_max)
|
||||
CollisionBBox(const Vec3 &aabb_min, const Vec3 &aabb_max) : BBox(aabb_min, aabb_max)
|
||||
{
|
||||
auto halfmin = aabb_min * 0.5f;
|
||||
auto halfmax = aabb_max * 0.5f;
|
||||
|
@ -57,15 +57,15 @@ public:
|
|||
Extents = halfmax - halfmin;
|
||||
}
|
||||
|
||||
kexVec3 Center;
|
||||
kexVec3 Extents;
|
||||
Vec3 Center;
|
||||
Vec3 Extents;
|
||||
float ssePadding = 0.0f; // Needed to safely load Extents directly into a sse register
|
||||
};
|
||||
|
||||
class RayBBox
|
||||
{
|
||||
public:
|
||||
RayBBox(const kexVec3 &ray_start, const kexVec3 &ray_end) : start(ray_start), end(ray_end)
|
||||
RayBBox(const Vec3 &ray_start, const Vec3 &ray_end) : start(ray_start), end(ray_end)
|
||||
{
|
||||
c = (ray_start + ray_end) * 0.5f;
|
||||
w = ray_end - c;
|
||||
|
@ -74,15 +74,15 @@ public:
|
|||
v.z = std::abs(w.z);
|
||||
}
|
||||
|
||||
kexVec3 start, end;
|
||||
kexVec3 c, w, v;
|
||||
Vec3 start, end;
|
||||
Vec3 c, w, v;
|
||||
float ssePadding = 0.0f; // Needed to safely load v directly into a sse register
|
||||
};
|
||||
|
||||
class TriangleMeshShape
|
||||
{
|
||||
public:
|
||||
TriangleMeshShape(const kexVec3 *vertices, int num_vertices, const unsigned int *elements, int num_elements);
|
||||
TriangleMeshShape(const Vec3 *vertices, int num_vertices, const unsigned int *elements, int num_elements);
|
||||
|
||||
int get_min_depth() const;
|
||||
int get_max_depth() const;
|
||||
|
@ -91,20 +91,20 @@ public:
|
|||
|
||||
const CollisionBBox &get_bbox() const { return nodes[root].aabb; }
|
||||
|
||||
static float sweep(TriangleMeshShape *shape1, SphereShape *shape2, const kexVec3 &target);
|
||||
static float sweep(TriangleMeshShape *shape1, SphereShape *shape2, const Vec3 &target);
|
||||
|
||||
static bool find_any_hit(TriangleMeshShape *shape1, TriangleMeshShape *shape2);
|
||||
static bool find_any_hit(TriangleMeshShape *shape1, SphereShape *shape2);
|
||||
static bool find_any_hit(TriangleMeshShape *shape, const kexVec3 &ray_start, const kexVec3 &ray_end);
|
||||
static bool find_any_hit(TriangleMeshShape *shape, const Vec3 &ray_start, const Vec3 &ray_end);
|
||||
|
||||
static TraceHit find_first_hit(TriangleMeshShape *shape, const kexVec3 &ray_start, const kexVec3 &ray_end);
|
||||
static TraceHit find_first_hit(TriangleMeshShape *shape, const Vec3 &ray_start, const Vec3 &ray_end);
|
||||
|
||||
private:
|
||||
struct Node
|
||||
{
|
||||
Node() = default;
|
||||
Node(const kexVec3 &aabb_min, const kexVec3 &aabb_max, int element_index) : aabb(aabb_min, aabb_max), element_index(element_index) { }
|
||||
Node(const kexVec3 &aabb_min, const kexVec3 &aabb_max, int left, int right) : aabb(aabb_min, aabb_max), left(left), right(right) { }
|
||||
Node(const Vec3 &aabb_min, const Vec3 &aabb_max, int element_index) : aabb(aabb_min, aabb_max), element_index(element_index) { }
|
||||
Node(const Vec3 &aabb_min, const Vec3 &aabb_max, int left, int right) : aabb(aabb_min, aabb_max), left(left), right(right) { }
|
||||
|
||||
CollisionBBox aabb;
|
||||
int left = -1;
|
||||
|
@ -112,7 +112,7 @@ private:
|
|||
int element_index = -1;
|
||||
};
|
||||
|
||||
const kexVec3 *vertices = nullptr;
|
||||
const Vec3 *vertices = nullptr;
|
||||
const int num_vertices = 0;
|
||||
const unsigned int *elements = nullptr;
|
||||
int num_elements = 0;
|
||||
|
@ -120,7 +120,7 @@ private:
|
|||
std::vector<Node> nodes;
|
||||
int root = -1;
|
||||
|
||||
static float sweep(TriangleMeshShape *shape1, SphereShape *shape2, int a, const kexVec3 &target);
|
||||
static float sweep(TriangleMeshShape *shape1, SphereShape *shape2, int a, const Vec3 &target);
|
||||
|
||||
static bool find_any_hit(TriangleMeshShape *shape1, TriangleMeshShape *shape2, int a, int b);
|
||||
static bool find_any_hit(TriangleMeshShape *shape1, SphereShape *shape2, int a);
|
||||
|
@ -131,8 +131,8 @@ private:
|
|||
inline static bool overlap_bv_ray(TriangleMeshShape *shape, const RayBBox &ray, int a);
|
||||
inline static float intersect_triangle_ray(TriangleMeshShape *shape, const RayBBox &ray, int a, float &barycentricB, float &barycentricC);
|
||||
|
||||
inline static bool sweep_overlap_bv_sphere(TriangleMeshShape *shape1, SphereShape *shape2, int a, const kexVec3 &target);
|
||||
inline static float sweep_intersect_triangle_sphere(TriangleMeshShape *shape1, SphereShape *shape2, int a, const kexVec3 &target);
|
||||
inline static bool sweep_overlap_bv_sphere(TriangleMeshShape *shape1, SphereShape *shape2, int a, const Vec3 &target);
|
||||
inline static float sweep_intersect_triangle_sphere(TriangleMeshShape *shape1, SphereShape *shape2, int a, const Vec3 &target);
|
||||
|
||||
inline static bool overlap_bv(TriangleMeshShape *shape1, TriangleMeshShape *shape2, int a, int b);
|
||||
inline static bool overlap_bv_triangle(TriangleMeshShape *shape1, TriangleMeshShape *shape2, int a, int b);
|
||||
|
@ -143,34 +143,34 @@ private:
|
|||
inline bool is_leaf(int node_index);
|
||||
inline float volume(int node_index);
|
||||
|
||||
int subdivide(int *triangles, int num_triangles, const kexVec3 *centroids, int *work_buffer);
|
||||
int subdivide(int *triangles, int num_triangles, const Vec3 *centroids, int *work_buffer);
|
||||
};
|
||||
|
||||
class kexOrientedBBox
|
||||
class OrientedBBox
|
||||
{
|
||||
public:
|
||||
kexVec3 Center;
|
||||
kexVec3 Extents;
|
||||
kexVec3 axis_x;
|
||||
kexVec3 axis_y;
|
||||
kexVec3 axis_z;
|
||||
Vec3 Center;
|
||||
Vec3 Extents;
|
||||
Vec3 axis_x;
|
||||
Vec3 axis_y;
|
||||
Vec3 axis_z;
|
||||
};
|
||||
|
||||
class FrustumPlanes
|
||||
{
|
||||
public:
|
||||
FrustumPlanes();
|
||||
explicit FrustumPlanes(const kexMatrix &world_to_projection);
|
||||
explicit FrustumPlanes(const Mat4 &world_to_projection);
|
||||
|
||||
kexVec4 planes[6];
|
||||
Vec4 planes[6];
|
||||
|
||||
private:
|
||||
static kexVec4 left_frustum_plane(const kexMatrix &matrix);
|
||||
static kexVec4 right_frustum_plane(const kexMatrix &matrix);
|
||||
static kexVec4 top_frustum_plane(const kexMatrix &matrix);
|
||||
static kexVec4 bottom_frustum_plane(const kexMatrix &matrix);
|
||||
static kexVec4 near_frustum_plane(const kexMatrix &matrix);
|
||||
static kexVec4 far_frustum_plane(const kexMatrix &matrix);
|
||||
static Vec4 left_frustum_plane(const Mat4 &matrix);
|
||||
static Vec4 right_frustum_plane(const Mat4 &matrix);
|
||||
static Vec4 top_frustum_plane(const Mat4 &matrix);
|
||||
static Vec4 bottom_frustum_plane(const Mat4 &matrix);
|
||||
static Vec4 near_frustum_plane(const Mat4 &matrix);
|
||||
static Vec4 far_frustum_plane(const Mat4 &matrix);
|
||||
};
|
||||
|
||||
class IntersectionTest
|
||||
|
@ -189,12 +189,12 @@ public:
|
|||
overlap
|
||||
};
|
||||
|
||||
static Result plane_aabb(const kexVec4 &plane, const kexBBox &aabb);
|
||||
static Result plane_obb(const kexVec4 &plane, const kexOrientedBBox &obb);
|
||||
static OverlapResult sphere(const kexVec3 ¢er1, float radius1, const kexVec3 ¢er2, float radius2);
|
||||
static OverlapResult sphere_aabb(const kexVec3 ¢er, float radius, const kexBBox &aabb);
|
||||
static OverlapResult aabb(const kexBBox &a, const kexBBox &b);
|
||||
static Result frustum_aabb(const FrustumPlanes &frustum, const kexBBox &box);
|
||||
static Result frustum_obb(const FrustumPlanes &frustum, const kexOrientedBBox &box);
|
||||
static Result plane_aabb(const Vec4 &plane, const BBox &aabb);
|
||||
static Result plane_obb(const Vec4 &plane, const OrientedBBox &obb);
|
||||
static OverlapResult sphere(const Vec3 ¢er1, float radius1, const Vec3 ¢er2, float radius2);
|
||||
static OverlapResult sphere_aabb(const Vec3 ¢er, float radius, const BBox &aabb);
|
||||
static OverlapResult aabb(const BBox &a, const BBox &b);
|
||||
static Result frustum_aabb(const FrustumPlanes &frustum, const BBox &box);
|
||||
static Result frustum_obb(const FrustumPlanes &frustum, const OrientedBBox &box);
|
||||
static OverlapResult ray_aabb(const RayBBox &ray, const CollisionBBox &box);
|
||||
};
|
||||
|
|
|
@ -49,17 +49,17 @@
|
|||
#endif
|
||||
|
||||
extern int Multisample;
|
||||
extern thread_local kexVec3 *colorSamples;
|
||||
extern thread_local Vec3 *colorSamples;
|
||||
|
||||
kexLightmapBuilder::kexLightmapBuilder()
|
||||
LightmapBuilder::LightmapBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
kexLightmapBuilder::~kexLightmapBuilder()
|
||||
LightmapBuilder::~LightmapBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
void kexLightmapBuilder::NewTexture()
|
||||
void LightmapBuilder::NewTexture()
|
||||
{
|
||||
numTextures++;
|
||||
|
||||
|
@ -68,7 +68,7 @@ void kexLightmapBuilder::NewTexture()
|
|||
}
|
||||
|
||||
// Determines where to map a new block on to the lightmap texture
|
||||
bool kexLightmapBuilder::MakeRoomForBlock(const int width, const int height, int *x, int *y, int *num)
|
||||
bool LightmapBuilder::MakeRoomForBlock(const int width, const int height, int *x, int *y, int *num)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
@ -131,12 +131,12 @@ bool kexLightmapBuilder::MakeRoomForBlock(const int width, const int height, int
|
|||
return false;
|
||||
}
|
||||
|
||||
kexBBox kexLightmapBuilder::GetBoundsFromSurface(const surface_t *surface)
|
||||
BBox LightmapBuilder::GetBoundsFromSurface(const surface_t *surface)
|
||||
{
|
||||
kexVec3 low(M_INFINITY, M_INFINITY, M_INFINITY);
|
||||
kexVec3 hi(-M_INFINITY, -M_INFINITY, -M_INFINITY);
|
||||
Vec3 low(M_INFINITY, M_INFINITY, M_INFINITY);
|
||||
Vec3 hi(-M_INFINITY, -M_INFINITY, -M_INFINITY);
|
||||
|
||||
kexBBox bounds;
|
||||
BBox bounds;
|
||||
bounds.Clear();
|
||||
|
||||
for (int i = 0; i < surface->numVerts; i++)
|
||||
|
@ -161,7 +161,7 @@ kexBBox kexLightmapBuilder::GetBoundsFromSurface(const surface_t *surface)
|
|||
}
|
||||
|
||||
// Traces to the ceiling surface. Will emit light if the surface that was traced is a sky
|
||||
bool kexLightmapBuilder::EmitFromCeiling(const surface_t *surface, const kexVec3 &origin, const kexVec3 &normal, kexVec3 &color)
|
||||
bool LightmapBuilder::EmitFromCeiling(const surface_t *surface, const Vec3 &origin, const Vec3 &normal, Vec3 &color)
|
||||
{
|
||||
float attenuation = surface ? normal.Dot(map->GetSunDirection()) : 1.0f;
|
||||
|
||||
|
@ -207,13 +207,13 @@ static float radians(float degrees)
|
|||
}
|
||||
|
||||
// Traces a line from the texel's origin to the sunlight direction and against all nearby thing lights
|
||||
kexVec3 kexLightmapBuilder::LightTexelSample(const kexVec3 &origin, surface_t *surface)
|
||||
Vec3 LightmapBuilder::LightTexelSample(const Vec3 &origin, surface_t *surface)
|
||||
{
|
||||
kexPlane plane;
|
||||
Plane plane;
|
||||
if (surface)
|
||||
plane = surface->plane;
|
||||
|
||||
kexVec3 color(0.0f, 0.0f, 0.0f);
|
||||
Vec3 color(0.0f, 0.0f, 0.0f);
|
||||
|
||||
// check all thing lights
|
||||
for (unsigned int i = 0; i < map->ThingLights.Size(); i++)
|
||||
|
@ -226,7 +226,7 @@ kexVec3 kexLightmapBuilder::LightTexelSample(const kexVec3 &origin, surface_t *s
|
|||
else
|
||||
originZ = tl->sector->ceilingplane.zAt(tl->origin.x, tl->origin.y) - tl->height;
|
||||
|
||||
kexVec3 lightOrigin(tl->origin.x, tl->origin.y, originZ);
|
||||
Vec3 lightOrigin(tl->origin.x, tl->origin.y, originZ);
|
||||
|
||||
if (surface && plane.Distance(lightOrigin) - plane.d < 0)
|
||||
{
|
||||
|
@ -243,7 +243,7 @@ kexVec3 kexLightmapBuilder::LightTexelSample(const kexVec3 &origin, surface_t *s
|
|||
continue;
|
||||
}
|
||||
|
||||
kexVec3 dir = (lightOrigin - origin);
|
||||
Vec3 dir = (lightOrigin - origin);
|
||||
float dist = dir.Unit();
|
||||
dir.Normalize();
|
||||
|
||||
|
@ -252,11 +252,11 @@ kexVec3 kexLightmapBuilder::LightTexelSample(const kexVec3 &origin, surface_t *s
|
|||
{
|
||||
float negPitch = -radians(tl->mapThing->pitch);
|
||||
float xyLen = std::cos(negPitch);
|
||||
kexVec3 spotDir;
|
||||
Vec3 spotDir;
|
||||
spotDir.x = std::sin(radians(tl->mapThing->angle)) * xyLen;
|
||||
spotDir.y = std::cos(radians(tl->mapThing->angle)) * xyLen;
|
||||
spotDir.z = -std::sin(negPitch);
|
||||
float cosDir = kexVec3::Dot(dir, spotDir);
|
||||
float cosDir = Vec3::Dot(dir, spotDir);
|
||||
spotAttenuation = smoothstep(tl->outerAngleCos, tl->innerAngleCos, cosDir);
|
||||
if (spotAttenuation <= 0.0f)
|
||||
{
|
||||
|
@ -286,14 +286,14 @@ kexVec3 kexLightmapBuilder::LightTexelSample(const kexVec3 &origin, surface_t *s
|
|||
if (!surface || surface->type != ST_CEILING)
|
||||
{
|
||||
// see if it's exposed to sunlight
|
||||
if (EmitFromCeiling(surface, origin, surface ? plane.Normal() : kexVec3::vecUp, color))
|
||||
if (EmitFromCeiling(surface, origin, surface ? plane.Normal() : Vec3::vecUp, color))
|
||||
tracedTexels++;
|
||||
}
|
||||
|
||||
// trace against surface lights
|
||||
for (size_t i = 0; i < lightSurfaces.size(); ++i)
|
||||
{
|
||||
kexLightSurface *surfaceLight = lightSurfaces[i].get();
|
||||
LightSurface *surfaceLight = lightSurfaces[i].get();
|
||||
|
||||
float attenuation = surfaceLight->TraceSurface(mesh.get(), surface, origin);
|
||||
if (attenuation > 0.0f)
|
||||
|
@ -308,15 +308,15 @@ kexVec3 kexLightmapBuilder::LightTexelSample(const kexVec3 &origin, surface_t *s
|
|||
|
||||
// Determines a lightmap block in which to map to the lightmap texture.
|
||||
// Width and height of the block is calcuated and steps are computed to determine where each texel will be positioned on the surface
|
||||
void kexLightmapBuilder::BuildSurfaceParams(surface_t *surface)
|
||||
void LightmapBuilder::BuildSurfaceParams(surface_t *surface)
|
||||
{
|
||||
kexPlane *plane;
|
||||
kexBBox bounds;
|
||||
kexVec3 roundedSize;
|
||||
Plane *plane;
|
||||
BBox bounds;
|
||||
Vec3 roundedSize;
|
||||
int i;
|
||||
kexPlane::planeAxis_t axis;
|
||||
kexVec3 tCoords[2];
|
||||
kexVec3 tOrigin;
|
||||
Plane::planeAxis_t axis;
|
||||
Vec3 tCoords[2];
|
||||
Vec3 tOrigin;
|
||||
int width;
|
||||
int height;
|
||||
float d;
|
||||
|
@ -327,8 +327,8 @@ void kexLightmapBuilder::BuildSurfaceParams(surface_t *surface)
|
|||
// round off dimentions
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
bounds.min[i] = samples * kexMath::Floor(bounds.min[i] / samples);
|
||||
bounds.max[i] = samples * kexMath::Ceil(bounds.max[i] / samples);
|
||||
bounds.min[i] = samples * Math::Floor(bounds.min[i] / samples);
|
||||
bounds.max[i] = samples * Math::Ceil(bounds.max[i] / samples);
|
||||
|
||||
roundedSize[i] = (bounds.max[i] - bounds.min[i]) / samples + 1;
|
||||
}
|
||||
|
@ -340,21 +340,21 @@ void kexLightmapBuilder::BuildSurfaceParams(surface_t *surface)
|
|||
|
||||
switch (axis)
|
||||
{
|
||||
case kexPlane::AXIS_YZ:
|
||||
case Plane::AXIS_YZ:
|
||||
width = (int)roundedSize.y;
|
||||
height = (int)roundedSize.z;
|
||||
tCoords[0].y = 1.0f / samples;
|
||||
tCoords[1].z = 1.0f / samples;
|
||||
break;
|
||||
|
||||
case kexPlane::AXIS_XZ:
|
||||
case Plane::AXIS_XZ:
|
||||
width = (int)roundedSize.x;
|
||||
height = (int)roundedSize.z;
|
||||
tCoords[0].x = 1.0f / samples;
|
||||
tCoords[1].z = 1.0f / samples;
|
||||
break;
|
||||
|
||||
case kexPlane::AXIS_XY:
|
||||
case Plane::AXIS_XY:
|
||||
width = (int)roundedSize.x;
|
||||
height = (int)roundedSize.y;
|
||||
tCoords[0].x = 1.0f / samples;
|
||||
|
@ -404,13 +404,13 @@ void kexLightmapBuilder::BuildSurfaceParams(surface_t *surface)
|
|||
|
||||
// Steps through each texel and traces a line to the world.
|
||||
// For each non-occluded trace, color is accumulated and saved off into the lightmap texture based on what block is mapped to
|
||||
void kexLightmapBuilder::TraceSurface(surface_t *surface)
|
||||
void LightmapBuilder::TraceSurface(surface_t *surface)
|
||||
{
|
||||
int sampleWidth;
|
||||
int sampleHeight;
|
||||
kexVec3 normal;
|
||||
kexVec3 pos;
|
||||
kexVec3 tDelta;
|
||||
Vec3 normal;
|
||||
Vec3 pos;
|
||||
Vec3 tDelta;
|
||||
int i;
|
||||
int j;
|
||||
uint16_t *currentTexture;
|
||||
|
@ -428,11 +428,11 @@ void kexLightmapBuilder::TraceSurface(surface_t *surface)
|
|||
{
|
||||
for (j = 0; j < sampleWidth; j++)
|
||||
{
|
||||
kexVec3 c(0.0f, 0.0f, 0.0f);
|
||||
Vec3 c(0.0f, 0.0f, 0.0f);
|
||||
|
||||
for (int k = 0; k < multisampleCount; k++)
|
||||
{
|
||||
kexVec2 multisamplePos((float)j, (float)i);
|
||||
Vec2 multisamplePos((float)j, (float)i);
|
||||
if (k > 0)
|
||||
{
|
||||
multisamplePos.x += rand() / (float)RAND_MAX - 0.5f;
|
||||
|
@ -541,12 +541,12 @@ static float RadicalInverse_VdC(uint32_t bits)
|
|||
return float(bits) * 2.3283064365386963e-10f; // / 0x100000000
|
||||
}
|
||||
|
||||
static kexVec2 Hammersley(uint32_t i, uint32_t N)
|
||||
static Vec2 Hammersley(uint32_t i, uint32_t N)
|
||||
{
|
||||
return kexVec2(float(i) / float(N), RadicalInverse_VdC(i));
|
||||
return Vec2(float(i) / float(N), RadicalInverse_VdC(i));
|
||||
}
|
||||
|
||||
static kexVec3 ImportanceSampleGGX(kexVec2 Xi, kexVec3 N, float roughness)
|
||||
static Vec3 ImportanceSampleGGX(Vec2 Xi, Vec3 N, float roughness)
|
||||
{
|
||||
float a = roughness * roughness;
|
||||
|
||||
|
@ -555,18 +555,18 @@ static kexVec3 ImportanceSampleGGX(kexVec2 Xi, kexVec3 N, float roughness)
|
|||
float sinTheta = sqrt(1.0f - cosTheta * cosTheta);
|
||||
|
||||
// from spherical coordinates to cartesian coordinates
|
||||
kexVec3 H(std::cos(phi) * sinTheta, std::sin(phi) * sinTheta, cosTheta);
|
||||
Vec3 H(std::cos(phi) * sinTheta, std::sin(phi) * sinTheta, cosTheta);
|
||||
|
||||
// from tangent-space vector to world-space sample vector
|
||||
kexVec3 up = std::abs(N.z) < 0.999f ? kexVec3(0.0f, 0.0f, 1.0f) : kexVec3(1.0f, 0.0f, 0.0f);
|
||||
kexVec3 tangent = kexVec3::Normalize(kexVec3::Cross(up, N));
|
||||
kexVec3 bitangent = kexVec3::Cross(N, tangent);
|
||||
Vec3 up = std::abs(N.z) < 0.999f ? Vec3(0.0f, 0.0f, 1.0f) : Vec3(1.0f, 0.0f, 0.0f);
|
||||
Vec3 tangent = Vec3::Normalize(Vec3::Cross(up, N));
|
||||
Vec3 bitangent = Vec3::Cross(N, tangent);
|
||||
|
||||
kexVec3 sampleVec = tangent * H.x + bitangent * H.y + N * H.z;
|
||||
return kexVec3::Normalize(sampleVec);
|
||||
Vec3 sampleVec = tangent * H.x + bitangent * H.y + N * H.z;
|
||||
return Vec3::Normalize(sampleVec);
|
||||
}
|
||||
|
||||
void kexLightmapBuilder::TraceIndirectLight(surface_t *surface)
|
||||
void LightmapBuilder::TraceIndirectLight(surface_t *surface)
|
||||
{
|
||||
if (surface->lightmapNum == -1)
|
||||
return;
|
||||
|
@ -574,7 +574,7 @@ void kexLightmapBuilder::TraceIndirectLight(surface_t *surface)
|
|||
int sampleWidth = surface->lightmapDims[0];
|
||||
int sampleHeight = surface->lightmapDims[1];
|
||||
|
||||
kexVec3 normal = surface->plane.Normal();
|
||||
Vec3 normal = surface->plane.Normal();
|
||||
|
||||
uint16_t *currentTexture = &indirectoutput[surface->lightmapNum * textureWidth * textureHeight * 3];
|
||||
|
||||
|
@ -582,29 +582,29 @@ void kexLightmapBuilder::TraceIndirectLight(surface_t *surface)
|
|||
{
|
||||
for (int j = 0; j < sampleWidth; j++)
|
||||
{
|
||||
kexVec3 pos = surface->lightmapOrigin + normal +
|
||||
Vec3 pos = surface->lightmapOrigin + normal +
|
||||
(surface->lightmapSteps[0] * (float)j) +
|
||||
(surface->lightmapSteps[1] * (float)i);
|
||||
|
||||
const int SAMPLE_COUNT = 128;// 1024;
|
||||
|
||||
float totalWeight = 0.0f;
|
||||
kexVec3 c(0.0f, 0.0f, 0.0f);
|
||||
Vec3 c(0.0f, 0.0f, 0.0f);
|
||||
|
||||
for (int i = 0; i < SAMPLE_COUNT; i++)
|
||||
{
|
||||
kexVec2 Xi = Hammersley(i, SAMPLE_COUNT);
|
||||
kexVec3 H = ImportanceSampleGGX(Xi, normal, 1.0f);
|
||||
kexVec3 L = kexVec3::Normalize(H * (2.0f * kexVec3::Dot(normal, H)) - normal);
|
||||
Vec2 Xi = Hammersley(i, SAMPLE_COUNT);
|
||||
Vec3 H = ImportanceSampleGGX(Xi, normal, 1.0f);
|
||||
Vec3 L = Vec3::Normalize(H * (2.0f * Vec3::Dot(normal, H)) - normal);
|
||||
|
||||
float NdotL = std::max(kexVec3::Dot(normal, L), 0.0f);
|
||||
float NdotL = std::max(Vec3::Dot(normal, L), 0.0f);
|
||||
if (NdotL > 0.0f)
|
||||
{
|
||||
tracedTexels++;
|
||||
LevelTraceHit hit = mesh->Trace(pos, pos + L * 1000.0f);
|
||||
if (hit.fraction < 1.0f)
|
||||
{
|
||||
kexVec3 surfaceLight;
|
||||
Vec3 surfaceLight;
|
||||
if (hit.hitSurface->bSky)
|
||||
{
|
||||
surfaceLight = { 0.5f, 0.5f, 0.5f };
|
||||
|
@ -651,7 +651,7 @@ void kexLightmapBuilder::TraceIndirectLight(surface_t *surface)
|
|||
}
|
||||
}
|
||||
|
||||
void kexLightmapBuilder::LightSurface(const int surfid)
|
||||
void LightmapBuilder::LightSurfacex(const int surfid)
|
||||
{
|
||||
BuildSurfaceParams(mesh->surfaces[surfid].get());
|
||||
TraceSurface(mesh->surfaces[surfid].get());
|
||||
|
@ -669,7 +669,7 @@ void kexLightmapBuilder::LightSurface(const int surfid)
|
|||
}
|
||||
}
|
||||
|
||||
void kexLightmapBuilder::LightIndirect(const int surfid)
|
||||
void LightmapBuilder::LightIndirect(const int surfid)
|
||||
{
|
||||
TraceIndirectLight(mesh->surfaces[surfid].get());
|
||||
|
||||
|
@ -684,7 +684,7 @@ void kexLightmapBuilder::LightIndirect(const int surfid)
|
|||
}
|
||||
}
|
||||
|
||||
void kexLightmapBuilder::CreateLightSurfaces()
|
||||
void LightmapBuilder::CreateLightSurfaces()
|
||||
{
|
||||
for (size_t j = 0; j < mesh->surfaces.size(); ++j)
|
||||
{
|
||||
|
@ -695,7 +695,7 @@ void kexLightmapBuilder::CreateLightSurfaces()
|
|||
int lightdefidx = map->Sides[surface->typeIndex].lightdef;
|
||||
if (lightdefidx != -1)
|
||||
{
|
||||
auto lightSurface = std::make_unique<kexLightSurface>(map->SurfaceLights[lightdefidx], surface);
|
||||
auto lightSurface = std::make_unique<LightSurface>(map->SurfaceLights[lightdefidx], surface);
|
||||
lightSurface->Subdivide(16);
|
||||
lightSurfaces.push_back(std::move(lightSurface));
|
||||
}
|
||||
|
@ -709,13 +709,13 @@ void kexLightmapBuilder::CreateLightSurfaces()
|
|||
{
|
||||
if (sector->floorlightdef != -1 && surface->type == ST_FLOOR)
|
||||
{
|
||||
auto lightSurface = std::make_unique<kexLightSurface>(map->SurfaceLights[sector->floorlightdef], surface);
|
||||
auto lightSurface = std::make_unique<LightSurface>(map->SurfaceLights[sector->floorlightdef], surface);
|
||||
lightSurface->Subdivide(16);
|
||||
lightSurfaces.push_back(std::move(lightSurface));
|
||||
}
|
||||
else if (sector->ceilinglightdef != -1 && surface->type == ST_CEILING)
|
||||
{
|
||||
auto lightSurface = std::make_unique<kexLightSurface>(map->SurfaceLights[sector->ceilinglightdef], surface);
|
||||
auto lightSurface = std::make_unique<LightSurface>(map->SurfaceLights[sector->ceilinglightdef], surface);
|
||||
lightSurface->Subdivide(16);
|
||||
lightSurfaces.push_back(std::move(lightSurface));
|
||||
}
|
||||
|
@ -724,7 +724,7 @@ void kexLightmapBuilder::CreateLightSurfaces()
|
|||
}
|
||||
}
|
||||
|
||||
void kexLightmapBuilder::CreateLightmaps(FLevel &doomMap)
|
||||
void LightmapBuilder::CreateLightmaps(FLevel &doomMap)
|
||||
{
|
||||
map = &doomMap;
|
||||
mesh = std::make_unique<LevelMesh>(doomMap);
|
||||
|
@ -737,7 +737,7 @@ void kexLightmapBuilder::CreateLightmaps(FLevel &doomMap)
|
|||
|
||||
processed = 0;
|
||||
tracedTexels = 0;
|
||||
kexWorker::RunJob(grid.blocks.size(), [=](int id) {
|
||||
Worker::RunJob(grid.blocks.size(), [=](int id) {
|
||||
LightBlock(id);
|
||||
});
|
||||
|
||||
|
@ -747,8 +747,8 @@ void kexLightmapBuilder::CreateLightmaps(FLevel &doomMap)
|
|||
|
||||
tracedTexels = 0;
|
||||
processed = 0;
|
||||
kexWorker::RunJob(mesh->surfaces.size(), [=](int id) {
|
||||
LightSurface(id);
|
||||
Worker::RunJob(mesh->surfaces.size(), [=](int id) {
|
||||
LightSurfacex(id);
|
||||
});
|
||||
|
||||
printf("Texels traced: %i \n\n", tracedTexels);
|
||||
|
@ -759,7 +759,7 @@ void kexLightmapBuilder::CreateLightmaps(FLevel &doomMap)
|
|||
|
||||
tracedTexels = 0;
|
||||
processed = 0;
|
||||
kexWorker::RunJob(mesh->surfaces.size(), [=](int id) {
|
||||
Worker::RunJob(mesh->surfaces.size(), [=](int id) {
|
||||
LightIndirect(id);
|
||||
});
|
||||
|
||||
|
@ -777,9 +777,9 @@ void kexLightmapBuilder::CreateLightmaps(FLevel &doomMap)
|
|||
printf("Texels traced: %i \n\n", tracedTexels);
|
||||
}
|
||||
|
||||
void kexLightmapBuilder::SetupLightCellGrid()
|
||||
void LightmapBuilder::SetupLightCellGrid()
|
||||
{
|
||||
kexBBox worldBBox = mesh->CollisionMesh->get_bbox();
|
||||
BBox worldBBox = mesh->CollisionMesh->get_bbox();
|
||||
float blockWorldSize = LIGHTCELL_BLOCK_SIZE * LIGHTCELL_SIZE;
|
||||
grid.x = static_cast<int>(std::floor(worldBBox.min.x / blockWorldSize));
|
||||
grid.y = static_cast<int>(std::floor(worldBBox.min.y / blockWorldSize));
|
||||
|
@ -788,7 +788,7 @@ void kexLightmapBuilder::SetupLightCellGrid()
|
|||
grid.blocks.resize(grid.width * grid.height);
|
||||
}
|
||||
|
||||
void kexLightmapBuilder::LightBlock(int id)
|
||||
void LightmapBuilder::LightBlock(int id)
|
||||
{
|
||||
float blockWorldSize = LIGHTCELL_BLOCK_SIZE * LIGHTCELL_SIZE;
|
||||
|
||||
|
@ -855,7 +855,7 @@ void kexLightmapBuilder::LightBlock(int id)
|
|||
{
|
||||
float cellWorldZ = (block.z + zz + 0.5f) * LIGHTCELL_SIZE;
|
||||
|
||||
kexVec3 color;
|
||||
Vec3 color;
|
||||
if (cellWorldZ > floors[idx] && cellWorldZ < ceilings[idx])
|
||||
{
|
||||
color = LightTexelSample({ cellWorldX, cellWorldY, cellWorldZ }, nullptr);
|
||||
|
@ -890,7 +890,7 @@ void kexLightmapBuilder::LightBlock(int id)
|
|||
}
|
||||
}
|
||||
|
||||
void kexLightmapBuilder::AddLightmapLump(FWadWriter &wadFile)
|
||||
void LightmapBuilder::AddLightmapLump(FWadWriter &wadFile)
|
||||
{
|
||||
const auto &surfaces = mesh->surfaces;
|
||||
|
||||
|
@ -919,7 +919,7 @@ void kexLightmapBuilder::AddLightmapLump(FWadWriter &wadFile)
|
|||
|
||||
// Setup buffer
|
||||
std::vector<uint8_t> buffer(lumpSize);
|
||||
kexBinFile lumpFile;
|
||||
BinFile lumpFile;
|
||||
lumpFile.SetBuffer(buffer.data());
|
||||
|
||||
// Write header
|
||||
|
@ -1035,9 +1035,9 @@ void kexLightmapBuilder::AddLightmapLump(FWadWriter &wadFile)
|
|||
}
|
||||
|
||||
/*
|
||||
void kexLightmapBuilder::WriteTexturesToTGA()
|
||||
void LightmapBuilder::WriteTexturesToTGA()
|
||||
{
|
||||
kexBinFile file;
|
||||
BinFile file;
|
||||
|
||||
for (unsigned int i = 0; i < textures.size(); i++)
|
||||
{
|
||||
|
|
|
@ -37,14 +37,14 @@
|
|||
#define LIGHTCELL_BLOCK_SIZE 16
|
||||
|
||||
class FWadWriter;
|
||||
class kexLightSurface;
|
||||
class LightSurface;
|
||||
|
||||
class LightCellBlock
|
||||
{
|
||||
public:
|
||||
int z;
|
||||
int layers;
|
||||
TArray<kexVec3> cells;
|
||||
TArray<Vec3> cells;
|
||||
};
|
||||
|
||||
class LightCellGrid
|
||||
|
@ -55,11 +55,11 @@ public:
|
|||
std::vector<LightCellBlock> blocks;
|
||||
};
|
||||
|
||||
class kexLightmapBuilder
|
||||
class LightmapBuilder
|
||||
{
|
||||
public:
|
||||
kexLightmapBuilder();
|
||||
~kexLightmapBuilder();
|
||||
LightmapBuilder();
|
||||
~LightmapBuilder();
|
||||
|
||||
void CreateLightmaps(FLevel &doomMap);
|
||||
//void WriteTexturesToTGA();
|
||||
|
@ -73,23 +73,23 @@ public:
|
|||
private:
|
||||
void NewTexture();
|
||||
bool MakeRoomForBlock(const int width, const int height, int *x, int *y, int *num);
|
||||
kexBBox GetBoundsFromSurface(const surface_t *surface);
|
||||
kexVec3 LightTexelSample(const kexVec3 &origin, surface_t *surface);
|
||||
bool EmitFromCeiling(const surface_t *surface, const kexVec3 &origin, const kexVec3 &normal, kexVec3 &color);
|
||||
BBox GetBoundsFromSurface(const surface_t *surface);
|
||||
Vec3 LightTexelSample(const Vec3 &origin, surface_t *surface);
|
||||
bool EmitFromCeiling(const surface_t *surface, const Vec3 &origin, const Vec3 &normal, Vec3 &color);
|
||||
|
||||
void BuildSurfaceParams(surface_t *surface);
|
||||
void TraceSurface(surface_t *surface);
|
||||
void TraceIndirectLight(surface_t *surface);
|
||||
void SetupLightCellGrid();
|
||||
void LightBlock(int blockid);
|
||||
void LightSurface(const int surfid);
|
||||
void LightSurfacex(const int surfid);
|
||||
void LightIndirect(const int surfid);
|
||||
|
||||
void CreateLightSurfaces();
|
||||
|
||||
std::unique_ptr<LevelMesh> mesh;
|
||||
FLevel *map;
|
||||
std::vector<std::unique_ptr<kexLightSurface>> lightSurfaces;
|
||||
std::vector<std::unique_ptr<LightSurface>> lightSurfaces;
|
||||
std::vector<std::vector<uint16_t>> textures;
|
||||
std::vector<uint16_t> indirectoutput;
|
||||
std::vector<std::vector<int>> allocBlocks;
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#include "level/level.h"
|
||||
#include "lightsurface.h"
|
||||
|
||||
kexLightSurface::kexLightSurface(const surfaceLightDef &lightSurfaceDef, surface_t *surface)
|
||||
LightSurface::LightSurface(const surfaceLightDef &lightSurfaceDef, surface_t *surface)
|
||||
{
|
||||
this->intensity = lightSurfaceDef.intensity;
|
||||
this->distance = lightSurfaceDef.distance;
|
||||
|
@ -44,12 +44,12 @@ kexLightSurface::kexLightSurface(const surfaceLightDef &lightSurfaceDef, surface
|
|||
this->surface = surface;
|
||||
}
|
||||
|
||||
kexLightSurface::~kexLightSurface()
|
||||
LightSurface::~LightSurface()
|
||||
{
|
||||
}
|
||||
|
||||
// Splits surface vertices into two groups while adding new ones caused by the split
|
||||
void kexLightSurface::Clip(vertexBatch_t &points, const kexVec3 &normal, float dist, vertexBatch_t *frontPoints, vertexBatch_t *backPoints)
|
||||
void LightSurface::Clip(vertexBatch_t &points, const Vec3 &normal, float dist, vertexBatch_t *frontPoints, vertexBatch_t *backPoints)
|
||||
{
|
||||
std::vector<float> dists;
|
||||
std::vector<char> sides;
|
||||
|
@ -80,7 +80,7 @@ void kexLightSurface::Clip(vertexBatch_t &points, const kexVec3 &normal, float d
|
|||
{
|
||||
int next;
|
||||
float frac;
|
||||
kexVec3 pt1, pt2, pt3;
|
||||
Vec3 pt1, pt2, pt3;
|
||||
|
||||
switch (sides[i])
|
||||
{
|
||||
|
@ -123,10 +123,10 @@ void kexLightSurface::Clip(vertexBatch_t &points, const kexVec3 &normal, float d
|
|||
}
|
||||
|
||||
// Recursively divides the surface
|
||||
bool kexLightSurface::SubdivideRecursion(vertexBatch_t &surfPoints, float divide, std::vector<std::unique_ptr<vertexBatch_t>> &points)
|
||||
bool LightSurface::SubdivideRecursion(vertexBatch_t &surfPoints, float divide, std::vector<std::unique_ptr<vertexBatch_t>> &points)
|
||||
{
|
||||
kexBBox bounds;
|
||||
kexVec3 splitNormal;
|
||||
BBox bounds;
|
||||
Vec3 splitNormal;
|
||||
float dist;
|
||||
|
||||
// get bounds from current set of points
|
||||
|
@ -168,7 +168,7 @@ bool kexLightSurface::SubdivideRecursion(vertexBatch_t &surfPoints, float divide
|
|||
return false;
|
||||
}
|
||||
|
||||
void kexLightSurface::Subdivide(const float divide)
|
||||
void LightSurface::Subdivide(const float divide)
|
||||
{
|
||||
if (surface->type == ST_CEILING || surface->type == ST_FLOOR)
|
||||
{
|
||||
|
@ -187,7 +187,7 @@ void kexLightSurface::Subdivide(const float divide)
|
|||
for (size_t i = 0; i < points.size(); ++i)
|
||||
{
|
||||
vertexBatch_t *vb = points[i].get();
|
||||
kexVec3 center;
|
||||
Vec3 center;
|
||||
|
||||
for (unsigned int j = 0; j < vb->size(); ++j)
|
||||
{
|
||||
|
@ -202,8 +202,8 @@ void kexLightSurface::Subdivide(const float divide)
|
|||
float length = surface->verts[0].Distance(surface->verts[1]);
|
||||
if (length < divide)
|
||||
{
|
||||
kexVec3 top = surface->verts[0] * 0.5f + surface->verts[1] * 0.5f;
|
||||
kexVec3 bottom = surface->verts[2] * 0.5f + surface->verts[3] * 0.5f;
|
||||
Vec3 top = surface->verts[0] * 0.5f + surface->verts[1] * 0.5f;
|
||||
Vec3 bottom = surface->verts[2] * 0.5f + surface->verts[3] * 0.5f;
|
||||
origins.push_back(top * 0.5f + bottom * 0.5f);
|
||||
}
|
||||
else
|
||||
|
@ -216,8 +216,8 @@ void kexLightSurface::Subdivide(const float divide)
|
|||
{
|
||||
float t = i / length;
|
||||
|
||||
kexVec3 top = surface->verts[0] * (1.0f - t) + surface->verts[1] * t;
|
||||
kexVec3 bottom = surface->verts[2] * (1.0f - t) + surface->verts[3] * t;
|
||||
Vec3 top = surface->verts[0] * (1.0f - t) + surface->verts[1] * t;
|
||||
Vec3 bottom = surface->verts[2] * (1.0f - t) + surface->verts[3] * t;
|
||||
|
||||
float length2 = top.Distance(bottom);
|
||||
if (length2 < divide)
|
||||
|
@ -241,13 +241,13 @@ void kexLightSurface::Subdivide(const float divide)
|
|||
}
|
||||
}
|
||||
|
||||
float kexLightSurface::TraceSurface(LevelMesh *mesh, const surface_t *fragmentSurface, const kexVec3 &fragmentPos)
|
||||
float LightSurface::TraceSurface(LevelMesh *mesh, const surface_t *fragmentSurface, const Vec3 &fragmentPos)
|
||||
{
|
||||
if (fragmentSurface == surface)
|
||||
return 1.0f; // light surface will always be fullbright
|
||||
|
||||
kexVec3 lightSurfaceNormal = surface->plane.Normal();
|
||||
kexVec3 fragmentNormal = fragmentSurface ? fragmentSurface->plane.Normal() : kexVec3(0.0f, 0.0f, 0.0f);
|
||||
Vec3 lightSurfaceNormal = surface->plane.Normal();
|
||||
Vec3 fragmentNormal = fragmentSurface ? fragmentSurface->plane.Normal() : Vec3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
float gzdoomRadiusScale = 2.0f; // 2.0 because gzdoom's dynlights do this and we want them to match
|
||||
|
||||
|
@ -257,16 +257,16 @@ float kexLightSurface::TraceSurface(LevelMesh *mesh, const surface_t *fragmentSu
|
|||
float maxDistanceSqr = closestDistance * closestDistance;
|
||||
for (size_t i = 0; i < origins.size(); ++i)
|
||||
{
|
||||
kexVec3 lightPos = origins[i];
|
||||
kexVec3 lightDir = (lightPos - fragmentPos);
|
||||
Vec3 lightPos = origins[i];
|
||||
Vec3 lightDir = (lightPos - fragmentPos);
|
||||
|
||||
float dsqr = kexVec3::Dot(lightDir, lightDir);
|
||||
float dsqr = Vec3::Dot(lightDir, lightDir);
|
||||
if (dsqr > maxDistanceSqr)
|
||||
continue; // out of range
|
||||
|
||||
count++;
|
||||
|
||||
float attenuation = fragmentSurface ? kexVec3::Dot(lightDir, fragmentNormal) : 1.0f;
|
||||
float attenuation = fragmentSurface ? Vec3::Dot(lightDir, fragmentNormal) : 1.0f;
|
||||
if (attenuation <= 0.0f)
|
||||
continue; // not even facing the light surface
|
||||
|
||||
|
|
|
@ -32,29 +32,29 @@
|
|||
struct FLevel;
|
||||
struct surfaceLightDef;
|
||||
|
||||
class kexLightSurface
|
||||
class LightSurface
|
||||
{
|
||||
public:
|
||||
kexLightSurface(const surfaceLightDef &lightSurfaceDef, surface_t *surface);
|
||||
~kexLightSurface();
|
||||
LightSurface(const surfaceLightDef &lightSurfaceDef, surface_t *surface);
|
||||
~LightSurface();
|
||||
|
||||
void Subdivide(const float divide);
|
||||
float TraceSurface(LevelMesh *map, const surface_t *surface, const kexVec3 &origin);
|
||||
float TraceSurface(LevelMesh *map, const surface_t *surface, const Vec3 &origin);
|
||||
|
||||
const float Distance() const { return distance; }
|
||||
const float Intensity() const { return intensity; }
|
||||
const kexVec3 GetRGB() const { return rgb; }
|
||||
const Vec3 GetRGB() const { return rgb; }
|
||||
const surface_t *Surface() const { return surface; }
|
||||
|
||||
private:
|
||||
typedef std::vector<kexVec3> vertexBatch_t;
|
||||
typedef std::vector<Vec3> vertexBatch_t;
|
||||
|
||||
bool SubdivideRecursion(vertexBatch_t &surfPoints, float divide, std::vector<std::unique_ptr<vertexBatch_t>> &points);
|
||||
void Clip(vertexBatch_t &points, const kexVec3 &normal, float dist, vertexBatch_t *frontPoints, vertexBatch_t *backPoints);
|
||||
void Clip(vertexBatch_t &points, const Vec3 &normal, float dist, vertexBatch_t *frontPoints, vertexBatch_t *backPoints);
|
||||
|
||||
float distance;
|
||||
float intensity;
|
||||
kexVec3 rgb;
|
||||
Vec3 rgb;
|
||||
vertexBatch_t origins;
|
||||
surface_t *surface;
|
||||
};
|
||||
|
|
|
@ -287,7 +287,7 @@ void LevelMesh::CreateFloorSurface(FLevel &doomMap, MapSubsectorEx *sub, IntSect
|
|||
}
|
||||
else
|
||||
{
|
||||
surf->plane = kexPlane::Inverse(sector->ceilingplane);
|
||||
surf->plane = Plane::Inverse(sector->ceilingplane);
|
||||
}
|
||||
|
||||
for (int j = 0; j < surf->numVerts; j++)
|
||||
|
@ -320,7 +320,7 @@ void LevelMesh::CreateCeilingSurface(FLevel &doomMap, MapSubsectorEx *sub, IntSe
|
|||
}
|
||||
else
|
||||
{
|
||||
surf->plane = kexPlane::Inverse(sector->floorplane);
|
||||
surf->plane = Plane::Inverse(sector->floorplane);
|
||||
}
|
||||
|
||||
for (int j = 0; j < surf->numVerts; j++)
|
||||
|
@ -372,7 +372,7 @@ void LevelMesh::CreateSubsectorSurfaces(FLevel &doomMap)
|
|||
printf("\nLeaf surfaces: %i\n", (int)surfaces.size() - doomMap.NumGLSubsectors);
|
||||
}
|
||||
|
||||
LevelTraceHit LevelMesh::Trace(const kexVec3 &startVec, const kexVec3 &endVec)
|
||||
LevelTraceHit LevelMesh::Trace(const Vec3 &startVec, const Vec3 &endVec)
|
||||
{
|
||||
TraceHit hit = TriangleMeshShape::find_first_hit(CollisionMesh.get(), startVec, endVec);
|
||||
|
||||
|
@ -402,12 +402,12 @@ LevelTraceHit LevelMesh::Trace(const kexVec3 &startVec, const kexVec3 &endVec)
|
|||
return trace;
|
||||
}
|
||||
|
||||
bool LevelMesh::TraceAnyHit(const kexVec3 &startVec, const kexVec3 &endVec)
|
||||
bool LevelMesh::TraceAnyHit(const Vec3 &startVec, const Vec3 &endVec)
|
||||
{
|
||||
return TriangleMeshShape::find_any_hit(CollisionMesh.get(), startVec, endVec);
|
||||
}
|
||||
|
||||
bool LevelMesh::IsDegenerate(const kexVec3 &v0, const kexVec3 &v1, const kexVec3 &v2)
|
||||
bool LevelMesh::IsDegenerate(const Vec3 &v0, const Vec3 &v1, const Vec3 &v2)
|
||||
{
|
||||
// A degenerate triangle has a zero cross product for two of its sides.
|
||||
float ax = v1.x - v0.x;
|
||||
|
|
|
@ -53,16 +53,16 @@ enum surfaceType_t
|
|||
|
||||
struct surface_t
|
||||
{
|
||||
kexPlane plane;
|
||||
Plane plane;
|
||||
int lightmapNum;
|
||||
int lightmapOffs[2];
|
||||
int lightmapDims[2];
|
||||
kexVec3 lightmapOrigin;
|
||||
kexVec3 lightmapSteps[2];
|
||||
kexVec3 textureCoords[2];
|
||||
kexBBox bounds;
|
||||
Vec3 lightmapOrigin;
|
||||
Vec3 lightmapSteps[2];
|
||||
Vec3 textureCoords[2];
|
||||
BBox bounds;
|
||||
int numVerts;
|
||||
std::vector<kexVec3> verts;
|
||||
std::vector<Vec3> verts;
|
||||
std::vector<float> lightmapCoords;
|
||||
surfaceType_t type;
|
||||
int typeIndex;
|
||||
|
@ -72,8 +72,8 @@ struct surface_t
|
|||
|
||||
struct LevelTraceHit
|
||||
{
|
||||
kexVec3 start;
|
||||
kexVec3 end;
|
||||
Vec3 start;
|
||||
Vec3 end;
|
||||
float fraction;
|
||||
|
||||
surface_t *hitSurface;
|
||||
|
@ -86,14 +86,14 @@ class LevelMesh
|
|||
public:
|
||||
LevelMesh(FLevel &doomMap);
|
||||
|
||||
LevelTraceHit Trace(const kexVec3 &startVec, const kexVec3 &endVec);
|
||||
bool TraceAnyHit(const kexVec3 &startVec, const kexVec3 &endVec);
|
||||
LevelTraceHit Trace(const Vec3 &startVec, const Vec3 &endVec);
|
||||
bool TraceAnyHit(const Vec3 &startVec, const Vec3 &endVec);
|
||||
|
||||
void WriteMeshToOBJ();
|
||||
|
||||
std::vector<std::unique_ptr<surface_t>> surfaces;
|
||||
|
||||
TArray<kexVec3> MeshVertices;
|
||||
TArray<Vec3> MeshVertices;
|
||||
TArray<int> MeshUVIndex;
|
||||
TArray<unsigned int> MeshElements;
|
||||
TArray<int> MeshSurfaces;
|
||||
|
@ -106,5 +106,5 @@ private:
|
|||
|
||||
void CreateSideSurfaces(FLevel &doomMap, IntSideDef *side);
|
||||
|
||||
static bool IsDegenerate(const kexVec3 &v0, const kexVec3 &v1, const kexVec3 &v2);
|
||||
static bool IsDegenerate(const Vec3 &v0, const Vec3 &v1, const Vec3 &v2);
|
||||
};
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
|
||||
extern int NumThreads;
|
||||
|
||||
thread_local kexVec3 *colorSamples;
|
||||
thread_local Vec3 *colorSamples;
|
||||
|
||||
void kexWorker::RunJob(int count, std::function<void(int)> callback)
|
||||
void Worker::RunJob(int count, std::function<void(int)> callback)
|
||||
{
|
||||
int numThreads = NumThreads;
|
||||
if (numThreads <= 0)
|
||||
|
@ -25,7 +25,7 @@ void kexWorker::RunJob(int count, std::function<void(int)> callback)
|
|||
{
|
||||
threads.push_back(std::thread([=]() {
|
||||
|
||||
std::vector<kexVec3> samples(LIGHTMAP_MAX_SIZE * LIGHTMAP_MAX_SIZE);
|
||||
std::vector<Vec3> samples(LIGHTMAP_MAX_SIZE * LIGHTMAP_MAX_SIZE);
|
||||
colorSamples = samples.data();
|
||||
|
||||
int start = threadIndex * count / numThreads;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <functional>
|
||||
|
||||
class kexWorker
|
||||
class Worker
|
||||
{
|
||||
public:
|
||||
static void RunJob(int count, std::function<void(int i)> callback);
|
||||
|
|
|
@ -437,13 +437,13 @@ static void ParseArgs(int argc, char **argv)
|
|||
Samples = atoi(optarg);
|
||||
if (Samples <= 0) Samples = 1;
|
||||
if (Samples > 128) Samples = 128;
|
||||
Samples = kexMath::RoundPowerOfTwo(Samples);
|
||||
Samples = Math::RoundPowerOfTwo(Samples);
|
||||
break;
|
||||
case 'S':
|
||||
LMDims = atoi(optarg);
|
||||
if (LMDims <= 0) LMDims = 1;
|
||||
if (LMDims > LIGHTMAP_MAX_SIZE) LMDims = LIGHTMAP_MAX_SIZE;
|
||||
LMDims = kexMath::RoundPowerOfTwo(LMDims);
|
||||
LMDims = Math::RoundPowerOfTwo(LMDims);
|
||||
break;
|
||||
case 'M':
|
||||
Multisample = atoi(optarg);
|
||||
|
|
|
@ -37,10 +37,10 @@
|
|||
#define FULLCIRCLE (M_PI * 2)
|
||||
|
||||
//
|
||||
// kexAngle::kexAngle
|
||||
// Angle::Angle
|
||||
//
|
||||
|
||||
kexAngle::kexAngle()
|
||||
Angle::Angle()
|
||||
{
|
||||
this->yaw = 0;
|
||||
this->pitch = 0;
|
||||
|
@ -48,10 +48,10 @@ kexAngle::kexAngle()
|
|||
}
|
||||
|
||||
//
|
||||
// kexAngle::kexAngle
|
||||
// Angle::Angle
|
||||
//
|
||||
|
||||
kexAngle::kexAngle(const float yaw, const float pitch, const float roll)
|
||||
Angle::Angle(const float yaw, const float pitch, const float roll)
|
||||
{
|
||||
this->yaw = yaw;
|
||||
this->pitch = pitch;
|
||||
|
@ -59,10 +59,10 @@ kexAngle::kexAngle(const float yaw, const float pitch, const float roll)
|
|||
}
|
||||
|
||||
//
|
||||
// kexAngle::kexAngle
|
||||
// Angle::Angle
|
||||
//
|
||||
|
||||
kexAngle::kexAngle(const kexVec3 &vector)
|
||||
Angle::Angle(const Vec3 &vector)
|
||||
{
|
||||
this->yaw = vector.x;
|
||||
this->pitch = vector.y;
|
||||
|
@ -72,10 +72,10 @@ kexAngle::kexAngle(const kexVec3 &vector)
|
|||
}
|
||||
|
||||
//
|
||||
// kexAngle::kexAngle
|
||||
// Angle::Angle
|
||||
//
|
||||
|
||||
kexAngle::kexAngle(const kexAngle &an)
|
||||
Angle::Angle(const Angle &an)
|
||||
{
|
||||
this->yaw = an.yaw;
|
||||
this->pitch = an.pitch;
|
||||
|
@ -83,10 +83,10 @@ kexAngle::kexAngle(const kexAngle &an)
|
|||
}
|
||||
|
||||
//
|
||||
// kexAngle::Clamp180
|
||||
// Angle::Clamp180
|
||||
//
|
||||
|
||||
kexAngle &kexAngle::Clamp180()
|
||||
Angle &Angle::Clamp180()
|
||||
{
|
||||
#define CLAMP180(x) \
|
||||
if(x < -M_PI) for(; x < -M_PI; x = x + FULLCIRCLE); \
|
||||
|
@ -100,10 +100,10 @@ kexAngle &kexAngle::Clamp180()
|
|||
}
|
||||
|
||||
//
|
||||
// kexAngle::Clamp180Invert
|
||||
// Angle::Clamp180Invert
|
||||
//
|
||||
|
||||
kexAngle &kexAngle::Clamp180Invert()
|
||||
Angle &Angle::Clamp180Invert()
|
||||
{
|
||||
#define CLAMP180(x) \
|
||||
for(; x < -M_PI; x = x + FULLCIRCLE); \
|
||||
|
@ -121,12 +121,12 @@ kexAngle &kexAngle::Clamp180Invert()
|
|||
}
|
||||
|
||||
//
|
||||
// kexAngle::Clamp180InvertSum
|
||||
// Angle::Clamp180InvertSum
|
||||
//
|
||||
|
||||
kexAngle &kexAngle::Clamp180InvertSum(const kexAngle &angle)
|
||||
Angle &Angle::Clamp180InvertSum(const Angle &angle)
|
||||
{
|
||||
kexAngle an = angle;
|
||||
Angle an = angle;
|
||||
|
||||
an.Clamp180Invert();
|
||||
|
||||
|
@ -144,10 +144,10 @@ kexAngle &kexAngle::Clamp180InvertSum(const kexAngle &angle)
|
|||
}
|
||||
|
||||
//
|
||||
// kexAngle::Round
|
||||
// Angle::Round
|
||||
//
|
||||
|
||||
kexAngle &kexAngle::Round()
|
||||
Angle &Angle::Round()
|
||||
{
|
||||
#define ROUND(x) \
|
||||
x = DEG2RAD((360.0f / 65536.0f) * \
|
||||
|
@ -161,13 +161,13 @@ kexAngle &kexAngle::Round()
|
|||
}
|
||||
|
||||
//
|
||||
// kexAngle::Diff
|
||||
// Angle::Diff
|
||||
//
|
||||
|
||||
kexAngle kexAngle::Diff(kexAngle &angle)
|
||||
Angle Angle::Diff(Angle &angle)
|
||||
{
|
||||
float an;
|
||||
kexAngle out;
|
||||
Angle out;
|
||||
|
||||
Clamp180();
|
||||
angle.Clamp180();
|
||||
|
@ -200,17 +200,17 @@ kexAngle kexAngle::Diff(kexAngle &angle)
|
|||
}
|
||||
|
||||
//
|
||||
// kexAngle::ToAxis
|
||||
// Angle::ToAxis
|
||||
//
|
||||
|
||||
void kexAngle::ToAxis(kexVec3 *forward, kexVec3 *up, kexVec3 *right)
|
||||
void Angle::ToAxis(Vec3 *forward, Vec3 *up, Vec3 *right)
|
||||
{
|
||||
float sy = kexMath::Sin(yaw);
|
||||
float cy = kexMath::Cos(yaw);
|
||||
float sp = kexMath::Sin(pitch);
|
||||
float cp = kexMath::Cos(pitch);
|
||||
float sr = kexMath::Sin(roll);
|
||||
float cr = kexMath::Cos(roll);
|
||||
float sy = Math::Sin(yaw);
|
||||
float cy = Math::Cos(yaw);
|
||||
float sp = Math::Sin(pitch);
|
||||
float cp = Math::Cos(pitch);
|
||||
float sr = Math::Sin(roll);
|
||||
float cr = Math::Cos(roll);
|
||||
|
||||
if (forward)
|
||||
{
|
||||
|
@ -233,103 +233,103 @@ void kexAngle::ToAxis(kexVec3 *forward, kexVec3 *up, kexVec3 *right)
|
|||
}
|
||||
|
||||
//
|
||||
// kexAngle::ToForwardAxis
|
||||
// Angle::ToForwardAxis
|
||||
//
|
||||
|
||||
kexVec3 kexAngle::ToForwardAxis()
|
||||
Vec3 Angle::ToForwardAxis()
|
||||
{
|
||||
kexVec3 vec;
|
||||
Vec3 vec;
|
||||
|
||||
ToAxis(&vec, nullptr, nullptr);
|
||||
return vec;
|
||||
}
|
||||
|
||||
//
|
||||
// kexAngle::ToUpAxis
|
||||
// Angle::ToUpAxis
|
||||
//
|
||||
|
||||
kexVec3 kexAngle::ToUpAxis()
|
||||
Vec3 Angle::ToUpAxis()
|
||||
{
|
||||
kexVec3 vec;
|
||||
Vec3 vec;
|
||||
|
||||
ToAxis(nullptr, &vec, nullptr);
|
||||
return vec;
|
||||
}
|
||||
|
||||
//
|
||||
// kexAngle::ToRightAxis
|
||||
// Angle::ToRightAxis
|
||||
//
|
||||
|
||||
kexVec3 kexAngle::ToRightAxis()
|
||||
Vec3 Angle::ToRightAxis()
|
||||
{
|
||||
kexVec3 vec;
|
||||
Vec3 vec;
|
||||
|
||||
ToAxis(nullptr, nullptr, &vec);
|
||||
return vec;
|
||||
}
|
||||
|
||||
//
|
||||
// kexAngle::ToVec3
|
||||
// Angle::ToVec3
|
||||
//
|
||||
|
||||
const kexVec3 &kexAngle::ToVec3() const
|
||||
const Vec3 &Angle::ToVec3() const
|
||||
{
|
||||
return *reinterpret_cast<const kexVec3*>(&yaw);
|
||||
return *reinterpret_cast<const Vec3*>(&yaw);
|
||||
}
|
||||
|
||||
//
|
||||
// kexAngle::ToVec3
|
||||
// Angle::ToVec3
|
||||
//
|
||||
|
||||
kexVec3 &kexAngle::ToVec3()
|
||||
Vec3 &Angle::ToVec3()
|
||||
{
|
||||
return *reinterpret_cast<kexVec3*>(&yaw);
|
||||
return *reinterpret_cast<Vec3*>(&yaw);
|
||||
}
|
||||
|
||||
//
|
||||
// kexAngle::ToQuat
|
||||
// Angle::ToQuat
|
||||
//
|
||||
|
||||
kexQuat kexAngle::ToQuat()
|
||||
Quat Angle::ToQuat()
|
||||
{
|
||||
return
|
||||
(kexQuat(pitch, kexVec3::vecRight) *
|
||||
(kexQuat(yaw, kexVec3::vecUp) *
|
||||
kexQuat(roll, kexVec3::vecForward)));
|
||||
(Quat(pitch, Vec3::vecRight) *
|
||||
(Quat(yaw, Vec3::vecUp) *
|
||||
Quat(roll, Vec3::vecForward)));
|
||||
}
|
||||
|
||||
//
|
||||
// kexAngle::operator+
|
||||
// Angle::operator+
|
||||
//
|
||||
|
||||
kexAngle kexAngle::operator+(const kexAngle &angle)
|
||||
Angle Angle::operator+(const Angle &angle)
|
||||
{
|
||||
return kexAngle(yaw + angle.yaw, pitch + angle.pitch, roll + angle.roll);
|
||||
return Angle(yaw + angle.yaw, pitch + angle.pitch, roll + angle.roll);
|
||||
}
|
||||
|
||||
//
|
||||
// kexAngle::operator-
|
||||
// Angle::operator-
|
||||
//
|
||||
|
||||
kexAngle kexAngle::operator-(const kexAngle &angle)
|
||||
Angle Angle::operator-(const Angle &angle)
|
||||
{
|
||||
return kexAngle(yaw - angle.yaw, pitch - angle.pitch, roll - angle.roll);
|
||||
return Angle(yaw - angle.yaw, pitch - angle.pitch, roll - angle.roll);
|
||||
}
|
||||
|
||||
//
|
||||
// kexAngle::operator-
|
||||
// Angle::operator-
|
||||
//
|
||||
|
||||
kexAngle kexAngle::operator-()
|
||||
Angle Angle::operator-()
|
||||
{
|
||||
return kexAngle(-yaw, -pitch, -roll);
|
||||
return Angle(-yaw, -pitch, -roll);
|
||||
}
|
||||
|
||||
//
|
||||
// kexAngle::operator+=
|
||||
// Angle::operator+=
|
||||
//
|
||||
|
||||
kexAngle &kexAngle::operator+=(const kexAngle &angle)
|
||||
Angle &Angle::operator+=(const Angle &angle)
|
||||
{
|
||||
yaw += angle.yaw;
|
||||
pitch += angle.pitch;
|
||||
|
@ -338,10 +338,10 @@ kexAngle &kexAngle::operator+=(const kexAngle &angle)
|
|||
}
|
||||
|
||||
//
|
||||
// kexAngle::operator-=
|
||||
// Angle::operator-=
|
||||
//
|
||||
|
||||
kexAngle &kexAngle::operator-=(const kexAngle &angle)
|
||||
Angle &Angle::operator-=(const Angle &angle)
|
||||
{
|
||||
yaw -= angle.yaw;
|
||||
pitch -= angle.pitch;
|
||||
|
@ -350,10 +350,10 @@ kexAngle &kexAngle::operator-=(const kexAngle &angle)
|
|||
}
|
||||
|
||||
//
|
||||
// kexAngle::operator=
|
||||
// Angle::operator=
|
||||
//
|
||||
|
||||
kexAngle &kexAngle::operator=(const kexAngle &angle)
|
||||
Angle &Angle::operator=(const Angle &angle)
|
||||
{
|
||||
yaw = angle.yaw;
|
||||
pitch = angle.pitch;
|
||||
|
@ -362,10 +362,10 @@ kexAngle &kexAngle::operator=(const kexAngle &angle)
|
|||
}
|
||||
|
||||
//
|
||||
// kexAngle::operator=
|
||||
// Angle::operator=
|
||||
//
|
||||
|
||||
kexAngle &kexAngle::operator=(const kexVec3 &vector)
|
||||
Angle &Angle::operator=(const Vec3 &vector)
|
||||
{
|
||||
yaw = vector.x;
|
||||
pitch = vector.y;
|
||||
|
@ -374,10 +374,10 @@ kexAngle &kexAngle::operator=(const kexVec3 &vector)
|
|||
}
|
||||
|
||||
//
|
||||
// kexAngle::operator=
|
||||
// Angle::operator=
|
||||
//
|
||||
|
||||
kexAngle &kexAngle::operator=(const float *vecs)
|
||||
Angle &Angle::operator=(const float *vecs)
|
||||
{
|
||||
yaw = vecs[0];
|
||||
pitch = vecs[1];
|
||||
|
@ -386,20 +386,20 @@ kexAngle &kexAngle::operator=(const float *vecs)
|
|||
}
|
||||
|
||||
//
|
||||
// kexAngle::operator[]
|
||||
// Angle::operator[]
|
||||
//
|
||||
|
||||
float kexAngle::operator[](int index) const
|
||||
float Angle::operator[](int index) const
|
||||
{
|
||||
assert(index >= 0 && index < 3);
|
||||
return (&yaw)[index];
|
||||
}
|
||||
|
||||
//
|
||||
// kexAngle::operator[]
|
||||
// Angle::operator[]
|
||||
//
|
||||
|
||||
float &kexAngle::operator[](int index)
|
||||
float &Angle::operator[](int index)
|
||||
{
|
||||
assert(index >= 0 && index < 3);
|
||||
return (&yaw)[index];
|
||||
|
|
|
@ -35,39 +35,39 @@
|
|||
#include <assert.h>
|
||||
|
||||
//
|
||||
// kexBBox::kexBBox
|
||||
// BBox::BBox
|
||||
//
|
||||
|
||||
kexBBox::kexBBox()
|
||||
BBox::BBox()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
//
|
||||
// kexBBox::kexBBox
|
||||
// BBox::BBox
|
||||
//
|
||||
|
||||
kexBBox::kexBBox(const kexVec3 &vMin, const kexVec3 &vMax)
|
||||
BBox::BBox(const Vec3 &vMin, const Vec3 &vMax)
|
||||
{
|
||||
this->min = vMin;
|
||||
this->max = vMax;
|
||||
}
|
||||
|
||||
//
|
||||
// kexBBox::Clear
|
||||
// BBox::Clear
|
||||
//
|
||||
|
||||
void kexBBox::Clear()
|
||||
void BBox::Clear()
|
||||
{
|
||||
min.Set(M_INFINITY, M_INFINITY, M_INFINITY);
|
||||
max.Set(-M_INFINITY, -M_INFINITY, -M_INFINITY);
|
||||
}
|
||||
|
||||
//
|
||||
// kexBBox::AddPoint
|
||||
// BBox::AddPoint
|
||||
//
|
||||
|
||||
void kexBBox::AddPoint(const kexVec3 &vec)
|
||||
void BBox::AddPoint(const Vec3 &vec)
|
||||
{
|
||||
float lowx = min.x;
|
||||
float lowy = min.y;
|
||||
|
@ -88,10 +88,10 @@ void kexBBox::AddPoint(const kexVec3 &vec)
|
|||
}
|
||||
|
||||
//
|
||||
// kexBBox::Radius
|
||||
// BBox::Radius
|
||||
//
|
||||
|
||||
float kexBBox::Radius() const
|
||||
float BBox::Radius() const
|
||||
{
|
||||
int i;
|
||||
float r = 0;
|
||||
|
@ -100,8 +100,8 @@ float kexBBox::Radius() const
|
|||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
r1 = kexMath::Fabs(min[i]);
|
||||
r2 = kexMath::Fabs(max[i]);
|
||||
r1 = Math::Fabs(min[i]);
|
||||
r2 = Math::Fabs(max[i]);
|
||||
|
||||
if (r1 > r2)
|
||||
{
|
||||
|
@ -113,46 +113,46 @@ float kexBBox::Radius() const
|
|||
}
|
||||
}
|
||||
|
||||
return kexMath::Sqrt(r);
|
||||
return Math::Sqrt(r);
|
||||
}
|
||||
|
||||
//
|
||||
// kexBBox::PointInside
|
||||
// BBox::PointInside
|
||||
//
|
||||
|
||||
bool kexBBox::PointInside(const kexVec3 &vec) const
|
||||
bool BBox::PointInside(const Vec3 &vec) const
|
||||
{
|
||||
return !(vec[0] < min[0] || vec[1] < min[1] || vec[2] < min[2] ||
|
||||
vec[0] > max[0] || vec[1] > max[1] || vec[2] > max[2]);
|
||||
}
|
||||
|
||||
//
|
||||
// kexBBox::IntersectingBox
|
||||
// BBox::IntersectingBox
|
||||
//
|
||||
|
||||
bool kexBBox::IntersectingBox(const kexBBox &box) const
|
||||
bool BBox::IntersectingBox(const BBox &box) const
|
||||
{
|
||||
return !(box.max[0] < min[0] || box.max[1] < min[1] || box.max[2] < min[2] ||
|
||||
box.min[0] > max[0] || box.min[1] > max[1] || box.min[2] > max[2]);
|
||||
}
|
||||
|
||||
//
|
||||
// kexBBox::IntersectingBox2D
|
||||
// BBox::IntersectingBox2D
|
||||
//
|
||||
|
||||
bool kexBBox::IntersectingBox2D(const kexBBox &box) const
|
||||
bool BBox::IntersectingBox2D(const BBox &box) const
|
||||
{
|
||||
return !(box.max[0] < min[0] || box.max[2] < min[2] ||
|
||||
box.min[0] > max[0] || box.min[2] > max[2]);
|
||||
}
|
||||
|
||||
//
|
||||
// kexBBox::DistanceToPlane
|
||||
// BBox::DistanceToPlane
|
||||
//
|
||||
|
||||
float kexBBox::DistanceToPlane(kexPlane &plane)
|
||||
float BBox::DistanceToPlane(Plane &plane)
|
||||
{
|
||||
kexVec3 c;
|
||||
Vec3 c;
|
||||
float distStart;
|
||||
float distEnd;
|
||||
float dist = 0;
|
||||
|
@ -160,9 +160,9 @@ float kexBBox::DistanceToPlane(kexPlane &plane)
|
|||
c = Center();
|
||||
|
||||
distStart = plane.Distance(c);
|
||||
distEnd = kexMath::Fabs((max.x - c.x) * plane.a) +
|
||||
kexMath::Fabs((max.y - c.y) * plane.b) +
|
||||
kexMath::Fabs((max.z - c.z) * plane.c);
|
||||
distEnd = Math::Fabs((max.x - c.x) * plane.a) +
|
||||
Math::Fabs((max.y - c.y) * plane.b) +
|
||||
Math::Fabs((max.z - c.z) * plane.c);
|
||||
|
||||
dist = distStart - distEnd;
|
||||
|
||||
|
@ -184,13 +184,13 @@ float kexBBox::DistanceToPlane(kexPlane &plane)
|
|||
}
|
||||
|
||||
//
|
||||
// kexBBox::operator+
|
||||
// BBox::operator+
|
||||
//
|
||||
|
||||
kexBBox kexBBox::operator+(const float radius) const
|
||||
BBox BBox::operator+(const float radius) const
|
||||
{
|
||||
kexVec3 vmin = min;
|
||||
kexVec3 vmax = max;
|
||||
Vec3 vmin = min;
|
||||
Vec3 vmax = max;
|
||||
|
||||
vmin.x -= radius;
|
||||
vmin.y -= radius;
|
||||
|
@ -200,14 +200,14 @@ kexBBox kexBBox::operator+(const float radius) const
|
|||
vmax.y += radius;
|
||||
vmax.z += radius;
|
||||
|
||||
return kexBBox(vmin, vmax);
|
||||
return BBox(vmin, vmax);
|
||||
}
|
||||
|
||||
//
|
||||
// kexBBox::operator+=
|
||||
// BBox::operator+=
|
||||
//
|
||||
|
||||
kexBBox &kexBBox::operator+=(const float radius)
|
||||
BBox &BBox::operator+=(const float radius)
|
||||
{
|
||||
min.x -= radius;
|
||||
min.y -= radius;
|
||||
|
@ -219,13 +219,13 @@ kexBBox &kexBBox::operator+=(const float radius)
|
|||
}
|
||||
|
||||
//
|
||||
// kexBBox::operator+
|
||||
// BBox::operator+
|
||||
//
|
||||
|
||||
kexBBox kexBBox::operator+(const kexVec3 &vec) const
|
||||
BBox BBox::operator+(const Vec3 &vec) const
|
||||
{
|
||||
kexVec3 vmin = min;
|
||||
kexVec3 vmax = max;
|
||||
Vec3 vmin = min;
|
||||
Vec3 vmax = max;
|
||||
|
||||
vmin.x += vec.x;
|
||||
vmin.y += vec.y;
|
||||
|
@ -235,17 +235,17 @@ kexBBox kexBBox::operator+(const kexVec3 &vec) const
|
|||
vmax.y += vec.y;
|
||||
vmax.z += vec.z;
|
||||
|
||||
return kexBBox(vmin, vmax);
|
||||
return BBox(vmin, vmax);
|
||||
}
|
||||
|
||||
//
|
||||
// kexBBox::operator-
|
||||
// BBox::operator-
|
||||
//
|
||||
|
||||
kexBBox kexBBox::operator-(const float radius) const
|
||||
BBox BBox::operator-(const float radius) const
|
||||
{
|
||||
kexVec3 vmin = min;
|
||||
kexVec3 vmax = max;
|
||||
Vec3 vmin = min;
|
||||
Vec3 vmax = max;
|
||||
|
||||
vmin.x += radius;
|
||||
vmin.y += radius;
|
||||
|
@ -255,17 +255,17 @@ kexBBox kexBBox::operator-(const float radius) const
|
|||
vmax.y -= radius;
|
||||
vmax.z -= radius;
|
||||
|
||||
return kexBBox(vmin, vmax);
|
||||
return BBox(vmin, vmax);
|
||||
}
|
||||
|
||||
//
|
||||
// kexBBox::operator-
|
||||
// BBox::operator-
|
||||
//
|
||||
|
||||
kexBBox kexBBox::operator-(const kexVec3 &vec) const
|
||||
BBox BBox::operator-(const Vec3 &vec) const
|
||||
{
|
||||
kexVec3 vmin = min;
|
||||
kexVec3 vmax = max;
|
||||
Vec3 vmin = min;
|
||||
Vec3 vmax = max;
|
||||
|
||||
vmin.x -= vec.x;
|
||||
vmin.y -= vec.y;
|
||||
|
@ -275,14 +275,14 @@ kexBBox kexBBox::operator-(const kexVec3 &vec) const
|
|||
vmax.y -= vec.y;
|
||||
vmax.z -= vec.z;
|
||||
|
||||
return kexBBox(vmin, vmax);
|
||||
return BBox(vmin, vmax);
|
||||
}
|
||||
|
||||
//
|
||||
// kexBBox::operator-=
|
||||
// BBox::operator-=
|
||||
//
|
||||
|
||||
kexBBox &kexBBox::operator-=(const float radius)
|
||||
BBox &BBox::operator-=(const float radius)
|
||||
{
|
||||
min.x += radius;
|
||||
min.y += radius;
|
||||
|
@ -294,25 +294,25 @@ kexBBox &kexBBox::operator-=(const float radius)
|
|||
}
|
||||
|
||||
//
|
||||
// kexBBox::operator*
|
||||
// BBox::operator*
|
||||
//
|
||||
|
||||
kexBBox kexBBox::operator*(const kexMatrix &matrix) const
|
||||
BBox BBox::operator*(const Mat4 &matrix) const
|
||||
{
|
||||
kexVec3 c = Center();
|
||||
kexVec3 ct = c * matrix;
|
||||
kexBBox box(ct, ct);
|
||||
Vec3 c = Center();
|
||||
Vec3 ct = c * matrix;
|
||||
BBox box(ct, ct);
|
||||
|
||||
kexMatrix mtx(matrix);
|
||||
Mat4 mtx(matrix);
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
mtx.vectors[i].x = kexMath::Fabs(mtx.vectors[i].x);
|
||||
mtx.vectors[i].y = kexMath::Fabs(mtx.vectors[i].y);
|
||||
mtx.vectors[i].z = kexMath::Fabs(mtx.vectors[i].z);
|
||||
mtx.vectors[i].x = Math::Fabs(mtx.vectors[i].x);
|
||||
mtx.vectors[i].y = Math::Fabs(mtx.vectors[i].y);
|
||||
mtx.vectors[i].z = Math::Fabs(mtx.vectors[i].z);
|
||||
}
|
||||
|
||||
kexVec3 ht = (max - c) * mtx;
|
||||
Vec3 ht = (max - c) * mtx;
|
||||
box.min -= ht;
|
||||
box.max += ht;
|
||||
|
||||
|
@ -320,24 +320,24 @@ kexBBox kexBBox::operator*(const kexMatrix &matrix) const
|
|||
}
|
||||
|
||||
//
|
||||
// kexBBox::operator*=
|
||||
// BBox::operator*=
|
||||
//
|
||||
|
||||
kexBBox &kexBBox::operator*=(const kexMatrix &matrix)
|
||||
BBox &BBox::operator*=(const Mat4 &matrix)
|
||||
{
|
||||
kexVec3 c = Center();
|
||||
kexVec3 ct = c * matrix;
|
||||
Vec3 c = Center();
|
||||
Vec3 ct = c * matrix;
|
||||
|
||||
kexMatrix mtx(matrix);
|
||||
Mat4 mtx(matrix);
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
mtx.vectors[i].x = kexMath::Fabs(mtx.vectors[i].x);
|
||||
mtx.vectors[i].y = kexMath::Fabs(mtx.vectors[i].y);
|
||||
mtx.vectors[i].z = kexMath::Fabs(mtx.vectors[i].z);
|
||||
mtx.vectors[i].x = Math::Fabs(mtx.vectors[i].x);
|
||||
mtx.vectors[i].y = Math::Fabs(mtx.vectors[i].y);
|
||||
mtx.vectors[i].z = Math::Fabs(mtx.vectors[i].z);
|
||||
}
|
||||
|
||||
kexVec3 ht = (max - c) * mtx;
|
||||
Vec3 ht = (max - c) * mtx;
|
||||
|
||||
min = (ct - ht);
|
||||
max = (ct + ht);
|
||||
|
@ -346,12 +346,12 @@ kexBBox &kexBBox::operator*=(const kexMatrix &matrix)
|
|||
}
|
||||
|
||||
//
|
||||
// kexBBox::operator*
|
||||
// BBox::operator*
|
||||
//
|
||||
|
||||
kexBBox kexBBox::operator*(const kexVec3 &vec) const
|
||||
BBox BBox::operator*(const Vec3 &vec) const
|
||||
{
|
||||
kexBBox box = *this;
|
||||
BBox box = *this;
|
||||
|
||||
if (vec.x < 0) { box.min.x += (vec.x - 1); }
|
||||
else { box.max.x += (vec.x + 1); }
|
||||
|
@ -364,10 +364,10 @@ kexBBox kexBBox::operator*(const kexVec3 &vec) const
|
|||
}
|
||||
|
||||
//
|
||||
// kexBBox::operator*=
|
||||
// BBox::operator*=
|
||||
//
|
||||
|
||||
kexBBox &kexBBox::operator*=(const kexVec3 &vec)
|
||||
BBox &BBox::operator*=(const Vec3 &vec)
|
||||
{
|
||||
if (vec.x < 0) { min.x += (vec.x - 1); }
|
||||
else { max.x += (vec.x + 1); }
|
||||
|
@ -380,10 +380,10 @@ kexBBox &kexBBox::operator*=(const kexVec3 &vec)
|
|||
}
|
||||
|
||||
//
|
||||
// kexBBox::operator=
|
||||
// BBox::operator=
|
||||
//
|
||||
|
||||
kexBBox &kexBBox::operator=(const kexBBox &bbox)
|
||||
BBox &BBox::operator=(const BBox &bbox)
|
||||
{
|
||||
min = bbox.min;
|
||||
max = bbox.max;
|
||||
|
@ -392,61 +392,61 @@ kexBBox &kexBBox::operator=(const kexBBox &bbox)
|
|||
}
|
||||
|
||||
//
|
||||
// kexBBox::operator[]
|
||||
// BBox::operator[]
|
||||
//
|
||||
|
||||
kexVec3 kexBBox::operator[](int index) const
|
||||
Vec3 BBox::operator[](int index) const
|
||||
{
|
||||
assert(index >= 0 && index < 2);
|
||||
return index == 0 ? min : max;
|
||||
}
|
||||
|
||||
//
|
||||
// kexBBox::operator[]
|
||||
// BBox::operator[]
|
||||
//
|
||||
|
||||
kexVec3 &kexBBox::operator[](int index)
|
||||
Vec3 &BBox::operator[](int index)
|
||||
{
|
||||
assert(index >= 0 && index < 2);
|
||||
return index == 0 ? min : max;
|
||||
}
|
||||
|
||||
//
|
||||
// kexBBox:LineIntersect
|
||||
// BBox:LineIntersect
|
||||
//
|
||||
|
||||
bool kexBBox::LineIntersect(const kexVec3 &start, const kexVec3 &end)
|
||||
bool BBox::LineIntersect(const Vec3 &start, const Vec3 &end)
|
||||
{
|
||||
float ld[3];
|
||||
kexVec3 center = Center();
|
||||
kexVec3 extents = max - center;
|
||||
kexVec3 lineDir = (end - start) * 0.5f;
|
||||
kexVec3 lineCenter = lineDir + start;
|
||||
kexVec3 dir = lineCenter - center;
|
||||
Vec3 center = Center();
|
||||
Vec3 extents = max - center;
|
||||
Vec3 lineDir = (end - start) * 0.5f;
|
||||
Vec3 lineCenter = lineDir + start;
|
||||
Vec3 dir = lineCenter - center;
|
||||
|
||||
ld[0] = kexMath::Fabs(lineDir.x);
|
||||
if (kexMath::Fabs(dir.x) > extents.x + ld[0]) { return false; }
|
||||
ld[1] = kexMath::Fabs(lineDir.y);
|
||||
if (kexMath::Fabs(dir.y) > extents.y + ld[1]) { return false; }
|
||||
ld[2] = kexMath::Fabs(lineDir.z);
|
||||
if (kexMath::Fabs(dir.z) > extents.z + ld[2]) { return false; }
|
||||
ld[0] = Math::Fabs(lineDir.x);
|
||||
if (Math::Fabs(dir.x) > extents.x + ld[0]) { return false; }
|
||||
ld[1] = Math::Fabs(lineDir.y);
|
||||
if (Math::Fabs(dir.y) > extents.y + ld[1]) { return false; }
|
||||
ld[2] = Math::Fabs(lineDir.z);
|
||||
if (Math::Fabs(dir.z) > extents.z + ld[2]) { return false; }
|
||||
|
||||
kexVec3 cross = lineDir.Cross(dir);
|
||||
Vec3 cross = lineDir.Cross(dir);
|
||||
|
||||
if (kexMath::Fabs(cross.x) > extents.y * ld[2] + extents.z * ld[1]) { return false; }
|
||||
if (kexMath::Fabs(cross.y) > extents.x * ld[2] + extents.z * ld[0]) { return false; }
|
||||
if (kexMath::Fabs(cross.z) > extents.x * ld[1] + extents.y * ld[0]) { return false; }
|
||||
if (Math::Fabs(cross.x) > extents.y * ld[2] + extents.z * ld[1]) { return false; }
|
||||
if (Math::Fabs(cross.y) > extents.x * ld[2] + extents.z * ld[0]) { return false; }
|
||||
if (Math::Fabs(cross.z) > extents.x * ld[1] + extents.y * ld[0]) { return false; }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// kexBBox::ToPoints
|
||||
// BBox::ToPoints
|
||||
//
|
||||
// Assumes points is an array of 24
|
||||
//
|
||||
|
||||
void kexBBox::ToPoints(float *points) const
|
||||
void BBox::ToPoints(float *points) const
|
||||
{
|
||||
points[0 * 3 + 0] = max[0];
|
||||
points[0 * 3 + 1] = min[1];
|
||||
|
@ -475,12 +475,12 @@ void kexBBox::ToPoints(float *points) const
|
|||
}
|
||||
|
||||
//
|
||||
// kexBBox::ToVectors
|
||||
// BBox::ToVectors
|
||||
//
|
||||
// Assumes vectors is an array of 8
|
||||
//
|
||||
|
||||
void kexBBox::ToVectors(kexVec3 *vectors) const
|
||||
void BBox::ToVectors(Vec3 *vectors) const
|
||||
{
|
||||
vectors[0][0] = max[0];
|
||||
vectors[0][1] = min[1];
|
||||
|
|
|
@ -33,10 +33,10 @@
|
|||
#include "mathlib.h"
|
||||
|
||||
//
|
||||
// kexMath::RoundPowerOfTwo
|
||||
// Math::RoundPowerOfTwo
|
||||
//
|
||||
|
||||
int kexMath::RoundPowerOfTwo(int x)
|
||||
int Math::RoundPowerOfTwo(int x)
|
||||
{
|
||||
int mask = 1;
|
||||
|
||||
|
@ -54,19 +54,19 @@ int kexMath::RoundPowerOfTwo(int x)
|
|||
}
|
||||
|
||||
//
|
||||
// kexMath::CubicCurve
|
||||
// Math::CubicCurve
|
||||
//
|
||||
|
||||
void kexMath::CubicCurve(const kexVec3 &start, const kexVec3 &end, const float time,
|
||||
const kexVec3 &point, kexVec3 *vec)
|
||||
void Math::CubicCurve(const Vec3 &start, const Vec3 &end, const float time,
|
||||
const Vec3 &point, Vec3 *vec)
|
||||
{
|
||||
int i;
|
||||
float xyz[3];
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
xyz[i] = kexMath::Pow(1 - time, 2) * start[i] +
|
||||
(2 * (1 - time)) * time * point[i] + kexMath::Pow(time, 2) * end[i];
|
||||
xyz[i] = Math::Pow(1 - time, 2) * start[i] +
|
||||
(2 * (1 - time)) * time * point[i] + Math::Pow(time, 2) * end[i];
|
||||
}
|
||||
|
||||
vec->x = xyz[0];
|
||||
|
@ -75,20 +75,20 @@ void kexMath::CubicCurve(const kexVec3 &start, const kexVec3 &end, const float t
|
|||
}
|
||||
|
||||
//
|
||||
// kexMath::QuadraticCurve
|
||||
// Math::QuadraticCurve
|
||||
//
|
||||
|
||||
void kexMath::QuadraticCurve(const kexVec3 &start, const kexVec3 &end, const float time,
|
||||
const kexVec3 &pt1, const kexVec3 &pt2, kexVec3 *vec)
|
||||
void Math::QuadraticCurve(const Vec3 &start, const Vec3 &end, const float time,
|
||||
const Vec3 &pt1, const Vec3 &pt2, Vec3 *vec)
|
||||
{
|
||||
int i;
|
||||
float xyz[3];
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
xyz[i] = kexMath::Pow(1 - time, 3) * start[i] + (3 * kexMath::Pow(1 - time, 2)) *
|
||||
time * pt1[i] + (3 * (1 - time)) * kexMath::Pow(time, 2) * pt2[i] +
|
||||
kexMath::Pow(time, 3) * end[i];
|
||||
xyz[i] = Math::Pow(1 - time, 3) * start[i] + (3 * Math::Pow(1 - time, 2)) *
|
||||
time * pt1[i] + (3 * (1 - time)) * Math::Pow(time, 2) * pt2[i] +
|
||||
Math::Pow(time, 3) * end[i];
|
||||
}
|
||||
|
||||
vec->x = xyz[0];
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -74,19 +74,19 @@
|
|||
#include "mathlib.h"
|
||||
|
||||
//
|
||||
// kexMatrix::kexMatrix
|
||||
// Mat4::Mat4
|
||||
//
|
||||
|
||||
kexMatrix::kexMatrix()
|
||||
Mat4::Mat4()
|
||||
{
|
||||
Identity();
|
||||
}
|
||||
|
||||
//
|
||||
// kexMatrix::kexMatrix
|
||||
// Mat4::Mat4
|
||||
//
|
||||
|
||||
kexMatrix::kexMatrix(const kexMatrix &mtx)
|
||||
Mat4::Mat4(const Mat4 &mtx)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
|
@ -98,19 +98,19 @@ kexMatrix::kexMatrix(const kexMatrix &mtx)
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::kexMatrix
|
||||
// Mat4::Mat4
|
||||
//
|
||||
|
||||
kexMatrix::kexMatrix(const float x, const float y, const float z)
|
||||
Mat4::Mat4(const float x, const float y, const float z)
|
||||
{
|
||||
Identity(x, y, z);
|
||||
}
|
||||
|
||||
//
|
||||
// kexMatrix::kexMatrix
|
||||
// Mat4::Mat4
|
||||
//
|
||||
|
||||
kexMatrix::kexMatrix(const kexQuat &quat)
|
||||
Mat4::Mat4(const Quat &quat)
|
||||
{
|
||||
float xx = quat.x * quat.x;
|
||||
float yx = quat.y * quat.x;
|
||||
|
@ -142,16 +142,16 @@ kexMatrix::kexMatrix(const kexQuat &quat)
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::kexMatrix
|
||||
// Mat4::Mat4
|
||||
//
|
||||
|
||||
kexMatrix::kexMatrix(const float angle, const int axis)
|
||||
Mat4::Mat4(const float angle, const int axis)
|
||||
{
|
||||
float s;
|
||||
float c;
|
||||
|
||||
s = kexMath::Sin(angle);
|
||||
c = kexMath::Cos(angle);
|
||||
s = Math::Sin(angle);
|
||||
c = Math::Cos(angle);
|
||||
|
||||
Identity();
|
||||
|
||||
|
@ -179,10 +179,10 @@ kexMatrix::kexMatrix(const float angle, const int axis)
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::Identity
|
||||
// Mat4::Identity
|
||||
//
|
||||
|
||||
kexMatrix &kexMatrix::Identity()
|
||||
Mat4 &Mat4::Identity()
|
||||
{
|
||||
vectors[0].Set(1, 0, 0, 0);
|
||||
vectors[1].Set(0, 1, 0, 0);
|
||||
|
@ -193,10 +193,10 @@ kexMatrix &kexMatrix::Identity()
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::Identity
|
||||
// Mat4::Identity
|
||||
//
|
||||
|
||||
kexMatrix &kexMatrix::Identity(const float x, const float y, const float z)
|
||||
Mat4 &Mat4::Identity(const float x, const float y, const float z)
|
||||
{
|
||||
vectors[0].Set(x, 0, 0, 0);
|
||||
vectors[1].Set(0, y, 0, 0);
|
||||
|
@ -207,30 +207,30 @@ kexMatrix &kexMatrix::Identity(const float x, const float y, const float z)
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::SetTranslation
|
||||
// Mat4::SetTranslation
|
||||
//
|
||||
|
||||
kexMatrix &kexMatrix::SetTranslation(const float x, const float y, const float z)
|
||||
Mat4 &Mat4::SetTranslation(const float x, const float y, const float z)
|
||||
{
|
||||
vectors[3].ToVec3().Set(x, y, z);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//
|
||||
// kexMatrix::SetTranslation
|
||||
// Mat4::SetTranslation
|
||||
//
|
||||
|
||||
kexMatrix &kexMatrix::SetTranslation(const kexVec3 &vector)
|
||||
Mat4 &Mat4::SetTranslation(const Vec3 &vector)
|
||||
{
|
||||
vectors[3].ToVec3() = vector;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//
|
||||
// kexMatrix::AddTranslation
|
||||
// Mat4::AddTranslation
|
||||
//
|
||||
|
||||
kexMatrix &kexMatrix::AddTranslation(const float x, const float y, const float z)
|
||||
Mat4 &Mat4::AddTranslation(const float x, const float y, const float z)
|
||||
{
|
||||
vectors[3].x += x;
|
||||
vectors[3].y += y;
|
||||
|
@ -239,20 +239,20 @@ kexMatrix &kexMatrix::AddTranslation(const float x, const float y, const float z
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::AddTranslation
|
||||
// Mat4::AddTranslation
|
||||
//
|
||||
|
||||
kexMatrix &kexMatrix::AddTranslation(const kexVec3 &vector)
|
||||
Mat4 &Mat4::AddTranslation(const Vec3 &vector)
|
||||
{
|
||||
vectors[3].ToVec3() += vector;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//
|
||||
// kexMatrix::Scale
|
||||
// Mat4::Scale
|
||||
//
|
||||
|
||||
kexMatrix &kexMatrix::Scale(const float x, const float y, const float z)
|
||||
Mat4 &Mat4::Scale(const float x, const float y, const float z)
|
||||
{
|
||||
vectors[0].ToVec3() *= x;
|
||||
vectors[1].ToVec3() *= y;
|
||||
|
@ -262,10 +262,10 @@ kexMatrix &kexMatrix::Scale(const float x, const float y, const float z)
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::Scale
|
||||
// Mat4::Scale
|
||||
//
|
||||
|
||||
kexMatrix &kexMatrix::Scale(const kexVec3 &vector)
|
||||
Mat4 &Mat4::Scale(const Vec3 &vector)
|
||||
{
|
||||
vectors[0].ToVec3() *= vector.x;
|
||||
vectors[1].ToVec3() *= vector.y;
|
||||
|
@ -275,12 +275,12 @@ kexMatrix &kexMatrix::Scale(const kexVec3 &vector)
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::Scale
|
||||
// Mat4::Scale
|
||||
//
|
||||
|
||||
kexMatrix kexMatrix::Scale(const kexMatrix &mtx, const float x, const float y, const float z)
|
||||
Mat4 Mat4::Scale(const Mat4 &mtx, const float x, const float y, const float z)
|
||||
{
|
||||
kexMatrix out;
|
||||
Mat4 out;
|
||||
|
||||
out.vectors[0].ToVec3() = mtx.vectors[0].ToVec3() * x;
|
||||
out.vectors[1].ToVec3() = mtx.vectors[1].ToVec3() * y;
|
||||
|
@ -290,13 +290,13 @@ kexMatrix kexMatrix::Scale(const kexMatrix &mtx, const float x, const float y, c
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::Transpose
|
||||
// Mat4::Transpose
|
||||
//
|
||||
|
||||
kexMatrix &kexMatrix::Transpose()
|
||||
Mat4 &Mat4::Transpose()
|
||||
{
|
||||
kexVec3 v1 = vectors[1].ToVec3();
|
||||
kexVec3 v2 = vectors[2].ToVec3();
|
||||
Vec3 v1 = vectors[1].ToVec3();
|
||||
Vec3 v2 = vectors[2].ToVec3();
|
||||
|
||||
vectors[1].ToVec3() = v2;
|
||||
vectors[2].ToVec3() = v1;
|
||||
|
@ -304,12 +304,12 @@ kexMatrix &kexMatrix::Transpose()
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::Transpose
|
||||
// Mat4::Transpose
|
||||
//
|
||||
|
||||
kexMatrix kexMatrix::Transpose(const kexMatrix &mtx)
|
||||
Mat4 Mat4::Transpose(const Mat4 &mtx)
|
||||
{
|
||||
kexMatrix out;
|
||||
Mat4 out;
|
||||
|
||||
out.vectors[0].ToVec3() = mtx.vectors[0].ToVec3();
|
||||
out.vectors[1].ToVec3() = mtx.vectors[2].ToVec3();
|
||||
|
@ -320,10 +320,10 @@ kexMatrix kexMatrix::Transpose(const kexMatrix &mtx)
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::Invert
|
||||
// Mat4::Invert
|
||||
//
|
||||
|
||||
kexMatrix kexMatrix::Invert(kexMatrix &mtx)
|
||||
Mat4 Mat4::Invert(Mat4 &mtx)
|
||||
{
|
||||
float d;
|
||||
float *m;
|
||||
|
@ -339,7 +339,7 @@ kexMatrix kexMatrix::Invert(kexMatrix &mtx)
|
|||
|
||||
if (d != 0.0f)
|
||||
{
|
||||
kexMatrix inv;
|
||||
Mat4 inv;
|
||||
|
||||
d = (1.0f / d);
|
||||
|
||||
|
@ -384,12 +384,12 @@ kexMatrix kexMatrix::Invert(kexMatrix &mtx)
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::SetViewProjection
|
||||
// Mat4::SetViewProjection
|
||||
//
|
||||
|
||||
void kexMatrix::SetViewProjection(float aspect, float fov, float zNear, float zFar)
|
||||
void Mat4::SetViewProjection(float aspect, float fov, float zNear, float zFar)
|
||||
{
|
||||
float top = zNear * kexMath::Tan(fov * M_PI / 360.0f);
|
||||
float top = zNear * Math::Tan(fov * M_PI / 360.0f);
|
||||
float bottom = -top;
|
||||
float left = bottom * aspect;
|
||||
float right = top * aspect;
|
||||
|
@ -415,10 +415,10 @@ void kexMatrix::SetViewProjection(float aspect, float fov, float zNear, float zF
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::SetOrtho
|
||||
// Mat4::SetOrtho
|
||||
//
|
||||
|
||||
void kexMatrix::SetOrtho(float left, float right,
|
||||
void Mat4::SetOrtho(float left, float right,
|
||||
float bottom, float top,
|
||||
float zNear, float zFar)
|
||||
{
|
||||
|
@ -443,10 +443,10 @@ void kexMatrix::SetOrtho(float left, float right,
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::ToQuat
|
||||
// Mat4::ToQuat
|
||||
//
|
||||
|
||||
kexQuat kexMatrix::ToQuat()
|
||||
Quat Mat4::ToQuat()
|
||||
{
|
||||
float t;
|
||||
float d;
|
||||
|
@ -456,7 +456,7 @@ kexQuat kexMatrix::ToQuat()
|
|||
float m21;
|
||||
float m20;
|
||||
float m10;
|
||||
kexQuat q;
|
||||
Quat q;
|
||||
|
||||
mx = vectors[0][0];
|
||||
my = vectors[1][1];
|
||||
|
@ -470,7 +470,7 @@ kexQuat kexMatrix::ToQuat()
|
|||
|
||||
if (t > 0)
|
||||
{
|
||||
d = 0.5f / kexMath::Sqrt(t);
|
||||
d = 0.5f / Math::Sqrt(t);
|
||||
q.x = m21 * d;
|
||||
q.y = m20 * d;
|
||||
q.z = m10 * d;
|
||||
|
@ -478,7 +478,7 @@ kexQuat kexMatrix::ToQuat()
|
|||
}
|
||||
else if (mx > my && mx > mz)
|
||||
{
|
||||
d = kexMath::Sqrt(1.0f + mx - my - mz) * 2;
|
||||
d = Math::Sqrt(1.0f + mx - my - mz) * 2;
|
||||
q.x = 0.5f / d;
|
||||
q.y = m10 / d;
|
||||
q.z = m20 / d;
|
||||
|
@ -486,7 +486,7 @@ kexQuat kexMatrix::ToQuat()
|
|||
}
|
||||
else if (my > mz)
|
||||
{
|
||||
d = kexMath::Sqrt(1.0f + my - mx - mz) * 2;
|
||||
d = Math::Sqrt(1.0f + my - mx - mz) * 2;
|
||||
q.x = m10 / d;
|
||||
q.y = 0.5f / d;
|
||||
q.z = m21 / d;
|
||||
|
@ -494,7 +494,7 @@ kexQuat kexMatrix::ToQuat()
|
|||
}
|
||||
else
|
||||
{
|
||||
d = kexMath::Sqrt(1.0f + mz - mx - my) * 2;
|
||||
d = Math::Sqrt(1.0f + mz - mx - my) * 2;
|
||||
q.x = m20 / d;
|
||||
q.y = m21 / d;
|
||||
q.z = 0.5f / d;
|
||||
|
@ -506,12 +506,12 @@ kexQuat kexMatrix::ToQuat()
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::operator*
|
||||
// Mat4::operator*
|
||||
//
|
||||
|
||||
kexMatrix kexMatrix::operator*(const kexVec3 &vector)
|
||||
Mat4 Mat4::operator*(const Vec3 &vector)
|
||||
{
|
||||
kexMatrix out(*this);
|
||||
Mat4 out(*this);
|
||||
|
||||
out.vectors[3].ToVec3() +=
|
||||
vectors[0].ToVec3() * vector.x +
|
||||
|
@ -521,10 +521,10 @@ kexMatrix kexMatrix::operator*(const kexVec3 &vector)
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::operator*=
|
||||
// Mat4::operator*=
|
||||
//
|
||||
|
||||
kexMatrix &kexMatrix::operator*=(const kexVec3 &vector)
|
||||
Mat4 &Mat4::operator*=(const Vec3 &vector)
|
||||
{
|
||||
vectors[3].ToVec3() +=
|
||||
vectors[0].ToVec3() * vector.x +
|
||||
|
@ -534,21 +534,21 @@ kexMatrix &kexMatrix::operator*=(const kexVec3 &vector)
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::ToFloatPtr
|
||||
// Mat4::ToFloatPtr
|
||||
//
|
||||
|
||||
float *kexMatrix::ToFloatPtr()
|
||||
float *Mat4::ToFloatPtr()
|
||||
{
|
||||
return reinterpret_cast<float*>(vectors);
|
||||
}
|
||||
|
||||
//
|
||||
// kexMatrix::operator*
|
||||
// Mat4::operator*
|
||||
//
|
||||
|
||||
kexMatrix kexMatrix::operator*(const kexMatrix &matrix)
|
||||
Mat4 Mat4::operator*(const Mat4 &matrix)
|
||||
{
|
||||
kexMatrix out;
|
||||
Mat4 out;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
|
@ -578,10 +578,10 @@ kexMatrix kexMatrix::operator*(const kexMatrix &matrix)
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::operator*=
|
||||
// Mat4::operator*=
|
||||
//
|
||||
|
||||
kexMatrix &kexMatrix::operator*=(const kexMatrix &matrix)
|
||||
Mat4 &Mat4::operator*=(const Mat4 &matrix)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
|
@ -611,12 +611,12 @@ kexMatrix &kexMatrix::operator*=(const kexMatrix &matrix)
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::operator*
|
||||
// Mat4::operator*
|
||||
//
|
||||
|
||||
kexMatrix operator*(const kexMatrix &m1, const kexMatrix &m2)
|
||||
Mat4 operator*(const Mat4 &m1, const Mat4 &m2)
|
||||
{
|
||||
kexMatrix out;
|
||||
Mat4 out;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
|
@ -646,12 +646,12 @@ kexMatrix operator*(const kexMatrix &m1, const kexMatrix &m2)
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::operator|
|
||||
// Mat4::operator|
|
||||
//
|
||||
|
||||
kexMatrix kexMatrix::operator|(const kexMatrix &matrix)
|
||||
Mat4 Mat4::operator|(const Mat4 &matrix)
|
||||
{
|
||||
kexMatrix out;
|
||||
Mat4 out;
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
|
@ -686,10 +686,10 @@ kexMatrix kexMatrix::operator|(const kexMatrix &matrix)
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::operator=
|
||||
// Mat4::operator=
|
||||
//
|
||||
|
||||
kexMatrix &kexMatrix::operator=(const kexMatrix &matrix)
|
||||
Mat4 &Mat4::operator=(const Mat4 &matrix)
|
||||
{
|
||||
vectors[0] = matrix.vectors[0];
|
||||
vectors[1] = matrix.vectors[1];
|
||||
|
@ -700,10 +700,10 @@ kexMatrix &kexMatrix::operator=(const kexMatrix &matrix)
|
|||
}
|
||||
|
||||
//
|
||||
// kexMatrix::operator=
|
||||
// Mat4::operator=
|
||||
//
|
||||
|
||||
kexMatrix &kexMatrix::operator=(const float *m)
|
||||
Mat4 &Mat4::operator=(const float *m)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
|
|
|
@ -34,10 +34,10 @@
|
|||
#include "mathlib.h"
|
||||
|
||||
//
|
||||
// kexPlane::kexPlane
|
||||
// Plane::Plane
|
||||
//
|
||||
|
||||
kexPlane::kexPlane()
|
||||
Plane::Plane()
|
||||
{
|
||||
this->a = 0;
|
||||
this->b = 0;
|
||||
|
@ -46,10 +46,10 @@ kexPlane::kexPlane()
|
|||
}
|
||||
|
||||
//
|
||||
// kexPlane::kexPlane
|
||||
// Plane::Plane
|
||||
//
|
||||
|
||||
kexPlane::kexPlane(const float a, const float b, const float c, const float d)
|
||||
Plane::Plane(const float a, const float b, const float c, const float d)
|
||||
{
|
||||
this->a = a;
|
||||
this->b = b;
|
||||
|
@ -58,20 +58,20 @@ kexPlane::kexPlane(const float a, const float b, const float c, const float d)
|
|||
}
|
||||
|
||||
//
|
||||
// kexPlane::kexPlane
|
||||
// Plane::Plane
|
||||
//
|
||||
|
||||
kexPlane::kexPlane(const kexVec3 &pt1, const kexVec3 &pt2, const kexVec3 &pt3)
|
||||
Plane::Plane(const Vec3 &pt1, const Vec3 &pt2, const Vec3 &pt3)
|
||||
{
|
||||
SetNormal(pt1, pt2, pt3);
|
||||
this->d = kexVec3::Dot(pt1, Normal());
|
||||
this->d = Vec3::Dot(pt1, Normal());
|
||||
}
|
||||
|
||||
//
|
||||
// kexPlane::kexPlane
|
||||
// Plane::Plane
|
||||
//
|
||||
|
||||
kexPlane::kexPlane(const kexVec3 &normal, const kexVec3 &point)
|
||||
Plane::Plane(const Vec3 &normal, const Vec3 &point)
|
||||
{
|
||||
this->a = normal.x;
|
||||
this->b = normal.y;
|
||||
|
@ -80,10 +80,10 @@ kexPlane::kexPlane(const kexVec3 &normal, const kexVec3 &point)
|
|||
}
|
||||
|
||||
//
|
||||
// kexPlane::kexPlane
|
||||
// Plane::Plane
|
||||
//
|
||||
|
||||
kexPlane::kexPlane(const kexPlane &plane)
|
||||
Plane::Plane(const Plane &plane)
|
||||
{
|
||||
this->a = plane.a;
|
||||
this->b = plane.b;
|
||||
|
@ -92,83 +92,83 @@ kexPlane::kexPlane(const kexPlane &plane)
|
|||
}
|
||||
|
||||
//
|
||||
// kexPlane::SetNormal
|
||||
// Plane::SetNormal
|
||||
//
|
||||
|
||||
kexPlane &kexPlane::SetNormal(const kexVec3 &normal)
|
||||
Plane &Plane::SetNormal(const Vec3 &normal)
|
||||
{
|
||||
Normal() = normal;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//
|
||||
// kexPlane::SetNormal
|
||||
// Plane::SetNormal
|
||||
//
|
||||
|
||||
kexPlane &kexPlane::SetNormal(const kexVec3 &pt1, const kexVec3 &pt2, const kexVec3 &pt3)
|
||||
Plane &Plane::SetNormal(const Vec3 &pt1, const Vec3 &pt2, const Vec3 &pt3)
|
||||
{
|
||||
Normal() = (pt2 - pt1).Cross(pt3 - pt2).Normalize();
|
||||
return *this;
|
||||
}
|
||||
|
||||
//
|
||||
// kexPlane::Normal
|
||||
// Plane::Normal
|
||||
//
|
||||
|
||||
kexVec3 const &kexPlane::Normal() const
|
||||
Vec3 const &Plane::Normal() const
|
||||
{
|
||||
return *reinterpret_cast<const kexVec3*>(&a);
|
||||
return *reinterpret_cast<const Vec3*>(&a);
|
||||
}
|
||||
|
||||
//
|
||||
// kexPlane::Normal
|
||||
// Plane::Normal
|
||||
//
|
||||
|
||||
kexVec3 &kexPlane::Normal()
|
||||
Vec3 &Plane::Normal()
|
||||
{
|
||||
return *reinterpret_cast<kexVec3*>(&a);
|
||||
return *reinterpret_cast<Vec3*>(&a);
|
||||
}
|
||||
|
||||
//
|
||||
// kexPlane::Distance
|
||||
// Plane::Distance
|
||||
//
|
||||
|
||||
float kexPlane::Distance(const kexVec3 &point)
|
||||
float Plane::Distance(const Vec3 &point)
|
||||
{
|
||||
return point.Dot(Normal());
|
||||
}
|
||||
|
||||
//
|
||||
// kexPlane::SetDistance
|
||||
// Plane::SetDistance
|
||||
//
|
||||
|
||||
kexPlane &kexPlane::SetDistance(const kexVec3 &point)
|
||||
Plane &Plane::SetDistance(const Vec3 &point)
|
||||
{
|
||||
this->d = point.Dot(Normal());
|
||||
return *this;
|
||||
}
|
||||
|
||||
//
|
||||
// kexPlane::IsFacing
|
||||
// Plane::IsFacing
|
||||
//
|
||||
|
||||
bool kexPlane::IsFacing(const float yaw)
|
||||
bool Plane::IsFacing(const float yaw)
|
||||
{
|
||||
return -kexMath::Sin(yaw) * a + -kexMath::Cos(yaw) * b < 0;
|
||||
return -Math::Sin(yaw) * a + -Math::Cos(yaw) * b < 0;
|
||||
}
|
||||
|
||||
//
|
||||
// kexPlane::ToYaw
|
||||
// Plane::ToYaw
|
||||
//
|
||||
|
||||
float kexPlane::ToYaw()
|
||||
float Plane::ToYaw()
|
||||
{
|
||||
float d = Normal().Unit();
|
||||
|
||||
if (d != 0)
|
||||
{
|
||||
float phi;
|
||||
phi = kexMath::ACos(b / d);
|
||||
phi = Math::ACos(b / d);
|
||||
if (a <= 0)
|
||||
{
|
||||
phi = -phi;
|
||||
|
@ -181,51 +181,51 @@ float kexPlane::ToYaw()
|
|||
}
|
||||
|
||||
//
|
||||
// kexPlane::ToPitch
|
||||
// Plane::ToPitch
|
||||
//
|
||||
|
||||
float kexPlane::ToPitch()
|
||||
float Plane::ToPitch()
|
||||
{
|
||||
return kexMath::ACos(kexVec3::vecUp.Dot(Normal()));
|
||||
return Math::ACos(Vec3::vecUp.Dot(Normal()));
|
||||
}
|
||||
|
||||
//
|
||||
// kexPlane::ToQuat
|
||||
// Plane::ToQuat
|
||||
//
|
||||
|
||||
kexQuat kexPlane::ToQuat()
|
||||
Quat Plane::ToQuat()
|
||||
{
|
||||
kexVec3 cross = kexVec3::vecUp.Cross(Normal()).Normalize();
|
||||
return kexQuat(kexMath::ACos(kexVec3::vecUp.Dot(Normal())), cross);
|
||||
Vec3 cross = Vec3::vecUp.Cross(Normal()).Normalize();
|
||||
return Quat(Math::ACos(Vec3::vecUp.Dot(Normal())), cross);
|
||||
}
|
||||
|
||||
//
|
||||
// kexPlane::ToVec4
|
||||
// Plane::ToVec4
|
||||
//
|
||||
|
||||
kexVec4 const &kexPlane::ToVec4() const
|
||||
Vec4 const &Plane::ToVec4() const
|
||||
{
|
||||
return *reinterpret_cast<const kexVec4*>(&a);
|
||||
return *reinterpret_cast<const Vec4*>(&a);
|
||||
}
|
||||
|
||||
//
|
||||
// kexPlane::ToVec4
|
||||
// Plane::ToVec4
|
||||
//
|
||||
|
||||
kexVec4 &kexPlane::ToVec4()
|
||||
Vec4 &Plane::ToVec4()
|
||||
{
|
||||
return *reinterpret_cast<kexVec4*>(&a);
|
||||
return *reinterpret_cast<Vec4*>(&a);
|
||||
}
|
||||
|
||||
//
|
||||
// kexPlane::BestAxis
|
||||
// Plane::BestAxis
|
||||
//
|
||||
|
||||
const kexPlane::planeAxis_t kexPlane::BestAxis() const
|
||||
const Plane::planeAxis_t Plane::BestAxis() const
|
||||
{
|
||||
float na = kexMath::Fabs(a);
|
||||
float nb = kexMath::Fabs(b);
|
||||
float nc = kexMath::Fabs(c);
|
||||
float na = Math::Fabs(a);
|
||||
float nb = Math::Fabs(b);
|
||||
float nc = Math::Fabs(c);
|
||||
|
||||
// figure out what axis the plane lies on
|
||||
if (na >= nb && na >= nc)
|
||||
|
@ -241,11 +241,11 @@ const kexPlane::planeAxis_t kexPlane::BestAxis() const
|
|||
}
|
||||
|
||||
//
|
||||
// kexPlane::GetInclination
|
||||
// Plane::GetInclination
|
||||
//
|
||||
|
||||
kexVec3 kexPlane::GetInclination()
|
||||
Vec3 Plane::GetInclination()
|
||||
{
|
||||
kexVec3 dir = Normal() * kexVec3::vecUp.Dot(Normal());
|
||||
return (kexVec3::vecUp - dir).Normalize();
|
||||
Vec3 dir = Normal() * Vec3::vecUp.Dot(Normal());
|
||||
return (Vec3::vecUp - dir).Normalize();
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ kexPluecker::kexPluecker()
|
|||
// kexPluecker::kexPluecker
|
||||
//
|
||||
|
||||
kexPluecker::kexPluecker(const kexVec3 &start, const kexVec3 &end, bool bRay)
|
||||
kexPluecker::kexPluecker(const Vec3 &start, const Vec3 &end, bool bRay)
|
||||
{
|
||||
bRay ? SetRay(start, end) : SetLine(start, end);
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ void kexPluecker::Clear()
|
|||
// kexPluecker::SetLine
|
||||
//
|
||||
|
||||
void kexPluecker::SetLine(const kexVec3 &start, const kexVec3 &end)
|
||||
void kexPluecker::SetLine(const Vec3 &start, const Vec3 &end)
|
||||
{
|
||||
p[0] = start.x * end.y - end.x * start.y;
|
||||
p[1] = start.x * end.z - end.x * start.z;
|
||||
|
@ -80,7 +80,7 @@ void kexPluecker::SetLine(const kexVec3 &start, const kexVec3 &end)
|
|||
// kexPluecker::SetRay
|
||||
//
|
||||
|
||||
void kexPluecker::SetRay(const kexVec3 &start, const kexVec3 &dir)
|
||||
void kexPluecker::SetRay(const Vec3 &start, const Vec3 &dir)
|
||||
{
|
||||
p[0] = start.x * dir.y - dir.x * start.y;
|
||||
p[1] = start.x * dir.z - dir.x * start.z;
|
||||
|
|
|
@ -34,22 +34,22 @@
|
|||
#include "mathlib.h"
|
||||
|
||||
//
|
||||
// kexQuat::kexQuat
|
||||
// Quat::Quat
|
||||
//
|
||||
|
||||
kexQuat::kexQuat()
|
||||
Quat::Quat()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
//
|
||||
// kexQuat::kexQuat
|
||||
// Quat::Quat
|
||||
//
|
||||
|
||||
kexQuat::kexQuat(const float angle, const float x, const float y, const float z)
|
||||
Quat::Quat(const float angle, const float x, const float y, const float z)
|
||||
{
|
||||
float s = kexMath::Sin(angle * 0.5f);
|
||||
float c = kexMath::Cos(angle * 0.5f);
|
||||
float s = Math::Sin(angle * 0.5f);
|
||||
float c = Math::Cos(angle * 0.5f);
|
||||
|
||||
this->x = x * s;
|
||||
this->y = y * s;
|
||||
|
@ -58,13 +58,13 @@ kexQuat::kexQuat(const float angle, const float x, const float y, const float z)
|
|||
}
|
||||
|
||||
//
|
||||
// kexQuat::kexQuat
|
||||
// Quat::Quat
|
||||
//
|
||||
|
||||
kexQuat::kexQuat(const float angle, kexVec3 &vector)
|
||||
Quat::Quat(const float angle, Vec3 &vector)
|
||||
{
|
||||
float s = kexMath::Sin(angle * 0.5f);
|
||||
float c = kexMath::Cos(angle * 0.5f);
|
||||
float s = Math::Sin(angle * 0.5f);
|
||||
float c = Math::Cos(angle * 0.5f);
|
||||
|
||||
this->x = vector.x * s;
|
||||
this->y = vector.y * s;
|
||||
|
@ -73,13 +73,13 @@ kexQuat::kexQuat(const float angle, kexVec3 &vector)
|
|||
}
|
||||
|
||||
//
|
||||
// kexQuat::kexQuat
|
||||
// Quat::Quat
|
||||
//
|
||||
|
||||
kexQuat::kexQuat(const float angle, const kexVec3 &vector)
|
||||
Quat::Quat(const float angle, const Vec3 &vector)
|
||||
{
|
||||
float s = kexMath::Sin(angle * 0.5f);
|
||||
float c = kexMath::Cos(angle * 0.5f);
|
||||
float s = Math::Sin(angle * 0.5f);
|
||||
float c = Math::Cos(angle * 0.5f);
|
||||
|
||||
this->x = vector.x * s;
|
||||
this->y = vector.y * s;
|
||||
|
@ -88,10 +88,10 @@ kexQuat::kexQuat(const float angle, const kexVec3 &vector)
|
|||
}
|
||||
|
||||
//
|
||||
// kexQuat::Set
|
||||
// Quat::Set
|
||||
//
|
||||
|
||||
void kexQuat::Set(const float x, const float y, const float z, const float w)
|
||||
void Quat::Set(const float x, const float y, const float z, const float w)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
|
@ -100,38 +100,38 @@ void kexQuat::Set(const float x, const float y, const float z, const float w)
|
|||
}
|
||||
|
||||
//
|
||||
// kexQuat::Clear
|
||||
// Quat::Clear
|
||||
//
|
||||
|
||||
void kexQuat::Clear()
|
||||
void Quat::Clear()
|
||||
{
|
||||
x = y = z = 0.0f;
|
||||
w = 1.0f;
|
||||
}
|
||||
|
||||
//
|
||||
// kexVec3::UnitSq
|
||||
// Vec3::UnitSq
|
||||
//
|
||||
|
||||
float kexQuat::UnitSq() const
|
||||
float Quat::UnitSq() const
|
||||
{
|
||||
return x * x + y * y + z * z + w * w;
|
||||
}
|
||||
|
||||
//
|
||||
// kexVec3::Unit
|
||||
// Vec3::Unit
|
||||
//
|
||||
|
||||
float kexQuat::Unit() const
|
||||
float Quat::Unit() const
|
||||
{
|
||||
return kexMath::Sqrt(UnitSq());
|
||||
return Math::Sqrt(UnitSq());
|
||||
}
|
||||
|
||||
//
|
||||
// kexQuat::Normalize
|
||||
// Quat::Normalize
|
||||
//
|
||||
|
||||
kexQuat &kexQuat::Normalize()
|
||||
Quat &Quat::Normalize()
|
||||
{
|
||||
float d = Unit();
|
||||
if (d != 0.0f)
|
||||
|
@ -143,23 +143,23 @@ kexQuat &kexQuat::Normalize()
|
|||
}
|
||||
|
||||
//
|
||||
// kexQuat::Inverse
|
||||
// Quat::Inverse
|
||||
//
|
||||
|
||||
kexQuat kexQuat::Inverse() const
|
||||
Quat Quat::Inverse() const
|
||||
{
|
||||
kexQuat out;
|
||||
Quat out;
|
||||
out.Set(-x, -y, -z, -w);
|
||||
return out;
|
||||
}
|
||||
|
||||
//
|
||||
// kexQuat::operator+
|
||||
// Quat::operator+
|
||||
//
|
||||
|
||||
kexQuat kexQuat::operator+(const kexQuat &quat)
|
||||
Quat Quat::operator+(const Quat &quat)
|
||||
{
|
||||
kexQuat out;
|
||||
Quat out;
|
||||
out.x = x + quat.x;
|
||||
out.y = y + quat.y;
|
||||
out.z = z + quat.z;
|
||||
|
@ -168,10 +168,10 @@ kexQuat kexQuat::operator+(const kexQuat &quat)
|
|||
}
|
||||
|
||||
//
|
||||
// kexQuat::operator+=
|
||||
// Quat::operator+=
|
||||
//
|
||||
|
||||
kexQuat &kexQuat::operator+=(const kexQuat &quat)
|
||||
Quat &Quat::operator+=(const Quat &quat)
|
||||
{
|
||||
x += quat.x;
|
||||
y += quat.y;
|
||||
|
@ -181,12 +181,12 @@ kexQuat &kexQuat::operator+=(const kexQuat &quat)
|
|||
}
|
||||
|
||||
//
|
||||
// kexQuat::operator-
|
||||
// Quat::operator-
|
||||
//
|
||||
|
||||
kexQuat kexQuat::operator-(const kexQuat &quat)
|
||||
Quat Quat::operator-(const Quat &quat)
|
||||
{
|
||||
kexQuat out;
|
||||
Quat out;
|
||||
out.x = x - quat.x;
|
||||
out.y = y - quat.y;
|
||||
out.z = z - quat.z;
|
||||
|
@ -195,10 +195,10 @@ kexQuat kexQuat::operator-(const kexQuat &quat)
|
|||
}
|
||||
|
||||
//
|
||||
// kexQuat::operator-=
|
||||
// Quat::operator-=
|
||||
//
|
||||
|
||||
kexQuat &kexQuat::operator-=(const kexQuat &quat)
|
||||
Quat &Quat::operator-=(const Quat &quat)
|
||||
{
|
||||
x -= quat.x;
|
||||
y -= quat.y;
|
||||
|
@ -208,12 +208,12 @@ kexQuat &kexQuat::operator-=(const kexQuat &quat)
|
|||
}
|
||||
|
||||
//
|
||||
// kexQuat::operator*
|
||||
// Quat::operator*
|
||||
//
|
||||
|
||||
kexQuat kexQuat::operator*(const kexQuat &quat)
|
||||
Quat Quat::operator*(const Quat &quat)
|
||||
{
|
||||
kexQuat out;
|
||||
Quat out;
|
||||
|
||||
out.x = x * quat.w - y * quat.z + quat.x * w + quat.y * z;
|
||||
out.y = x * quat.z + y * quat.w - quat.x * z + w * quat.y;
|
||||
|
@ -224,10 +224,10 @@ kexQuat kexQuat::operator*(const kexQuat &quat)
|
|||
}
|
||||
|
||||
//
|
||||
// kexQuat::operator*=
|
||||
// Quat::operator*=
|
||||
//
|
||||
|
||||
kexQuat &kexQuat::operator*=(const kexQuat &quat)
|
||||
Quat &Quat::operator*=(const Quat &quat)
|
||||
{
|
||||
float tx = x;
|
||||
float ty = y;
|
||||
|
@ -243,12 +243,12 @@ kexQuat &kexQuat::operator*=(const kexQuat &quat)
|
|||
}
|
||||
|
||||
//
|
||||
// kexQuat::operator*
|
||||
// Quat::operator*
|
||||
//
|
||||
|
||||
kexQuat kexQuat::operator*(const float val) const
|
||||
Quat Quat::operator*(const float val) const
|
||||
{
|
||||
kexQuat out;
|
||||
Quat out;
|
||||
out.x = x * val;
|
||||
out.y = y * val;
|
||||
out.z = z * val;
|
||||
|
@ -257,10 +257,10 @@ kexQuat kexQuat::operator*(const float val) const
|
|||
}
|
||||
|
||||
//
|
||||
// kexQuat::operator*=
|
||||
// Quat::operator*=
|
||||
//
|
||||
|
||||
kexQuat &kexQuat::operator*=(const float val)
|
||||
Quat &Quat::operator*=(const float val)
|
||||
{
|
||||
x *= val;
|
||||
y *= val;
|
||||
|
@ -271,10 +271,10 @@ kexQuat &kexQuat::operator*=(const float val)
|
|||
}
|
||||
|
||||
//
|
||||
// kexQuat::operator|
|
||||
// Quat::operator|
|
||||
//
|
||||
|
||||
kexVec3 kexQuat::operator|(const kexVec3 &vector)
|
||||
Vec3 Quat::operator|(const Vec3 &vector)
|
||||
{
|
||||
float xx = x * x;
|
||||
float yx = y * x;
|
||||
|
@ -287,7 +287,7 @@ kexVec3 kexQuat::operator|(const kexVec3 &vector)
|
|||
float wz = w * z;
|
||||
float ww = w * w;
|
||||
|
||||
return kexVec3(
|
||||
return Vec3(
|
||||
((yx + yx) - (wz + wz)) * vector.y +
|
||||
((wy + wy + zx + zx)) * vector.z +
|
||||
(((ww + xx) - yy) - zz) * vector.x,
|
||||
|
@ -301,21 +301,21 @@ kexVec3 kexQuat::operator|(const kexVec3 &vector)
|
|||
}
|
||||
|
||||
//
|
||||
// kexQuat::Dot
|
||||
// Quat::Dot
|
||||
//
|
||||
|
||||
float kexQuat::Dot(const kexQuat &quat) const
|
||||
float Quat::Dot(const Quat &quat) const
|
||||
{
|
||||
return (x * quat.x + y * quat.y + z * quat.z + w * quat.w);
|
||||
}
|
||||
|
||||
//
|
||||
// kexQuat::Slerp
|
||||
// Quat::Slerp
|
||||
//
|
||||
|
||||
kexQuat kexQuat::Slerp(const kexQuat &quat, float movement) const
|
||||
Quat Quat::Slerp(const Quat &quat, float movement) const
|
||||
{
|
||||
kexQuat rdest = quat;
|
||||
Quat rdest = quat;
|
||||
float d1 = Dot(quat);
|
||||
float d2 = Dot(quat.Inverse());
|
||||
|
||||
|
@ -327,12 +327,12 @@ kexQuat kexQuat::Slerp(const kexQuat &quat, float movement) const
|
|||
|
||||
if (d1 <= 0.7071067811865001f)
|
||||
{
|
||||
float halfcos = kexMath::ACos(d1);
|
||||
float halfsin = kexMath::Sin(halfcos);
|
||||
float halfcos = Math::ACos(d1);
|
||||
float halfsin = Math::Sin(halfcos);
|
||||
|
||||
if (halfsin == 0)
|
||||
{
|
||||
kexQuat out;
|
||||
Quat out;
|
||||
out.Set(x, y, z, w);
|
||||
return out;
|
||||
}
|
||||
|
@ -343,8 +343,8 @@ kexQuat kexQuat::Slerp(const kexQuat &quat, float movement) const
|
|||
float ms2;
|
||||
|
||||
d = 1.0f / halfsin;
|
||||
ms1 = kexMath::Sin((1.0f - movement) * halfcos) * d;
|
||||
ms2 = kexMath::Sin(halfcos * movement) * d;
|
||||
ms1 = Math::Sin((1.0f - movement) * halfcos) * d;
|
||||
ms2 = Math::Sin(halfcos * movement) * d;
|
||||
|
||||
if (ms2 < 0)
|
||||
{
|
||||
|
@ -356,43 +356,43 @@ kexQuat kexQuat::Slerp(const kexQuat &quat, float movement) const
|
|||
}
|
||||
else
|
||||
{
|
||||
kexQuat out = (rdest - *this) * movement + *this;
|
||||
Quat out = (rdest - *this) * movement + *this;
|
||||
out.Normalize();
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// kexQuat::RotateFrom
|
||||
// Quat::RotateFrom
|
||||
//
|
||||
|
||||
kexQuat kexQuat::RotateFrom(const kexVec3 &location, const kexVec3 &target, float maxAngle)
|
||||
Quat Quat::RotateFrom(const Vec3 &location, const Vec3 &target, float maxAngle)
|
||||
{
|
||||
kexVec3 axis;
|
||||
kexVec3 dir;
|
||||
kexVec3 cp;
|
||||
kexQuat prot;
|
||||
Vec3 axis;
|
||||
Vec3 dir;
|
||||
Vec3 cp;
|
||||
Quat prot;
|
||||
float an;
|
||||
|
||||
dir = (*this | kexVec3::vecForward);
|
||||
dir = (*this | Vec3::vecForward);
|
||||
axis = (target - location).Normalize();
|
||||
cp = dir.Cross(axis).Normalize();
|
||||
|
||||
an = kexMath::ACos(axis.Dot(dir));
|
||||
an = Math::ACos(axis.Dot(dir));
|
||||
|
||||
if (maxAngle != 0 && an >= maxAngle)
|
||||
{
|
||||
an = maxAngle;
|
||||
}
|
||||
|
||||
return (*this * kexQuat(an, cp));
|
||||
return (*this * Quat(an, cp));
|
||||
}
|
||||
|
||||
//
|
||||
// kexQuat::operator=
|
||||
// Quat::operator=
|
||||
//
|
||||
|
||||
kexQuat &kexQuat::operator=(const kexQuat &quat)
|
||||
Quat &Quat::operator=(const Quat &quat)
|
||||
{
|
||||
x = quat.x;
|
||||
y = quat.y;
|
||||
|
@ -402,10 +402,10 @@ kexQuat &kexQuat::operator=(const kexQuat &quat)
|
|||
}
|
||||
|
||||
//
|
||||
// kexQuat::operator=
|
||||
// Quat::operator=
|
||||
//
|
||||
|
||||
kexQuat &kexQuat::operator=(const kexVec4 &vec)
|
||||
Quat &Quat::operator=(const Vec4 &vec)
|
||||
{
|
||||
x = vec.x;
|
||||
y = vec.y;
|
||||
|
@ -415,10 +415,10 @@ kexQuat &kexQuat::operator=(const kexVec4 &vec)
|
|||
}
|
||||
|
||||
//
|
||||
// kexQuat::operator=
|
||||
// Quat::operator=
|
||||
//
|
||||
|
||||
kexQuat &kexQuat::operator=(const float *vecs)
|
||||
Quat &Quat::operator=(const float *vecs)
|
||||
{
|
||||
x = vecs[0];
|
||||
y = vecs[1];
|
||||
|
@ -428,19 +428,19 @@ kexQuat &kexQuat::operator=(const float *vecs)
|
|||
}
|
||||
|
||||
//
|
||||
// kexQuat::ToVec3
|
||||
// Quat::ToVec3
|
||||
//
|
||||
|
||||
kexVec3 const &kexQuat::ToVec3() const
|
||||
Vec3 const &Quat::ToVec3() const
|
||||
{
|
||||
return *reinterpret_cast<const kexVec3*>(this);
|
||||
return *reinterpret_cast<const Vec3*>(this);
|
||||
}
|
||||
|
||||
//
|
||||
// kexQuat::ToVec3
|
||||
// Quat::ToVec3
|
||||
//
|
||||
|
||||
kexVec3 &kexQuat::ToVec3()
|
||||
Vec3 &Quat::ToVec3()
|
||||
{
|
||||
return *reinterpret_cast<kexVec3*>(this);
|
||||
return *reinterpret_cast<Vec3*>(this);
|
||||
}
|
||||
|
|
|
@ -34,10 +34,10 @@
|
|||
#include "mathlib.h"
|
||||
#include <assert.h>
|
||||
|
||||
const kexVec3 kexVec3::vecRight(1, 0, 0);
|
||||
const kexVec3 kexVec3::vecUp(0, 0, 1);
|
||||
const kexVec3 kexVec3::vecForward(0, 1, 0);
|
||||
const Vec3 Vec3::vecRight(1, 0, 0);
|
||||
const Vec3 Vec3::vecUp(0, 0, 1);
|
||||
const Vec3 Vec3::vecForward(0, 1, 0);
|
||||
|
||||
const kexVec2 kexVec2::vecRight(1, 0);
|
||||
const kexVec2 kexVec2::vecUp(0, 1);
|
||||
kexVec2 kexVec2::vecZero(0, 0);
|
||||
const Vec2 Vec2::vecRight(1, 0);
|
||||
const Vec2 Vec2::vecUp(0, 1);
|
||||
Vec2 Vec2::vecZero(0, 0);
|
||||
|
|
Loading…
Reference in a new issue