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