From b588b809ea04cd24e6b19f3587c82e10db8123c7 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 2 Nov 2018 23:17:46 +0100 Subject: [PATCH] - reformat files --- src/lightmap/kexlib/array.h | 306 ++++----- src/lightmap/kexlib/binfile.cpp | 404 +++++------- src/lightmap/kexlib/binfile.h | 66 +- src/lightmap/kexlib/kstring.cpp | 832 +++++++++--------------- src/lightmap/kexlib/kstring.h | 126 ++-- src/lightmap/kexlib/math/angle.cpp | 224 +++---- src/lightmap/kexlib/math/bounds.cpp | 466 ++++++------- src/lightmap/kexlib/math/mathlib.cpp | 66 +- src/lightmap/kexlib/math/mathlib.h | 704 ++++++++++---------- src/lightmap/kexlib/math/matrix.cpp | 740 ++++++++++----------- src/lightmap/kexlib/math/plane.cpp | 120 ++-- src/lightmap/kexlib/math/pluecker.cpp | 44 +- src/lightmap/kexlib/math/quaternion.cpp | 354 +++++----- src/lightmap/kexlib/math/random.cpp | 22 +- src/lightmap/kexlib/math/vector.cpp | 620 +++++++++--------- src/lightmap/kexlib/memheap.cpp | 350 +++++----- src/lightmap/kexlib/memheap.h | 78 +-- src/lightmap/lightmap.cpp | 664 +++++++++---------- src/lightmap/lightmap.h | 52 +- src/lightmap/lightsurface.cpp | 460 ++++++------- src/lightmap/lightsurface.h | 44 +- src/lightmap/surfaces.cpp | 278 ++++---- src/lightmap/surfaces.h | 40 +- src/lightmap/trace.cpp | 6 +- src/lightmap/trace.h | 14 +- 25 files changed, 3375 insertions(+), 3705 deletions(-) diff --git a/src/lightmap/kexlib/array.h b/src/lightmap/kexlib/array.h index cb185ec..87fbfb4 100644 --- a/src/lightmap/kexlib/array.h +++ b/src/lightmap/kexlib/array.h @@ -33,277 +33,231 @@ template class kexArray { public: - kexArray(); - ~kexArray(); + kexArray(); + ~kexArray(); - typedef int compare_t(const type*, const type*); + typedef int compare_t(const type*, const type*); - void Push(type o); - void Pop(); - void Empty(); - void Init(); - void Resize(unsigned int size); - type IndexOf(unsigned int index) const; - bool Contains(const type check) const; - void Splice(const unsigned int start, unsigned int len); - void Sort(compare_t *function); - void Sort(compare_t *function, unsigned int count); + void Push(type o); + void Pop(); + void Empty(); + void Init(); + void Resize(unsigned int size); + type IndexOf(unsigned int index) const; + bool Contains(const type check) const; + void Splice(const unsigned int start, unsigned int len); + void Sort(compare_t *function); + void Sort(compare_t *function, unsigned int count); - const unsigned int Length() const { return length; } - type GetData(const int index) { return data[index]; } + const unsigned int Length() const { return length; } + type GetData(const int index) { return data[index]; } - type &operator[](unsigned int index); - kexArray &operator=(const kexArray &arr); + type &operator[](unsigned int index); + kexArray &operator=(const kexArray &arr); protected: - type *data; - unsigned int length; - unsigned int aidx; + type *data; + unsigned int length; + unsigned int aidx; }; -// -// kexArray::kexArray -// template kexArray::kexArray() { - Init(); + Init(); } -// -// kexArray::~kexArray -// template kexArray::~kexArray() { - Empty(); + Empty(); } -// -// kexArray::Init -// template void kexArray::Init() { - data = NULL; - length = 0; - aidx = 0; + data = NULL; + length = 0; + aidx = 0; } -// -// kexArray::Resize -// template void kexArray::Resize(unsigned int size) { - type *tmp; + type *tmp; - if(size == length) - { - return; - } + if (size == length) + { + return; + } - if(size <= 0 && length != 0) - { - delete[] data; - data = NULL; - length = 0; - return; - } + if (size <= 0 && length != 0) + { + delete[] data; + data = NULL; + length = 0; + return; + } - if(length == 0) - { - data = new type[size]; - length = size; - return; - } + if (length == 0) + { + data = new type[size]; + length = size; + return; + } - tmp = data; - data = new type[size]; + tmp = data; + data = new type[size]; - for(unsigned int i = 0; i < length; i++) - { - data[i] = tmp[i]; - } + for (unsigned int i = 0; i < length; i++) + { + data[i] = tmp[i]; + } - length = size; - delete[] tmp; + length = size; + delete[] tmp; } -// -// kexArray::Push -// template void kexArray::Push(type o) { - Resize(length+1); - data[aidx++] = o; + Resize(length + 1); + data[aidx++] = o; } -// -// kexArray::Pop -// template void kexArray::Pop() { - if(length == 0) - { - return; - } + if (length == 0) + { + return; + } - Resize(length-1); - aidx--; + Resize(length - 1); + aidx--; } -// -// kexArray::Empty -// template void kexArray::Empty() { - if(data && length > 0) - { - delete[] data; - data = NULL; - length = 0; - aidx = 0; - } + if (data && length > 0) + { + delete[] data; + data = NULL; + length = 0; + aidx = 0; + } } -// -// kexArray::IndexOf -// template type kexArray::IndexOf(unsigned int index) const { - if(index >= length) - { - index = length-1; - } + if (index >= length) + { + index = length - 1; + } - return data[index]; + return data[index]; } -// -// kexArray::Contains -// template bool kexArray::Contains(const type check) const { - for(unsigned int i = 0; i < length; ++i) - { - if(data[i] == check) - { - return true; - } - } + for (unsigned int i = 0; i < length; ++i) + { + if (data[i] == check) + { + return true; + } + } - return false; + return false; } -// -// kexArray::Splice -// template void kexArray::Splice(const unsigned int start, unsigned int len) { - if(length == 0 || len == 0) - { - return; - } + if (length == 0 || len == 0) + { + return; + } - if(len >= length) - { - len = length; - } + if (len >= length) + { + len = length; + } - type *tmp = new type[len]; + type *tmp = new type[len]; - for(unsigned int i = 0; i < len; i++) - { - tmp[i] = data[start+i]; - } + for (unsigned int i = 0; i < len; i++) + { + tmp[i] = data[start + i]; + } - delete[] data; - data = tmp; - length = length - len; - aidx = length-1; + delete[] data; + data = tmp; + length = length - len; + aidx = length - 1; } -// -// kexArray::Sort -// -// Note that data will be shuffled around, so this could invalidate any -// pointers that relies on the array/data -// +// Note that data will be shuffled around, so this could invalidate any pointers that relies on the array/data template void kexArray::Sort(compare_t *function) { - if(data == NULL) - { - return; - } + if (data == NULL) + { + return; + } - typedef int compareCast(const void*, const void*); - compareCast *cmpFunc = (compareCast*)function; + typedef int compareCast(const void*, const void*); + compareCast *cmpFunc = (compareCast*)function; - qsort((void*)data, length, sizeof(type), cmpFunc); + qsort((void*)data, length, sizeof(type), cmpFunc); } -// -// kexArray::Sort -// -// Note that data will be shuffled around, so this could invalidate any -// pointers that relies on the array/data -// +// Note that data will be shuffled around, so this could invalidate any pointers that relies on the array/data template void kexArray::Sort(compare_t *function, unsigned int count) { - if(data == NULL) - { - return; - } + if (data == NULL) + { + return; + } - typedef int compareCast(const void*, const void*); - compareCast *cmpFunc = (compareCast*)function; + typedef int compareCast(const void*, const void*); + compareCast *cmpFunc = (compareCast*)function; - qsort((void*)data, count, sizeof(type), cmpFunc); + qsort((void*)data, count, sizeof(type), cmpFunc); } -// -// kexArray::operator[] -// template type &kexArray::operator[](unsigned int index) { - assert(index < length); - return data[index]; + assert(index < length); + return data[index]; } -// -// kexArray::operator= -// template kexArray &kexArray::operator=(const kexArray &arr) { - if(data) - { - delete[] data; - } + if (data) + { + delete[] data; + } - data = NULL; - length = arr.length; - aidx = arr.aidx; + data = NULL; + length = arr.length; + aidx = arr.aidx; - if(arr.length > 0) - { - data = new type[arr.length]; + if (arr.length > 0) + { + data = new type[arr.length]; - for(unsigned int i = 0; i < arr.length; i++) - { - data[i] = arr.data[i]; - } - } + for (unsigned int i = 0; i < arr.length; i++) + { + data[i] = arr.data[i]; + } + } - return *this; + return *this; } diff --git a/src/lightmap/kexlib/binfile.cpp b/src/lightmap/kexlib/binfile.cpp index 66fb4c7..962679d 100644 --- a/src/lightmap/kexlib/binfile.cpp +++ b/src/lightmap/kexlib/binfile.cpp @@ -33,367 +33,279 @@ #include "lightmap/common.h" #include "lightmap/kexlib/binfile.h" -// -// kexBinFile::kexBinFile -// - kexBinFile::kexBinFile() { - this->handle = NULL; - this->buffer = NULL; - this->bufferOffset = 0; - this->bOpened = false; + this->handle = NULL; + this->buffer = NULL; + this->bufferOffset = 0; + this->bOpened = false; } -// -// kexBinFile::~kexBinFile -// - kexBinFile::~kexBinFile() { - Close(); + Close(); } -// -// kexBinFile::Open -// - bool kexBinFile::Open(const char *file, kexHeapBlock &heapBlock) { - if((handle = fopen(file, "rb"))) - { - size_t length; + if ((handle = fopen(file, "rb"))) + { + size_t length; - fseek(handle, 0, SEEK_END); - length = ftell(handle); - fseek(handle, 0, SEEK_SET); + fseek(handle, 0, SEEK_END); + length = ftell(handle); + fseek(handle, 0, SEEK_SET); - buffer = (byte*)Mem_Calloc(length+1, heapBlock); + buffer = (byte*)Mem_Calloc(length + 1, heapBlock); - if(fread(buffer, 1, length, handle) == length) - { - if(length > 0) - { - bOpened = true; - bufferOffset = 0; - return true; - } - } + if (fread(buffer, 1, length, handle) == length) + { + if (length > 0) + { + bOpened = true; + bufferOffset = 0; + return true; + } + } - Mem_Free(buffer); - buffer = NULL; - fclose(handle); - } + Mem_Free(buffer); + buffer = NULL; + fclose(handle); + } - return false; + return false; } -// -// kexBinFile::Create -// - bool kexBinFile::Create(const char *file) { - if((handle = fopen(file, "wb"))) - { - bOpened = true; - bufferOffset = 0; - return true; - } + if ((handle = fopen(file, "wb"))) + { + bOpened = true; + bufferOffset = 0; + return true; + } - return false; + return false; } -// -// kexBinFile::Close -// - void kexBinFile::Close() { - if(bOpened == false) - { - return; - } - if(handle) - { - fclose(handle); - handle = NULL; - if(buffer) - { - Mem_Free(buffer); - } - } + if (bOpened == false) + { + return; + } + if (handle) + { + fclose(handle); + handle = NULL; + if (buffer) + { + Mem_Free(buffer); + } + } - bOpened = false; + bOpened = false; } -// -// kexBinFile::Exists -// - bool kexBinFile::Exists(const char *file) { - FILE *fstream; + FILE *fstream; - fstream = fopen(file, "r"); + fstream = fopen(file, "r"); - if(fstream != NULL) - { - fclose(fstream); - return true; - } + if (fstream != NULL) + { + fclose(fstream); + return true; + } #ifdef KEX_WIN32 - else - { - // If we can't open because the file is a directory, the - // "file" exists at least! - if(errno == 21) - { - return true; - } - } + else + { + // If we can't open because the file is a directory, the + // "file" exists at least! + if (errno == 21) + { + return true; + } + } #endif - return false; + return false; } -// -// kexBinFile::Duplicate -// - void kexBinFile::Duplicate(const char *newFileName) { - FILE *f; + FILE *f; - if(bOpened == false) - { - return; - } + if (bOpened == false) + { + return; + } - f = fopen(newFileName, "wb"); + f = fopen(newFileName, "wb"); - if(f == NULL) - { - return; - } + if (f == NULL) + { + return; + } - fwrite(buffer, Length(), 1, f); - fclose(f); + fwrite(buffer, Length(), 1, f); + fclose(f); } -// -// kexBinFile::Length -// - int kexBinFile::Length() { - long savedpos; - long length; + long savedpos; + long length; - if(bOpened == false) - { - return 0; - } + if (bOpened == false) + { + return 0; + } - // save the current position in the file - savedpos = ftell(handle); + // save the current position in the file + savedpos = ftell(handle); - // jump to the end and find the length - fseek(handle, 0, SEEK_END); - length = ftell(handle); + // jump to the end and find the length + fseek(handle, 0, SEEK_END); + length = ftell(handle); - // go back to the old location - fseek(handle, savedpos, SEEK_SET); + // go back to the old location + fseek(handle, savedpos, SEEK_SET); - return length; + return length; } -// -// kexBinFile::Read8 -// - byte kexBinFile::Read8() { - byte result; - result = buffer[bufferOffset++]; - return result; + byte result; + result = buffer[bufferOffset++]; + return result; } -// -// kexBinFile::Read16 -// - short kexBinFile::Read16() { - int result; - result = Read8(); - result |= Read8() << 8; - return result; + int result; + result = Read8(); + result |= Read8() << 8; + return result; } -// -// kexBinFile::Read32 -// - int kexBinFile::Read32() { - int result; - result = Read8(); - result |= Read8() << 8; - result |= Read8() << 16; - result |= Read8() << 24; - return result; + int result; + result = Read8(); + result |= Read8() << 8; + result |= Read8() << 16; + result |= Read8() << 24; + return result; } -// -// kexBinFile::ReadFloat -// - float kexBinFile::ReadFloat() { - fint_t fi; - fi.i = Read32(); - return fi.f; + fint_t fi; + fi.i = Read32(); + return fi.f; } -// -// kexBinFile::ReadVector -// - kexVec3 kexBinFile::ReadVector() { - kexVec3 vec; + kexVec3 vec; - vec.x = ReadFloat(); - vec.y = ReadFloat(); - vec.z = ReadFloat(); + vec.x = ReadFloat(); + vec.y = ReadFloat(); + vec.z = ReadFloat(); - return vec; + return vec; } -// -// kexBinFile::ReadString -// - kexStr kexBinFile::ReadString() { - kexStr str; - char c = 0; + kexStr str; + char c = 0; - while(1) - { - if(!(c = Read8())) - { - break; - } + while (1) + { + if (!(c = Read8())) + { + break; + } - str += c; - } + str += c; + } - return str; + return str; } -// -// kexBinFile::Write8 -// - void kexBinFile::Write8(const byte val) { - if(bOpened) - { - fwrite(&val, 1, 1, handle); - } - else - { - buffer[bufferOffset] = val; - } - bufferOffset++; + if (bOpened) + { + fwrite(&val, 1, 1, handle); + } + else + { + buffer[bufferOffset] = val; + } + bufferOffset++; } -// -// kexBinFile::Write16 -// - void kexBinFile::Write16(const short val) { - Write8(val & 0xff); - Write8((val >> 8) & 0xff); + Write8(val & 0xff); + Write8((val >> 8) & 0xff); } -// -// kexBinFile::Write32 -// - void kexBinFile::Write32(const int val) { - Write8(val & 0xff); - Write8((val >> 8) & 0xff); - Write8((val >> 16) & 0xff); - Write8((val >> 24) & 0xff); + Write8(val & 0xff); + Write8((val >> 8) & 0xff); + Write8((val >> 16) & 0xff); + Write8((val >> 24) & 0xff); } -// -// kexBinFile::WriteFloat -// - void kexBinFile::WriteFloat(const float val) { - fint_t fi; - fi.f = val; - Write32(fi.i); + fint_t fi; + fi.f = val; + Write32(fi.i); } -// -// kexBinFile::WriteVector -// - void kexBinFile::WriteVector(const kexVec3 &val) { - WriteFloat(val.x); - WriteFloat(val.y); - WriteFloat(val.z); + WriteFloat(val.x); + WriteFloat(val.y); + WriteFloat(val.z); } -// -// kexBinFile::WriteString -// - void kexBinFile::WriteString(const kexStr &val) { - const char *c = val.c_str(); + const char *c = val.c_str(); - for(int i = 0; i < val.Length(); i++) - { - Write8(c[i]); - } + for (int i = 0; i < val.Length(); i++) + { + Write8(c[i]); + } - Write8(0); + Write8(0); } -// -// kexBinFile::GetOffsetValue -// - int kexBinFile::GetOffsetValue(int id) { - return *(int*)(buffer + (id << 2)); + return *(int*)(buffer + (id << 2)); } -// -// kexBinFile::GetOffset -// - byte *kexBinFile::GetOffset(int id, byte *subdata, int *count) { - byte *data = (subdata == NULL) ? buffer : subdata; + byte *data = (subdata == NULL) ? buffer : subdata; - bufferOffset = GetOffsetValue(id); - byte *dataOffs = &data[bufferOffset]; + bufferOffset = GetOffsetValue(id); + byte *dataOffs = &data[bufferOffset]; - if(count) - { - *count = *(int*)(dataOffs); - } + if (count) + { + *count = *(int*)(dataOffs); + } - return dataOffs; + return dataOffs; } diff --git a/src/lightmap/kexlib/binfile.h b/src/lightmap/kexlib/binfile.h index 1539a98..c1e8403 100644 --- a/src/lightmap/kexlib/binfile.h +++ b/src/lightmap/kexlib/binfile.h @@ -32,45 +32,43 @@ class kexBinFile { public: - kexBinFile(); - ~kexBinFile(); + kexBinFile(); + ~kexBinFile(); - bool Open(const char *file, kexHeapBlock &heapBlock = hb_static); - bool Create(const char *file); - void Close(); - bool Exists(const char *file); - int Length(); - void Duplicate(const char *newFileName); + bool Open(const char *file, kexHeapBlock &heapBlock = hb_static); + bool Create(const char *file); + void Close(); + bool Exists(const char *file); + int Length(); + void Duplicate(const char *newFileName); - byte Read8(); - short Read16(); - int Read32(); - float ReadFloat(); - kexVec3 ReadVector(); - kexStr ReadString(); + byte Read8(); + short Read16(); + int Read32(); + float ReadFloat(); + kexVec3 ReadVector(); + kexStr ReadString(); - void Write8(const byte val); - void Write16(const short val); - void Write32(const int val); - void WriteFloat(const float val); - void WriteVector(const kexVec3 &val); - void WriteString(const kexStr &val); + void Write8(const byte val); + void Write16(const short val); + void Write32(const int val); + void WriteFloat(const float val); + void WriteVector(const kexVec3 &val); + void WriteString(const kexStr &val); - int GetOffsetValue(int id); - byte *GetOffset(int id, - byte *subdata = NULL, - int *count = NULL); + int GetOffsetValue(int id); + byte *GetOffset(int id, byte *subdata = NULL, int *count = NULL); - FILE *Handle() const { return handle; } - byte *Buffer() const { return buffer; } - void SetBuffer(byte *ptr) { buffer = ptr; } - byte *BufferAt() const { return &buffer[bufferOffset]; } - bool Opened() const { return bOpened; } - void SetOffset(const int offset) { bufferOffset = offset; } + FILE *Handle() const { return handle; } + byte *Buffer() const { return buffer; } + void SetBuffer(byte *ptr) { buffer = ptr; } + byte *BufferAt() const { return &buffer[bufferOffset]; } + bool Opened() const { return bOpened; } + void SetOffset(const int offset) { bufferOffset = offset; } private: - FILE *handle; - byte *buffer; - unsigned int bufferOffset; - bool bOpened; + FILE *handle; + byte *buffer; + unsigned int bufferOffset; + bool bOpened; }; diff --git a/src/lightmap/kexlib/kstring.cpp b/src/lightmap/kexlib/kstring.cpp index 8eecd81..5d1bad0 100644 --- a/src/lightmap/kexlib/kstring.cpp +++ b/src/lightmap/kexlib/kstring.cpp @@ -33,772 +33,580 @@ #include #include "kstring.h" -// -// kexStr::Init -// - void kexStr::Init() { - length = 0; - bufferLength = STRING_DEFAULT_SIZE; - charPtr = defaultBuffer; - charPtr[0] = '\0'; + length = 0; + bufferLength = STRING_DEFAULT_SIZE; + charPtr = defaultBuffer; + charPtr[0] = '\0'; } -// -// kexStr::CheckSize -// - void kexStr::CheckSize(int size, bool bKeepString) { - if(size <= bufferLength) - { - return; - } + if (size <= bufferLength) + { + return; + } - Resize(size, bKeepString); + Resize(size, bKeepString); } -// -// kexStr::CopyNew -// - void kexStr::CopyNew(const char *string, int len) { - CheckSize(len+1, false); - strcpy(charPtr, string); - length = len; + CheckSize(len + 1, false); + strcpy(charPtr, string); + length = len; } -// -// kexStr::kexStr -// - kexStr::kexStr() { - Init(); + Init(); } -// -// kexStr::kexStr -// - kexStr::kexStr(const char *string) { - Init(); + Init(); - if(string == NULL) - { - return; - } + if (string == NULL) + { + return; + } - CopyNew(string, strlen(string)); + CopyNew(string, strlen(string)); } -// -// kexStr::kexStr -// - kexStr::kexStr(const char *string, const int length) { - Init(); + Init(); - if(string == NULL) - { - return; - } + if (string == NULL) + { + return; + } - CopyNew(string, length); + CopyNew(string, length); } -// -// kexStr::kexStr -// - kexStr::kexStr(const kexStr &string) { - Init(); + Init(); - if(string.charPtr == NULL) - { - return; - } + if (string.charPtr == NULL) + { + return; + } - CopyNew(string.charPtr, string.Length()); + CopyNew(string.charPtr, string.Length()); } -// -// kexStr::~kexStr -// - kexStr::~kexStr() { - if(charPtr != defaultBuffer) - { - delete[] charPtr; - charPtr = defaultBuffer; - } + if (charPtr != defaultBuffer) + { + delete[] charPtr; + charPtr = defaultBuffer; + } - charPtr[0] = '\0'; - length = 0; + charPtr[0] = '\0'; + length = 0; } -// -// kexStr::Concat -// - kexStr &kexStr::Concat(const char *string) { - return Concat(string, strlen(string)); + return Concat(string, strlen(string)); } -// -// kexStr::Concat -// - kexStr &kexStr::Concat(const char c) { - CheckSize((length + 1)+1, true); - charPtr[length++] = c; - charPtr[length] = '\0'; - return *this; + CheckSize((length + 1) + 1, true); + charPtr[length++] = c; + charPtr[length] = '\0'; + return *this; } -// -// kexStr::Concat -// - kexStr &kexStr::Concat(const char *string, int len) { - CheckSize((length + len)+1, true); + CheckSize((length + len) + 1, true); - for(int i = 0; i < len; i++) - { - charPtr[length+i] = string[i]; - } + for (int i = 0; i < len; i++) + { + charPtr[length + i] = string[i]; + } - length += len; - charPtr[length] = '\0'; + length += len; + charPtr[length] = '\0'; - return *this; + return *this; } -// -// kexStr::Copy -// - kexStr &kexStr::Copy(const kexStr &src, int len) { - int i = 0; - const char *p = src; - CheckSize((length + len)+1, true); + int i = 0; + const char *p = src; + CheckSize((length + len) + 1, true); - while((len--) >= 0) - { - charPtr[i] = p[i]; - i++; - } + while ((len--) >= 0) + { + charPtr[i] = p[i]; + i++; + } - return *this; + return *this; } -// -// kexStr::Copy -// - kexStr &kexStr::Copy(const kexStr &src) { - return Copy(src, src.Length()); + return Copy(src, src.Length()); } -// -// kexStr::operator= -// - kexStr &kexStr::operator=(const kexStr &str) { - int len = str.Length(); + int len = str.Length(); - CheckSize(len+1, false); - strncpy(charPtr, str.charPtr, len); - length = len; - charPtr[length] = '\0'; + CheckSize(len + 1, false); + strncpy(charPtr, str.charPtr, len); + length = len; + charPtr[length] = '\0'; - return *this; + return *this; } -// -// kexStr::operator= -// - kexStr &kexStr::operator=(const char *str) { - int len = strlen(str); + int len = strlen(str); - CheckSize(len+1, false); - strncpy(charPtr, str, len); - length = len; - charPtr[length] = '\0'; + CheckSize(len + 1, false); + strncpy(charPtr, str, len); + length = len; + charPtr[length] = '\0'; - return *this; + return *this; } -// -// kexStr::operator= -// - kexStr &kexStr::operator=(const bool b) { - const char *str = b ? "true" : "false"; - int len = strlen(str); + const char *str = b ? "true" : "false"; + int len = strlen(str); - CheckSize(len+1, false); - strncpy(charPtr, str, len); - length = len; - charPtr[length] = '\0'; + CheckSize(len + 1, false); + strncpy(charPtr, str, len); + length = len; + charPtr[length] = '\0'; - return *this; + return *this; } -// -// kexStr::operator+ -// - kexStr kexStr::operator+(const kexStr &str) { - kexStr out(*this); + kexStr out(*this); - return out.Concat(str.c_str()); + return out.Concat(str.c_str()); } -// -// kexStr::operator+ -// - kexStr kexStr::operator+(const char *str) { - kexStr out(*this); + kexStr out(*this); - return out.Concat(str); + return out.Concat(str); } -// -// kexStr::operator+ -// - kexStr kexStr::operator+(const bool b) { - kexStr out(*this); + kexStr out(*this); - return out.Concat(b ? "true" : "false"); + return out.Concat(b ? "true" : "false"); } -// -// kexStr::operator+ -// - kexStr kexStr::operator+(const int i) { - kexStr out(*this); + kexStr out(*this); - char tmp[64]; - sprintf(tmp, "%i", i); + char tmp[64]; + sprintf(tmp, "%i", i); - return out.Concat(tmp); + return out.Concat(tmp); } -// -// kexStr::operator+ -// - kexStr kexStr::operator+(const float f) { - kexStr out(*this); + kexStr out(*this); - char tmp[64]; - sprintf(tmp, "%f", f); + char tmp[64]; + sprintf(tmp, "%f", f); - return out.Concat(tmp); + return out.Concat(tmp); } -// -// kexStr::operator+= -// - kexStr &kexStr::operator+=(const kexStr &str) { - return Concat(str.c_str()); + return Concat(str.c_str()); } -// -// kexStr::operator+= -// - kexStr &kexStr::operator+=(const char *str) { - return Concat(str); + return Concat(str); } -// -// kexStr::operator+= -// - kexStr &kexStr::operator+=(const char c) { - return Concat(c); + return Concat(c); } -// -// kexStr::operator+= -// - kexStr &kexStr::operator+=(const bool b) { - return Concat(b ? "true" : "false"); + return Concat(b ? "true" : "false"); } -// -// kexStr::operator[] -// - const char kexStr::operator[](int index) const { - assert(index >= 0 && index < length); - return charPtr[index]; + assert(index >= 0 && index < length); + return charPtr[index]; } -// -// kexStr::Resize -// - void kexStr::Resize(int size, bool bKeepString) { - if(size <= 0) - { - return; - } + if (size <= 0) + { + return; + } - int newsize = size + ((32 - (size & 31)) & 31); - char *newbuffer = new char[newsize]; + int newsize = size + ((32 - (size & 31)) & 31); + char *newbuffer = new char[newsize]; - if(bKeepString) - { - strncpy(newbuffer, charPtr, length); - } + if (bKeepString) + { + strncpy(newbuffer, charPtr, length); + } - if(charPtr != defaultBuffer) - { - delete[] charPtr; - } + if (charPtr != defaultBuffer) + { + delete[] charPtr; + } - charPtr = newbuffer; - bufferLength = newsize; + charPtr = newbuffer; + bufferLength = newsize; } -// -// kexStr::IndexOf -// - int kexStr::IndexOf(const char *pattern) const { - int patlen = strlen(pattern); - int i = 0; - int j = 0; + int patlen = strlen(pattern); + int i = 0; + int j = 0; - while(i + j < Length()) - { - if(charPtr[i + j] == pattern[j]) - { - if(++j == patlen) - { - return i; - } - } - else - { - i++; - j = 0; - } - } + while (i + j < Length()) + { + if (charPtr[i + j] == pattern[j]) + { + if (++j == patlen) + { + return i; + } + } + else + { + i++; + j = 0; + } + } - return -1; + return -1; } -// -// kexStr::IndexOf -// - int kexStr::IndexOf(const char *string, const char *pattern) { - int patlen = strlen(pattern); - int i = 0; - int j = 0; + int patlen = strlen(pattern); + int i = 0; + int j = 0; - while(i + j < (int)strlen(string)) - { - if(string[i + j] == pattern[j]) - { - if(++j == patlen) - { - return i; - } - } - else - { - i++; - j = 0; - } - } + while (i + j < (int)strlen(string)) + { + if (string[i + j] == pattern[j]) + { + if (++j == patlen) + { + return i; + } + } + else + { + i++; + j = 0; + } + } - return -1; + return -1; } -// -// kexStr::IndexOf -// - int kexStr::IndexOf(const kexStr &pattern) const { - return IndexOf(pattern.c_str()); + return IndexOf(pattern.c_str()); } -// -// kexStr::NormalizeSlashes -// - kexStr &kexStr::NormalizeSlashes() { - for(int i = 0; i < length; i++) - { - if((charPtr[i] == '/' || charPtr[i] == '\\') && charPtr[i] != DIR_SEPARATOR) - { - charPtr[i] = DIR_SEPARATOR; - } - } + for (int i = 0; i < length; i++) + { + if ((charPtr[i] == '/' || charPtr[i] == '\\') && charPtr[i] != DIR_SEPARATOR) + { + charPtr[i] = DIR_SEPARATOR; + } + } - return *this; + return *this; } -// -// kexStr::StripPath -// - kexStr &kexStr::StripPath() { - int pos = 0; - int i = 0; + int pos = 0; + int i = 0; - pos = length; + pos = length; - for(i = length - 1; charPtr[i] != '\\' && charPtr[i] != '/'; i--, pos--) - { - if(pos <= 0) - { - return *this; - } - } - length = length - pos; - for(i = 0; i < length; i++) - { - charPtr[i] = charPtr[pos+i]; - } + for (i = length - 1; charPtr[i] != '\\' && charPtr[i] != '/'; i--, pos--) + { + if (pos <= 0) + { + return *this; + } + } + length = length - pos; + for (i = 0; i < length; i++) + { + charPtr[i] = charPtr[pos + i]; + } - CheckSize(length, true); - charPtr[length] = '\0'; - return *this; + CheckSize(length, true); + charPtr[length] = '\0'; + return *this; } -// -// kexStr::StripExtension -// - kexStr &kexStr::StripExtension() { - int pos = IndexOf("."); + int pos = IndexOf("."); - if(pos == -1) - { - return *this; - } + if (pos == -1) + { + return *this; + } - length = pos; - CheckSize(length, true); - charPtr[length] = '\0'; + length = pos; + CheckSize(length, true); + charPtr[length] = '\0'; - return *this; + return *this; } -// -// kexStr::StripFile -// - kexStr &kexStr::StripFile() { - int pos = 0; - int i = 0; + int pos = 0; + int i = 0; - if(IndexOf(".") == -1) - { - return *this; - } + if (IndexOf(".") == -1) + { + return *this; + } - pos = length; + pos = length; - for(i = length - 1; charPtr[i] != '\\' && charPtr[i] != '/'; i--, pos--) - { - if(pos <= 0) - { - return *this; - } - } + for (i = length - 1; charPtr[i] != '\\' && charPtr[i] != '/'; i--, pos--) + { + if (pos <= 0) + { + return *this; + } + } - length = pos; - CheckSize(length, true); - charPtr[length] = '\0'; + length = pos; + CheckSize(length, true); + charPtr[length] = '\0'; - return *this; + return *this; } -// -// kexStr::Hash -// - int kexStr::Hash() { - unsigned int hash = 0; - char *str = (char*)charPtr; - char c; + unsigned int hash = 0; + char *str = (char*)charPtr; + char c; - while((c = *str++)) - { - hash = c + (hash << 6) + (hash << 16) - hash; - } + while ((c = *str++)) + { + hash = c + (hash << 6) + (hash << 16) - hash; + } - return hash & (MAX_HASH-1); + return hash & (MAX_HASH - 1); } -// -// kexStr::Hash -// - int kexStr::Hash(const char *s) { - unsigned int hash = 0; - char *str = (char*)s; - char c; + unsigned int hash = 0; + char *str = (char*)s; + char c; - while((c = *str++)) - { - hash = c + (hash << 6) + (hash << 16) - hash; - } + while ((c = *str++)) + { + hash = c + (hash << 6) + (hash << 16) - hash; + } - return hash & (MAX_HASH-1); + return hash & (MAX_HASH - 1); } -// -// kexStr::Format -// - char *kexStr::Format(const char *str, ...) { - va_list v; - static char vastr[1024]; + va_list v; + static char vastr[1024]; - va_start(v, str); - vsprintf(vastr, str,v); - va_end(v); + va_start(v, str); + vsprintf(vastr, str, v); + va_end(v); - return vastr; + return vastr; } -// -// kexStr::Substr -// - kexStr kexStr::Substr(int start, int len) const { - kexStr str; - int l = Length(); + kexStr str; + int l = Length(); - if(l <= 0 || start >= l) - { - return str; - } + if (l <= 0 || start >= l) + { + return str; + } - if(start + len >= l) - { - len = l - start; - } + if (start + len >= l) + { + len = l - start; + } - return str.Concat((const char*)&charPtr[start], len); + return str.Concat((const char*)&charPtr[start], len); } -// -// kexStr::Split -// - void kexStr::Split(kexStrList &list, const char seperator) { - int splitLen = 0; - int startOffs = 0; - for(int i = 0; i < length; i++) - { - if(charPtr[i] == seperator) - { - if(splitLen == 0) - { - continue; - } + int splitLen = 0; + int startOffs = 0; + for (int i = 0; i < length; i++) + { + if (charPtr[i] == seperator) + { + if (splitLen == 0) + { + continue; + } - list.Push(kexStr(&charPtr[startOffs], splitLen)); - startOffs += (splitLen+1); - splitLen = 0; - continue; - } + list.Push(kexStr(&charPtr[startOffs], splitLen)); + startOffs += (splitLen + 1); + splitLen = 0; + continue; + } - splitLen++; - } + splitLen++; + } - if(splitLen != 0 && startOffs != 0) - { - list.Push(kexStr(&charPtr[startOffs], splitLen)); - } + if (splitLen != 0 && startOffs != 0) + { + list.Push(kexStr(&charPtr[startOffs], splitLen)); + } } -// -// kexStr::Atoi -// - int kexStr::Atoi() { - return atoi(charPtr); + return atoi(charPtr); } -// -// kexStr::Atof -// - float kexStr::Atof() { - return (float)atof(charPtr); + return (float)atof(charPtr); } -// -// kexStr::WriteToFile -// - void kexStr::WriteToFile(const char *file) { - if(length <= 0) - { - return; - } + if (length <= 0) + { + return; + } - FILE *f = fopen(file, "w"); - fprintf(f, "%s", charPtr); - fclose(f); + FILE *f = fopen(file, "w"); + fprintf(f, "%s", charPtr); + fclose(f); } -// -// kexStr::ToUpper -// - kexStr &kexStr::ToUpper() { - char c; - for(int i = 0; i < length; i++) - { - c = charPtr[i]; - if(c >= 'a' && c <= 'z') - { - c -= 'a'-'A'; - } - charPtr[i] = c; - } + char c; + for (int i = 0; i < length; i++) + { + c = charPtr[i]; + if (c >= 'a' && c <= 'z') + { + c -= 'a' - 'A'; + } + charPtr[i] = c; + } - return *this; + return *this; } -// -// kexStr::ToLower -// - kexStr &kexStr::ToLower() { - char c; - for(int i = 0; i < length; i++) - { - c = charPtr[i]; - if(c >= 'A' && c <= 'Z') - { - c += 32; - } - charPtr[i] = c; - } + char c; + for (int i = 0; i < length; i++) + { + c = charPtr[i]; + if (c >= 'A' && c <= 'Z') + { + c += 32; + } + charPtr[i] = c; + } - return *this; + return *this; } -// -// kexStr::CompareCase -// - bool kexStr::CompareCase(const char *s1, const char *s2) { - while(*s1 && *s2) - { - if(*s1 != *s2) - { - return (*s2 - *s1) != 0; - } - s1++; - s2++; - } - if(*s1 != *s2) - { - return (*s2 - *s1) != 0; - } + while (*s1 && *s2) + { + if (*s1 != *s2) + { + return (*s2 - *s1) != 0; + } + s1++; + s2++; + } + if (*s1 != *s2) + { + return (*s2 - *s1) != 0; + } - return false; + return false; } -// -// kexStr::CompareCase -// - bool kexStr::CompareCase(const kexStr &a, const kexStr &b) { - return CompareCase(a.c_str(), b.c_str()); + return CompareCase(a.c_str(), b.c_str()); } -// -// kexStr::Compare -// - bool kexStr::Compare(const char *s1, const char *s2) { - const byte *us1 = (const byte*)s1; - const byte *us2 = (const byte*)s2; + const byte *us1 = (const byte*)s1; + const byte *us2 = (const byte*)s2; - while(tolower(*us1) == tolower(*us2)) - { - if(*us1++ == '\0') - { - return false; - } + while (tolower(*us1) == tolower(*us2)) + { + if (*us1++ == '\0') + { + return false; + } - us2++; - } + us2++; + } - return (tolower(*us1) - tolower(*us2)) != 0; + return (tolower(*us1) - tolower(*us2)) != 0; } -// -// kexStr::Compare -// - bool kexStr::Compare(const kexStr &a, const kexStr &b) { - return Compare(a.c_str(), b.c_str()); + return Compare(a.c_str(), b.c_str()); } diff --git a/src/lightmap/kexlib/kstring.h b/src/lightmap/kexlib/kstring.h index 2bded5f..b767853 100644 --- a/src/lightmap/kexlib/kstring.h +++ b/src/lightmap/kexlib/kstring.h @@ -38,91 +38,91 @@ typedef kexArray kexStrList; class kexStr { public: - kexStr(); - kexStr(const char *string); - kexStr(const char *string, const int length); - kexStr(const kexStr &string); - ~kexStr(); + kexStr(); + kexStr(const char *string); + kexStr(const char *string, const int length); + kexStr(const kexStr &string); + ~kexStr(); - void CheckSize(int size, bool bKeepString); - int IndexOf(const char *pattern) const; - int IndexOf(const kexStr &pattern) const; - kexStr &Concat(const char *string); - kexStr &Concat(const char *string, int len); - kexStr &Concat(const char c); - kexStr &NormalizeSlashes(); - kexStr &StripPath(); - kexStr &StripExtension(); - kexStr &StripFile(); - kexStr &Copy(const kexStr &src, int len); - kexStr &Copy(const kexStr &src); - kexStr &ToUpper(); - kexStr &ToLower(); - int Hash(); - kexStr Substr(int start, int len) const; - void Split(kexStrList &list, const char seperator); - int Atoi(); - float Atof(); - void WriteToFile(const char *file); + void CheckSize(int size, bool bKeepString); + int IndexOf(const char *pattern) const; + int IndexOf(const kexStr &pattern) const; + kexStr &Concat(const char *string); + kexStr &Concat(const char *string, int len); + kexStr &Concat(const char c); + kexStr &NormalizeSlashes(); + kexStr &StripPath(); + kexStr &StripExtension(); + kexStr &StripFile(); + kexStr &Copy(const kexStr &src, int len); + kexStr &Copy(const kexStr &src); + kexStr &ToUpper(); + kexStr &ToLower(); + int Hash(); + kexStr Substr(int start, int len) const; + void Split(kexStrList &list, const char seperator); + int Atoi(); + float Atof(); + void WriteToFile(const char *file); - int Length() const { return length; } - const char *c_str() const { return charPtr; } + int Length() const { return length; } + const char *c_str() const { return charPtr; } - kexStr &operator=(const kexStr &str); - kexStr &operator=(const char *str); - kexStr &operator=(const bool b); - kexStr operator+(const kexStr &str); - kexStr operator+(const char *str); - kexStr operator+(const bool b); - kexStr operator+(const int i); - kexStr operator+(const float f); - kexStr &operator+=(const kexStr &str); - kexStr &operator+=(const char *str); - kexStr &operator+=(const char c); - kexStr &operator+=(const bool b); - const char operator[](int index) const; + kexStr &operator=(const kexStr &str); + kexStr &operator=(const char *str); + kexStr &operator=(const bool b); + kexStr operator+(const kexStr &str); + kexStr operator+(const char *str); + kexStr operator+(const bool b); + kexStr operator+(const int i); + kexStr operator+(const float f); + kexStr &operator+=(const kexStr &str); + kexStr &operator+=(const char *str); + kexStr &operator+=(const char c); + kexStr &operator+=(const bool b); + const char operator[](int index) const; - friend bool operator==(const kexStr &a, const kexStr &b); - friend bool operator==(const char *a, const kexStr &b); - friend bool operator==(const kexStr &a, const char *b); + friend bool operator==(const kexStr &a, const kexStr &b); + friend bool operator==(const char *a, const kexStr &b); + friend bool operator==(const kexStr &a, const char *b); - operator const char *() const { return c_str(); } - operator const char *() { return c_str(); } + operator const char *() const { return c_str(); } + operator const char *() { return c_str(); } - static bool CompareCase(const char *s1, const char *s2); - static bool CompareCase(const kexStr &a, const kexStr &b); - static bool Compare(const char *s1, const char *s2); - static bool Compare(const kexStr &a, const kexStr &b); - static int IndexOf(const char *string, const char *pattern); - static int Hash(const char *s); - static char *Format(const char *str, ...); + static bool CompareCase(const char *s1, const char *s2); + static bool CompareCase(const kexStr &a, const kexStr &b); + static bool Compare(const char *s1, const char *s2); + static bool Compare(const kexStr &a, const kexStr &b); + static int IndexOf(const char *string, const char *pattern); + static int Hash(const char *s); + static char *Format(const char *str, ...); private: - void Resize(int size, bool bKeepString); - void CopyNew(const char *string, int len); + void Resize(int size, bool bKeepString); + void CopyNew(const char *string, int len); protected: - void Init(); + void Init(); - static const int STRING_DEFAULT_SIZE = 32; + static const int STRING_DEFAULT_SIZE = 32; - char *charPtr; - char defaultBuffer[STRING_DEFAULT_SIZE]; - int length; - int bufferLength; + char *charPtr; + char defaultBuffer[STRING_DEFAULT_SIZE]; + int length; + int bufferLength; }; d_inline bool operator==(const kexStr &a, const kexStr &b) { - return (!strcmp(a.charPtr, b.charPtr)); + return (!strcmp(a.charPtr, b.charPtr)); } d_inline bool operator==(const char *a, const kexStr &b) { - return (!strcmp(a, b.charPtr)); + return (!strcmp(a, b.charPtr)); } d_inline bool operator==(const kexStr &a, const char *b) { - return (!strcmp(a.charPtr, b)); + return (!strcmp(a.charPtr, b)); } diff --git a/src/lightmap/kexlib/math/angle.cpp b/src/lightmap/kexlib/math/angle.cpp index 9710981..e6e38ca 100644 --- a/src/lightmap/kexlib/math/angle.cpp +++ b/src/lightmap/kexlib/math/angle.cpp @@ -41,9 +41,9 @@ kexAngle::kexAngle() { - this->yaw = 0; - this->pitch = 0; - this->roll = 0; + this->yaw = 0; + this->pitch = 0; + this->roll = 0; } // @@ -52,9 +52,9 @@ kexAngle::kexAngle() kexAngle::kexAngle(const float yaw, const float pitch, const float roll) { - this->yaw = yaw; - this->pitch = pitch; - this->roll = roll; + this->yaw = yaw; + this->pitch = pitch; + this->roll = roll; } // @@ -63,11 +63,11 @@ kexAngle::kexAngle(const float yaw, const float pitch, const float roll) kexAngle::kexAngle(const kexVec3 &vector) { - this->yaw = vector.x; - this->pitch = vector.y; - this->roll = vector.z; + this->yaw = vector.x; + this->pitch = vector.y; + this->roll = vector.z; - Clamp180(); + Clamp180(); } // @@ -76,9 +76,9 @@ kexAngle::kexAngle(const kexVec3 &vector) kexAngle::kexAngle(const kexAngle &an) { - this->yaw = an.yaw; - this->pitch = an.pitch; - this->roll = an.roll; + this->yaw = an.yaw; + this->pitch = an.pitch; + this->roll = an.roll; } // @@ -90,12 +90,12 @@ kexAngle &kexAngle::Clamp180() #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) - CLAMP180(yaw); - CLAMP180(pitch); - CLAMP180(roll); + CLAMP180(yaw); + CLAMP180(pitch); + CLAMP180(roll); #undef CLAMP180 - return *this; + return *this; } // @@ -107,16 +107,16 @@ kexAngle &kexAngle::Clamp180Invert() #define CLAMP180(x) \ for(; x < -M_PI; x = x + FULLCIRCLE); \ for(; x > M_PI; x = x - FULLCIRCLE) - CLAMP180(yaw); - CLAMP180(pitch); - CLAMP180(roll); + CLAMP180(yaw); + CLAMP180(pitch); + CLAMP180(roll); #undef CLAMP180 - yaw = -yaw; - pitch = -pitch; - roll = -roll; + yaw = -yaw; + pitch = -pitch; + roll = -roll; - return *this; + return *this; } // @@ -125,21 +125,21 @@ kexAngle &kexAngle::Clamp180Invert() kexAngle &kexAngle::Clamp180InvertSum(const kexAngle &angle) { - kexAngle an = angle; + kexAngle an = angle; - an.Clamp180Invert(); + an.Clamp180Invert(); - an.yaw += this->yaw; - an.pitch += this->pitch; - an.roll += this->roll; + an.yaw += this->yaw; + an.pitch += this->pitch; + an.roll += this->roll; - an.Clamp180Invert(); + an.Clamp180Invert(); - this->yaw = an.yaw; - this->pitch = an.pitch; - this->roll = an.roll; + this->yaw = an.yaw; + this->pitch = an.pitch; + this->roll = an.roll; - return *this; + return *this; } // @@ -151,12 +151,12 @@ kexAngle &kexAngle::Round() #define ROUND(x) \ x = DEG2RAD((360.0f / 65536.0f) * \ ((int)(RAD2DEG(x) * (65536.0f / 360.0f)) & 65535)) - yaw = ROUND(yaw); - pitch = ROUND(pitch); - roll = ROUND(roll); + yaw = ROUND(yaw); + pitch = ROUND(pitch); + roll = ROUND(roll); #undef ROUND - return Clamp180(); + return Clamp180(); } // @@ -165,11 +165,11 @@ kexAngle &kexAngle::Round() kexAngle kexAngle::Diff(kexAngle &angle) { - float an; - kexAngle out; + float an; + kexAngle out; - Clamp180(); - angle.Clamp180(); + Clamp180(); + angle.Clamp180(); #define DIFF(x) \ if(x <= angle.x) { \ @@ -190,12 +190,12 @@ kexAngle kexAngle::Diff(kexAngle &angle) out.x = x - an; \ } \ } - DIFF(yaw); - DIFF(pitch); - DIFF(roll); + DIFF(yaw); + DIFF(pitch); + DIFF(roll); #undef DIFF - return out; + return out; } // @@ -204,31 +204,31 @@ kexAngle kexAngle::Diff(kexAngle &angle) void kexAngle::ToAxis(kexVec3 *forward, kexVec3 *up, kexVec3 *right) { - float sy = kexMath::Sin(yaw); - float cy = kexMath::Cos(yaw); - float sp = kexMath::Sin(pitch); - float cp = kexMath::Cos(pitch); - float sr = kexMath::Sin(roll); - float cr = kexMath::Cos(roll); + float sy = kexMath::Sin(yaw); + float cy = kexMath::Cos(yaw); + float sp = kexMath::Sin(pitch); + float cp = kexMath::Cos(pitch); + float sr = kexMath::Sin(roll); + float cr = kexMath::Cos(roll); - if(forward) - { - forward->x = sy * cp; - forward->y = sp; - forward->z = cy * cp; - } - if(right) - { - right->x = sr * sp * sy + cr * cy; - right->y = sr * cp; - right->z = sr * sp * cy + cr * -sy; - } - if(up) - { - up->x = cr * sp * sy + -sr * cy; - up->y = cr * cp; - up->z = cr * sp * cy + -sr * -sy; - } + if (forward) + { + forward->x = sy * cp; + forward->y = sp; + forward->z = cy * cp; + } + if (right) + { + right->x = sr * sp * sy + cr * cy; + right->y = sr * cp; + right->z = sr * sp * cy + cr * -sy; + } + if (up) + { + up->x = cr * sp * sy + -sr * cy; + up->y = cr * cp; + up->z = cr * sp * cy + -sr * -sy; + } } // @@ -237,10 +237,10 @@ void kexAngle::ToAxis(kexVec3 *forward, kexVec3 *up, kexVec3 *right) kexVec3 kexAngle::ToForwardAxis() { - kexVec3 vec; + kexVec3 vec; - ToAxis(&vec, NULL, NULL); - return vec; + ToAxis(&vec, NULL, NULL); + return vec; } // @@ -249,10 +249,10 @@ kexVec3 kexAngle::ToForwardAxis() kexVec3 kexAngle::ToUpAxis() { - kexVec3 vec; + kexVec3 vec; - ToAxis(NULL, &vec, NULL); - return vec; + ToAxis(NULL, &vec, NULL); + return vec; } // @@ -261,10 +261,10 @@ kexVec3 kexAngle::ToUpAxis() kexVec3 kexAngle::ToRightAxis() { - kexVec3 vec; + kexVec3 vec; - ToAxis(NULL, NULL, &vec); - return vec; + ToAxis(NULL, NULL, &vec); + return vec; } // @@ -273,7 +273,7 @@ kexVec3 kexAngle::ToRightAxis() const kexVec3 &kexAngle::ToVec3() const { - return *reinterpret_cast(&yaw); + return *reinterpret_cast(&yaw); } // @@ -282,7 +282,7 @@ const kexVec3 &kexAngle::ToVec3() const kexVec3 &kexAngle::ToVec3() { - return *reinterpret_cast(&yaw); + return *reinterpret_cast(&yaw); } // @@ -291,10 +291,10 @@ kexVec3 &kexAngle::ToVec3() kexQuat kexAngle::ToQuat() { - return - (kexQuat(pitch, kexVec3::vecRight) * - (kexQuat(yaw, kexVec3::vecUp) * - kexQuat(roll, kexVec3::vecForward))); + return + (kexQuat(pitch, kexVec3::vecRight) * + (kexQuat(yaw, kexVec3::vecUp) * + kexQuat(roll, kexVec3::vecForward))); } // @@ -303,7 +303,7 @@ kexQuat kexAngle::ToQuat() kexAngle kexAngle::operator+(const kexAngle &angle) { - return kexAngle(yaw + angle.yaw, pitch + angle.pitch, roll + angle.roll); + return kexAngle(yaw + angle.yaw, pitch + angle.pitch, roll + angle.roll); } // @@ -312,7 +312,7 @@ kexAngle kexAngle::operator+(const kexAngle &angle) kexAngle kexAngle::operator-(const kexAngle &angle) { - return kexAngle(yaw - angle.yaw, pitch - angle.pitch, roll - angle.roll); + return kexAngle(yaw - angle.yaw, pitch - angle.pitch, roll - angle.roll); } // @@ -321,7 +321,7 @@ kexAngle kexAngle::operator-(const kexAngle &angle) kexAngle kexAngle::operator-() { - return kexAngle(-yaw, -pitch, -roll); + return kexAngle(-yaw, -pitch, -roll); } // @@ -330,10 +330,10 @@ kexAngle kexAngle::operator-() kexAngle &kexAngle::operator+=(const kexAngle &angle) { - yaw += angle.yaw; - pitch += angle.pitch; - roll += angle.roll; - return *this; + yaw += angle.yaw; + pitch += angle.pitch; + roll += angle.roll; + return *this; } // @@ -342,10 +342,10 @@ kexAngle &kexAngle::operator+=(const kexAngle &angle) kexAngle &kexAngle::operator-=(const kexAngle &angle) { - yaw -= angle.yaw; - pitch -= angle.pitch; - roll -= angle.roll; - return *this; + yaw -= angle.yaw; + pitch -= angle.pitch; + roll -= angle.roll; + return *this; } // @@ -354,10 +354,10 @@ kexAngle &kexAngle::operator-=(const kexAngle &angle) kexAngle &kexAngle::operator=(const kexAngle &angle) { - yaw = angle.yaw; - pitch = angle.pitch; - roll = angle.roll; - return *this; + yaw = angle.yaw; + pitch = angle.pitch; + roll = angle.roll; + return *this; } // @@ -366,10 +366,10 @@ kexAngle &kexAngle::operator=(const kexAngle &angle) kexAngle &kexAngle::operator=(const kexVec3 &vector) { - yaw = vector.x; - pitch = vector.y; - roll = vector.z; - return *this; + yaw = vector.x; + pitch = vector.y; + roll = vector.z; + return *this; } // @@ -378,10 +378,10 @@ kexAngle &kexAngle::operator=(const kexVec3 &vector) kexAngle &kexAngle::operator=(const float *vecs) { - yaw = vecs[0]; - pitch = vecs[1]; - roll = vecs[2]; - return *this; + yaw = vecs[0]; + pitch = vecs[1]; + roll = vecs[2]; + return *this; } // @@ -390,8 +390,8 @@ kexAngle &kexAngle::operator=(const float *vecs) float kexAngle::operator[](int index) const { - assert(index >= 0 && index < 3); - return (&yaw)[index]; + assert(index >= 0 && index < 3); + return (&yaw)[index]; } // @@ -400,6 +400,6 @@ float kexAngle::operator[](int index) const float &kexAngle::operator[](int index) { - assert(index >= 0 && index < 3); - return (&yaw)[index]; + assert(index >= 0 && index < 3); + return (&yaw)[index]; } diff --git a/src/lightmap/kexlib/math/bounds.cpp b/src/lightmap/kexlib/math/bounds.cpp index fd7f6c2..71d4a6c 100644 --- a/src/lightmap/kexlib/math/bounds.cpp +++ b/src/lightmap/kexlib/math/bounds.cpp @@ -39,7 +39,7 @@ kexBBox::kexBBox() { - Clear(); + Clear(); } // @@ -48,8 +48,8 @@ kexBBox::kexBBox() kexBBox::kexBBox(const kexVec3 &vMin, const kexVec3 &vMax) { - this->min = vMin; - this->max = vMax; + this->min = vMin; + this->max = vMax; } // @@ -58,8 +58,8 @@ kexBBox::kexBBox(const kexVec3 &vMin, const kexVec3 &vMax) void kexBBox::Clear() { - min.Set(M_INFINITY, M_INFINITY, M_INFINITY); - max.Set(-M_INFINITY, -M_INFINITY, -M_INFINITY); + min.Set(M_INFINITY, M_INFINITY, M_INFINITY); + max.Set(-M_INFINITY, -M_INFINITY, -M_INFINITY); } // @@ -68,22 +68,22 @@ void kexBBox::Clear() void kexBBox::AddPoint(const kexVec3 &vec) { - float lowx = min.x; - float lowy = min.y; - float lowz = min.z; - float hix = max.x; - float hiy = max.y; - float hiz = max.z; + float lowx = min.x; + float lowy = min.y; + float lowz = min.z; + float hix = max.x; + float hiy = max.y; + float hiz = max.z; - if(vec.x < lowx) { lowx = vec.x; } - if(vec.y < lowy) { lowy = vec.y; } - if(vec.z < lowz) { lowz = vec.z; } - if(vec.x > hix) { hix = vec.x; } - if(vec.y > hiy) { hiy = vec.y; } - if(vec.z > hiz) { hiz = vec.z; } + if (vec.x < lowx) { lowx = vec.x; } + if (vec.y < lowy) { lowy = vec.y; } + if (vec.z < lowz) { lowz = vec.z; } + if (vec.x > hix) { hix = vec.x; } + if (vec.y > hiy) { hiy = vec.y; } + if (vec.z > hiz) { hiz = vec.z; } - min.Set(lowx, lowy, lowz); - max.Set(hix, hiy, hiz); + min.Set(lowx, lowy, lowz); + max.Set(hix, hiy, hiz); } // @@ -92,10 +92,10 @@ void kexBBox::AddPoint(const kexVec3 &vec) kexVec3 kexBBox::Center() const { - return kexVec3( - (max.x + min.x) * 0.5f, - (max.y + min.y) * 0.5f, - (max.z + min.z) * 0.5f); + return kexVec3( + (max.x + min.x) * 0.5f, + (max.y + min.y) * 0.5f, + (max.z + min.z) * 0.5f); } kexVec3 kexBBox::Extents() const @@ -112,27 +112,27 @@ kexVec3 kexBBox::Extents() const float kexBBox::Radius() const { - int i; - float r = 0; - float r1; - float r2; + int i; + float r = 0; + float r1; + float r2; - for(i = 0; i < 3; i++) - { - r1 = kexMath::Fabs(min[i]); - r2 = kexMath::Fabs(max[i]); + for (i = 0; i < 3; i++) + { + r1 = kexMath::Fabs(min[i]); + r2 = kexMath::Fabs(max[i]); - if(r1 > r2) - { - r += r1 * r1; - } - else - { - r += r2 * r2; - } - } + if (r1 > r2) + { + r += r1 * r1; + } + else + { + r += r2 * r2; + } + } - return kexMath::Sqrt(r); + return kexMath::Sqrt(r); } // @@ -141,8 +141,8 @@ float kexBBox::Radius() const bool kexBBox::PointInside(const kexVec3 &vec) const { - return !(vec[0] < min[0] || vec[1] < min[1] || vec[2] < min[2] || - vec[0] > max[0] || vec[1] > max[1] || vec[2] > max[2]); + 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]); } // @@ -151,8 +151,8 @@ bool kexBBox::PointInside(const kexVec3 &vec) const bool kexBBox::IntersectingBox(const kexBBox &box) const { - return !(box.max[0] < min[0] || box.max[1] < min[1] || box.max[2] < min[2] || - box.min[0] > max[0] || box.min[1] > max[1] || box.min[2] > max[2]); + 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]); } // @@ -161,8 +161,8 @@ bool kexBBox::IntersectingBox(const kexBBox &box) const bool kexBBox::IntersectingBox2D(const kexBBox &box) const { - return !(box.max[0] < min[0] || box.max[2] < min[2] || - box.min[0] > max[0] || box.min[2] > max[2]); + return !(box.max[0] < min[0] || box.max[2] < min[2] || + box.min[0] > max[0] || box.min[2] > max[2]); } // @@ -171,35 +171,35 @@ bool kexBBox::IntersectingBox2D(const kexBBox &box) const float kexBBox::DistanceToPlane(kexPlane &plane) { - kexVec3 c; - float distStart; - float distEnd; - float dist = 0; + kexVec3 c; + float distStart; + float distEnd; + float dist = 0; - c = Center(); + c = Center(); - distStart = plane.Distance(c); - distEnd = kexMath::Fabs((max.x - c.x) * plane.a) + - kexMath::Fabs((max.y - c.y) * plane.b) + - kexMath::Fabs((max.z - c.z) * plane.c); + distStart = plane.Distance(c); + distEnd = kexMath::Fabs((max.x - c.x) * plane.a) + + kexMath::Fabs((max.y - c.y) * plane.b) + + kexMath::Fabs((max.z - c.z) * plane.c); - dist = distStart - distEnd; + dist = distStart - distEnd; - if(dist > 0) - { - // in front - return dist; - } + if (dist > 0) + { + // in front + return dist; + } - dist = distStart + distEnd; + dist = distStart + distEnd; - if(dist < 0) - { - // behind - return dist; - } + if (dist < 0) + { + // behind + return dist; + } - return 0; + return 0; } // @@ -208,18 +208,18 @@ float kexBBox::DistanceToPlane(kexPlane &plane) kexBBox kexBBox::operator+(const float radius) const { - kexVec3 vmin = min; - kexVec3 vmax = max; + kexVec3 vmin = min; + kexVec3 vmax = max; - vmin.x -= radius; - vmin.y -= radius; - vmin.z -= radius; + vmin.x -= radius; + vmin.y -= radius; + vmin.z -= radius; - vmax.x += radius; - vmax.y += radius; - vmax.z += radius; + vmax.x += radius; + vmax.y += radius; + vmax.z += radius; - return kexBBox(vmin, vmax); + return kexBBox(vmin, vmax); } // @@ -228,13 +228,13 @@ kexBBox kexBBox::operator+(const float radius) const kexBBox &kexBBox::operator+=(const float radius) { - min.x -= radius; - min.y -= radius; - min.z -= radius; - max.x += radius; - max.y += radius; - max.z += radius; - return *this; + min.x -= radius; + min.y -= radius; + min.z -= radius; + max.x += radius; + max.y += radius; + max.z += radius; + return *this; } // @@ -243,18 +243,18 @@ kexBBox &kexBBox::operator+=(const float radius) kexBBox kexBBox::operator+(const kexVec3 &vec) const { - kexVec3 vmin = min; - kexVec3 vmax = max; + kexVec3 vmin = min; + kexVec3 vmax = max; - vmin.x += vec.x; - vmin.y += vec.y; - vmin.z += vec.z; + vmin.x += vec.x; + vmin.y += vec.y; + vmin.z += vec.z; - vmax.x += vec.x; - vmax.y += vec.y; - vmax.z += vec.z; + vmax.x += vec.x; + vmax.y += vec.y; + vmax.z += vec.z; - return kexBBox(vmin, vmax); + return kexBBox(vmin, vmax); } // @@ -263,18 +263,18 @@ kexBBox kexBBox::operator+(const kexVec3 &vec) const kexBBox kexBBox::operator-(const float radius) const { - kexVec3 vmin = min; - kexVec3 vmax = max; + kexVec3 vmin = min; + kexVec3 vmax = max; - vmin.x += radius; - vmin.y += radius; - vmin.z += radius; + vmin.x += radius; + vmin.y += radius; + vmin.z += radius; - vmax.x -= radius; - vmax.y -= radius; - vmax.z -= radius; + vmax.x -= radius; + vmax.y -= radius; + vmax.z -= radius; - return kexBBox(vmin, vmax); + return kexBBox(vmin, vmax); } // @@ -283,18 +283,18 @@ kexBBox kexBBox::operator-(const float radius) const kexBBox kexBBox::operator-(const kexVec3 &vec) const { - kexVec3 vmin = min; - kexVec3 vmax = max; + kexVec3 vmin = min; + kexVec3 vmax = max; - vmin.x -= vec.x; - vmin.y -= vec.y; - vmin.z -= vec.z; + vmin.x -= vec.x; + vmin.y -= vec.y; + vmin.z -= vec.z; - vmax.x -= vec.x; - vmax.y -= vec.y; - vmax.z -= vec.z; + vmax.x -= vec.x; + vmax.y -= vec.y; + vmax.z -= vec.z; - return kexBBox(vmin, vmax); + return kexBBox(vmin, vmax); } // @@ -303,13 +303,13 @@ kexBBox kexBBox::operator-(const kexVec3 &vec) const kexBBox &kexBBox::operator-=(const float radius) { - min.x += radius; - min.y += radius; - min.z += radius; - max.x -= radius; - max.y -= radius; - max.z -= radius; - return *this; + min.x += radius; + min.y += radius; + min.z += radius; + max.x -= radius; + max.y -= radius; + max.z -= radius; + return *this; } // @@ -318,24 +318,24 @@ kexBBox &kexBBox::operator-=(const float radius) kexBBox kexBBox::operator*(const kexMatrix &matrix) const { - kexVec3 c = Center(); - kexVec3 ct = c * matrix; - kexBBox box(ct, ct); + kexVec3 c = Center(); + kexVec3 ct = c * matrix; + kexBBox box(ct, ct); - kexMatrix mtx(matrix); + kexMatrix mtx(matrix); - for(int i = 0; i < 3; i++) - { - mtx.vectors[i].x = kexMath::Fabs(mtx.vectors[i].x); - mtx.vectors[i].y = kexMath::Fabs(mtx.vectors[i].y); - mtx.vectors[i].z = kexMath::Fabs(mtx.vectors[i].z); - } + for (int i = 0; i < 3; i++) + { + mtx.vectors[i].x = kexMath::Fabs(mtx.vectors[i].x); + mtx.vectors[i].y = kexMath::Fabs(mtx.vectors[i].y); + mtx.vectors[i].z = kexMath::Fabs(mtx.vectors[i].z); + } - kexVec3 ht = (max - c) * mtx; - box.min -= ht; - box.max += ht; + kexVec3 ht = (max - c) * mtx; + box.min -= ht; + box.max += ht; - return box; + return box; } // @@ -344,24 +344,24 @@ kexBBox kexBBox::operator*(const kexMatrix &matrix) const kexBBox &kexBBox::operator*=(const kexMatrix &matrix) { - kexVec3 c = Center(); - kexVec3 ct = c * matrix; + kexVec3 c = Center(); + kexVec3 ct = c * matrix; - kexMatrix mtx(matrix); + kexMatrix mtx(matrix); - for(int i = 0; i < 3; i++) - { - mtx.vectors[i].x = kexMath::Fabs(mtx.vectors[i].x); - mtx.vectors[i].y = kexMath::Fabs(mtx.vectors[i].y); - mtx.vectors[i].z = kexMath::Fabs(mtx.vectors[i].z); - } + for (int i = 0; i < 3; i++) + { + mtx.vectors[i].x = kexMath::Fabs(mtx.vectors[i].x); + mtx.vectors[i].y = kexMath::Fabs(mtx.vectors[i].y); + mtx.vectors[i].z = kexMath::Fabs(mtx.vectors[i].z); + } - kexVec3 ht = (max - c) * mtx; + kexVec3 ht = (max - c) * mtx; - min = (ct - ht); - max = (ct + ht); + min = (ct - ht); + max = (ct + ht); - return *this; + return *this; } // @@ -370,16 +370,16 @@ kexBBox &kexBBox::operator*=(const kexMatrix &matrix) kexBBox kexBBox::operator*(const kexVec3 &vec) const { - kexBBox box = *this; + kexBBox box = *this; - if(vec.x < 0) { box.min.x += (vec.x-1); } - else { box.max.x += (vec.x+1); } - if(vec.y < 0) { box.min.y += (vec.y-1); } - else { box.max.y += (vec.y+1); } - if(vec.z < 0) { box.min.z += (vec.z-1); } - else { box.max.z += (vec.z+1); } + if (vec.x < 0) { box.min.x += (vec.x - 1); } + else { box.max.x += (vec.x + 1); } + if (vec.y < 0) { box.min.y += (vec.y - 1); } + else { box.max.y += (vec.y + 1); } + if (vec.z < 0) { box.min.z += (vec.z - 1); } + else { box.max.z += (vec.z + 1); } - return box; + return box; } // @@ -388,14 +388,14 @@ kexBBox kexBBox::operator*(const kexVec3 &vec) const kexBBox &kexBBox::operator*=(const kexVec3 &vec) { - if(vec.x < 0) { min.x += (vec.x-1); } - else { max.x += (vec.x+1); } - if(vec.y < 0) { min.y += (vec.y-1); } - else { max.y += (vec.y+1); } - if(vec.z < 0) { min.z += (vec.z-1); } - else { max.z += (vec.z+1); } + if (vec.x < 0) { min.x += (vec.x - 1); } + else { max.x += (vec.x + 1); } + if (vec.y < 0) { min.y += (vec.y - 1); } + else { max.y += (vec.y + 1); } + if (vec.z < 0) { min.z += (vec.z - 1); } + else { max.z += (vec.z + 1); } - return *this; + return *this; } // @@ -404,10 +404,10 @@ kexBBox &kexBBox::operator*=(const kexVec3 &vec) kexBBox &kexBBox::operator=(const kexBBox &bbox) { - min = bbox.min; - max = bbox.max; + min = bbox.min; + max = bbox.max; - return *this; + return *this; } // @@ -416,8 +416,8 @@ kexBBox &kexBBox::operator=(const kexBBox &bbox) kexVec3 kexBBox::operator[](int index) const { - assert(index >= 0 && index < 2); - return index == 0 ? min : max; + assert(index >= 0 && index < 2); + return index == 0 ? min : max; } // @@ -426,8 +426,8 @@ kexVec3 kexBBox::operator[](int index) const kexVec3 &kexBBox::operator[](int index) { - assert(index >= 0 && index < 2); - return index == 0 ? min : max; + assert(index >= 0 && index < 2); + return index == 0 ? min : max; } // @@ -436,27 +436,27 @@ kexVec3 &kexBBox::operator[](int index) bool kexBBox::LineIntersect(const kexVec3 &start, const kexVec3 &end) { - float ld[3]; - kexVec3 center = Center(); - kexVec3 extents = max - center; - kexVec3 lineDir = (end - start) * 0.5f; - kexVec3 lineCenter = lineDir + start; - kexVec3 dir = lineCenter - center; + float ld[3]; + kexVec3 center = Center(); + kexVec3 extents = max - center; + kexVec3 lineDir = (end - start) * 0.5f; + kexVec3 lineCenter = lineDir + start; + kexVec3 dir = lineCenter - center; - ld[0] = kexMath::Fabs(lineDir.x); - if(kexMath::Fabs(dir.x) > extents.x + ld[0]) { return false; } - ld[1] = kexMath::Fabs(lineDir.y); - if(kexMath::Fabs(dir.y) > extents.y + ld[1]) { return false; } - ld[2] = kexMath::Fabs(lineDir.z); - if(kexMath::Fabs(dir.z) > extents.z + ld[2]) { return false; } + ld[0] = kexMath::Fabs(lineDir.x); + if (kexMath::Fabs(dir.x) > extents.x + ld[0]) { return false; } + ld[1] = kexMath::Fabs(lineDir.y); + if (kexMath::Fabs(dir.y) > extents.y + ld[1]) { return false; } + ld[2] = kexMath::Fabs(lineDir.z); + if (kexMath::Fabs(dir.z) > extents.z + ld[2]) { return false; } - kexVec3 cross = lineDir.Cross(dir); + kexVec3 cross = lineDir.Cross(dir); - if(kexMath::Fabs(cross.x) > extents.y * ld[2] + extents.z * ld[1]) { return false; } - if(kexMath::Fabs(cross.y) > extents.x * ld[2] + extents.z * ld[0]) { return false; } - if(kexMath::Fabs(cross.z) > extents.x * ld[1] + extents.y * ld[0]) { return false; } + if (kexMath::Fabs(cross.x) > extents.y * ld[2] + extents.z * ld[1]) { return false; } + if (kexMath::Fabs(cross.y) > extents.x * ld[2] + extents.z * ld[0]) { return false; } + if (kexMath::Fabs(cross.z) > extents.x * ld[1] + extents.y * ld[0]) { return false; } - return true; + return true; } // @@ -467,30 +467,30 @@ bool kexBBox::LineIntersect(const kexVec3 &start, const kexVec3 &end) void kexBBox::ToPoints(float *points) const { - points[0 * 3 + 0] = max[0]; - points[0 * 3 + 1] = min[1]; - points[0 * 3 + 2] = min[2]; - points[1 * 3 + 0] = max[0]; - points[1 * 3 + 1] = min[1]; - points[1 * 3 + 2] = max[2]; - points[2 * 3 + 0] = min[0]; - points[2 * 3 + 1] = min[1]; - points[2 * 3 + 2] = max[2]; - points[3 * 3 + 0] = min[0]; - points[3 * 3 + 1] = min[1]; - points[3 * 3 + 2] = min[2]; - points[4 * 3 + 0] = max[0]; - points[4 * 3 + 1] = max[1]; - points[4 * 3 + 2] = min[2]; - points[5 * 3 + 0] = max[0]; - points[5 * 3 + 1] = max[1]; - points[5 * 3 + 2] = max[2]; - points[6 * 3 + 0] = min[0]; - points[6 * 3 + 1] = max[1]; - points[6 * 3 + 2] = max[2]; - points[7 * 3 + 0] = min[0]; - points[7 * 3 + 1] = max[1]; - points[7 * 3 + 2] = min[2]; + points[0 * 3 + 0] = max[0]; + points[0 * 3 + 1] = min[1]; + points[0 * 3 + 2] = min[2]; + points[1 * 3 + 0] = max[0]; + points[1 * 3 + 1] = min[1]; + points[1 * 3 + 2] = max[2]; + points[2 * 3 + 0] = min[0]; + points[2 * 3 + 1] = min[1]; + points[2 * 3 + 2] = max[2]; + points[3 * 3 + 0] = min[0]; + points[3 * 3 + 1] = min[1]; + points[3 * 3 + 2] = min[2]; + points[4 * 3 + 0] = max[0]; + points[4 * 3 + 1] = max[1]; + points[4 * 3 + 2] = min[2]; + points[5 * 3 + 0] = max[0]; + points[5 * 3 + 1] = max[1]; + points[5 * 3 + 2] = max[2]; + points[6 * 3 + 0] = min[0]; + points[6 * 3 + 1] = max[1]; + points[6 * 3 + 2] = max[2]; + points[7 * 3 + 0] = min[0]; + points[7 * 3 + 1] = max[1]; + points[7 * 3 + 2] = min[2]; } // @@ -501,28 +501,28 @@ void kexBBox::ToPoints(float *points) const void kexBBox::ToVectors(kexVec3 *vectors) const { - vectors[0][0] = max[0]; - vectors[0][1] = min[1]; - vectors[0][2] = min[2]; - vectors[1][0] = max[0]; - vectors[1][1] = min[1]; - vectors[1][2] = max[2]; - vectors[2][0] = min[0]; - vectors[2][1] = min[1]; - vectors[2][2] = max[2]; - vectors[3][0] = min[0]; - vectors[3][1] = min[1]; - vectors[3][2] = min[2]; - vectors[4][0] = max[0]; - vectors[4][1] = max[1]; - vectors[4][2] = min[2]; - vectors[5][0] = max[0]; - vectors[5][1] = max[1]; - vectors[5][2] = max[2]; - vectors[6][0] = min[0]; - vectors[6][1] = max[1]; - vectors[6][2] = max[2]; - vectors[7][0] = min[0]; - vectors[7][1] = max[1]; - vectors[7][2] = min[2]; + vectors[0][0] = max[0]; + vectors[0][1] = min[1]; + vectors[0][2] = min[2]; + vectors[1][0] = max[0]; + vectors[1][1] = min[1]; + vectors[1][2] = max[2]; + vectors[2][0] = min[0]; + vectors[2][1] = min[1]; + vectors[2][2] = max[2]; + vectors[3][0] = min[0]; + vectors[3][1] = min[1]; + vectors[3][2] = min[2]; + vectors[4][0] = max[0]; + vectors[4][1] = max[1]; + vectors[4][2] = min[2]; + vectors[5][0] = max[0]; + vectors[5][1] = max[1]; + vectors[5][2] = max[2]; + vectors[6][0] = min[0]; + vectors[6][1] = max[1]; + vectors[6][2] = max[2]; + vectors[7][0] = min[0]; + vectors[7][1] = max[1]; + vectors[7][2] = min[2]; } diff --git a/src/lightmap/kexlib/math/mathlib.cpp b/src/lightmap/kexlib/math/mathlib.cpp index cd48acd..5552e01 100644 --- a/src/lightmap/kexlib/math/mathlib.cpp +++ b/src/lightmap/kexlib/math/mathlib.cpp @@ -39,19 +39,19 @@ int kexMath::RoundPowerOfTwo(int x) { - int mask = 1; + int mask = 1; - while(mask < 0x40000000) - { - if(x == mask || (x & (mask-1)) == x) - { - return mask; - } + while (mask < 0x40000000) + { + if (x == mask || (x & (mask - 1)) == x) + { + return mask; + } - mask <<= 1; - } + mask <<= 1; + } - return x; + return x; } // @@ -59,20 +59,20 @@ int kexMath::RoundPowerOfTwo(int x) // void kexMath::CubicCurve(const kexVec3 &start, const kexVec3 &end, const float time, - const kexVec3 &point, kexVec3 *vec) + const kexVec3 &point, kexVec3 *vec) { - int i; - float xyz[3]; + int i; + float xyz[3]; - for(i = 0; i < 3; i++) - { - xyz[i] = kexMath::Pow(1-time, 2) * start[i] + - (2 * (1-time)) * time * point[i] + kexMath::Pow(time, 2) * end[i]; - } + for (i = 0; i < 3; i++) + { + xyz[i] = kexMath::Pow(1 - time, 2) * start[i] + + (2 * (1 - time)) * time * point[i] + kexMath::Pow(time, 2) * end[i]; + } - vec->x = xyz[0]; - vec->y = xyz[1]; - vec->z = xyz[2]; + vec->x = xyz[0]; + vec->y = xyz[1]; + vec->z = xyz[2]; } // @@ -80,20 +80,20 @@ void kexMath::CubicCurve(const kexVec3 &start, const kexVec3 &end, const float t // void kexMath::QuadraticCurve(const kexVec3 &start, const kexVec3 &end, const float time, - const kexVec3 &pt1, const kexVec3 &pt2, kexVec3 *vec) + const kexVec3 &pt1, const kexVec3 &pt2, kexVec3 *vec) { - int i; - float xyz[3]; + int i; + float xyz[3]; - for(i = 0; i < 3; i++) - { - xyz[i] = kexMath::Pow(1-time, 3) * start[i] + (3 * kexMath::Pow(1-time, 2)) * - time * pt1[i] + (3 * (1-time)) * kexMath::Pow(time, 2) * pt2[i] + - kexMath::Pow(time, 3) * end[i]; - } + for (i = 0; i < 3; i++) + { + xyz[i] = kexMath::Pow(1 - time, 3) * start[i] + (3 * kexMath::Pow(1 - time, 2)) * + time * pt1[i] + (3 * (1 - time)) * kexMath::Pow(time, 2) * pt2[i] + + kexMath::Pow(time, 3) * end[i]; + } - vec->x = xyz[0]; - vec->y = xyz[1]; - vec->z = xyz[2]; + vec->x = xyz[0]; + vec->y = xyz[1]; + vec->z = xyz[2]; } diff --git a/src/lightmap/kexlib/math/mathlib.h b/src/lightmap/kexlib/math/mathlib.h index 959edfb..aae91a7 100644 --- a/src/lightmap/kexlib/math/mathlib.h +++ b/src/lightmap/kexlib/math/mathlib.h @@ -54,248 +54,248 @@ class kexStr; class kexMath { public: - static float Sin(float x); - static float Cos(float x); - static float Tan(float x); - static float ATan2(float x, float y); - static float ACos(float x); - static float Sqrt(float x); - static float Pow(float x, float y); - static float Log(float x); - static float Floor(float x); - static float Ceil(float x); - static float Deg2Rad(float x); - static float Rad2Deg(float x); + static float Sin(float x); + static float Cos(float x); + static float Tan(float x); + static float ATan2(float x, float y); + static float ACos(float x); + static float Sqrt(float x); + static float Pow(float x, float y); + static float Log(float x); + static float Floor(float x); + static float Ceil(float x); + static float Deg2Rad(float x); + static float Rad2Deg(float x); - static int Abs(int x); - static float Fabs(float x); - static int RoundPowerOfTwo(int x); - static float InvSqrt(float x); - static void Clamp(float &f, const float min, const float max); - static void Clamp(int &i, const int min, const int max); - static void Clamp(byte &b, const byte min, const byte max); - static void Clamp(kexVec3 &f, const float min, const float max); + static int Abs(int x); + static float Fabs(float x); + static int RoundPowerOfTwo(int x); + static float InvSqrt(float x); + static void Clamp(float &f, const float min, const float max); + static void Clamp(int &i, const int min, const int max); + static void Clamp(byte &b, const byte min, const byte max); + static void Clamp(kexVec3 &f, const float min, const float max); - static void CubicCurve(const kexVec3 &start, const kexVec3 &end, const float time, - const kexVec3 &point, kexVec3 *vec); - static void QuadraticCurve(const kexVec3 &start, const kexVec3 &end, const float time, - const kexVec3 &pt1, const kexVec3 &pt2, kexVec3 *vec); + static void CubicCurve(const kexVec3 &start, const kexVec3 &end, const float time, + const kexVec3 &point, kexVec3 *vec); + static void QuadraticCurve(const kexVec3 &start, const kexVec3 &end, const float time, + const kexVec3 &pt1, const kexVec3 &pt2, kexVec3 *vec); }; class kexRand { public: - static void SetSeed(const int randSeed); - static int SysRand(); - static int Int(); - static int Max(const int max); - static float Float(); - static float CFloat(); + static void SetSeed(const int randSeed); + static int SysRand(); + static int Int(); + static int Max(const int max); + static float Float(); + static float CFloat(); private: - static int seed; + static int seed; }; class kexQuat { public: - kexQuat(); + kexQuat(); - explicit kexQuat(const float angle, const float x, const float y, const float z); - explicit kexQuat(const float angle, kexVec3 &vector); - explicit kexQuat(const float angle, const kexVec3 &vector); + explicit kexQuat(const float angle, const float x, const float y, const float z); + explicit kexQuat(const float angle, kexVec3 &vector); + explicit kexQuat(const float angle, const kexVec3 &vector); - void Set(const float x, const float y, const float z, const float w); - void Clear(); - float Dot(const kexQuat &quat) const; - float UnitSq() const; - float Unit() const; - kexQuat &Normalize(); - kexQuat Slerp(const kexQuat &quat, float movement) const; - kexQuat RotateFrom(const kexVec3 &location, const kexVec3 &target, float maxAngle); - kexQuat Inverse() const; + void Set(const float x, const float y, const float z, const float w); + void Clear(); + float Dot(const kexQuat &quat) const; + float UnitSq() const; + float Unit() const; + kexQuat &Normalize(); + kexQuat Slerp(const kexQuat &quat, float movement) const; + kexQuat RotateFrom(const kexVec3 &location, const kexVec3 &target, float maxAngle); + kexQuat Inverse() const; - kexQuat operator+(const kexQuat &quat); - kexQuat &operator+=(const kexQuat &quat); - kexQuat operator-(const kexQuat &quat); - kexQuat &operator-=(const kexQuat &quat); - kexQuat operator*(const kexQuat &quat); - kexQuat operator*(const float val) const; - kexQuat &operator*=(const kexQuat &quat); - kexQuat &operator*=(const float val); - kexQuat &operator=(const kexQuat &quat); - kexQuat &operator=(const kexVec4 &vec); - kexQuat &operator=(const float *vecs); - kexVec3 operator|(const kexVec3 &vector); + kexQuat operator+(const kexQuat &quat); + kexQuat &operator+=(const kexQuat &quat); + kexQuat operator-(const kexQuat &quat); + kexQuat &operator-=(const kexQuat &quat); + kexQuat operator*(const kexQuat &quat); + kexQuat operator*(const float val) const; + kexQuat &operator*=(const kexQuat &quat); + kexQuat &operator*=(const float val); + kexQuat &operator=(const kexQuat &quat); + kexQuat &operator=(const kexVec4 &vec); + kexQuat &operator=(const float *vecs); + kexVec3 operator|(const kexVec3 &vector); - const kexVec3 &ToVec3() const; - kexVec3 &ToVec3(); + const kexVec3 &ToVec3() const; + kexVec3 &ToVec3(); - float x; - float y; - float z; - float w; + float x; + float y; + float z; + float w; }; class kexVec2 { public: - kexVec2(); - explicit kexVec2(const float x, const float y); + kexVec2(); + explicit kexVec2(const float x, const float y); - void Set(const float x, const float y); - void Clear(); - float Dot(const kexVec2 &vec) const; - static float Dot(const kexVec2 &vec1, const kexVec2 &vec2); - float CrossScalar(const kexVec2 &vec) const; - kexVec2 Cross(const kexVec2 &vec) const; - kexVec2 &Cross(const kexVec2 &vec1, const kexVec2 &vec2); - float Dot(const kexVec3 &vec) const; - static float Dot(const kexVec3 &vec1, const kexVec3 &vec2); - kexVec2 Cross(const kexVec3 &vec) const; - kexVec2 &Cross(const kexVec3 &vec1, const kexVec3 &vec2); - float UnitSq() const; - float Unit() const; - float DistanceSq(const kexVec2 &vec) const; - float Distance(const kexVec2 &vec) const; - kexVec2 &Normalize(); - kexVec2 Lerp(const kexVec2 &next, float movement) const; - kexVec2 &Lerp(const kexVec2 &next, const float movement); - kexVec2 &Lerp(const kexVec2 &start, const kexVec2 &next, float movement); - kexStr ToString() const; - float ToYaw() const; - float *ToFloatPtr(); - kexVec3 ToVec3(); + void Set(const float x, const float y); + void Clear(); + float Dot(const kexVec2 &vec) const; + static float Dot(const kexVec2 &vec1, const kexVec2 &vec2); + float CrossScalar(const kexVec2 &vec) const; + kexVec2 Cross(const kexVec2 &vec) const; + kexVec2 &Cross(const kexVec2 &vec1, const kexVec2 &vec2); + float Dot(const kexVec3 &vec) const; + static float Dot(const kexVec3 &vec1, const kexVec3 &vec2); + kexVec2 Cross(const kexVec3 &vec) const; + kexVec2 &Cross(const kexVec3 &vec1, const kexVec3 &vec2); + float UnitSq() const; + float Unit() const; + float DistanceSq(const kexVec2 &vec) const; + float Distance(const kexVec2 &vec) const; + kexVec2 &Normalize(); + kexVec2 Lerp(const kexVec2 &next, float movement) const; + kexVec2 &Lerp(const kexVec2 &next, const float movement); + kexVec2 &Lerp(const kexVec2 &start, const kexVec2 &next, float movement); + kexStr ToString() const; + float ToYaw() const; + float *ToFloatPtr(); + kexVec3 ToVec3(); - kexVec2 operator+(const kexVec2 &vec); - kexVec2 operator+(const kexVec2 &vec) const; - kexVec2 operator+(kexVec2 &vec); - kexVec2 operator-() const; - kexVec2 operator-(const kexVec2 &vec) const; - kexVec2 operator*(const kexVec2 &vec); - kexVec2 operator*(const float val); - kexVec2 operator*(const float val) const; - kexVec2 operator/(const kexVec2 &vec); - kexVec2 operator/(const float val); - kexVec2 &operator=(kexVec3 &vec); - kexVec2 &operator=(const kexVec2 &vec); - kexVec2 &operator=(const kexVec3 &vec); - kexVec2 &operator=(const float *vecs); - kexVec2 &operator+=(const kexVec2 &vec); - kexVec2 &operator-=(const kexVec2 &vec); - kexVec2 &operator*=(const kexVec2 &vec); - kexVec2 &operator*=(const float val); - kexVec2 &operator/=(const kexVec2 &vec); - kexVec2 &operator/=(const float val); - kexVec2 operator*(const kexMatrix &mtx); - kexVec2 operator*(const kexMatrix &mtx) const; - kexVec2 &operator*=(const kexMatrix &mtx); - float operator[](int index) const; - float &operator[](int index); - bool operator==(const kexVec2 &vec); + kexVec2 operator+(const kexVec2 &vec); + kexVec2 operator+(const kexVec2 &vec) const; + kexVec2 operator+(kexVec2 &vec); + kexVec2 operator-() const; + kexVec2 operator-(const kexVec2 &vec) const; + kexVec2 operator*(const kexVec2 &vec); + kexVec2 operator*(const float val); + kexVec2 operator*(const float val) const; + kexVec2 operator/(const kexVec2 &vec); + kexVec2 operator/(const float val); + kexVec2 &operator=(kexVec3 &vec); + kexVec2 &operator=(const kexVec2 &vec); + kexVec2 &operator=(const kexVec3 &vec); + kexVec2 &operator=(const float *vecs); + kexVec2 &operator+=(const kexVec2 &vec); + kexVec2 &operator-=(const kexVec2 &vec); + kexVec2 &operator*=(const kexVec2 &vec); + kexVec2 &operator*=(const float val); + kexVec2 &operator/=(const kexVec2 &vec); + kexVec2 &operator/=(const float val); + kexVec2 operator*(const kexMatrix &mtx); + kexVec2 operator*(const kexMatrix &mtx) const; + kexVec2 &operator*=(const kexMatrix &mtx); + float operator[](int index) const; + float &operator[](int index); + bool operator==(const kexVec2 &vec); - operator float *() { return reinterpret_cast(&x); } + operator float *() { return reinterpret_cast(&x); } - static kexVec2 vecZero; - static const kexVec2 vecRight; - static const kexVec2 vecUp; + static kexVec2 vecZero; + static const kexVec2 vecRight; + static const kexVec2 vecUp; - float x; - float y; + float x; + float y; }; class kexVec3 { public: - kexVec3(); - explicit kexVec3(const float x, const float y, const float z); + kexVec3(); + explicit kexVec3(const float x, const float y, const float z); - void Set(const float x, const float y, const float z); - void Clear(); - float Dot(const kexVec3 &vec) const; - static float Dot(const kexVec3 &vec1, const kexVec3 &vec2); - kexVec3 Cross(const kexVec3 &vec) const; - static kexVec3 Cross(const kexVec3 &vec1, const kexVec3 &vec2); - float UnitSq() const; - float Unit() const; + void Set(const float x, const float y, const float z); + void Clear(); + float Dot(const kexVec3 &vec) const; + static float Dot(const kexVec3 &vec1, const kexVec3 &vec2); + kexVec3 Cross(const kexVec3 &vec) const; + static kexVec3 Cross(const kexVec3 &vec1, const kexVec3 &vec2); + float UnitSq() const; + float Unit() const; float LengthSq() const { return UnitSq(); } float Length() const { return Unit(); } float DistanceSq(const kexVec3 &vec) const; - float Distance(const kexVec3 &vec) const; - kexVec3 &Normalize(); + float Distance(const kexVec3 &vec) const; + kexVec3 &Normalize(); static kexVec3 Normalize(kexVec3 a); - kexAngle PointAt(kexVec3 &location) const; - kexVec3 Lerp(const kexVec3 &next, float movement) const; - kexVec3 &Lerp(const kexVec3 &start, const kexVec3 &next, float movement); - kexQuat ToQuat(); - float ToYaw() const; - float ToPitch() const; - kexStr ToString() const; - float *ToFloatPtr(); - kexVec2 ToVec2(); - kexVec2 ToVec2() const; - kexVec3 ScreenProject(kexMatrix &proj, kexMatrix &model, - const int width, const int height, - const int wx, const int wy); + kexAngle PointAt(kexVec3 &location) const; + kexVec3 Lerp(const kexVec3 &next, float movement) const; + kexVec3 &Lerp(const kexVec3 &start, const kexVec3 &next, float movement); + kexQuat ToQuat(); + float ToYaw() const; + float ToPitch() const; + kexStr ToString() const; + float *ToFloatPtr(); + kexVec2 ToVec2(); + kexVec2 ToVec2() const; + kexVec3 ScreenProject(kexMatrix &proj, kexMatrix &model, + const int width, const int height, + const int wx, const int wy); - kexVec3 operator+(const kexVec3 &vec); - kexVec3 operator+(const kexVec3 &vec) const; - kexVec3 operator+(kexVec3 &vec); + kexVec3 operator+(const kexVec3 &vec); + kexVec3 operator+(const kexVec3 &vec) const; + kexVec3 operator+(kexVec3 &vec); kexVec3 operator+(const float val) const; kexVec3 operator-() const; kexVec3 operator-(const float val) const; kexVec3 operator-(const kexVec3 &vec) const; - kexVec3 operator*(const kexVec3 &vec); - kexVec3 operator*(const float val); - kexVec3 operator*(const float val) const; - kexVec3 operator/(const kexVec3 &vec); - kexVec3 operator/(const float val); - kexVec3 operator*(const kexQuat &quat); - kexVec3 operator*(const kexMatrix &mtx); - kexVec3 operator*(const kexMatrix &mtx) const; - kexVec3 &operator=(const kexVec3 &vec); - kexVec3 &operator=(const float *vecs); - kexVec3 &operator+=(const kexVec3 &vec); + kexVec3 operator*(const kexVec3 &vec); + kexVec3 operator*(const float val); + kexVec3 operator*(const float val) const; + kexVec3 operator/(const kexVec3 &vec); + kexVec3 operator/(const float val); + kexVec3 operator*(const kexQuat &quat); + kexVec3 operator*(const kexMatrix &mtx); + kexVec3 operator*(const kexMatrix &mtx) const; + kexVec3 &operator=(const kexVec3 &vec); + kexVec3 &operator=(const float *vecs); + kexVec3 &operator+=(const kexVec3 &vec); kexVec3 &operator+=(const float val); kexVec3 &operator-=(const kexVec3 &vec); kexVec3 &operator-=(const float val); kexVec3 &operator*=(const kexVec3 &vec); - kexVec3 &operator*=(const float val); - kexVec3 &operator/=(const kexVec3 &vec); - kexVec3 &operator/=(const float val); - kexVec3 &operator*=(const kexQuat &quat); - kexVec3 &operator*=(const kexMatrix &mtx); - float operator[](int index) const; - float &operator[](int index); + kexVec3 &operator*=(const float val); + kexVec3 &operator/=(const kexVec3 &vec); + kexVec3 &operator/=(const float val); + kexVec3 &operator*=(const kexQuat &quat); + kexVec3 &operator*=(const kexMatrix &mtx); + float operator[](int index) const; + float &operator[](int index); - operator float *() { return reinterpret_cast(&x); } + operator float *() { return reinterpret_cast(&x); } - static const kexVec3 vecForward; - static const kexVec3 vecUp; - static const kexVec3 vecRight; + static const kexVec3 vecForward; + static const kexVec3 vecUp; + static const kexVec3 vecRight; - float x; - float y; - float z; + float x; + float y; + float z; }; class kexVec4 { public: - kexVec4(); - explicit kexVec4(const float x, const float y, const float z, const float w); + kexVec4(); + explicit kexVec4(const float x, const float y, const float z, const float w); explicit kexVec4(const kexVec3 &v, const float w); - void Set(const float x, const float y, const float z, const float w); - void Clear(); - float *ToFloatPtr(); + void Set(const float x, const float y, const float z, const float w); + void Clear(); + float *ToFloatPtr(); static float Dot(const kexVec4 &a, const kexVec4 &b) { return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; } - const kexVec3 &ToVec3() const; - kexVec3 &ToVec3(); - kexVec4 operator|(const kexMatrix &mtx); - kexVec4 &operator|=(const kexMatrix &mtx); + const kexVec3 &ToVec3() const; + kexVec3 &ToVec3(); + kexVec4 operator|(const kexMatrix &mtx); + kexVec4 &operator|=(const kexMatrix &mtx); kexVec4 operator+(const kexVec4 &vec) const; kexVec4 operator+(const float val) const; kexVec4 operator-(const kexVec4 &vec) const; @@ -313,187 +313,187 @@ public: kexVec4 &operator/=(const kexVec4 &vec); kexVec4 &operator/=(const float val); float operator[](int index) const; - float &operator[](int index); + float &operator[](int index); - float x; - float y; - float z; - float w; + float x; + float y; + float z; + float w; }; class kexMatrix { public: - kexMatrix(); - kexMatrix(const kexMatrix &mtx); - kexMatrix(const float x, const float y, const float z); - kexMatrix(const kexQuat &quat); - kexMatrix(const float angle, const int axis); + kexMatrix(); + kexMatrix(const kexMatrix &mtx); + kexMatrix(const float x, const float y, const float z); + kexMatrix(const kexQuat &quat); + kexMatrix(const float angle, const int axis); - kexMatrix &Identity(); - kexMatrix &Identity(const float x, const float y, const float z); - kexMatrix &SetTranslation(const float x, const float y, const float z); - kexMatrix &SetTranslation(const kexVec3 &vector); - kexMatrix &AddTranslation(const float x, const float y, const float z); - kexMatrix &AddTranslation(const kexVec3 &vector); - kexMatrix &Scale(const float x, const float y, const float z); - kexMatrix &Scale(const kexVec3 &vector); - static kexMatrix Scale(const kexMatrix &mtx, const float x, const float y, const float z); - kexMatrix &Transpose(); - static kexMatrix Transpose(const kexMatrix &mtx); - static kexMatrix Invert(kexMatrix &mtx); - kexQuat ToQuat(); - float *ToFloatPtr(); - void SetViewProjection(float aspect, float fov, float zNear, float zFar); - void SetOrtho(float left, float right, - float bottom, float top, - float zNear, float zFar); + kexMatrix &Identity(); + kexMatrix &Identity(const float x, const float y, const float z); + kexMatrix &SetTranslation(const float x, const float y, const float z); + kexMatrix &SetTranslation(const kexVec3 &vector); + kexMatrix &AddTranslation(const float x, const float y, const float z); + kexMatrix &AddTranslation(const kexVec3 &vector); + kexMatrix &Scale(const float x, const float y, const float z); + kexMatrix &Scale(const kexVec3 &vector); + static kexMatrix Scale(const kexMatrix &mtx, const float x, const float y, const float z); + kexMatrix &Transpose(); + static kexMatrix Transpose(const kexMatrix &mtx); + static kexMatrix Invert(kexMatrix &mtx); + kexQuat ToQuat(); + float *ToFloatPtr(); + void SetViewProjection(float aspect, float fov, float zNear, float zFar); + void SetOrtho(float left, float right, + float bottom, float top, + float zNear, float zFar); - kexMatrix operator*(const kexVec3 &vector); - kexMatrix &operator*=(const kexVec3 &vector); - kexMatrix operator*(const kexMatrix &matrix); - kexMatrix &operator*=(const kexMatrix &matrix); - friend kexMatrix operator*(const kexMatrix &m1, const kexMatrix &m2); - kexMatrix &operator=(const kexMatrix &matrix); - kexMatrix &operator=(const float *m); - kexMatrix operator|(const kexMatrix &matrix); + kexMatrix operator*(const kexVec3 &vector); + kexMatrix &operator*=(const kexVec3 &vector); + kexMatrix operator*(const kexMatrix &matrix); + kexMatrix &operator*=(const kexMatrix &matrix); + friend kexMatrix operator*(const kexMatrix &m1, const kexMatrix &m2); + kexMatrix &operator=(const kexMatrix &matrix); + kexMatrix &operator=(const float *m); + kexMatrix operator|(const kexMatrix &matrix); float operator[](size_t i) const { return vectors[i >> 2][i & 3]; } float &operator[](size_t i) { return vectors[i >> 2][i & 3]; } - kexVec4 vectors[4]; + kexVec4 vectors[4]; }; class kexPluecker { public: - kexPluecker(); - kexPluecker(const kexVec3 &start, const kexVec3 &end, bool bRay = false); + kexPluecker(); + kexPluecker(const kexVec3 &start, const kexVec3 &end, bool bRay = false); - void Clear(); - void SetLine(const kexVec3 &start, const kexVec3 &end); - void SetRay(const kexVec3 &start, const kexVec3 &dir); - float InnerProduct(const kexPluecker &pluecker) const; + void Clear(); + void SetLine(const kexVec3 &start, const kexVec3 &end); + void SetRay(const kexVec3 &start, const kexVec3 &dir); + float InnerProduct(const kexPluecker &pluecker) const; - float p[6]; + float p[6]; }; class kexPlane { public: - kexPlane(); - kexPlane(const float a, const float b, const float c, const float d); - kexPlane(const kexVec3 &pt1, const kexVec3 &pt2, const kexVec3 &pt3); - kexPlane(const kexVec3 &normal, const kexVec3 &point); - kexPlane(const kexPlane &plane); + kexPlane(); + kexPlane(const float a, const float b, const float c, const float d); + kexPlane(const kexVec3 &pt1, const kexVec3 &pt2, const kexVec3 &pt3); + kexPlane(const kexVec3 &normal, const kexVec3 &point); + kexPlane(const kexPlane &plane); - enum planeAxis_t - { - AXIS_YZ = 0, - AXIS_XZ, - AXIS_XY - }; + enum planeAxis_t + { + AXIS_YZ = 0, + AXIS_XZ, + AXIS_XY + }; - const kexVec3 &Normal() const; - kexVec3 &Normal(); - kexPlane &SetNormal(const kexVec3 &normal); - kexPlane &SetNormal(const kexVec3 &pt1, const kexVec3 &pt2, const kexVec3 &pt3); - float Distance(const kexVec3 &point); - kexPlane &SetDistance(const kexVec3 &point); - bool IsFacing(const float yaw); - float ToYaw(); - float ToPitch(); - kexQuat ToQuat(); - const kexVec4 &ToVec4() const; - kexVec4 &ToVec4(); - const planeAxis_t BestAxis() const; - kexVec3 GetInclination(); + const kexVec3 &Normal() const; + kexVec3 &Normal(); + kexPlane &SetNormal(const kexVec3 &normal); + kexPlane &SetNormal(const kexVec3 &pt1, const kexVec3 &pt2, const kexVec3 &pt3); + float Distance(const kexVec3 &point); + kexPlane &SetDistance(const kexVec3 &point); + bool IsFacing(const float yaw); + float ToYaw(); + float ToPitch(); + kexQuat ToQuat(); + const kexVec4 &ToVec4() const; + kexVec4 &ToVec4(); + const planeAxis_t BestAxis() const; + kexVec3 GetInclination(); float zAt(float x, float y) const { return (d - a * x - b * y) / c; } - kexPlane &operator|(const kexQuat &quat); - kexPlane &operator|=(const kexQuat &quat); - kexPlane &operator|(const kexMatrix &mtx); - kexPlane &operator|=(const kexMatrix &mtx); + kexPlane &operator|(const kexQuat &quat); + kexPlane &operator|=(const kexQuat &quat); + kexPlane &operator|(const kexMatrix &mtx); + kexPlane &operator|=(const kexMatrix &mtx); - float a; - float b; - float c; - float d; + float a; + float b; + float c; + float d; }; class kexAngle { public: - kexAngle(); - kexAngle(const float yaw, const float pitch, const float roll); - kexAngle(const kexVec3 &vector); - kexAngle(const kexAngle &an); + kexAngle(); + kexAngle(const float yaw, const float pitch, const float roll); + kexAngle(const kexVec3 &vector); + kexAngle(const kexAngle &an); - kexAngle &Round(); - kexAngle &Clamp180(); - kexAngle &Clamp180Invert(); - kexAngle &Clamp180InvertSum(const kexAngle &angle); - kexAngle Diff(kexAngle &angle); - void ToAxis(kexVec3 *forward, kexVec3 *up, kexVec3 *right); - kexVec3 ToForwardAxis(); - kexVec3 ToUpAxis(); - kexVec3 ToRightAxis(); - const kexVec3 &ToVec3() const; - kexVec3 &ToVec3(); - kexQuat ToQuat(); + kexAngle &Round(); + kexAngle &Clamp180(); + kexAngle &Clamp180Invert(); + kexAngle &Clamp180InvertSum(const kexAngle &angle); + kexAngle Diff(kexAngle &angle); + void ToAxis(kexVec3 *forward, kexVec3 *up, kexVec3 *right); + kexVec3 ToForwardAxis(); + kexVec3 ToUpAxis(); + kexVec3 ToRightAxis(); + const kexVec3 &ToVec3() const; + kexVec3 &ToVec3(); + kexQuat ToQuat(); - kexAngle operator+(const kexAngle &angle); - kexAngle operator-(const kexAngle &angle); - kexAngle &operator+=(const kexAngle &angle); - kexAngle &operator-=(const kexAngle &angle); - kexAngle &operator=(const kexAngle &angle); - kexAngle &operator=(const kexVec3 &vector); - kexAngle &operator=(const float *vecs); - kexAngle operator-(); - float operator[](int index) const; - float &operator[](int index); + kexAngle operator+(const kexAngle &angle); + kexAngle operator-(const kexAngle &angle); + kexAngle &operator+=(const kexAngle &angle); + kexAngle &operator-=(const kexAngle &angle); + kexAngle &operator=(const kexAngle &angle); + kexAngle &operator=(const kexVec3 &vector); + kexAngle &operator=(const float *vecs); + kexAngle operator-(); + float operator[](int index) const; + float &operator[](int index); - float yaw; - float pitch; - float roll; + float yaw; + float pitch; + float roll; }; class kexBBox { public: - kexBBox(); - explicit kexBBox(const kexVec3 &vMin, const kexVec3 &vMax); + kexBBox(); + explicit kexBBox(const kexVec3 &vMin, const kexVec3 &vMax); - void Clear(); - kexVec3 Center() const; + void Clear(); + kexVec3 Center() const; kexVec3 Extents() const; float Radius() const; - void AddPoint(const kexVec3 &vec); - bool PointInside(const kexVec3 &vec) const; - bool IntersectingBox(const kexBBox &box) const; - bool IntersectingBox2D(const kexBBox &box) const; - float DistanceToPlane(kexPlane &plane); - bool LineIntersect(const kexVec3 &start, const kexVec3 &end); - void ToPoints(float *points) const; - void ToVectors(kexVec3 *vectors) const; + void AddPoint(const kexVec3 &vec); + bool PointInside(const kexVec3 &vec) const; + bool IntersectingBox(const kexBBox &box) const; + bool IntersectingBox2D(const kexBBox &box) const; + float DistanceToPlane(kexPlane &plane); + bool LineIntersect(const kexVec3 &start, const kexVec3 &end); + void ToPoints(float *points) const; + void ToVectors(kexVec3 *vectors) const; - kexBBox operator+(const float radius) const; - kexBBox &operator+=(const float radius); - kexBBox operator+(const kexVec3 &vec) const; - kexBBox operator-(const float radius) const; - kexBBox operator-(const kexVec3 &vec) const; - kexBBox &operator-=(const float radius); - kexBBox operator*(const kexMatrix &matrix) const; - kexBBox &operator*=(const kexMatrix &matrix); - kexBBox operator*(const kexVec3 &vec) const; - kexBBox &operator*=(const kexVec3 &vec); - kexBBox &operator=(const kexBBox &bbox); - kexVec3 operator[](int index) const; - kexVec3 &operator[](int index); + kexBBox operator+(const float radius) const; + kexBBox &operator+=(const float radius); + kexBBox operator+(const kexVec3 &vec) const; + kexBBox operator-(const float radius) const; + kexBBox operator-(const kexVec3 &vec) const; + kexBBox &operator-=(const float radius); + kexBBox operator*(const kexMatrix &matrix) const; + kexBBox &operator*=(const kexMatrix &matrix); + kexBBox operator*(const kexVec3 &vec) const; + kexBBox &operator*=(const kexVec3 &vec); + kexBBox &operator=(const kexBBox &bbox); + kexVec3 operator[](int index) const; + kexVec3 &operator[](int index); - kexVec3 min; - kexVec3 max; + kexVec3 min; + kexVec3 max; }; // @@ -502,7 +502,7 @@ public: d_inline float kexMath::Sin(float x) { - return sinf(x); + return sinf(x); } // @@ -511,7 +511,7 @@ d_inline float kexMath::Sin(float x) d_inline float kexMath::Cos(float x) { - return cosf(x); + return cosf(x); } // @@ -520,7 +520,7 @@ d_inline float kexMath::Cos(float x) d_inline float kexMath::Tan(float x) { - return tanf(x); + return tanf(x); } // @@ -529,7 +529,7 @@ d_inline float kexMath::Tan(float x) d_inline float kexMath::ATan2(float x, float y) { - return atan2f(x, y); + return atan2f(x, y); } // @@ -538,7 +538,7 @@ d_inline float kexMath::ATan2(float x, float y) d_inline float kexMath::ACos(float x) { - return acosf(x); + return acosf(x); } // @@ -547,7 +547,7 @@ d_inline float kexMath::ACos(float x) d_inline float kexMath::Sqrt(float x) { - return x * InvSqrt(x); + return x * InvSqrt(x); } // @@ -556,7 +556,7 @@ d_inline float kexMath::Sqrt(float x) d_inline float kexMath::Pow(float x, float y) { - return powf(x, y); + return powf(x, y); } // @@ -565,7 +565,7 @@ d_inline float kexMath::Pow(float x, float y) d_inline float kexMath::Log(float x) { - return logf(x); + return logf(x); } // @@ -574,7 +574,7 @@ d_inline float kexMath::Log(float x) d_inline float kexMath::Floor(float x) { - return floorf(x); + return floorf(x); } // @@ -583,7 +583,7 @@ d_inline float kexMath::Floor(float x) d_inline float kexMath::Ceil(float x) { - return ceilf(x); + return ceilf(x); } // @@ -592,7 +592,7 @@ d_inline float kexMath::Ceil(float x) d_inline float kexMath::Deg2Rad(float x) { - return DEG2RAD(x); + return DEG2RAD(x); } // @@ -601,7 +601,7 @@ d_inline float kexMath::Deg2Rad(float x) d_inline float kexMath::Rad2Deg(float x) { - return RAD2DEG(x); + return RAD2DEG(x); } // @@ -610,8 +610,8 @@ d_inline float kexMath::Rad2Deg(float x) d_inline int kexMath::Abs(int x) { - int y = x >> 31; - return ((x ^ y) - y); + int y = x >> 31; + return ((x ^ y) - y); } // @@ -620,9 +620,9 @@ d_inline int kexMath::Abs(int x) d_inline float kexMath::Fabs(float x) { - int tmp = *reinterpret_cast(&x); - tmp &= 0x7FFFFFFF; - return *reinterpret_cast(&tmp); + int tmp = *reinterpret_cast(&x); + tmp &= 0x7FFFFFFF; + return *reinterpret_cast(&tmp); } // @@ -631,17 +631,17 @@ d_inline float kexMath::Fabs(float x) d_inline float kexMath::InvSqrt(float x) { - unsigned int i; - float r; - float y; + unsigned int i; + float r; + float y; - y = x * 0.5f; - i = *reinterpret_cast(&x); - i = 0x5f3759df - (i >> 1); - r = *reinterpret_cast(&i); - r = r * (1.5f - r * r * y); + y = x * 0.5f; + i = *reinterpret_cast(&x); + i = 0x5f3759df - (i >> 1); + r = *reinterpret_cast(&i); + r = r * (1.5f - r * r * y); - return r; + return r; } // @@ -650,8 +650,8 @@ d_inline float kexMath::InvSqrt(float x) d_inline void kexMath::Clamp(float &f, const float min, const float max) { - if(f < min) { f = min; } - if(f > max) { f = max; } + if (f < min) { f = min; } + if (f > max) { f = max; } } // @@ -660,8 +660,8 @@ d_inline void kexMath::Clamp(float &f, const float min, const float max) d_inline void kexMath::Clamp(byte &b, const byte min, const byte max) { - if(b < min) { b = min; } - if(b > max) { b = max; } + if (b < min) { b = min; } + if (b > max) { b = max; } } // @@ -670,8 +670,8 @@ d_inline void kexMath::Clamp(byte &b, const byte min, const byte max) d_inline void kexMath::Clamp(int &i, const int min, const int max) { - if(i < min) { i = min; } - if(i > max) { i = max; } + if (i < min) { i = min; } + if (i > max) { i = max; } } // @@ -680,10 +680,10 @@ d_inline void kexMath::Clamp(int &i, const int min, const int max) d_inline void kexMath::Clamp(kexVec3 &v, const float min, const float max) { - if(v.x < min) { v.x = min; } - if(v.x > max) { v.x = max; } - if(v.y < min) { v.y = min; } - if(v.y > max) { v.y = max; } - if(v.z < min) { v.z = min; } - if(v.z > max) { v.z = max; } + if (v.x < min) { v.x = min; } + if (v.x > max) { v.x = max; } + if (v.y < min) { v.y = min; } + if (v.y > max) { v.y = max; } + if (v.z < min) { v.z = min; } + if (v.z > max) { v.z = max; } } diff --git a/src/lightmap/kexlib/math/matrix.cpp b/src/lightmap/kexlib/math/matrix.cpp index 137b243..9a7e7f9 100644 --- a/src/lightmap/kexlib/math/matrix.cpp +++ b/src/lightmap/kexlib/math/matrix.cpp @@ -79,7 +79,7 @@ kexMatrix::kexMatrix() { - Identity(); + Identity(); } // @@ -88,13 +88,13 @@ kexMatrix::kexMatrix() kexMatrix::kexMatrix(const kexMatrix &mtx) { - for(int i = 0; i < 4; i++) - { - vectors[i].x = mtx.vectors[i].x; - vectors[i].y = mtx.vectors[i].y; - vectors[i].z = mtx.vectors[i].z; - vectors[i].w = mtx.vectors[i].w; - } + for (int i = 0; i < 4; i++) + { + vectors[i].x = mtx.vectors[i].x; + vectors[i].y = mtx.vectors[i].y; + vectors[i].z = mtx.vectors[i].z; + vectors[i].w = mtx.vectors[i].w; + } } // @@ -103,7 +103,7 @@ kexMatrix::kexMatrix(const kexMatrix &mtx) kexMatrix::kexMatrix(const float x, const float y, const float z) { - Identity(x, y, z); + Identity(x, y, z); } // @@ -112,33 +112,33 @@ kexMatrix::kexMatrix(const float x, const float y, const float z) kexMatrix::kexMatrix(const kexQuat &quat) { - float xx = quat.x * quat.x; - float yx = quat.y * quat.x; - float zx = quat.z * quat.x; - float wx = quat.w * quat.x; - float yy = quat.y * quat.y; - float zy = quat.z * quat.y; - float wy = quat.w * quat.y; - float zz = quat.z * quat.z; - float wz = quat.w * quat.z; - float ww = quat.w * quat.w; + float xx = quat.x * quat.x; + float yx = quat.y * quat.x; + float zx = quat.z * quat.x; + float wx = quat.w * quat.x; + float yy = quat.y * quat.y; + float zy = quat.z * quat.y; + float wy = quat.w * quat.y; + float zz = quat.z * quat.z; + float wz = quat.w * quat.z; + float ww = quat.w * quat.w; - vectors[0].Set( - ((ww + xx) - yy) - zz, - (wz + wz) + (yx + yx), - (zx + zx) - (wy + wy), - 0); - vectors[1].Set( - (yx + yx) - (wz + wz), - (yy + (ww - xx)) - zz, - (wx + wx) + (zy + zy), - 0); - vectors[2].Set( - (wy + wy + zx + zx), - (zy + zy) - (wx + wx), - ((ww - xx) - yy) + zz, - 0); - vectors[3].Set(0, 0, 0, 1); + vectors[0].Set( + ((ww + xx) - yy) - zz, + (wz + wz) + (yx + yx), + (zx + zx) - (wy + wy), + 0); + vectors[1].Set( + (yx + yx) - (wz + wz), + (yy + (ww - xx)) - zz, + (wx + wx) + (zy + zy), + 0); + vectors[2].Set( + (wy + wy + zx + zx), + (zy + zy) - (wx + wx), + ((ww - xx) - yy) + zz, + 0); + vectors[3].Set(0, 0, 0, 1); } // @@ -147,35 +147,35 @@ kexMatrix::kexMatrix(const kexQuat &quat) kexMatrix::kexMatrix(const float angle, const int axis) { - float s; - float c; + float s; + float c; - s = kexMath::Sin(angle); - c = kexMath::Cos(angle); + s = kexMath::Sin(angle); + c = kexMath::Cos(angle); - Identity(); + Identity(); - switch(axis) - { - case 0: - this->vectors[0].x = c; - this->vectors[0].z = -s; - this->vectors[3].x = s; - this->vectors[3].z = c; - break; - case 1: - this->vectors[1].y = c; - this->vectors[1].z = s; - this->vectors[2].y = -s; - this->vectors[2].z = c; - break; - case 2: - this->vectors[0].x = c; - this->vectors[0].y = s; - this->vectors[1].x = -s; - this->vectors[1].y = c; - break; - } + switch (axis) + { + case 0: + this->vectors[0].x = c; + this->vectors[0].z = -s; + this->vectors[3].x = s; + this->vectors[3].z = c; + break; + case 1: + this->vectors[1].y = c; + this->vectors[1].z = s; + this->vectors[2].y = -s; + this->vectors[2].z = c; + break; + case 2: + this->vectors[0].x = c; + this->vectors[0].y = s; + this->vectors[1].x = -s; + this->vectors[1].y = c; + break; + } } // @@ -184,12 +184,12 @@ kexMatrix::kexMatrix(const float angle, const int axis) kexMatrix &kexMatrix::Identity() { - vectors[0].Set(1, 0, 0, 0); - vectors[1].Set(0, 1, 0, 0); - vectors[2].Set(0, 0, 1, 0); - vectors[3].Set(0, 0, 0, 1); + vectors[0].Set(1, 0, 0, 0); + vectors[1].Set(0, 1, 0, 0); + vectors[2].Set(0, 0, 1, 0); + vectors[3].Set(0, 0, 0, 1); - return *this; + return *this; } // @@ -198,12 +198,12 @@ kexMatrix &kexMatrix::Identity() kexMatrix &kexMatrix::Identity(const float x, const float y, const float z) { - vectors[0].Set(x, 0, 0, 0); - vectors[1].Set(0, y, 0, 0); - vectors[2].Set(0, 0, z, 0); - vectors[3].Set(0, 0, 0, 1); + vectors[0].Set(x, 0, 0, 0); + vectors[1].Set(0, y, 0, 0); + vectors[2].Set(0, 0, z, 0); + vectors[3].Set(0, 0, 0, 1); - return *this; + return *this; } // @@ -212,8 +212,8 @@ kexMatrix &kexMatrix::Identity(const float x, const float y, const float z) kexMatrix &kexMatrix::SetTranslation(const float x, const float y, const float z) { - vectors[3].ToVec3().Set(x, y, z); - return *this; + vectors[3].ToVec3().Set(x, y, z); + return *this; } // @@ -222,8 +222,8 @@ kexMatrix &kexMatrix::SetTranslation(const float x, const float y, const float z kexMatrix &kexMatrix::SetTranslation(const kexVec3 &vector) { - vectors[3].ToVec3() = vector; - return *this; + vectors[3].ToVec3() = vector; + return *this; } // @@ -232,10 +232,10 @@ kexMatrix &kexMatrix::SetTranslation(const kexVec3 &vector) kexMatrix &kexMatrix::AddTranslation(const float x, const float y, const float z) { - vectors[3].x += x; - vectors[3].y += y; - vectors[3].z += z; - return *this; + vectors[3].x += x; + vectors[3].y += y; + vectors[3].z += z; + return *this; } // @@ -244,8 +244,8 @@ kexMatrix &kexMatrix::AddTranslation(const float x, const float y, const float z kexMatrix &kexMatrix::AddTranslation(const kexVec3 &vector) { - vectors[3].ToVec3() += vector; - return *this; + vectors[3].ToVec3() += vector; + return *this; } // @@ -254,11 +254,11 @@ kexMatrix &kexMatrix::AddTranslation(const kexVec3 &vector) kexMatrix &kexMatrix::Scale(const float x, const float y, const float z) { - vectors[0].ToVec3() *= x; - vectors[1].ToVec3() *= y; - vectors[2].ToVec3() *= z; + vectors[0].ToVec3() *= x; + vectors[1].ToVec3() *= y; + vectors[2].ToVec3() *= z; - return *this; + return *this; } // @@ -267,11 +267,11 @@ kexMatrix &kexMatrix::Scale(const float x, const float y, const float z) kexMatrix &kexMatrix::Scale(const kexVec3 &vector) { - vectors[0].ToVec3() *= vector.x; - vectors[1].ToVec3() *= vector.y; - vectors[2].ToVec3() *= vector.z; + vectors[0].ToVec3() *= vector.x; + vectors[1].ToVec3() *= vector.y; + vectors[2].ToVec3() *= vector.z; - return *this; + return *this; } // @@ -280,13 +280,13 @@ kexMatrix &kexMatrix::Scale(const kexVec3 &vector) kexMatrix kexMatrix::Scale(const kexMatrix &mtx, const float x, const float y, const float z) { - kexMatrix out; + kexMatrix out; - out.vectors[0].ToVec3() = mtx.vectors[0].ToVec3() * x; - out.vectors[1].ToVec3() = mtx.vectors[1].ToVec3() * y; - out.vectors[2].ToVec3() = mtx.vectors[2].ToVec3() * z; + out.vectors[0].ToVec3() = mtx.vectors[0].ToVec3() * x; + out.vectors[1].ToVec3() = mtx.vectors[1].ToVec3() * y; + out.vectors[2].ToVec3() = mtx.vectors[2].ToVec3() * z; - return out; + return out; } // @@ -295,12 +295,12 @@ kexMatrix kexMatrix::Scale(const kexMatrix &mtx, const float x, const float y, c kexMatrix &kexMatrix::Transpose() { - kexVec3 v1 = vectors[1].ToVec3(); - kexVec3 v2 = vectors[2].ToVec3(); + kexVec3 v1 = vectors[1].ToVec3(); + kexVec3 v2 = vectors[2].ToVec3(); - vectors[1].ToVec3() = v2; - vectors[2].ToVec3() = v1; - return *this; + vectors[1].ToVec3() = v2; + vectors[2].ToVec3() = v1; + return *this; } // @@ -309,14 +309,14 @@ kexMatrix &kexMatrix::Transpose() kexMatrix kexMatrix::Transpose(const kexMatrix &mtx) { - kexMatrix out; + kexMatrix out; - out.vectors[0].ToVec3() = mtx.vectors[0].ToVec3(); - out.vectors[1].ToVec3() = mtx.vectors[2].ToVec3(); - out.vectors[2].ToVec3() = mtx.vectors[1].ToVec3(); - out.vectors[3].ToVec3() = mtx.vectors[3].ToVec3(); + out.vectors[0].ToVec3() = mtx.vectors[0].ToVec3(); + out.vectors[1].ToVec3() = mtx.vectors[2].ToVec3(); + out.vectors[2].ToVec3() = mtx.vectors[1].ToVec3(); + out.vectors[3].ToVec3() = mtx.vectors[3].ToVec3(); - return out; + return out; } // @@ -325,62 +325,62 @@ kexMatrix kexMatrix::Transpose(const kexMatrix &mtx) kexMatrix kexMatrix::Invert(kexMatrix &mtx) { - float d; - float *m; + float d; + float *m; - m = mtx.ToFloatPtr(); + m = mtx.ToFloatPtr(); - d = m[ 0] * m[10] * m[ 5] - - m[ 0] * m[ 9] * m[ 6] - - m[ 1] * m[ 4] * m[10] + - m[ 2] * m[ 4] * m[ 9] + - m[ 1] * m[ 6] * m[ 8] - - m[ 2] * m[ 5] * m[ 8]; + d = m[0] * m[10] * m[5] - + m[0] * m[9] * m[6] - + m[1] * m[4] * m[10] + + m[2] * m[4] * m[9] + + m[1] * m[6] * m[8] - + m[2] * m[5] * m[8]; - if(d != 0.0f) - { - kexMatrix inv; + if (d != 0.0f) + { + kexMatrix inv; - d = (1.0f / d); + d = (1.0f / d); - inv.vectors[0].x = ( m[10] * m[ 5] - m[ 9] * m[ 6]) * d; - inv.vectors[0].y = -((m[ 1] * m[10] - m[ 2] * m[ 9]) * d); - inv.vectors[0].z = ( m[ 1] * m[ 6] - m[ 2] * m[ 5]) * d; - inv.vectors[0].w = 0; - inv.vectors[1].x = ( m[ 6] * m[ 8] - m[ 4] * m[10]) * d; - inv.vectors[1].y = ( m[ 0] * m[10] - m[ 2] * m[ 8]) * d; - inv.vectors[1].z = -((m[ 0] * m[ 6] - m[ 2] * m[ 4]) * d); - inv.vectors[1].w = 0; - inv.vectors[2].x = -((m[ 5] * m[ 8] - m[ 4] * m[ 9]) * d); - inv.vectors[2].y = ( m[ 1] * m[ 8] - m[ 0] * m[ 9]) * d; - inv.vectors[2].z = -((m[ 1] * m[ 4] - m[ 0] * m[ 5]) * d); - inv.vectors[2].w = 0; - inv.vectors[3].x = ( - ( m[13] * m[10] - m[14] * m[ 9]) * m[ 4] - + m[14] * m[ 5] * m[ 8] - - m[13] * m[ 6] * m[ 8] - - m[12] * m[10] * m[ 5] - + m[12] * m[ 9] * m[ 6]) * d; - inv.vectors[3].y = ( - m[ 0] * m[14] * m[ 9] - - m[ 0] * m[13] * m[10] - - m[14] * m[ 1] * m[ 8] - + m[13] * m[ 2] * m[ 8] - + m[12] * m[ 1] * m[10] - - m[12] * m[ 2] * m[ 9]) * d; - inv.vectors[3].z = -( - ( m[ 0] * m[14] * m[ 5] - - m[ 0] * m[13] * m[ 6] - - m[14] * m[ 1] * m[ 4] - + m[13] * m[ 2] * m[ 4] - + m[12] * m[ 1] * m[ 6] - - m[12] * m[ 2] * m[ 5]) * d); - inv.vectors[3].w = 1.0f; + inv.vectors[0].x = (m[10] * m[5] - m[9] * m[6]) * d; + inv.vectors[0].y = -((m[1] * m[10] - m[2] * m[9]) * d); + inv.vectors[0].z = (m[1] * m[6] - m[2] * m[5]) * d; + inv.vectors[0].w = 0; + inv.vectors[1].x = (m[6] * m[8] - m[4] * m[10]) * d; + inv.vectors[1].y = (m[0] * m[10] - m[2] * m[8]) * d; + inv.vectors[1].z = -((m[0] * m[6] - m[2] * m[4]) * d); + inv.vectors[1].w = 0; + inv.vectors[2].x = -((m[5] * m[8] - m[4] * m[9]) * d); + inv.vectors[2].y = (m[1] * m[8] - m[0] * m[9]) * d; + inv.vectors[2].z = -((m[1] * m[4] - m[0] * m[5]) * d); + inv.vectors[2].w = 0; + inv.vectors[3].x = ( + (m[13] * m[10] - m[14] * m[9]) * m[4] + + m[14] * m[5] * m[8] + - m[13] * m[6] * m[8] + - m[12] * m[10] * m[5] + + m[12] * m[9] * m[6]) * d; + inv.vectors[3].y = ( + m[0] * m[14] * m[9] + - m[0] * m[13] * m[10] + - m[14] * m[1] * m[8] + + m[13] * m[2] * m[8] + + m[12] * m[1] * m[10] + - m[12] * m[2] * m[9]) * d; + inv.vectors[3].z = -( + (m[0] * m[14] * m[5] + - m[0] * m[13] * m[6] + - m[14] * m[1] * m[4] + + m[13] * m[2] * m[4] + + m[12] * m[1] * m[6] + - m[12] * m[2] * m[5]) * d); + inv.vectors[3].w = 1.0f; - return inv; - } + return inv; + } - return mtx; + return mtx; } // @@ -389,29 +389,29 @@ kexMatrix kexMatrix::Invert(kexMatrix &mtx) void kexMatrix::SetViewProjection(float aspect, float fov, float zNear, float zFar) { - float top = zNear * kexMath::Tan(fov * M_PI / 360.0f); - float bottom = -top; - float left = bottom * aspect; - float right = top * aspect; + float top = zNear * kexMath::Tan(fov * M_PI / 360.0f); + float bottom = -top; + float left = bottom * aspect; + float right = top * aspect; - vectors[0].x = (2 * zNear) / (right - left); - vectors[1].y = (2 * zNear) / (top - bottom); - vectors[3].z = -(2 * zFar * zNear) / (zFar - zNear); + vectors[0].x = (2 * zNear) / (right - left); + vectors[1].y = (2 * zNear) / (top - bottom); + vectors[3].z = -(2 * zFar * zNear) / (zFar - zNear); - vectors[2].x = (right + left) / (right - left); - vectors[2].y = (top + bottom) / (top - bottom); - vectors[2].z = -(zFar + zNear) / (zFar - zNear); + vectors[2].x = (right + left) / (right - left); + vectors[2].y = (top + bottom) / (top - bottom); + vectors[2].z = -(zFar + zNear) / (zFar - zNear); - vectors[0].y = 0; - vectors[0].z = 0; - vectors[0].w = 0; - vectors[1].x = 0; - vectors[1].w = 0; - vectors[1].z = 0; - vectors[2].w = -1; - vectors[3].x = 0; - vectors[3].y = 0; - vectors[3].w = 0; + vectors[0].y = 0; + vectors[0].z = 0; + vectors[0].w = 0; + vectors[1].x = 0; + vectors[1].w = 0; + vectors[1].z = 0; + vectors[2].w = -1; + vectors[3].x = 0; + vectors[3].y = 0; + vectors[3].w = 0; } // @@ -419,27 +419,27 @@ void kexMatrix::SetViewProjection(float aspect, float fov, float zNear, float zF // void kexMatrix::SetOrtho(float left, float right, - float bottom, float top, - float zNear, float zFar) + float bottom, float top, + float zNear, float zFar) { - vectors[0].x = 2 / (right - left); - vectors[1].y = 2 / (top - bottom); - vectors[2].z = -2 / (zFar - zNear); + vectors[0].x = 2 / (right - left); + vectors[1].y = 2 / (top - bottom); + vectors[2].z = -2 / (zFar - zNear); - vectors[3].x = -(right + left) / (right - left); - vectors[3].y = -(top + bottom) / (top - bottom); - vectors[3].z = -(zFar + zNear) / (zFar - zNear); - vectors[3].w = 1; + vectors[3].x = -(right + left) / (right - left); + vectors[3].y = -(top + bottom) / (top - bottom); + vectors[3].z = -(zFar + zNear) / (zFar - zNear); + vectors[3].w = 1; - vectors[0].y = 0; - vectors[0].z = 0; - vectors[0].w = 0; - vectors[1].x = 0; - vectors[1].z = 0; - vectors[1].w = 0; - vectors[2].x = 0; - vectors[2].y = 0; - vectors[2].w = 0; + vectors[0].y = 0; + vectors[0].z = 0; + vectors[0].w = 0; + vectors[1].x = 0; + vectors[1].z = 0; + vectors[1].w = 0; + vectors[2].x = 0; + vectors[2].y = 0; + vectors[2].w = 0; } // @@ -448,61 +448,61 @@ void kexMatrix::SetOrtho(float left, float right, kexQuat kexMatrix::ToQuat() { - float t; - float d; - float mx; - float my; - float mz; - float m21; - float m20; - float m10; - kexQuat q; + float t; + float d; + float mx; + float my; + float mz; + float m21; + float m20; + float m10; + kexQuat q; - mx = vectors[0][0]; - my = vectors[1][1]; - mz = vectors[2][2]; + mx = vectors[0][0]; + my = vectors[1][1]; + mz = vectors[2][2]; - m21 = (vectors[2][1] - vectors[1][2]); - m20 = (vectors[2][0] - vectors[0][2]); - m10 = (vectors[1][0] - vectors[0][1]); + m21 = (vectors[2][1] - vectors[1][2]); + m20 = (vectors[2][0] - vectors[0][2]); + m10 = (vectors[1][0] - vectors[0][1]); - t = 1.0f + mx + my + mz; + t = 1.0f + mx + my + mz; - if(t > 0) - { - d = 0.5f / kexMath::Sqrt(t); - q.x = m21 * d; - q.y = m20 * d; - q.z = m10 * d; - q.w = 0.25f / d; - } - else if(mx > my && mx > mz) - { - d = kexMath::Sqrt(1.0f + mx - my - mz) * 2; - q.x = 0.5f / d; - q.y = m10 / d; - q.z = m20 / d; - q.w = m21 / d; - } - else if(my > mz) - { - d = kexMath::Sqrt(1.0f + my - mx - mz) * 2; - q.x = m10 / d; - q.y = 0.5f / d; - q.z = m21 / d; - q.w = m20 / d; - } - else - { - d = kexMath::Sqrt(1.0f + mz - mx - my) * 2; - q.x = m20 / d; - q.y = m21 / d; - q.z = 0.5f / d; - q.w = m10 / d; - } + if (t > 0) + { + d = 0.5f / kexMath::Sqrt(t); + q.x = m21 * d; + q.y = m20 * d; + q.z = m10 * d; + q.w = 0.25f / d; + } + else if (mx > my && mx > mz) + { + d = kexMath::Sqrt(1.0f + mx - my - mz) * 2; + q.x = 0.5f / d; + q.y = m10 / d; + q.z = m20 / d; + q.w = m21 / d; + } + else if (my > mz) + { + d = kexMath::Sqrt(1.0f + my - mx - mz) * 2; + q.x = m10 / d; + q.y = 0.5f / d; + q.z = m21 / d; + q.w = m20 / d; + } + else + { + d = kexMath::Sqrt(1.0f + mz - mx - my) * 2; + q.x = m20 / d; + q.y = m21 / d; + q.z = 0.5f / d; + q.w = m10 / d; + } - q.Normalize(); - return q; + q.Normalize(); + return q; } // @@ -511,13 +511,13 @@ kexQuat kexMatrix::ToQuat() kexMatrix kexMatrix::operator*(const kexVec3 &vector) { - kexMatrix out(*this); + kexMatrix out(*this); - out.vectors[3].ToVec3() += - vectors[0].ToVec3() * vector.x + - vectors[1].ToVec3() * vector.y + - vectors[2].ToVec3() * vector.z; - return out; + out.vectors[3].ToVec3() += + vectors[0].ToVec3() * vector.x + + vectors[1].ToVec3() * vector.y + + vectors[2].ToVec3() * vector.z; + return out; } // @@ -526,11 +526,11 @@ kexMatrix kexMatrix::operator*(const kexVec3 &vector) kexMatrix &kexMatrix::operator*=(const kexVec3 &vector) { - vectors[3].ToVec3() += - vectors[0].ToVec3() * vector.x + - vectors[1].ToVec3() * vector.y + - vectors[2].ToVec3() * vector.z; - return *this; + vectors[3].ToVec3() += + vectors[0].ToVec3() * vector.x + + vectors[1].ToVec3() * vector.y + + vectors[2].ToVec3() * vector.z; + return *this; } // @@ -539,7 +539,7 @@ kexMatrix &kexMatrix::operator*=(const kexVec3 &vector) float *kexMatrix::ToFloatPtr() { - return reinterpret_cast(vectors); + return reinterpret_cast(vectors); } // @@ -548,33 +548,33 @@ float *kexMatrix::ToFloatPtr() kexMatrix kexMatrix::operator*(const kexMatrix &matrix) { - kexMatrix out; + kexMatrix out; - for(int i = 0; i < 4; i++) - { - out.vectors[i].x = - vectors[i].x * matrix.vectors[0].x + - vectors[i].y * matrix.vectors[1].x + - vectors[i].z * matrix.vectors[2].x + - vectors[i].w * matrix.vectors[3].x; - out.vectors[i].y = - vectors[i].x * matrix.vectors[0].y + - vectors[i].y * matrix.vectors[1].y + - vectors[i].z * matrix.vectors[2].y + - vectors[i].w * matrix.vectors[3].y; - out.vectors[i].z = - vectors[i].x * matrix.vectors[0].z + - vectors[i].y * matrix.vectors[1].z + - vectors[i].z * matrix.vectors[2].z + - vectors[i].w * matrix.vectors[3].z; - out.vectors[i].w = - vectors[i].x * matrix.vectors[0].w + - vectors[i].y * matrix.vectors[1].w + - vectors[i].z * matrix.vectors[2].w + - vectors[i].w * matrix.vectors[3].w; - } + for (int i = 0; i < 4; i++) + { + out.vectors[i].x = + vectors[i].x * matrix.vectors[0].x + + vectors[i].y * matrix.vectors[1].x + + vectors[i].z * matrix.vectors[2].x + + vectors[i].w * matrix.vectors[3].x; + out.vectors[i].y = + vectors[i].x * matrix.vectors[0].y + + vectors[i].y * matrix.vectors[1].y + + vectors[i].z * matrix.vectors[2].y + + vectors[i].w * matrix.vectors[3].y; + out.vectors[i].z = + vectors[i].x * matrix.vectors[0].z + + vectors[i].y * matrix.vectors[1].z + + vectors[i].z * matrix.vectors[2].z + + vectors[i].w * matrix.vectors[3].z; + out.vectors[i].w = + vectors[i].x * matrix.vectors[0].w + + vectors[i].y * matrix.vectors[1].w + + vectors[i].z * matrix.vectors[2].w + + vectors[i].w * matrix.vectors[3].w; + } - return out; + return out; } // @@ -583,31 +583,31 @@ kexMatrix kexMatrix::operator*(const kexMatrix &matrix) kexMatrix &kexMatrix::operator*=(const kexMatrix &matrix) { - for(int i = 0; i < 4; i++) - { - vectors[i].x = - vectors[i].x * matrix.vectors[0].x + - vectors[i].y * matrix.vectors[1].x + - vectors[i].z * matrix.vectors[2].x + - vectors[i].w * matrix.vectors[3].x; - vectors[i].y = - vectors[i].x * matrix.vectors[0].y + - vectors[i].y * matrix.vectors[1].y + - vectors[i].z * matrix.vectors[2].y + - vectors[i].w * matrix.vectors[3].y; - vectors[i].z = - vectors[i].x * matrix.vectors[0].z + - vectors[i].y * matrix.vectors[1].z + - vectors[i].z * matrix.vectors[2].z + - vectors[i].w * matrix.vectors[3].z; - vectors[i].w = - vectors[i].x * matrix.vectors[0].w + - vectors[i].y * matrix.vectors[1].w + - vectors[i].z * matrix.vectors[2].w + - vectors[i].w * matrix.vectors[3].w; - } + for (int i = 0; i < 4; i++) + { + vectors[i].x = + vectors[i].x * matrix.vectors[0].x + + vectors[i].y * matrix.vectors[1].x + + vectors[i].z * matrix.vectors[2].x + + vectors[i].w * matrix.vectors[3].x; + vectors[i].y = + vectors[i].x * matrix.vectors[0].y + + vectors[i].y * matrix.vectors[1].y + + vectors[i].z * matrix.vectors[2].y + + vectors[i].w * matrix.vectors[3].y; + vectors[i].z = + vectors[i].x * matrix.vectors[0].z + + vectors[i].y * matrix.vectors[1].z + + vectors[i].z * matrix.vectors[2].z + + vectors[i].w * matrix.vectors[3].z; + vectors[i].w = + vectors[i].x * matrix.vectors[0].w + + vectors[i].y * matrix.vectors[1].w + + vectors[i].z * matrix.vectors[2].w + + vectors[i].w * matrix.vectors[3].w; + } - return *this; + return *this; } // @@ -616,33 +616,33 @@ kexMatrix &kexMatrix::operator*=(const kexMatrix &matrix) kexMatrix operator*(const kexMatrix &m1, const kexMatrix &m2) { - kexMatrix out; + kexMatrix out; - for(int i = 0; i < 4; i++) - { - out.vectors[i].x = - m1.vectors[i].x * m2.vectors[0].x + - m1.vectors[i].y * m2.vectors[1].x + - m1.vectors[i].z * m2.vectors[2].x + - m1.vectors[i].w * m2.vectors[3].x; - out.vectors[i].y = - m1.vectors[i].x * m2.vectors[0].y + - m1.vectors[i].y * m2.vectors[1].y + - m1.vectors[i].z * m2.vectors[2].y + - m1.vectors[i].w * m2.vectors[3].y; - out.vectors[i].z = - m1.vectors[i].x * m2.vectors[0].z + - m1.vectors[i].y * m2.vectors[1].z + - m1.vectors[i].z * m2.vectors[2].z + - m1.vectors[i].w * m2.vectors[3].z; - out.vectors[i].w = - m1.vectors[i].x * m2.vectors[0].w + - m1.vectors[i].y * m2.vectors[1].w + - m1.vectors[i].z * m2.vectors[2].w + - m1.vectors[i].w * m2.vectors[3].w; - } + for (int i = 0; i < 4; i++) + { + out.vectors[i].x = + m1.vectors[i].x * m2.vectors[0].x + + m1.vectors[i].y * m2.vectors[1].x + + m1.vectors[i].z * m2.vectors[2].x + + m1.vectors[i].w * m2.vectors[3].x; + out.vectors[i].y = + m1.vectors[i].x * m2.vectors[0].y + + m1.vectors[i].y * m2.vectors[1].y + + m1.vectors[i].z * m2.vectors[2].y + + m1.vectors[i].w * m2.vectors[3].y; + out.vectors[i].z = + m1.vectors[i].x * m2.vectors[0].z + + m1.vectors[i].y * m2.vectors[1].z + + m1.vectors[i].z * m2.vectors[2].z + + m1.vectors[i].w * m2.vectors[3].z; + out.vectors[i].w = + m1.vectors[i].x * m2.vectors[0].w + + m1.vectors[i].y * m2.vectors[1].w + + m1.vectors[i].z * m2.vectors[2].w + + m1.vectors[i].w * m2.vectors[3].w; + } - return out; + return out; } // @@ -651,38 +651,38 @@ kexMatrix operator*(const kexMatrix &m1, const kexMatrix &m2) kexMatrix kexMatrix::operator|(const kexMatrix &matrix) { - kexMatrix out; + kexMatrix out; - for(int i = 0; i < 3; i++) - { - out.vectors[i].x = - vectors[i].x * matrix.vectors[0].x + - vectors[i].y * matrix.vectors[1].x + - vectors[i].z * matrix.vectors[2].x; - out.vectors[i].y = - vectors[i].x * matrix.vectors[0].y + - vectors[i].y * matrix.vectors[1].y + - vectors[i].z * matrix.vectors[2].y; - out.vectors[i].z = - vectors[i].x * matrix.vectors[0].z + - vectors[i].y * matrix.vectors[1].z + - vectors[i].z * matrix.vectors[2].z; - } + for (int i = 0; i < 3; i++) + { + out.vectors[i].x = + vectors[i].x * matrix.vectors[0].x + + vectors[i].y * matrix.vectors[1].x + + vectors[i].z * matrix.vectors[2].x; + out.vectors[i].y = + vectors[i].x * matrix.vectors[0].y + + vectors[i].y * matrix.vectors[1].y + + vectors[i].z * matrix.vectors[2].y; + out.vectors[i].z = + vectors[i].x * matrix.vectors[0].z + + vectors[i].y * matrix.vectors[1].z + + vectors[i].z * matrix.vectors[2].z; + } - out.vectors[3].x = - vectors[3].x * matrix.vectors[0].x + - vectors[3].y * matrix.vectors[1].x + - vectors[3].z * matrix.vectors[2].x + matrix.vectors[3].x; - out.vectors[3].y = - vectors[3].x * matrix.vectors[0].y + - vectors[3].y * matrix.vectors[1].y + - vectors[3].z * matrix.vectors[2].y + matrix.vectors[3].y; - out.vectors[3].z = - vectors[3].x * matrix.vectors[0].z + - vectors[3].y * matrix.vectors[1].z + - vectors[3].z * matrix.vectors[2].z + matrix.vectors[3].z; + out.vectors[3].x = + vectors[3].x * matrix.vectors[0].x + + vectors[3].y * matrix.vectors[1].x + + vectors[3].z * matrix.vectors[2].x + matrix.vectors[3].x; + out.vectors[3].y = + vectors[3].x * matrix.vectors[0].y + + vectors[3].y * matrix.vectors[1].y + + vectors[3].z * matrix.vectors[2].y + matrix.vectors[3].y; + out.vectors[3].z = + vectors[3].x * matrix.vectors[0].z + + vectors[3].y * matrix.vectors[1].z + + vectors[3].z * matrix.vectors[2].z + matrix.vectors[3].z; - return out; + return out; } // @@ -691,12 +691,12 @@ kexMatrix kexMatrix::operator|(const kexMatrix &matrix) kexMatrix &kexMatrix::operator=(const kexMatrix &matrix) { - vectors[0] = matrix.vectors[0]; - vectors[1] = matrix.vectors[1]; - vectors[2] = matrix.vectors[2]; - vectors[3] = matrix.vectors[3]; + vectors[0] = matrix.vectors[0]; + vectors[1] = matrix.vectors[1]; + vectors[2] = matrix.vectors[2]; + vectors[3] = matrix.vectors[3]; - return *this; + return *this; } // @@ -705,13 +705,13 @@ kexMatrix &kexMatrix::operator=(const kexMatrix &matrix) kexMatrix &kexMatrix::operator=(const float *m) { - for(int i = 0; i < 4; i++) - { - for(int j = 0; j < 4; j++) - { - vectors[i][j] = m[i * 4 + j]; - } - } + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + vectors[i][j] = m[i * 4 + j]; + } + } - return *this; + return *this; } diff --git a/src/lightmap/kexlib/math/plane.cpp b/src/lightmap/kexlib/math/plane.cpp index f14e7d0..3a2d1c0 100644 --- a/src/lightmap/kexlib/math/plane.cpp +++ b/src/lightmap/kexlib/math/plane.cpp @@ -39,10 +39,10 @@ kexPlane::kexPlane() { - this->a = 0; - this->b = 0; - this->c = 0; - this->d = 0; + this->a = 0; + this->b = 0; + this->c = 0; + this->d = 0; } // @@ -51,10 +51,10 @@ kexPlane::kexPlane() kexPlane::kexPlane(const float a, const float b, const float c, const float d) { - this->a = a; - this->b = b; - this->c = c; - this->d = d; + this->a = a; + this->b = b; + this->c = c; + this->d = d; } // @@ -63,8 +63,8 @@ kexPlane::kexPlane(const float a, const float b, const float c, const float d) kexPlane::kexPlane(const kexVec3 &pt1, const kexVec3 &pt2, const kexVec3 &pt3) { - SetNormal(pt1, pt2, pt3); - this->d = kexVec3::Dot(pt1, Normal()); + SetNormal(pt1, pt2, pt3); + this->d = kexVec3::Dot(pt1, Normal()); } // @@ -73,10 +73,10 @@ kexPlane::kexPlane(const kexVec3 &pt1, const kexVec3 &pt2, const kexVec3 &pt3) kexPlane::kexPlane(const kexVec3 &normal, const kexVec3 &point) { - this->a = normal.x; - this->b = normal.y; - this->c = normal.z; - this->d = point.Dot(normal); + this->a = normal.x; + this->b = normal.y; + this->c = normal.z; + this->d = point.Dot(normal); } // @@ -85,10 +85,10 @@ kexPlane::kexPlane(const kexVec3 &normal, const kexVec3 &point) kexPlane::kexPlane(const kexPlane &plane) { - this->a = plane.a; - this->b = plane.b; - this->c = plane.c; - this->d = plane.d; + this->a = plane.a; + this->b = plane.b; + this->c = plane.c; + this->d = plane.d; } // @@ -97,8 +97,8 @@ kexPlane::kexPlane(const kexPlane &plane) kexPlane &kexPlane::SetNormal(const kexVec3 &normal) { - Normal() = normal; - return *this; + Normal() = normal; + return *this; } // @@ -107,8 +107,8 @@ kexPlane &kexPlane::SetNormal(const kexVec3 &normal) kexPlane &kexPlane::SetNormal(const kexVec3 &pt1, const kexVec3 &pt2, const kexVec3 &pt3) { - Normal() = (pt2 - pt1).Cross(pt3 - pt2).Normalize(); - return *this; + Normal() = (pt2 - pt1).Cross(pt3 - pt2).Normalize(); + return *this; } // @@ -117,7 +117,7 @@ kexPlane &kexPlane::SetNormal(const kexVec3 &pt1, const kexVec3 &pt2, const kexV kexVec3 const &kexPlane::Normal() const { - return *reinterpret_cast(&a); + return *reinterpret_cast(&a); } // @@ -126,7 +126,7 @@ kexVec3 const &kexPlane::Normal() const kexVec3 &kexPlane::Normal() { - return *reinterpret_cast(&a); + return *reinterpret_cast(&a); } // @@ -135,7 +135,7 @@ kexVec3 &kexPlane::Normal() float kexPlane::Distance(const kexVec3 &point) { - return point.Dot(Normal()); + return point.Dot(Normal()); } // @@ -144,8 +144,8 @@ float kexPlane::Distance(const kexVec3 &point) kexPlane &kexPlane::SetDistance(const kexVec3 &point) { - this->d = point.Dot(Normal()); - return *this; + this->d = point.Dot(Normal()); + return *this; } // @@ -154,7 +154,7 @@ kexPlane &kexPlane::SetDistance(const kexVec3 &point) bool kexPlane::IsFacing(const float yaw) { - return -kexMath::Sin(yaw) * a + -kexMath::Cos(yaw) * b < 0; + return -kexMath::Sin(yaw) * a + -kexMath::Cos(yaw) * b < 0; } // @@ -163,21 +163,21 @@ bool kexPlane::IsFacing(const float yaw) float kexPlane::ToYaw() { - float d = Normal().Unit(); + float d = Normal().Unit(); - if(d != 0) - { - float phi; - phi = kexMath::ACos(b / d); - if(a <= 0) - { - phi = -phi; - } + if (d != 0) + { + float phi; + phi = kexMath::ACos(b / d); + if (a <= 0) + { + phi = -phi; + } - return phi; - } + return phi; + } - return 0; + return 0; } // @@ -186,7 +186,7 @@ float kexPlane::ToYaw() float kexPlane::ToPitch() { - return kexMath::ACos(kexVec3::vecUp.Dot(Normal())); + return kexMath::ACos(kexVec3::vecUp.Dot(Normal())); } // @@ -195,8 +195,8 @@ float kexPlane::ToPitch() kexQuat kexPlane::ToQuat() { - kexVec3 cross = kexVec3::vecUp.Cross(Normal()).Normalize(); - return kexQuat(kexMath::ACos(kexVec3::vecUp.Dot(Normal())), cross); + kexVec3 cross = kexVec3::vecUp.Cross(Normal()).Normalize(); + return kexQuat(kexMath::ACos(kexVec3::vecUp.Dot(Normal())), cross); } // @@ -205,7 +205,7 @@ kexQuat kexPlane::ToQuat() kexVec4 const &kexPlane::ToVec4() const { - return *reinterpret_cast(&a); + return *reinterpret_cast(&a); } // @@ -214,7 +214,7 @@ kexVec4 const &kexPlane::ToVec4() const kexVec4 &kexPlane::ToVec4() { - return *reinterpret_cast(&a); + return *reinterpret_cast(&a); } // @@ -223,21 +223,21 @@ kexVec4 &kexPlane::ToVec4() const kexPlane::planeAxis_t kexPlane::BestAxis() const { - float na = kexMath::Fabs(a); - float nb = kexMath::Fabs(b); - float nc = kexMath::Fabs(c); + float na = kexMath::Fabs(a); + float nb = kexMath::Fabs(b); + float nc = kexMath::Fabs(c); - // figure out what axis the plane lies on - if(na >= nb && na >= nc) - { - return AXIS_YZ; - } - else if(nb >= na && nb >= nc) - { - return AXIS_XZ; - } + // figure out what axis the plane lies on + if (na >= nb && na >= nc) + { + return AXIS_YZ; + } + else if (nb >= na && nb >= nc) + { + return AXIS_XZ; + } - return AXIS_XY; + return AXIS_XY; } // @@ -246,6 +246,6 @@ const kexPlane::planeAxis_t kexPlane::BestAxis() const kexVec3 kexPlane::GetInclination() { - kexVec3 dir = Normal() * kexVec3::vecUp.Dot(Normal()); - return (kexVec3::vecUp - dir).Normalize(); + kexVec3 dir = Normal() * kexVec3::vecUp.Dot(Normal()); + return (kexVec3::vecUp - dir).Normalize(); } diff --git a/src/lightmap/kexlib/math/pluecker.cpp b/src/lightmap/kexlib/math/pluecker.cpp index 6f84f7b..c6d93bd 100644 --- a/src/lightmap/kexlib/math/pluecker.cpp +++ b/src/lightmap/kexlib/math/pluecker.cpp @@ -40,7 +40,7 @@ kexPluecker::kexPluecker() { - Clear(); + Clear(); } // @@ -49,7 +49,7 @@ kexPluecker::kexPluecker() kexPluecker::kexPluecker(const kexVec3 &start, const kexVec3 &end, bool bRay) { - bRay ? SetRay(start, end) : SetLine(start, end); + bRay ? SetRay(start, end) : SetLine(start, end); } // @@ -58,7 +58,7 @@ kexPluecker::kexPluecker(const kexVec3 &start, const kexVec3 &end, bool bRay) void kexPluecker::Clear() { - p[0] = p[1] = p[2] = p[3] = p[4] = p[5] = 0; + p[0] = p[1] = p[2] = p[3] = p[4] = p[5] = 0; } // @@ -67,13 +67,13 @@ void kexPluecker::Clear() void kexPluecker::SetLine(const kexVec3 &start, const kexVec3 &end) { - p[0] = start.x * end.y - end.x * start.y; - p[1] = start.x * end.z - end.x * start.z; - p[3] = start.y * end.z - end.y * start.z; + p[0] = start.x * end.y - end.x * start.y; + p[1] = start.x * end.z - end.x * start.z; + p[3] = start.y * end.z - end.y * start.z; - p[2] = start.x - end.x; - p[5] = end.y - start.y; - p[4] = start.z - end.z; + p[2] = start.x - end.x; + p[5] = end.y - start.y; + p[4] = start.z - end.z; } // @@ -82,13 +82,13 @@ void kexPluecker::SetLine(const kexVec3 &start, const kexVec3 &end) void kexPluecker::SetRay(const kexVec3 &start, const kexVec3 &dir) { - p[0] = start.x * dir.y - dir.x * start.y; - p[1] = start.x * dir.z - dir.x * start.z; - p[3] = start.y * dir.z - dir.y * start.z; + p[0] = start.x * dir.y - dir.x * start.y; + p[1] = start.x * dir.z - dir.x * start.z; + p[3] = start.y * dir.z - dir.y * start.z; - p[2] = -dir.x; - p[5] = dir.y; - p[4] = -dir.z; + p[2] = -dir.x; + p[5] = dir.y; + p[4] = -dir.z; } // @@ -97,11 +97,11 @@ void kexPluecker::SetRay(const kexVec3 &start, const kexVec3 &dir) float kexPluecker::InnerProduct(const kexPluecker &pluecker) const { - return - p[0] * pluecker.p[4] + - p[1] * pluecker.p[5] + - p[2] * pluecker.p[3] + - p[4] * pluecker.p[0] + - p[5] * pluecker.p[1] + - p[3] * pluecker.p[2]; + return + p[0] * pluecker.p[4] + + p[1] * pluecker.p[5] + + p[2] * pluecker.p[3] + + p[4] * pluecker.p[0] + + p[5] * pluecker.p[1] + + p[3] * pluecker.p[2]; } diff --git a/src/lightmap/kexlib/math/quaternion.cpp b/src/lightmap/kexlib/math/quaternion.cpp index fc4bfda..37d445a 100644 --- a/src/lightmap/kexlib/math/quaternion.cpp +++ b/src/lightmap/kexlib/math/quaternion.cpp @@ -39,7 +39,7 @@ kexQuat::kexQuat() { - Clear(); + Clear(); } // @@ -48,13 +48,13 @@ kexQuat::kexQuat() kexQuat::kexQuat(const float angle, const float x, const float y, const float z) { - float s = kexMath::Sin(angle * 0.5f); - float c = kexMath::Cos(angle * 0.5f); + float s = kexMath::Sin(angle * 0.5f); + float c = kexMath::Cos(angle * 0.5f); - this->x = x * s; - this->y = y * s; - this->z = z * s; - this->w = c; + this->x = x * s; + this->y = y * s; + this->z = z * s; + this->w = c; } // @@ -63,13 +63,13 @@ kexQuat::kexQuat(const float angle, const float x, const float y, const float z) kexQuat::kexQuat(const float angle, kexVec3 &vector) { - float s = kexMath::Sin(angle * 0.5f); - float c = kexMath::Cos(angle * 0.5f); + float s = kexMath::Sin(angle * 0.5f); + float c = kexMath::Cos(angle * 0.5f); - this->x = vector.x * s; - this->y = vector.y * s; - this->z = vector.z * s; - this->w = c; + this->x = vector.x * s; + this->y = vector.y * s; + this->z = vector.z * s; + this->w = c; } // @@ -78,13 +78,13 @@ kexQuat::kexQuat(const float angle, kexVec3 &vector) kexQuat::kexQuat(const float angle, const kexVec3 &vector) { - float s = kexMath::Sin(angle * 0.5f); - float c = kexMath::Cos(angle * 0.5f); + float s = kexMath::Sin(angle * 0.5f); + float c = kexMath::Cos(angle * 0.5f); - this->x = vector.x * s; - this->y = vector.y * s; - this->z = vector.z * s; - this->w = c; + this->x = vector.x * s; + this->y = vector.y * s; + this->z = vector.z * s; + this->w = c; } // @@ -93,10 +93,10 @@ kexQuat::kexQuat(const float angle, const kexVec3 &vector) void kexQuat::Set(const float x, const float y, const float z, const float w) { - this->x = x; - this->y = y; - this->z = z; - this->w = w; + this->x = x; + this->y = y; + this->z = z; + this->w = w; } // @@ -105,8 +105,8 @@ void kexQuat::Set(const float x, const float y, const float z, const float w) void kexQuat::Clear() { - x = y = z = 0.0f; - w = 1.0f; + x = y = z = 0.0f; + w = 1.0f; } // @@ -115,7 +115,7 @@ void kexQuat::Clear() float kexQuat::UnitSq() const { - return x * x + y * y + z * z + w * w; + return x * x + y * y + z * z + w * w; } // @@ -124,7 +124,7 @@ float kexQuat::UnitSq() const float kexQuat::Unit() const { - return kexMath::Sqrt(UnitSq()); + return kexMath::Sqrt(UnitSq()); } // @@ -133,13 +133,13 @@ float kexQuat::Unit() const kexQuat &kexQuat::Normalize() { - float d = Unit(); - if(d != 0.0f) - { - d = 1.0f / d; - *this *= d; - } - return *this; + float d = Unit(); + if (d != 0.0f) + { + d = 1.0f / d; + *this *= d; + } + return *this; } // @@ -148,9 +148,9 @@ kexQuat &kexQuat::Normalize() kexQuat kexQuat::Inverse() const { - kexQuat out; - out.Set(-x, -y, -z, -w); - return out; + kexQuat out; + out.Set(-x, -y, -z, -w); + return out; } // @@ -159,12 +159,12 @@ kexQuat kexQuat::Inverse() const kexQuat kexQuat::operator+(const kexQuat &quat) { - kexQuat out; - out.x = x + quat.x; - out.y = y + quat.y; - out.z = z + quat.z; - out.w = w + quat.w; - return out; + kexQuat out; + out.x = x + quat.x; + out.y = y + quat.y; + out.z = z + quat.z; + out.w = w + quat.w; + return out; } // @@ -173,11 +173,11 @@ kexQuat kexQuat::operator+(const kexQuat &quat) kexQuat &kexQuat::operator+=(const kexQuat &quat) { - x += quat.x; - y += quat.y; - z += quat.z; - w += quat.w; - return *this; + x += quat.x; + y += quat.y; + z += quat.z; + w += quat.w; + return *this; } // @@ -186,12 +186,12 @@ kexQuat &kexQuat::operator+=(const kexQuat &quat) kexQuat kexQuat::operator-(const kexQuat &quat) { - kexQuat out; - out.x = x - quat.x; - out.y = y - quat.y; - out.z = z - quat.z; - out.w = w - quat.w; - return out; + kexQuat out; + out.x = x - quat.x; + out.y = y - quat.y; + out.z = z - quat.z; + out.w = w - quat.w; + return out; } // @@ -200,11 +200,11 @@ kexQuat kexQuat::operator-(const kexQuat &quat) kexQuat &kexQuat::operator-=(const kexQuat &quat) { - x -= quat.x; - y -= quat.y; - z -= quat.z; - w -= quat.w; - return *this; + x -= quat.x; + y -= quat.y; + z -= quat.z; + w -= quat.w; + return *this; } // @@ -213,14 +213,14 @@ kexQuat &kexQuat::operator-=(const kexQuat &quat) kexQuat kexQuat::operator*(const kexQuat &quat) { - kexQuat out; + kexQuat out; - out.x = x * quat.w - y * quat.z + quat.x * w + quat.y * z; - out.y = x * quat.z + y * quat.w - quat.x * z + w * quat.y; - out.z = quat.x * y + w * quat.z + z * quat.w - x * quat.y; - out.w = w * quat.w - quat.y * y + z * quat.z + quat.x * x; + 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.z = quat.x * y + w * quat.z + z * quat.w - x * quat.y; + out.w = w * quat.w - quat.y * y + z * quat.z + quat.x * x; - return out; + return out; } // @@ -229,17 +229,17 @@ kexQuat kexQuat::operator*(const kexQuat &quat) kexQuat &kexQuat::operator*=(const kexQuat &quat) { - float tx = x; - float ty = y; - float tz = z; - float tw = w; + float tx = x; + float ty = y; + float tz = z; + float tw = w; - x = tx * quat.w - ty * quat.z + quat.x * tw + quat.y * z; - y = tx * quat.z + ty * quat.w - quat.x * tz + tw * quat.y; - z = quat.x * ty + tw * quat.z + tz * quat.w - tx * quat.y; - w = tw * quat.w - quat.y * ty + tz * quat.z + quat.x * x; + x = tx * quat.w - ty * quat.z + quat.x * tw + quat.y * z; + y = tx * quat.z + ty * quat.w - quat.x * tz + tw * quat.y; + z = quat.x * ty + tw * quat.z + tz * quat.w - tx * quat.y; + w = tw * quat.w - quat.y * ty + tz * quat.z + quat.x * x; - return *this; + return *this; } // @@ -248,12 +248,12 @@ kexQuat &kexQuat::operator*=(const kexQuat &quat) kexQuat kexQuat::operator*(const float val) const { - kexQuat out; - out.x = x * val; - out.y = y * val; - out.z = z * val; - out.w = w * val; - return out; + kexQuat out; + out.x = x * val; + out.y = y * val; + out.z = z * val; + out.w = w * val; + return out; } // @@ -262,12 +262,12 @@ kexQuat kexQuat::operator*(const float val) const kexQuat &kexQuat::operator*=(const float val) { - x *= val; - y *= val; - z *= val; - w *= val; + x *= val; + y *= val; + z *= val; + w *= val; - return *this; + return *this; } // @@ -276,28 +276,28 @@ kexQuat &kexQuat::operator*=(const float val) kexVec3 kexQuat::operator|(const kexVec3 &vector) { - float xx = x * x; - float yx = y * x; - float zx = z * x; - float wx = w * x; - float yy = y * y; - float zy = z * y; - float wy = w * y; - float zz = z * z; - float wz = w * z; - float ww = w * w; + float xx = x * x; + float yx = y * x; + float zx = z * x; + float wx = w * x; + float yy = y * y; + float zy = z * y; + float wy = w * y; + float zz = z * z; + float wz = w * z; + float ww = w * w; - return kexVec3( - ((yx + yx) - (wz + wz)) * vector.y + - ((wy + wy + zx + zx)) * vector.z + - (((ww + xx) - yy) - zz) * vector.x, - ((yy + (ww - xx)) - zz) * vector.y + - ((zy + zy) - (wx + wx)) * vector.z + - ((wz + wz) + (yx + yx)) * vector.x, - ((wx + wx) + (zy + zy)) * vector.y + - (((ww - xx) - yy) + zz) * vector.z + - ((zx + zx) - (wy + wy)) * vector.x - ); + return kexVec3( + ((yx + yx) - (wz + wz)) * vector.y + + ((wy + wy + zx + zx)) * vector.z + + (((ww + xx) - yy) - zz) * vector.x, + ((yy + (ww - xx)) - zz) * vector.y + + ((zy + zy) - (wx + wx)) * vector.z + + ((wz + wz) + (yx + yx)) * vector.x, + ((wx + wx) + (zy + zy)) * vector.y + + (((ww - xx) - yy) + zz) * vector.z + + ((zx + zx) - (wy + wy)) * vector.x + ); } // @@ -306,7 +306,7 @@ kexVec3 kexQuat::operator|(const kexVec3 &vector) float kexQuat::Dot(const kexQuat &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); } // @@ -315,51 +315,51 @@ float kexQuat::Dot(const kexQuat &quat) const kexQuat kexQuat::Slerp(const kexQuat &quat, float movement) const { - kexQuat rdest = quat; - float d1 = Dot(quat); - float d2 = Dot(quat.Inverse()); + kexQuat rdest = quat; + float d1 = Dot(quat); + float d2 = Dot(quat.Inverse()); - if(d1 < d2) - { - rdest = quat.Inverse(); - d1 = d2; - } + if (d1 < d2) + { + rdest = quat.Inverse(); + d1 = d2; + } - if(d1 <= 0.7071067811865001f) - { - float halfcos = kexMath::ACos(d1); - float halfsin = kexMath::Sin(halfcos); + if (d1 <= 0.7071067811865001f) + { + float halfcos = kexMath::ACos(d1); + float halfsin = kexMath::Sin(halfcos); - if(halfsin == 0) - { - kexQuat out; - out.Set(x, y, z, w); - return out; - } - else - { - float d; - float ms1; - float ms2; + if (halfsin == 0) + { + kexQuat out; + out.Set(x, y, z, w); + return out; + } + else + { + float d; + float ms1; + float ms2; - d = 1.0f / halfsin; - ms1 = kexMath::Sin((1.0f - movement) * halfcos) * d; - ms2 = kexMath::Sin(halfcos * movement) * d; + d = 1.0f / halfsin; + ms1 = kexMath::Sin((1.0f - movement) * halfcos) * d; + ms2 = kexMath::Sin(halfcos * movement) * d; - if(ms2 < 0) - { - rdest = quat.Inverse(); - } + if (ms2 < 0) + { + rdest = quat.Inverse(); + } - return *this * ms1 + rdest * ms2; - } - } - else - { - kexQuat out = (rdest - *this) * movement + *this; - out.Normalize(); - return out; - } + return *this * ms1 + rdest * ms2; + } + } + else + { + kexQuat out = (rdest - *this) * movement + *this; + out.Normalize(); + return out; + } } // @@ -368,24 +368,24 @@ kexQuat kexQuat::Slerp(const kexQuat &quat, float movement) const kexQuat kexQuat::RotateFrom(const kexVec3 &location, const kexVec3 &target, float maxAngle) { - kexVec3 axis; - kexVec3 dir; - kexVec3 cp; - kexQuat prot; - float an; + kexVec3 axis; + kexVec3 dir; + kexVec3 cp; + kexQuat prot; + float an; - dir = (*this | kexVec3::vecForward); - axis = (target - location).Normalize(); - cp = dir.Cross(axis).Normalize(); + dir = (*this | kexVec3::vecForward); + axis = (target - location).Normalize(); + cp = dir.Cross(axis).Normalize(); - an = kexMath::ACos(axis.Dot(dir)); + an = kexMath::ACos(axis.Dot(dir)); - if(maxAngle != 0 && an >= maxAngle) - { - an = maxAngle; - } + if (maxAngle != 0 && an >= maxAngle) + { + an = maxAngle; + } - return (*this * kexQuat(an, cp)); + return (*this * kexQuat(an, cp)); } // @@ -394,11 +394,11 @@ kexQuat kexQuat::RotateFrom(const kexVec3 &location, const kexVec3 &target, floa kexQuat &kexQuat::operator=(const kexQuat &quat) { - x = quat.x; - y = quat.y; - z = quat.z; - w = quat.w; - return *this; + x = quat.x; + y = quat.y; + z = quat.z; + w = quat.w; + return *this; } // @@ -407,11 +407,11 @@ kexQuat &kexQuat::operator=(const kexQuat &quat) kexQuat &kexQuat::operator=(const kexVec4 &vec) { - x = vec.x; - y = vec.y; - z = vec.z; - w = vec.w; - return *this; + x = vec.x; + y = vec.y; + z = vec.z; + w = vec.w; + return *this; } // @@ -420,11 +420,11 @@ kexQuat &kexQuat::operator=(const kexVec4 &vec) kexQuat &kexQuat::operator=(const float *vecs) { - x = vecs[0]; - y = vecs[1]; - z = vecs[2]; - w = vecs[3]; - return *this; + x = vecs[0]; + y = vecs[1]; + z = vecs[2]; + w = vecs[3]; + return *this; } // @@ -433,7 +433,7 @@ kexQuat &kexQuat::operator=(const float *vecs) kexVec3 const &kexQuat::ToVec3() const { - return *reinterpret_cast(this); + return *reinterpret_cast(this); } // @@ -442,5 +442,5 @@ kexVec3 const &kexQuat::ToVec3() const kexVec3 &kexQuat::ToVec3() { - return *reinterpret_cast(this); + return *reinterpret_cast(this); } diff --git a/src/lightmap/kexlib/math/random.cpp b/src/lightmap/kexlib/math/random.cpp index 012d244..175a6b9 100644 --- a/src/lightmap/kexlib/math/random.cpp +++ b/src/lightmap/kexlib/math/random.cpp @@ -43,7 +43,7 @@ int kexRand::seed = 0; void kexRand::SetSeed(const int randSeed) { - seed = randSeed; + seed = randSeed; } // @@ -52,7 +52,7 @@ void kexRand::SetSeed(const int randSeed) int kexRand::SysRand() { - return rand(); + return rand(); } // @@ -61,8 +61,8 @@ int kexRand::SysRand() int kexRand::Int() { - seed = 1479838765 - 1471521965 * seed; - return seed & RANDOM_MAX; + seed = 1479838765 - 1471521965 * seed; + return seed & RANDOM_MAX; } // @@ -71,12 +71,12 @@ int kexRand::Int() int kexRand::Max(const int max) { - if(max == 0) - { - return 0; - } + if (max == 0) + { + return 0; + } - return Int() % max; + return Int() % max; } // @@ -85,7 +85,7 @@ int kexRand::Max(const int max) float kexRand::Float() { - return (float)Max(RANDOM_MAX+1) / ((float)RANDOM_MAX+1); + return (float)Max(RANDOM_MAX + 1) / ((float)RANDOM_MAX + 1); } // @@ -94,6 +94,6 @@ float kexRand::Float() float kexRand::CFloat() { - return (float)(Max(20000) - 10000) * 0.0001f; + return (float)(Max(20000) - 10000) * 0.0001f; } diff --git a/src/lightmap/kexlib/math/vector.cpp b/src/lightmap/kexlib/math/vector.cpp index b18a476..be12ee7 100644 --- a/src/lightmap/kexlib/math/vector.cpp +++ b/src/lightmap/kexlib/math/vector.cpp @@ -47,7 +47,7 @@ kexVec2 kexVec2::vecZero(0, 0); kexVec2::kexVec2() { - Clear(); + Clear(); } // @@ -56,7 +56,7 @@ kexVec2::kexVec2() kexVec2::kexVec2(const float x, const float y) { - Set(x, y); + Set(x, y); } // @@ -65,8 +65,8 @@ kexVec2::kexVec2(const float x, const float y) void kexVec2::Set(const float x, const float y) { - this->x = x; - this->y = y; + this->x = x; + this->y = y; } // @@ -75,7 +75,7 @@ void kexVec2::Set(const float x, const float y) void kexVec2::Clear() { - x = y = 0.0f; + x = y = 0.0f; } // @@ -84,7 +84,7 @@ void kexVec2::Clear() float kexVec2::Dot(const kexVec2 &vec) const { - return (x * vec.x + y * vec.y); + return (x * vec.x + y * vec.y); } // @@ -93,7 +93,7 @@ float kexVec2::Dot(const kexVec2 &vec) const float kexVec2::Dot(const kexVec2 &vec1, const kexVec2 &vec2) { - return (vec1.x * vec2.x + vec1.y * vec2.y); + return (vec1.x * vec2.x + vec1.y * vec2.y); } // @@ -102,7 +102,7 @@ float kexVec2::Dot(const kexVec2 &vec1, const kexVec2 &vec2) float kexVec2::Dot(const kexVec3 &vec) const { - return (x * vec.x + y * vec.y); + return (x * vec.x + y * vec.y); } // @@ -111,7 +111,7 @@ float kexVec2::Dot(const kexVec3 &vec) const float kexVec2::Dot(const kexVec3 &vec1, const kexVec3 &vec2) { - return (vec1.x * vec2.x + vec1.y * vec2.y); + return (vec1.x * vec2.x + vec1.y * vec2.y); } // @@ -120,7 +120,7 @@ float kexVec2::Dot(const kexVec3 &vec1, const kexVec3 &vec2) float kexVec2::CrossScalar(const kexVec2 &vec) const { - return vec.x * y - vec.y * x; + return vec.x * y - vec.y * x; } // @@ -129,10 +129,10 @@ float kexVec2::CrossScalar(const kexVec2 &vec) const kexVec2 kexVec2::Cross(const kexVec2 &vec) const { - return kexVec2( - vec.y - y, - x - vec.x - ); + return kexVec2( + vec.y - y, + x - vec.x + ); } // @@ -141,10 +141,10 @@ kexVec2 kexVec2::Cross(const kexVec2 &vec) const kexVec2 &kexVec2::Cross(const kexVec2 &vec1, const kexVec2 &vec2) { - x = vec2.y - vec1.y; - y = vec1.x - vec2.x; + x = vec2.y - vec1.y; + y = vec1.x - vec2.x; - return *this; + return *this; } // @@ -153,10 +153,10 @@ kexVec2 &kexVec2::Cross(const kexVec2 &vec1, const kexVec2 &vec2) kexVec2 kexVec2::Cross(const kexVec3 &vec) const { - return kexVec2( - vec.y - y, - x - vec.x - ); + return kexVec2( + vec.y - y, + x - vec.x + ); } // @@ -165,10 +165,10 @@ kexVec2 kexVec2::Cross(const kexVec3 &vec) const kexVec2 &kexVec2::Cross(const kexVec3 &vec1, const kexVec3 &vec2) { - x = vec2.y - vec1.y; - y = vec1.x - vec2.x; + x = vec2.y - vec1.y; + y = vec1.x - vec2.x; - return *this; + return *this; } // @@ -177,7 +177,7 @@ kexVec2 &kexVec2::Cross(const kexVec3 &vec1, const kexVec3 &vec2) float kexVec2::UnitSq() const { - return x * x + y * y; + return x * x + y * y; } // @@ -186,7 +186,7 @@ float kexVec2::UnitSq() const float kexVec2::Unit() const { - return kexMath::Sqrt(UnitSq()); + return kexMath::Sqrt(UnitSq()); } // @@ -195,10 +195,10 @@ float kexVec2::Unit() const float kexVec2::DistanceSq(const kexVec2 &vec) const { - return ( - (x - vec.x) * (x - vec.x) + - (y - vec.y) * (y - vec.y) - ); + return ( + (x - vec.x) * (x - vec.x) + + (y - vec.y) * (y - vec.y) + ); } // @@ -207,7 +207,7 @@ float kexVec2::DistanceSq(const kexVec2 &vec) const float kexVec2::Distance(const kexVec2 &vec) const { - return kexMath::Sqrt(DistanceSq(vec)); + return kexMath::Sqrt(DistanceSq(vec)); } // @@ -216,8 +216,8 @@ float kexVec2::Distance(const kexVec2 &vec) const kexVec2 &kexVec2::Normalize() { - *this *= kexMath::InvSqrt(UnitSq()); - return *this; + *this *= kexMath::InvSqrt(UnitSq()); + return *this; } // @@ -226,7 +226,7 @@ kexVec2 &kexVec2::Normalize() kexVec2 kexVec2::Lerp(const kexVec2 &next, float movement) const { - return (next - *this) * movement + *this; + return (next - *this) * movement + *this; } // @@ -235,8 +235,8 @@ kexVec2 kexVec2::Lerp(const kexVec2 &next, float movement) const kexVec2 &kexVec2::Lerp(const kexVec2 &next, const float movement) { - *this = (next - *this) * movement + *this; - return *this; + *this = (next - *this) * movement + *this; + return *this; } // @@ -245,8 +245,8 @@ kexVec2 &kexVec2::Lerp(const kexVec2 &next, const float movement) kexVec2 &kexVec2::Lerp(const kexVec2 &start, const kexVec2 &next, float movement) { - *this = (next - start) * movement + start; - return *this; + *this = (next - start) * movement + start; + return *this; } // @@ -255,14 +255,14 @@ kexVec2 &kexVec2::Lerp(const kexVec2 &start, const kexVec2 &next, float movement float kexVec2::ToYaw() const { - float d = x * x + y * y; + float d = x * x + y * y; - if(d == 0.0f) - { - return 0.0f; - } + if (d == 0.0f) + { + return 0.0f; + } - return kexMath::ATan2(x, y); + return kexMath::ATan2(x, y); } // @@ -271,9 +271,9 @@ float kexVec2::ToYaw() const kexStr kexVec2::ToString() const { - kexStr str; - str = str + x + " " + y; - return str; + kexStr str; + str = str + x + " " + y; + return str; } // @@ -282,7 +282,7 @@ kexStr kexVec2::ToString() const float *kexVec2::ToFloatPtr() { - return reinterpret_cast(&x); + return reinterpret_cast(&x); } // @@ -291,7 +291,7 @@ float *kexVec2::ToFloatPtr() kexVec3 kexVec2::ToVec3() { - return kexVec3(x, y, 0); + return kexVec3(x, y, 0); } // @@ -300,7 +300,7 @@ kexVec3 kexVec2::ToVec3() kexVec2 kexVec2::operator+(const kexVec2 &vec) { - return kexVec2(x + vec.x, y + vec.y); + return kexVec2(x + vec.x, y + vec.y); } // @@ -309,7 +309,7 @@ kexVec2 kexVec2::operator+(const kexVec2 &vec) kexVec2 kexVec2::operator+(const kexVec2 &vec) const { - return kexVec2(x + vec.x, y + vec.y); + return kexVec2(x + vec.x, y + vec.y); } // @@ -318,7 +318,7 @@ kexVec2 kexVec2::operator+(const kexVec2 &vec) const kexVec2 kexVec2::operator+(kexVec2 &vec) { - return kexVec2(x + vec.x, y + vec.y); + return kexVec2(x + vec.x, y + vec.y); } // @@ -327,9 +327,9 @@ kexVec2 kexVec2::operator+(kexVec2 &vec) kexVec2 &kexVec2::operator+=(const kexVec2 &vec) { - x += vec.x; - y += vec.y; - return *this; + x += vec.x; + y += vec.y; + return *this; } // @@ -338,7 +338,7 @@ kexVec2 &kexVec2::operator+=(const kexVec2 &vec) kexVec2 kexVec2::operator-(const kexVec2 &vec) const { - return kexVec2(x - vec.x, y - vec.y); + return kexVec2(x - vec.x, y - vec.y); } // @@ -347,7 +347,7 @@ kexVec2 kexVec2::operator-(const kexVec2 &vec) const kexVec2 kexVec2::operator-() const { - return kexVec2(-x, -y); + return kexVec2(-x, -y); } // @@ -356,9 +356,9 @@ kexVec2 kexVec2::operator-() const kexVec2 &kexVec2::operator-=(const kexVec2 &vec) { - x -= vec.x; - y -= vec.y; - return *this; + x -= vec.x; + y -= vec.y; + return *this; } // @@ -367,7 +367,7 @@ kexVec2 &kexVec2::operator-=(const kexVec2 &vec) kexVec2 kexVec2::operator*(const kexVec2 &vec) { - return kexVec2(x * vec.x, y * vec.y); + return kexVec2(x * vec.x, y * vec.y); } // @@ -376,9 +376,9 @@ kexVec2 kexVec2::operator*(const kexVec2 &vec) kexVec2 &kexVec2::operator*=(const kexVec2 &vec) { - x *= vec.x; - y *= vec.y; - return *this; + x *= vec.x; + y *= vec.y; + return *this; } // @@ -387,7 +387,7 @@ kexVec2 &kexVec2::operator*=(const kexVec2 &vec) kexVec2 kexVec2::operator*(const float val) { - return kexVec2(x * val, y * val); + return kexVec2(x * val, y * val); } // @@ -396,7 +396,7 @@ kexVec2 kexVec2::operator*(const float val) kexVec2 kexVec2::operator*(const float val) const { - return kexVec2(x * val, y * val); + return kexVec2(x * val, y * val); } // @@ -405,9 +405,9 @@ kexVec2 kexVec2::operator*(const float val) const kexVec2 &kexVec2::operator*=(const float val) { - x *= val; - y *= val; - return *this; + x *= val; + y *= val; + return *this; } // @@ -416,7 +416,7 @@ kexVec2 &kexVec2::operator*=(const float val) kexVec2 kexVec2::operator/(const kexVec2 &vec) { - return kexVec2(x / vec.x, y / vec.y); + return kexVec2(x / vec.x, y / vec.y); } // @@ -425,9 +425,9 @@ kexVec2 kexVec2::operator/(const kexVec2 &vec) kexVec2 &kexVec2::operator/=(const kexVec2 &vec) { - x /= vec.x; - y /= vec.y; - return *this; + x /= vec.x; + y /= vec.y; + return *this; } // @@ -436,7 +436,7 @@ kexVec2 &kexVec2::operator/=(const kexVec2 &vec) kexVec2 kexVec2::operator/(const float val) { - return kexVec2(x / val, y / val); + return kexVec2(x / val, y / val); } // @@ -445,9 +445,9 @@ kexVec2 kexVec2::operator/(const float val) kexVec2 &kexVec2::operator/=(const float val) { - x /= val; - y /= val; - return *this; + x /= val; + y /= val; + return *this; } // @@ -456,8 +456,8 @@ kexVec2 &kexVec2::operator/=(const float val) kexVec2 kexVec2::operator*(const kexMatrix &mtx) { - return kexVec2(mtx.vectors[1].x * y + mtx.vectors[0].x * x + mtx.vectors[3].x, - mtx.vectors[1].y * y + mtx.vectors[0].y * x + mtx.vectors[3].y); + return kexVec2(mtx.vectors[1].x * y + mtx.vectors[0].x * x + mtx.vectors[3].x, + mtx.vectors[1].y * y + mtx.vectors[0].y * x + mtx.vectors[3].y); } // @@ -466,8 +466,8 @@ kexVec2 kexVec2::operator*(const kexMatrix &mtx) kexVec2 kexVec2::operator*(const kexMatrix &mtx) const { - return kexVec2(mtx.vectors[1].x * y + mtx.vectors[0].x * x + mtx.vectors[3].x, - mtx.vectors[1].y * y + mtx.vectors[0].y * x + mtx.vectors[3].y); + return kexVec2(mtx.vectors[1].x * y + mtx.vectors[0].x * x + mtx.vectors[3].x, + mtx.vectors[1].y * y + mtx.vectors[0].y * x + mtx.vectors[3].y); } // @@ -476,13 +476,13 @@ kexVec2 kexVec2::operator*(const kexMatrix &mtx) const kexVec2 &kexVec2::operator*=(const kexMatrix &mtx) { - float _x = x; - float _y = y; + float _x = x; + float _y = y; - x = mtx.vectors[1].x * _y + mtx.vectors[0].x * _x + mtx.vectors[3].x; - y = mtx.vectors[1].y * _y + mtx.vectors[0].y * _x + mtx.vectors[3].y; + x = mtx.vectors[1].x * _y + mtx.vectors[0].x * _x + mtx.vectors[3].x; + y = mtx.vectors[1].y * _y + mtx.vectors[0].y * _x + mtx.vectors[3].y; - return *this; + return *this; } // @@ -491,9 +491,9 @@ kexVec2 &kexVec2::operator*=(const kexMatrix &mtx) kexVec2 &kexVec2::operator=(const kexVec2 &vec) { - x = vec.x; - y = vec.y; - return *this; + x = vec.x; + y = vec.y; + return *this; } // @@ -502,9 +502,9 @@ kexVec2 &kexVec2::operator=(const kexVec2 &vec) kexVec2 &kexVec2::operator=(const kexVec3 &vec) { - x = vec.x; - y = vec.y; - return *this; + x = vec.x; + y = vec.y; + return *this; } // @@ -513,9 +513,9 @@ kexVec2 &kexVec2::operator=(const kexVec3 &vec) kexVec2 &kexVec2::operator=(kexVec3 &vec) { - x = vec.x; - y = vec.y; - return *this; + x = vec.x; + y = vec.y; + return *this; } // @@ -524,9 +524,9 @@ kexVec2 &kexVec2::operator=(kexVec3 &vec) kexVec2 &kexVec2::operator=(const float *vecs) { - x = vecs[0]; - y = vecs[2]; - return *this; + x = vecs[0]; + y = vecs[2]; + return *this; } // @@ -535,8 +535,8 @@ kexVec2 &kexVec2::operator=(const float *vecs) float kexVec2::operator[](int index) const { - assert(index >= 0 && index < 2); - return (&x)[index]; + assert(index >= 0 && index < 2); + return (&x)[index]; } // @@ -545,8 +545,8 @@ float kexVec2::operator[](int index) const float &kexVec2::operator[](int index) { - assert(index >= 0 && index < 2); - return (&x)[index]; + assert(index >= 0 && index < 2); + return (&x)[index]; } // @@ -555,7 +555,7 @@ float &kexVec2::operator[](int index) bool kexVec2::operator==(const kexVec2 &vec) { - return ((x == vec.x) && (y == vec.y)); + return ((x == vec.x) && (y == vec.y)); } // @@ -564,7 +564,7 @@ bool kexVec2::operator==(const kexVec2 &vec) kexVec3::kexVec3() { - Clear(); + Clear(); } // @@ -573,7 +573,7 @@ kexVec3::kexVec3() kexVec3::kexVec3(const float x, const float y, const float z) { - Set(x, y, z); + Set(x, y, z); } // @@ -582,9 +582,9 @@ kexVec3::kexVec3(const float x, const float y, const float z) void kexVec3::Set(const float x, const float y, const float z) { - this->x = x; - this->y = y; - this->z = z; + this->x = x; + this->y = y; + this->z = z; } // @@ -593,7 +593,7 @@ void kexVec3::Set(const float x, const float y, const float z) void kexVec3::Clear() { - x = y = z = 0.0f; + x = y = z = 0.0f; } // @@ -602,7 +602,7 @@ void kexVec3::Clear() float kexVec3::Dot(const kexVec3 &vec) const { - return (x * vec.x + y * vec.y + z * vec.z); + return (x * vec.x + y * vec.y + z * vec.z); } // @@ -611,7 +611,7 @@ float kexVec3::Dot(const kexVec3 &vec) const float kexVec3::Dot(const kexVec3 &vec1, const kexVec3 &vec2) { - return (vec1.x * vec2.x + vec1.y * vec2.y + vec1.z * vec2.z); + return (vec1.x * vec2.x + vec1.y * vec2.y + vec1.z * vec2.z); } // @@ -620,11 +620,11 @@ float kexVec3::Dot(const kexVec3 &vec1, const kexVec3 &vec2) kexVec3 kexVec3::Cross(const kexVec3 &vec) const { - return kexVec3( - vec.z * y - z * vec.y, - vec.x * z - x * vec.z, - x * vec.y - vec.x * y - ); + return kexVec3( + vec.z * y - z * vec.y, + vec.x * z - x * vec.z, + x * vec.y - vec.x * y + ); } // @@ -642,7 +642,7 @@ kexVec3 kexVec3::Cross(const kexVec3 &vec1, const kexVec3 &vec2) float kexVec3::UnitSq() const { - return x * x + y * y + z * z; + return x * x + y * y + z * z; } // @@ -651,7 +651,7 @@ float kexVec3::UnitSq() const float kexVec3::Unit() const { - return kexMath::Sqrt(UnitSq()); + return kexMath::Sqrt(UnitSq()); } // @@ -660,11 +660,11 @@ float kexVec3::Unit() const float kexVec3::DistanceSq(const kexVec3 &vec) const { - return ( - (x - vec.x) * (x - vec.x) + - (y - vec.y) * (y - vec.y) + - (z - vec.z) * (z - vec.z) - ); + return ( + (x - vec.x) * (x - vec.x) + + (y - vec.y) * (y - vec.y) + + (z - vec.z) * (z - vec.z) + ); } // @@ -673,7 +673,7 @@ float kexVec3::DistanceSq(const kexVec3 &vec) const float kexVec3::Distance(const kexVec3 &vec) const { - return kexMath::Sqrt(DistanceSq(vec)); + return kexMath::Sqrt(DistanceSq(vec)); } // @@ -682,8 +682,8 @@ float kexVec3::Distance(const kexVec3 &vec) const kexVec3 &kexVec3::Normalize() { - *this *= kexMath::InvSqrt(UnitSq()); - return *this; + *this *= kexMath::InvSqrt(UnitSq()); + return *this; } kexVec3 kexVec3::Normalize(kexVec3 a) @@ -698,9 +698,9 @@ kexVec3 kexVec3::Normalize(kexVec3 a) kexAngle kexVec3::PointAt(kexVec3 &location) const { - kexVec3 dir = (*this - location).Normalize(); + kexVec3 dir = (*this - location).Normalize(); - return kexAngle(dir.ToYaw(), dir.ToPitch(), 0); + return kexAngle(dir.ToYaw(), dir.ToPitch(), 0); } // @@ -709,7 +709,7 @@ kexAngle kexVec3::PointAt(kexVec3 &location) const kexVec3 kexVec3::Lerp(const kexVec3 &next, float movement) const { - return (next - *this) * movement + *this; + return (next - *this) * movement + *this; } // @@ -718,8 +718,8 @@ kexVec3 kexVec3::Lerp(const kexVec3 &next, float movement) const kexVec3 &kexVec3::Lerp(const kexVec3 &start, const kexVec3 &next, float movement) { - *this = (next - start) * movement + start; - return *this; + *this = (next - start) * movement + start; + return *this; } // @@ -728,8 +728,8 @@ kexVec3 &kexVec3::Lerp(const kexVec3 &start, const kexVec3 &next, float movement kexQuat kexVec3::ToQuat() { - kexVec3 scv = *this * kexMath::InvSqrt(UnitSq()); - return kexQuat(kexMath::ACos(scv.z), vecForward.Cross(scv).Normalize()); + kexVec3 scv = *this * kexMath::InvSqrt(UnitSq()); + return kexQuat(kexMath::ACos(scv.z), vecForward.Cross(scv).Normalize()); } // @@ -738,14 +738,14 @@ kexQuat kexVec3::ToQuat() float kexVec3::ToYaw() const { - float d = x * x + z * z; + float d = x * x + z * z; - if(d == 0.0f) - { - return 0.0f; - } + if (d == 0.0f) + { + return 0.0f; + } - return kexMath::ATan2(x, z); + return kexMath::ATan2(x, z); } // @@ -754,21 +754,21 @@ float kexVec3::ToYaw() const float kexVec3::ToPitch() const { - float d = x * x + z * z; + float d = x * x + z * z; - if(d == 0.0f) - { - if(y > 0.0f) - { - return DEG2RAD(90); - } - else - { - return DEG2RAD(-90); - } - } + if (d == 0.0f) + { + if (y > 0.0f) + { + return DEG2RAD(90); + } + else + { + return DEG2RAD(-90); + } + } - return kexMath::ATan2(y, d); + return kexMath::ATan2(y, d); } // @@ -777,9 +777,9 @@ float kexVec3::ToPitch() const kexStr kexVec3::ToString() const { - kexStr str; - str = str + x + " " + y + " " + z; - return str; + kexStr str; + str = str + x + " " + y + " " + z; + return str; } // @@ -788,7 +788,7 @@ kexStr kexVec3::ToString() const float *kexVec3::ToFloatPtr() { - return reinterpret_cast(&x); + return reinterpret_cast(&x); } // @@ -797,7 +797,7 @@ float *kexVec3::ToFloatPtr() kexVec2 kexVec3::ToVec2() { - return kexVec2(x, y); + return kexVec2(x, y); } // @@ -806,7 +806,7 @@ kexVec2 kexVec3::ToVec2() kexVec2 kexVec3::ToVec2() const { - return kexVec2(x, y); + return kexVec2(x, y); } // @@ -814,34 +814,34 @@ kexVec2 kexVec3::ToVec2() const // kexVec3 kexVec3::ScreenProject(kexMatrix &proj, kexMatrix &model, - const int width, const int height, - const int wx, const int wy) + const int width, const int height, + const int wx, const int wy) { - kexVec4 projVec; - kexVec4 modelVec; + kexVec4 projVec; + kexVec4 modelVec; - modelVec.ToVec3() = *this; - modelVec |= model; + modelVec.ToVec3() = *this; + modelVec |= model; - projVec = (modelVec | proj); - projVec.x *= modelVec.w; - projVec.y *= modelVec.w; - projVec.z *= modelVec.w; + projVec = (modelVec | proj); + projVec.x *= modelVec.w; + projVec.y *= modelVec.w; + projVec.z *= modelVec.w; - if(projVec.w != 0) - { - projVec.w = 1.0f / projVec.w; - projVec.x *= projVec.w; - projVec.y *= projVec.w; - projVec.z *= projVec.w; + if (projVec.w != 0) + { + projVec.w = 1.0f / projVec.w; + projVec.x *= projVec.w; + projVec.y *= projVec.w; + projVec.z *= projVec.w; - return kexVec3( - (projVec.x * 0.5f + 0.5f) * width + wx, - (-projVec.y * 0.5f + 0.5f) * height + wy, - (1.0f + projVec.z) * 0.5f); - } + return kexVec3( + (projVec.x * 0.5f + 0.5f) * width + wx, + (-projVec.y * 0.5f + 0.5f) * height + wy, + (1.0f + projVec.z) * 0.5f); + } - return kexVec3(*this); + return kexVec3(*this); } // @@ -850,7 +850,7 @@ kexVec3 kexVec3::ScreenProject(kexMatrix &proj, kexMatrix &model, kexVec3 kexVec3::operator+(const kexVec3 &vec) { - return kexVec3(x + vec.x, y + vec.y, z + vec.z); + return kexVec3(x + vec.x, y + vec.y, z + vec.z); } // @@ -859,7 +859,7 @@ kexVec3 kexVec3::operator+(const kexVec3 &vec) kexVec3 kexVec3::operator+(const kexVec3 &vec) const { - return kexVec3(x + vec.x, y + vec.y, z + vec.z); + return kexVec3(x + vec.x, y + vec.y, z + vec.z); } kexVec3 kexVec3::operator+(const float val) const @@ -873,7 +873,7 @@ kexVec3 kexVec3::operator+(const float val) const kexVec3 kexVec3::operator+(kexVec3 &vec) { - return kexVec3(x + vec.x, y + vec.y, z + vec.z); + return kexVec3(x + vec.x, y + vec.y, z + vec.z); } // @@ -882,10 +882,10 @@ kexVec3 kexVec3::operator+(kexVec3 &vec) kexVec3 &kexVec3::operator+=(const kexVec3 &vec) { - x += vec.x; - y += vec.y; - z += vec.z; - return *this; + x += vec.x; + y += vec.y; + z += vec.z; + return *this; } kexVec3 &kexVec3::operator+=(const float val) @@ -902,7 +902,7 @@ kexVec3 &kexVec3::operator+=(const float val) kexVec3 kexVec3::operator-(const kexVec3 &vec) const { - return kexVec3(x - vec.x, y - vec.y, z - vec.z); + return kexVec3(x - vec.x, y - vec.y, z - vec.z); } kexVec3 kexVec3::operator-(const float val) const @@ -916,7 +916,7 @@ kexVec3 kexVec3::operator-(const float val) const kexVec3 kexVec3::operator-() const { - return kexVec3(-x, -y, -z); + return kexVec3(-x, -y, -z); } // @@ -925,10 +925,10 @@ kexVec3 kexVec3::operator-() const kexVec3 &kexVec3::operator-=(const kexVec3 &vec) { - x -= vec.x; - y -= vec.y; - z -= vec.z; - return *this; + x -= vec.x; + y -= vec.y; + z -= vec.z; + return *this; } kexVec3 &kexVec3::operator-=(const float val) @@ -945,7 +945,7 @@ kexVec3 &kexVec3::operator-=(const float val) kexVec3 kexVec3::operator*(const kexVec3 &vec) { - return kexVec3(x * vec.x, y * vec.y, z * vec.z); + return kexVec3(x * vec.x, y * vec.y, z * vec.z); } // @@ -954,10 +954,10 @@ kexVec3 kexVec3::operator*(const kexVec3 &vec) kexVec3 &kexVec3::operator*=(const kexVec3 &vec) { - x *= vec.x; - y *= vec.y; - z *= vec.z; - return *this; + x *= vec.x; + y *= vec.y; + z *= vec.z; + return *this; } // @@ -966,7 +966,7 @@ kexVec3 &kexVec3::operator*=(const kexVec3 &vec) kexVec3 kexVec3::operator*(const float val) { - return kexVec3(x * val, y * val, z * val); + return kexVec3(x * val, y * val, z * val); } // @@ -975,7 +975,7 @@ kexVec3 kexVec3::operator*(const float val) kexVec3 kexVec3::operator*(const float val) const { - return kexVec3(x * val, y * val, z * val); + return kexVec3(x * val, y * val, z * val); } // @@ -984,10 +984,10 @@ kexVec3 kexVec3::operator*(const float val) const kexVec3 &kexVec3::operator*=(const float val) { - x *= val; - y *= val; - z *= val; - return *this; + x *= val; + y *= val; + z *= val; + return *this; } // @@ -996,7 +996,7 @@ kexVec3 &kexVec3::operator*=(const float val) kexVec3 kexVec3::operator/(const kexVec3 &vec) { - return kexVec3(x / vec.x, y / vec.y, z / vec.z); + return kexVec3(x / vec.x, y / vec.y, z / vec.z); } // @@ -1005,10 +1005,10 @@ kexVec3 kexVec3::operator/(const kexVec3 &vec) kexVec3 &kexVec3::operator/=(const kexVec3 &vec) { - x /= vec.x; - y /= vec.y; - z /= vec.z; - return *this; + x /= vec.x; + y /= vec.y; + z /= vec.z; + return *this; } // @@ -1017,7 +1017,7 @@ kexVec3 &kexVec3::operator/=(const kexVec3 &vec) kexVec3 kexVec3::operator/(const float val) { - return kexVec3(x / val, y / val, z / val); + return kexVec3(x / val, y / val, z / val); } // @@ -1026,10 +1026,10 @@ kexVec3 kexVec3::operator/(const float val) kexVec3 &kexVec3::operator/=(const float val) { - x /= val; - y /= val; - z /= val; - return *this; + x /= val; + y /= val; + z /= val; + return *this; } // @@ -1038,28 +1038,28 @@ kexVec3 &kexVec3::operator/=(const float val) kexVec3 kexVec3::operator*(const kexQuat &quat) { - float xx = quat.x * quat.x; - float yx = quat.y * quat.x; - float zx = quat.z * quat.x; - float wx = quat.w * quat.x; - float yy = quat.y * quat.y; - float zy = quat.z * quat.y; - float wy = quat.w * quat.y; - float zz = quat.z * quat.z; - float wz = quat.w * quat.z; - float ww = quat.w * quat.w; + float xx = quat.x * quat.x; + float yx = quat.y * quat.x; + float zx = quat.z * quat.x; + float wx = quat.w * quat.x; + float yy = quat.y * quat.y; + float zy = quat.z * quat.y; + float wy = quat.w * quat.y; + float zz = quat.z * quat.z; + float wz = quat.w * quat.z; + float ww = quat.w * quat.w; - return kexVec3( - ((yx + yx) - (wz + wz)) * y + - ((wy + wy + zx + zx)) * z + - (((ww + xx) - yy) - zz) * x, - ((yy + (ww - xx)) - zz) * y + - ((zy + zy) - (wx + wx)) * z + - ((wz + wz) + (yx + yx)) * x, - ((wx + wx) + (zy + zy)) * y + - (((ww - xx) - yy) + zz) * z + - ((zx + zx) - (wy + wy)) * x - ); + return kexVec3( + ((yx + yx) - (wz + wz)) * y + + ((wy + wy + zx + zx)) * z + + (((ww + xx) - yy) - zz) * x, + ((yy + (ww - xx)) - zz) * y + + ((zy + zy) - (wx + wx)) * z + + ((wz + wz) + (yx + yx)) * x, + ((wx + wx) + (zy + zy)) * y + + (((ww - xx) - yy) + zz) * z + + ((zx + zx) - (wy + wy)) * x + ); } // @@ -1068,9 +1068,9 @@ kexVec3 kexVec3::operator*(const kexQuat &quat) kexVec3 kexVec3::operator*(const kexMatrix &mtx) { - return kexVec3(mtx.vectors[1].x * y + mtx.vectors[2].x * z + mtx.vectors[0].x * x + mtx.vectors[3].x, - mtx.vectors[1].y * y + mtx.vectors[2].y * z + mtx.vectors[0].y * x + mtx.vectors[3].y, - mtx.vectors[1].z * y + mtx.vectors[2].z * z + mtx.vectors[0].z * x + mtx.vectors[3].z); + return kexVec3(mtx.vectors[1].x * y + mtx.vectors[2].x * z + mtx.vectors[0].x * x + mtx.vectors[3].x, + mtx.vectors[1].y * y + mtx.vectors[2].y * z + mtx.vectors[0].y * x + mtx.vectors[3].y, + mtx.vectors[1].z * y + mtx.vectors[2].z * z + mtx.vectors[0].z * x + mtx.vectors[3].z); } // @@ -1079,9 +1079,9 @@ kexVec3 kexVec3::operator*(const kexMatrix &mtx) kexVec3 kexVec3::operator*(const kexMatrix &mtx) const { - return kexVec3(mtx.vectors[1].x * y + mtx.vectors[2].x * z + mtx.vectors[0].x * x + mtx.vectors[3].x, - mtx.vectors[1].y * y + mtx.vectors[2].y * z + mtx.vectors[0].y * x + mtx.vectors[3].y, - mtx.vectors[1].z * y + mtx.vectors[2].z * z + mtx.vectors[0].z * x + mtx.vectors[3].z); + return kexVec3(mtx.vectors[1].x * y + mtx.vectors[2].x * z + mtx.vectors[0].x * x + mtx.vectors[3].x, + mtx.vectors[1].y * y + mtx.vectors[2].y * z + mtx.vectors[0].y * x + mtx.vectors[3].y, + mtx.vectors[1].z * y + mtx.vectors[2].z * z + mtx.vectors[0].z * x + mtx.vectors[3].z); } // @@ -1090,15 +1090,15 @@ kexVec3 kexVec3::operator*(const kexMatrix &mtx) const kexVec3 &kexVec3::operator*=(const kexMatrix &mtx) { - float _x = x; - float _y = y; - float _z = z; + float _x = x; + float _y = y; + float _z = z; - x = mtx.vectors[1].x * _y + mtx.vectors[2].x * _z + mtx.vectors[0].x * _x + mtx.vectors[3].x; - y = mtx.vectors[1].y * _y + mtx.vectors[2].y * _z + mtx.vectors[0].y * _x + mtx.vectors[3].y; - z = mtx.vectors[1].z * _y + mtx.vectors[2].z * _z + mtx.vectors[0].z * _x + mtx.vectors[3].z; + x = mtx.vectors[1].x * _y + mtx.vectors[2].x * _z + mtx.vectors[0].x * _x + mtx.vectors[3].x; + y = mtx.vectors[1].y * _y + mtx.vectors[2].y * _z + mtx.vectors[0].y * _x + mtx.vectors[3].y; + z = mtx.vectors[1].z * _y + mtx.vectors[2].z * _z + mtx.vectors[0].z * _x + mtx.vectors[3].z; - return *this; + return *this; } // @@ -1107,31 +1107,31 @@ kexVec3 &kexVec3::operator*=(const kexMatrix &mtx) kexVec3 &kexVec3::operator*=(const kexQuat &quat) { - float xx = quat.x * quat.x; - float yx = quat.y * quat.x; - float zx = quat.z * quat.x; - float wx = quat.w * quat.x; - float yy = quat.y * quat.y; - float zy = quat.z * quat.y; - float wy = quat.w * quat.y; - float zz = quat.z * quat.z; - float wz = quat.w * quat.z; - float ww = quat.w * quat.w; - float vx = x; - float vy = y; - float vz = z; + float xx = quat.x * quat.x; + float yx = quat.y * quat.x; + float zx = quat.z * quat.x; + float wx = quat.w * quat.x; + float yy = quat.y * quat.y; + float zy = quat.z * quat.y; + float wy = quat.w * quat.y; + float zz = quat.z * quat.z; + float wz = quat.w * quat.z; + float ww = quat.w * quat.w; + float vx = x; + float vy = y; + float vz = z; - x = ((yx + yx) - (wz + wz)) * vy + - ((wy + wy + zx + zx)) * vz + - (((ww + xx) - yy) - zz) * vx; - y = ((yy + (ww - xx)) - zz) * vy + - ((zy + zy) - (wx + wx)) * vz + - ((wz + wz) + (yx + yx)) * vx; - z = ((wx + wx) + (zy + zy)) * vy + - (((ww - xx) - yy) + zz) * vz + - ((zx + zx) - (wy + wy)) * vx; + x = ((yx + yx) - (wz + wz)) * vy + + ((wy + wy + zx + zx)) * vz + + (((ww + xx) - yy) - zz) * vx; + y = ((yy + (ww - xx)) - zz) * vy + + ((zy + zy) - (wx + wx)) * vz + + ((wz + wz) + (yx + yx)) * vx; + z = ((wx + wx) + (zy + zy)) * vy + + (((ww - xx) - yy) + zz) * vz + + ((zx + zx) - (wy + wy)) * vx; - return *this; + return *this; } // @@ -1140,10 +1140,10 @@ kexVec3 &kexVec3::operator*=(const kexQuat &quat) kexVec3 &kexVec3::operator=(const kexVec3 &vec) { - x = vec.x; - y = vec.y; - z = vec.z; - return *this; + x = vec.x; + y = vec.y; + z = vec.z; + return *this; } // @@ -1152,10 +1152,10 @@ kexVec3 &kexVec3::operator=(const kexVec3 &vec) kexVec3 &kexVec3::operator=(const float *vecs) { - x = vecs[0]; - y = vecs[1]; - z = vecs[2]; - return *this; + x = vecs[0]; + y = vecs[1]; + z = vecs[2]; + return *this; } // @@ -1164,8 +1164,8 @@ kexVec3 &kexVec3::operator=(const float *vecs) float kexVec3::operator[](int index) const { - assert(index >= 0 && index < 3); - return (&x)[index]; + assert(index >= 0 && index < 3); + return (&x)[index]; } // @@ -1174,8 +1174,8 @@ float kexVec3::operator[](int index) const float &kexVec3::operator[](int index) { - assert(index >= 0 && index < 3); - return (&x)[index]; + assert(index >= 0 && index < 3); + return (&x)[index]; } // @@ -1184,7 +1184,7 @@ float &kexVec3::operator[](int index) kexVec4::kexVec4() { - Clear(); + Clear(); } // @@ -1193,7 +1193,7 @@ kexVec4::kexVec4() kexVec4::kexVec4(const float x, const float y, const float z, const float w) { - Set(x, y, z, w); + Set(x, y, z, w); } kexVec4::kexVec4(const kexVec3 &v, const float w) @@ -1207,10 +1207,10 @@ kexVec4::kexVec4(const kexVec3 &v, const float w) void kexVec4::Set(const float x, const float y, const float z, const float w) { - this->x = x; - this->y = y; - this->z = z; - this->w = w; + this->x = x; + this->y = y; + this->z = z; + this->w = w; } // @@ -1219,7 +1219,7 @@ void kexVec4::Set(const float x, const float y, const float z, const float w) void kexVec4::Clear() { - x = y = z = w = 0.0f; + x = y = z = w = 0.0f; } // @@ -1228,7 +1228,7 @@ void kexVec4::Clear() kexVec3 const &kexVec4::ToVec3() const { - return *reinterpret_cast(this); + return *reinterpret_cast(this); } // @@ -1237,7 +1237,7 @@ kexVec3 const &kexVec4::ToVec3() const kexVec3 &kexVec4::ToVec3() { - return *reinterpret_cast(this); + return *reinterpret_cast(this); } // @@ -1246,7 +1246,7 @@ kexVec3 &kexVec4::ToVec3() float *kexVec4::ToFloatPtr() { - return reinterpret_cast(&x); + return reinterpret_cast(&x); } kexVec4 kexVec4::operator+(const kexVec4 &vec) const @@ -1343,11 +1343,11 @@ kexVec4 &kexVec4::operator/=(const float val) kexVec4 kexVec4::operator|(const kexMatrix &mtx) { - return kexVec4( - mtx.vectors[1].x * y + mtx.vectors[2].x * z + mtx.vectors[0].x * x + mtx.vectors[3].x, - mtx.vectors[1].y * y + mtx.vectors[2].y * z + mtx.vectors[0].y * x + mtx.vectors[3].y, - mtx.vectors[1].z * y + mtx.vectors[2].z * z + mtx.vectors[0].z * x + mtx.vectors[3].z, - mtx.vectors[1].w * y + mtx.vectors[2].w * z + mtx.vectors[0].w * x + mtx.vectors[3].w); + return kexVec4( + mtx.vectors[1].x * y + mtx.vectors[2].x * z + mtx.vectors[0].x * x + mtx.vectors[3].x, + mtx.vectors[1].y * y + mtx.vectors[2].y * z + mtx.vectors[0].y * x + mtx.vectors[3].y, + mtx.vectors[1].z * y + mtx.vectors[2].z * z + mtx.vectors[0].z * x + mtx.vectors[3].z, + mtx.vectors[1].w * y + mtx.vectors[2].w * z + mtx.vectors[0].w * x + mtx.vectors[3].w); } // @@ -1356,16 +1356,16 @@ kexVec4 kexVec4::operator|(const kexMatrix &mtx) kexVec4 &kexVec4::operator|=(const kexMatrix &mtx) { - float _x = x; - float _y = y; - float _z = z; + float _x = x; + float _y = y; + float _z = z; - x = mtx.vectors[1].x * _y + mtx.vectors[2].x * _z + mtx.vectors[0].x * _x + mtx.vectors[3].x; - y = mtx.vectors[1].y * _y + mtx.vectors[2].y * _z + mtx.vectors[0].y * _x + mtx.vectors[3].y; - z = mtx.vectors[1].z * _y + mtx.vectors[2].z * _z + mtx.vectors[0].z * _x + mtx.vectors[3].z; - w = mtx.vectors[1].w * _y + mtx.vectors[2].w * _z + mtx.vectors[0].w * _x + mtx.vectors[3].w; + x = mtx.vectors[1].x * _y + mtx.vectors[2].x * _z + mtx.vectors[0].x * _x + mtx.vectors[3].x; + y = mtx.vectors[1].y * _y + mtx.vectors[2].y * _z + mtx.vectors[0].y * _x + mtx.vectors[3].y; + z = mtx.vectors[1].z * _y + mtx.vectors[2].z * _z + mtx.vectors[0].z * _x + mtx.vectors[3].z; + w = mtx.vectors[1].w * _y + mtx.vectors[2].w * _z + mtx.vectors[0].w * _x + mtx.vectors[3].w; - return *this; + return *this; } // @@ -1374,8 +1374,8 @@ kexVec4 &kexVec4::operator|=(const kexMatrix &mtx) float kexVec4::operator[](int index) const { - assert(index >= 0 && index < 3); - return (&x)[index]; + assert(index >= 0 && index < 3); + return (&x)[index]; } // @@ -1384,6 +1384,6 @@ float kexVec4::operator[](int index) const float &kexVec4::operator[](int index) { - assert(index >= 0 && index < 3); - return (&x)[index]; + assert(index >= 0 && index < 3); + return (&x)[index]; } diff --git a/src/lightmap/kexlib/memheap.cpp b/src/lightmap/kexlib/memheap.cpp index f8d9eaf..5117b86 100644 --- a/src/lightmap/kexlib/memheap.cpp +++ b/src/lightmap/kexlib/memheap.cpp @@ -51,40 +51,40 @@ kexHeapBlock hb_object("object", false, NULL, NULL); // kexHeapBlock::kexHeapBlock(const char *name, bool bGarbageCollect, - blockFunc_t funcFree, blockFunc_t funcGC) + blockFunc_t funcFree, blockFunc_t funcGC) { - this->name = (char*)name; - this->freeFunc = funcFree; - this->gcFunc = funcGC; - this->blocks = NULL; - this->bGC = bGarbageCollect; - this->purgeID = kexHeap::numHeapBlocks++; + this->name = (char*)name; + this->freeFunc = funcFree; + this->gcFunc = funcGC; + this->blocks = NULL; + this->bGC = bGarbageCollect; + this->purgeID = kexHeap::numHeapBlocks++; - // add heap block to main block list - if(kexHeap::blockList) - { - if(kexHeap::blockList->prev) - { - kexHeap::blockList->prev->next = this; - this->prev = kexHeap::blockList->prev; - this->next = NULL; - kexHeap::blockList->prev = this; - } - else - { - kexHeap::blockList->prev = this; - kexHeap::blockList->next = this; - this->prev = kexHeap::blockList; - this->next = NULL; - } + // add heap block to main block list + if (kexHeap::blockList) + { + if (kexHeap::blockList->prev) + { + kexHeap::blockList->prev->next = this; + this->prev = kexHeap::blockList->prev; + this->next = NULL; + kexHeap::blockList->prev = this; + } + else + { + kexHeap::blockList->prev = this; + kexHeap::blockList->next = this; + this->prev = kexHeap::blockList; + this->next = NULL; + } - } - else - { - kexHeap::blockList = this; - this->prev = NULL; - this->next = NULL; - } + } + else + { + kexHeap::blockList = this; + this->prev = NULL; + this->next = NULL; + } } // @@ -103,26 +103,26 @@ kexHeapBlock::~kexHeapBlock() kexHeapBlock *kexHeapBlock::operator[](int index) { - if(kexHeap::currentHeapBlockID == index) - { - return kexHeap::currentHeapBlock; - } + if (kexHeap::currentHeapBlockID == index) + { + return kexHeap::currentHeapBlock; + } - kexHeapBlock *heapBlock = this; + kexHeapBlock *heapBlock = this; - for(int i = 0; i < index; i++) - { - heapBlock = heapBlock->next; - if(heapBlock == NULL) - { - return NULL; - } - } + for (int i = 0; i < index; i++) + { + heapBlock = heapBlock->next; + if (heapBlock == NULL) + { + return NULL; + } + } - kexHeap::currentHeapBlockID = index; - kexHeap::currentHeapBlock = heapBlock; + kexHeap::currentHeapBlockID = index; + kexHeap::currentHeapBlock = heapBlock; - return heapBlock; + return heapBlock; } // @@ -131,16 +131,16 @@ kexHeapBlock *kexHeapBlock::operator[](int index) void kexHeap::AddBlock(memBlock *block, kexHeapBlock *heapBlock) { - block->prev = NULL; - block->next = heapBlock->blocks; - heapBlock->blocks = block; + block->prev = NULL; + block->next = heapBlock->blocks; + heapBlock->blocks = block; - block->heapBlock = heapBlock; + block->heapBlock = heapBlock; - if(block->next != NULL) - { - block->next->prev = block; - } + if (block->next != NULL) + { + block->next->prev = block; + } } // @@ -149,21 +149,21 @@ void kexHeap::AddBlock(memBlock *block, kexHeapBlock *heapBlock) void kexHeap::RemoveBlock(memBlock *block) { - if(block->prev == NULL) - { - block->heapBlock->blocks = block->next; - } - else - { - block->prev->next = block->next; - } + if (block->prev == NULL) + { + block->heapBlock->blocks = block->next; + } + else + { + block->prev->next = block->next; + } - if(block->next != NULL) - { - block->next->prev = block->prev; - } + if (block->next != NULL) + { + block->next->prev = block->prev; + } - block->heapBlock = NULL; + block->heapBlock = NULL; } // @@ -172,16 +172,16 @@ void kexHeap::RemoveBlock(memBlock *block) memBlock *kexHeap::GetBlock(void *ptr, const char *file, int line) { - memBlock* block; + memBlock* block; - block = (memBlock*)((byte*)ptr - sizeof(memBlock)); + block = (memBlock*)((byte*)ptr - sizeof(memBlock)); - if(block->heapTag != kexHeap::HeapTag) - { - Error("kexHeap::GetBlock: found a pointer without heap tag (%s:%d)", file, line); - } + if (block->heapTag != kexHeap::HeapTag) + { + Error("kexHeap::GetBlock: found a pointer without heap tag (%s:%d)", file, line); + } - return block; + return block; } // @@ -190,25 +190,25 @@ memBlock *kexHeap::GetBlock(void *ptr, const char *file, int line) void *kexHeap::Malloc(int size, kexHeapBlock &heapBlock, const char *file, int line) { - memBlock *newblock; + memBlock *newblock; - assert(size > 0); + assert(size > 0); - newblock = NULL; + newblock = NULL; - if(!(newblock = (memBlock*)malloc(sizeof(memBlock) + size))) - { - Error("kexHeap::Malloc: failed on allocation of %u bytes (%s:%d)", size, file, line); - } + if (!(newblock = (memBlock*)malloc(sizeof(memBlock) + size))) + { + Error("kexHeap::Malloc: failed on allocation of %u bytes (%s:%d)", size, file, line); + } - newblock->purgeID = heapBlock.purgeID; - newblock->heapTag = kexHeap::HeapTag; - newblock->size = size; - newblock->ptrRef = NULL; + newblock->purgeID = heapBlock.purgeID; + newblock->heapTag = kexHeap::HeapTag; + newblock->size = size; + newblock->ptrRef = NULL; - kexHeap::AddBlock(newblock, &heapBlock); + kexHeap::AddBlock(newblock, &heapBlock); - return ((byte*)newblock) + sizeof(memBlock); + return ((byte*)newblock) + sizeof(memBlock); } // @@ -217,7 +217,7 @@ void *kexHeap::Malloc(int size, kexHeapBlock &heapBlock, const char *file, int l void *kexHeap::Calloc(int size, kexHeapBlock &heapBlock, const char *file, int line) { - return memset(kexHeap::Malloc(size, heapBlock, file, line), 0, size); + return memset(kexHeap::Malloc(size, heapBlock, file, line), 0, size); } // @@ -226,48 +226,48 @@ void *kexHeap::Calloc(int size, kexHeapBlock &heapBlock, const char *file, int l void *kexHeap::Realloc(void *ptr, int size, kexHeapBlock &heapBlock, const char *file, int line) { - memBlock *block; - memBlock *newblock; + memBlock *block; + memBlock *newblock; - if(!ptr) - { - return kexHeap::Malloc(size, heapBlock, file, line); - } + if (!ptr) + { + return kexHeap::Malloc(size, heapBlock, file, line); + } - assert(size >= 0); + assert(size >= 0); - if(size == 0) - { - kexHeap::Free(ptr, file, line); - return NULL; - } + if (size == 0) + { + kexHeap::Free(ptr, file, line); + return NULL; + } - block = kexHeap::GetBlock(ptr, file, line); - newblock = NULL; + block = kexHeap::GetBlock(ptr, file, line); + newblock = NULL; - kexHeap::RemoveBlock(block); + kexHeap::RemoveBlock(block); - block->next = NULL; - block->prev = NULL; + block->next = NULL; + block->prev = NULL; - if(block->ptrRef) - { - *block->ptrRef = NULL; - } + if (block->ptrRef) + { + *block->ptrRef = NULL; + } - if(!(newblock = (memBlock*)realloc(block, sizeof(memBlock) + size))) - { - Error("kexHeap::Realloc: failed on allocation of %u bytes (%s:%d)", size, file, line); - } + if (!(newblock = (memBlock*)realloc(block, sizeof(memBlock) + size))) + { + Error("kexHeap::Realloc: failed on allocation of %u bytes (%s:%d)", size, file, line); + } - newblock->purgeID = heapBlock.purgeID; - newblock->heapTag = kexHeap::HeapTag; - newblock->size = size; - newblock->ptrRef = NULL; + newblock->purgeID = heapBlock.purgeID; + newblock->heapTag = kexHeap::HeapTag; + newblock->size = size; + newblock->ptrRef = NULL; - kexHeap::AddBlock(newblock, &heapBlock); + kexHeap::AddBlock(newblock, &heapBlock); - return ((byte*)newblock) + sizeof(memBlock); + return ((byte*)newblock) + sizeof(memBlock); } // @@ -276,7 +276,7 @@ void *kexHeap::Realloc(void *ptr, int size, kexHeapBlock &heapBlock, const char void *kexHeap::Alloca(int size, const char *file, int line) { - return size == 0 ? NULL : kexHeap::Calloc(size, hb_auto, file, line); + return size == 0 ? NULL : kexHeap::Calloc(size, hb_auto, file, line); } // @@ -285,18 +285,18 @@ void *kexHeap::Alloca(int size, const char *file, int line) void kexHeap::Free(void *ptr, const char *file, int line) { - memBlock* block; + memBlock* block; - block = kexHeap::GetBlock(ptr, file, line); - if(block->ptrRef) - { - *block->ptrRef = NULL; - } + block = kexHeap::GetBlock(ptr, file, line); + if (block->ptrRef) + { + *block->ptrRef = NULL; + } - kexHeap::RemoveBlock(block); + kexHeap::RemoveBlock(block); - // free back to system - free(block); + // free back to system + free(block); } // @@ -305,28 +305,28 @@ void kexHeap::Free(void *ptr, const char *file, int line) void kexHeap::Purge(kexHeapBlock &heapBlock, const char *file, int line) { - memBlock *block; - memBlock *next; + memBlock *block; + memBlock *next; - for(block = heapBlock.blocks; block != NULL;) - { - next = block->next; + for (block = heapBlock.blocks; block != NULL;) + { + next = block->next; - if(block->heapTag != kexHeap::HeapTag) - { - Error("kexHeap::Purge: Purging without heap tag (%s:%d)", file, line); - } + if (block->heapTag != kexHeap::HeapTag) + { + Error("kexHeap::Purge: Purging without heap tag (%s:%d)", file, line); + } - if(block->ptrRef) - { - *block->ptrRef = NULL; - } + if (block->ptrRef) + { + *block->ptrRef = NULL; + } - free(block); - block = next; - } + free(block); + block = next; + } - heapBlock.blocks = NULL; + heapBlock.blocks = NULL; } // @@ -335,7 +335,7 @@ void kexHeap::Purge(kexHeapBlock &heapBlock, const char *file, int line) void kexHeap::SetCacheRef(void **ptr, const char *file, int line) { - kexHeap::GetBlock(*ptr, file, line)->ptrRef = ptr; + kexHeap::GetBlock(*ptr, file, line)->ptrRef = ptr; } // @@ -344,7 +344,7 @@ void kexHeap::SetCacheRef(void **ptr, const char *file, int line) void kexHeap::GarbageCollect(const char *file, int line) { - kexHeap::Purge(hb_auto, file, line); + kexHeap::Purge(hb_auto, file, line); } // @@ -353,28 +353,28 @@ void kexHeap::GarbageCollect(const char *file, int line) void kexHeap::CheckBlocks(const char *file, int line) { - memBlock *block; - memBlock *prev; - kexHeapBlock *heapBlock; + memBlock *block; + memBlock *prev; + kexHeapBlock *heapBlock; - for(heapBlock = kexHeap::blockList; heapBlock; heapBlock = heapBlock->next) - { - prev = NULL; + for (heapBlock = kexHeap::blockList; heapBlock; heapBlock = heapBlock->next) + { + prev = NULL; - for(block = heapBlock->blocks; block != NULL; block = block->next) - { - if(block->heapTag != kexHeap::HeapTag) - { - Error("kexHeap::CheckBlocks: found block without heap tag (%s:%d)", file, line); - } - if(block->prev != prev) - { - Error("kexHeap::CheckBlocks: bad link list found (%s:%d)", file, line); - } + for (block = heapBlock->blocks; block != NULL; block = block->next) + { + if (block->heapTag != kexHeap::HeapTag) + { + Error("kexHeap::CheckBlocks: found block without heap tag (%s:%d)", file, line); + } + if (block->prev != prev) + { + Error("kexHeap::CheckBlocks: bad link list found (%s:%d)", file, line); + } - prev = block; - } - } + prev = block; + } + } } // @@ -391,13 +391,13 @@ void kexHeap::Touch(void *ptr, const char *file, int line) int kexHeap::Usage(const kexHeapBlock &heapBlock) { - int bytes = 0; - memBlock *block; + int bytes = 0; + memBlock *block; - for(block = heapBlock.blocks; block != NULL; block = block->next) - { - bytes += block->size; - } + for (block = heapBlock.blocks; block != NULL; block = block->next) + { + bytes += block->size; + } - return bytes; + return bytes; } diff --git a/src/lightmap/kexlib/memheap.h b/src/lightmap/kexlib/memheap.h index 9f4398e..c40253a 100644 --- a/src/lightmap/kexlib/memheap.h +++ b/src/lightmap/kexlib/memheap.h @@ -27,66 +27,66 @@ #pragma once -typedef void (*blockFunc_t)(void*); +typedef void(*blockFunc_t)(void*); class kexHeapBlock; struct memBlock { - int heapTag; - int purgeID; - int size; - kexHeapBlock *heapBlock; - void **ptrRef; - memBlock *prev; - memBlock *next; + int heapTag; + int purgeID; + int size; + kexHeapBlock *heapBlock; + void **ptrRef; + memBlock *prev; + memBlock *next; }; class kexHeapBlock { public: - kexHeapBlock(const char *name, bool bGarbageCollect, - blockFunc_t funcFree, blockFunc_t funcGC); - ~kexHeapBlock(); + kexHeapBlock(const char *name, bool bGarbageCollect, + blockFunc_t funcFree, blockFunc_t funcGC); + ~kexHeapBlock(); - kexHeapBlock *operator[](int index); + kexHeapBlock *operator[](int index); - char *name; - memBlock *blocks; - bool bGC; - blockFunc_t freeFunc; - blockFunc_t gcFunc; - int purgeID; - kexHeapBlock *prev; - kexHeapBlock *next; + char *name; + memBlock *blocks; + bool bGC; + blockFunc_t freeFunc; + blockFunc_t gcFunc; + int purgeID; + kexHeapBlock *prev; + kexHeapBlock *next; }; class kexHeap { public: - static void *Malloc(int size, kexHeapBlock &heapBlock, const char *file, int line); - static void *Calloc(int size, kexHeapBlock &heapBlock, const char *file, int line); - static void *Realloc(void *ptr, int size, kexHeapBlock &heapBlock, const char *file, int line); - static void *Alloca(int size, const char *file, int line); - static void Free(void *ptr, const char *file, int line); - static void Purge(kexHeapBlock &heapBlock, const char *file, int line); - static void GarbageCollect(const char *file, int line); - static void CheckBlocks(const char *file, int line); - static void Touch(void *ptr, const char *file, int line); - static int Usage(const kexHeapBlock &heapBlock); - static void SetCacheRef(void **ptr, const char *file, int line); + static void *Malloc(int size, kexHeapBlock &heapBlock, const char *file, int line); + static void *Calloc(int size, kexHeapBlock &heapBlock, const char *file, int line); + static void *Realloc(void *ptr, int size, kexHeapBlock &heapBlock, const char *file, int line); + static void *Alloca(int size, const char *file, int line); + static void Free(void *ptr, const char *file, int line); + static void Purge(kexHeapBlock &heapBlock, const char *file, int line); + static void GarbageCollect(const char *file, int line); + static void CheckBlocks(const char *file, int line); + static void Touch(void *ptr, const char *file, int line); + static int Usage(const kexHeapBlock &heapBlock); + static void SetCacheRef(void **ptr, const char *file, int line); - static int numHeapBlocks; - static kexHeapBlock *currentHeapBlock; - static int currentHeapBlockID; - static kexHeapBlock *blockList; + static int numHeapBlocks; + static kexHeapBlock *currentHeapBlock; + static int currentHeapBlockID; + static kexHeapBlock *blockList; private: - static void AddBlock(memBlock *block, kexHeapBlock *heapBlock); - static void RemoveBlock(memBlock *block); - static memBlock *GetBlock(void *ptr, const char *file, int line); + static void AddBlock(memBlock *block, kexHeapBlock *heapBlock); + static void RemoveBlock(memBlock *block); + static memBlock *GetBlock(void *ptr, const char *file, int line); - static const int HeapTag = 0x03151983; + static const int HeapTag = 0x03151983; }; extern kexHeapBlock hb_static; diff --git a/src/lightmap/lightmap.cpp b/src/lightmap/lightmap.cpp index 7e1788f..4d8b452 100644 --- a/src/lightmap/lightmap.cpp +++ b/src/lightmap/lightmap.cpp @@ -48,14 +48,14 @@ const kexVec3 kexLightmapBuilder::gridSize(64, 64, 128); kexLightmapBuilder::kexLightmapBuilder() { - this->textureWidth = 128; - this->textureHeight = 128; - this->allocBlocks = NULL; - this->numTextures = 0; - this->samples = 16; - this->extraSamples = 2; - this->ambience = 0.0f; - this->tracedTexels = 0; + this->textureWidth = 128; + this->textureHeight = 128; + this->allocBlocks = NULL; + this->numTextures = 0; + this->samples = 16; + this->extraSamples = 2; + this->ambience = 0.0f; + this->tracedTexels = 0; } kexLightmapBuilder::~kexLightmapBuilder() @@ -64,142 +64,142 @@ kexLightmapBuilder::~kexLightmapBuilder() void kexLightmapBuilder::NewTexture() { - numTextures++; + numTextures++; - allocBlocks = (int**)Mem_Realloc(allocBlocks, sizeof(int*) * numTextures, hb_static); - allocBlocks[numTextures-1] = (int*)Mem_Calloc(sizeof(int) * textureWidth, hb_static); + allocBlocks = (int**)Mem_Realloc(allocBlocks, sizeof(int*) * numTextures, hb_static); + allocBlocks[numTextures - 1] = (int*)Mem_Calloc(sizeof(int) * textureWidth, hb_static); - memset(allocBlocks[numTextures-1], 0, sizeof(int) * textureWidth); + memset(allocBlocks[numTextures - 1], 0, sizeof(int) * textureWidth); - uint16_t *texture = (uint16_t*)Mem_Calloc((textureWidth * textureHeight) * 3 * 2, hb_static); - textures.Push(texture); + uint16_t *texture = (uint16_t*)Mem_Calloc((textureWidth * textureHeight) * 3 * 2, hb_static); + textures.Push(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) { - int i; - int j; - int k; - int bestRow1; - int bestRow2; + int i; + int j; + int k; + int bestRow1; + int bestRow2; - *num = -1; + *num = -1; - if(allocBlocks == NULL) - { - return false; - } + if (allocBlocks == NULL) + { + return false; + } - for(k = 0; k < numTextures; ++k) - { - bestRow1 = textureHeight; + for (k = 0; k < numTextures; ++k) + { + bestRow1 = textureHeight; - for(i = 0; i <= textureWidth - width; i++) - { - bestRow2 = 0; + for (i = 0; i <= textureWidth - width; i++) + { + bestRow2 = 0; - for(j = 0; j < width; j++) - { - if(allocBlocks[k][i + j] >= bestRow1) - { - break; - } + for (j = 0; j < width; j++) + { + if (allocBlocks[k][i + j] >= bestRow1) + { + break; + } - if(allocBlocks[k][i + j] > bestRow2) - { - bestRow2 = allocBlocks[k][i + j]; - } - } + if (allocBlocks[k][i + j] > bestRow2) + { + bestRow2 = allocBlocks[k][i + j]; + } + } - // found a free block - if(j == width) - { - *x = i; - *y = bestRow1 = bestRow2; - } - } + // found a free block + if (j == width) + { + *x = i; + *y = bestRow1 = bestRow2; + } + } - if(bestRow1 + height > textureHeight) - { - // no room - continue; - } + if (bestRow1 + height > textureHeight) + { + // no room + continue; + } - for(i = 0; i < width; i++) - { - // store row offset - allocBlocks[k][*x + i] = bestRow1 + height; - } + for (i = 0; i < width; i++) + { + // store row offset + allocBlocks[k][*x + i] = bestRow1 + height; + } - *num = k; - return true; - } + *num = k; + return true; + } - return false; + return false; } kexBBox kexLightmapBuilder::GetBoundsFromSurface(const surface_t *surface) { - kexVec3 low(M_INFINITY, M_INFINITY, M_INFINITY); - kexVec3 hi(-M_INFINITY, -M_INFINITY, -M_INFINITY); + kexVec3 low(M_INFINITY, M_INFINITY, M_INFINITY); + kexVec3 hi(-M_INFINITY, -M_INFINITY, -M_INFINITY); - kexBBox bounds; - bounds.Clear(); + kexBBox bounds; + bounds.Clear(); - for(int i = 0; i < surface->numVerts; i++) - { - for(int j = 0; j < 3; j++) - { - if(surface->verts[i][j] < low[j]) - { - low[j] = surface->verts[i][j]; - } - if(surface->verts[i][j] > hi[j]) - { - hi[j] = surface->verts[i][j]; - } - } - } + for (int i = 0; i < surface->numVerts; i++) + { + for (int j = 0; j < 3; j++) + { + if (surface->verts[i][j] < low[j]) + { + low[j] = surface->verts[i][j]; + } + if (surface->verts[i][j] > hi[j]) + { + hi[j] = surface->verts[i][j]; + } + } + } - bounds.min = low; - bounds.max = hi; + bounds.min = low; + bounds.max = hi; - return bounds; + return bounds; } // Traces to the ceiling surface. Will emit light if the surface that was traced is a sky bool kexLightmapBuilder::EmitFromCeiling(kexTrace &trace, const surface_t *surface, const kexVec3 &origin, const kexVec3 &normal, kexVec3 &color) { - float attenuation = normal.Dot(map->GetSunDirection()); + float attenuation = normal.Dot(map->GetSunDirection()); - if(attenuation <= 0) - { - // plane is not even facing the sunlight - return false; - } + if (attenuation <= 0) + { + // plane is not even facing the sunlight + return false; + } - trace.Trace(origin, origin + (map->GetSunDirection() * 32768.0f)); + trace.Trace(origin, origin + (map->GetSunDirection() * 32768.0f)); - if(trace.fraction == 1.0f) - { - // nothing was hit + if (trace.fraction == 1.0f) + { + // nothing was hit //color.x += 1.0f; - return false; - } + return false; + } - if(trace.hitSurface->bSky == false) - { + if (trace.hitSurface->bSky == false) + { if (trace.hitSurface->type == ST_CEILING) return false; - // not a ceiling/sky surface - return false; - } + // not a ceiling/sky surface + return false; + } color += map->GetSunColor() * attenuation; - return true; + return true; } template @@ -217,13 +217,13 @@ static float radians(float degrees) // Traces a line from the texel's origin to the sunlight direction and against all nearby thing lights kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &origin, surface_t *surface) { - kexPlane plane = surface->plane; + kexPlane plane = surface->plane; kexVec3 color(0.0f, 0.0f, 0.0f); - // check all thing lights - for(unsigned int i = 0; i < map->thingLights.Size(); i++) - { - thingLight_t *tl = map->thingLights[i]; + // check all thing lights + for (unsigned int i = 0; i < map->thingLights.Size(); i++) + { + thingLight_t *tl = map->thingLights[i]; float originZ; if (!tl->bCeiling) @@ -233,20 +233,20 @@ kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &ori kexVec3 lightOrigin(tl->origin.x, tl->origin.y, originZ); - if(plane.Distance(lightOrigin) - plane.d < 0) - { - // completely behind the plane - continue; - } + if (plane.Distance(lightOrigin) - plane.d < 0) + { + // completely behind the plane + continue; + } - float radius = tl->radius * 2.0f; // 2.0 because gzdoom's dynlights do this and we want them to match - float intensity = tl->intensity; + float radius = tl->radius * 2.0f; // 2.0 because gzdoom's dynlights do this and we want them to match + float intensity = tl->intensity; - if(origin.DistanceSq(lightOrigin) > (radius*radius)) - { - // not within range - continue; - } + if (origin.DistanceSq(lightOrigin) > (radius*radius)) + { + // not within range + continue; + } kexVec3 dir = (lightOrigin - origin); float dist = dir.Unit(); @@ -270,177 +270,177 @@ kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &ori } } - trace.Trace(lightOrigin, origin); + trace.Trace(lightOrigin, origin); - if(trace.fraction != 1) - { - // this light is occluded by something - continue; - } + if (trace.fraction != 1) + { + // this light is occluded by something + continue; + } float attenuation = 1.0f - (dist / radius); attenuation *= spotAttenuation; attenuation *= plane.Normal().Dot(dir); attenuation *= intensity; - // accumulate results - color += tl->rgb * attenuation; + // accumulate results + color += tl->rgb * attenuation; - tracedTexels++; - } + tracedTexels++; + } - if(surface->type != ST_CEILING) - { - // see if it's exposed to sunlight - if(EmitFromCeiling(trace, surface, origin, plane.Normal(), color)) - tracedTexels++; - } + if (surface->type != ST_CEILING) + { + // see if it's exposed to sunlight + if (EmitFromCeiling(trace, surface, origin, plane.Normal(), color)) + tracedTexels++; + } - // trace against surface lights - for(unsigned int i = 0; i < map->lightSurfaces.Size(); ++i) - { - kexLightSurface *surfaceLight = map->lightSurfaces[i]; + // trace against surface lights + for (unsigned int i = 0; i < map->lightSurfaces.Size(); ++i) + { + kexLightSurface *surfaceLight = map->lightSurfaces[i]; float attenuation; - if(surfaceLight->TraceSurface(map, trace, surface, origin, &attenuation)) - { - color += surfaceLight->GetRGB() * attenuation; + if (surfaceLight->TraceSurface(map, trace, surface, origin, &attenuation)) + { + color += surfaceLight->GetRGB() * attenuation; - tracedTexels++; - } - } + tracedTexels++; + } + } - return color; + return color; } // Determines a lightmap block in which to map to the lightmap texture. // Width and height of the block is calcuated and steps are computed to determine where each texel will be positioned on the surface void kexLightmapBuilder::BuildSurfaceParams(surface_t *surface) { - kexPlane *plane; - kexBBox bounds; - kexVec3 roundedSize; - int i; - kexPlane::planeAxis_t axis; - kexVec3 tCoords[2]; - kexVec3 tOrigin; - int width; - int height; - float d; + kexPlane *plane; + kexBBox bounds; + kexVec3 roundedSize; + int i; + kexPlane::planeAxis_t axis; + kexVec3 tCoords[2]; + kexVec3 tOrigin; + int width; + int height; + float d; - plane = &surface->plane; - bounds = GetBoundsFromSurface(surface); + plane = &surface->plane; + bounds = GetBoundsFromSurface(surface); - // round off dimentions - for(i = 0; i < 3; i++) - { - bounds.min[i] = samples * kexMath::Floor(bounds.min[i] / samples); - bounds.max[i] = samples * kexMath::Ceil(bounds.max[i] / samples); + // round off dimentions + for (i = 0; i < 3; i++) + { + bounds.min[i] = samples * kexMath::Floor(bounds.min[i] / samples); + bounds.max[i] = samples * kexMath::Ceil(bounds.max[i] / samples); - roundedSize[i] = (bounds.max[i] - bounds.min[i]) / samples + 1; - } + roundedSize[i] = (bounds.max[i] - bounds.min[i]) / samples + 1; + } - tCoords[0].Clear(); - tCoords[1].Clear(); + tCoords[0].Clear(); + tCoords[1].Clear(); - axis = plane->BestAxis(); + axis = plane->BestAxis(); - switch(axis) - { - case kexPlane::AXIS_YZ: - width = (int)roundedSize.y; - height = (int)roundedSize.z; - tCoords[0].y = 1.0f / samples; - tCoords[1].z = 1.0f / samples; - break; + switch (axis) + { + case kexPlane::AXIS_YZ: + width = (int)roundedSize.y; + height = (int)roundedSize.z; + tCoords[0].y = 1.0f / samples; + tCoords[1].z = 1.0f / samples; + break; - case kexPlane::AXIS_XZ: - width = (int)roundedSize.x; - height = (int)roundedSize.z; - tCoords[0].x = 1.0f / samples; - tCoords[1].z = 1.0f / samples; - break; + case kexPlane::AXIS_XZ: + width = (int)roundedSize.x; + height = (int)roundedSize.z; + tCoords[0].x = 1.0f / samples; + tCoords[1].z = 1.0f / samples; + break; - case kexPlane::AXIS_XY: - width = (int)roundedSize.x; - height = (int)roundedSize.y; - tCoords[0].x = 1.0f / samples; - tCoords[1].y = 1.0f / samples; - break; - } + case kexPlane::AXIS_XY: + width = (int)roundedSize.x; + height = (int)roundedSize.y; + tCoords[0].x = 1.0f / samples; + tCoords[1].y = 1.0f / samples; + break; + } - // clamp width - if(width > textureWidth) - { - tCoords[0] *= ((float)textureWidth / (float)width); - width = textureWidth; - } + // clamp width + if (width > textureWidth) + { + tCoords[0] *= ((float)textureWidth / (float)width); + width = textureWidth; + } - // clamp height - if(height > textureHeight) - { - tCoords[1] *= ((float)textureHeight / (float)height); - height = textureHeight; - } + // clamp height + if (height > textureHeight) + { + tCoords[1] *= ((float)textureHeight / (float)height); + height = textureHeight; + } - surface->lightmapCoords = (float*)Mem_Calloc(sizeof(float) * - surface->numVerts * 2, hb_static); + surface->lightmapCoords = (float*)Mem_Calloc(sizeof(float) * + surface->numVerts * 2, hb_static); - surface->textureCoords[0] = tCoords[0]; - surface->textureCoords[1] = tCoords[1]; + surface->textureCoords[0] = tCoords[0]; + surface->textureCoords[1] = tCoords[1]; - tOrigin = bounds.min; + tOrigin = bounds.min; - // project tOrigin and tCoords so they lie on the plane - d = (plane->Distance(bounds.min) - plane->d) / plane->Normal()[axis]; - tOrigin[axis] -= d; + // project tOrigin and tCoords so they lie on the plane + d = (plane->Distance(bounds.min) - plane->d) / plane->Normal()[axis]; + tOrigin[axis] -= d; - for(i = 0; i < 2; i++) - { - tCoords[i].Normalize(); - d = plane->Distance(tCoords[i]) / plane->Normal()[axis]; - tCoords[i][axis] -= d; - } + for (i = 0; i < 2; i++) + { + tCoords[i].Normalize(); + d = plane->Distance(tCoords[i]) / plane->Normal()[axis]; + tCoords[i][axis] -= d; + } - surface->bounds = bounds; - surface->lightmapDims[0] = width; - surface->lightmapDims[1] = height; - surface->lightmapOrigin = tOrigin; - surface->lightmapSteps[0] = tCoords[0] * (float)samples; - surface->lightmapSteps[1] = tCoords[1] * (float)samples; + surface->bounds = bounds; + surface->lightmapDims[0] = width; + surface->lightmapDims[1] = height; + surface->lightmapOrigin = tOrigin; + surface->lightmapSteps[0] = tCoords[0] * (float)samples; + surface->lightmapSteps[1] = tCoords[1] * (float)samples; } // Steps through each texel and traces a line to the world. // For each non-occluded trace, color is accumulated and saved off into the lightmap texture based on what block is mapped to void kexLightmapBuilder::TraceSurface(surface_t *surface) { - static thread_local kexVec3 colorSamples[1024 * 1024]; + static thread_local kexVec3 colorSamples[1024 * 1024]; - int sampleWidth; - int sampleHeight; - kexVec3 normal; - kexVec3 pos; - kexVec3 tDelta; - int i; - int j; - kexTrace trace; - uint16_t *currentTexture; - bool bShouldLookupTexture = false; + int sampleWidth; + int sampleHeight; + kexVec3 normal; + kexVec3 pos; + kexVec3 tDelta; + int i; + int j; + kexTrace trace; + uint16_t *currentTexture; + bool bShouldLookupTexture = false; - trace.Init(*map); + trace.Init(*map); - sampleWidth = surface->lightmapDims[0]; - sampleHeight = surface->lightmapDims[1]; + sampleWidth = surface->lightmapDims[0]; + sampleHeight = surface->lightmapDims[1]; - normal = surface->plane.Normal(); + normal = surface->plane.Normal(); int multisampleCount = Multisample; - // start walking through each texel - for(i = 0; i < sampleHeight; i++) - { - for(j = 0; j < sampleWidth; j++) - { + // start walking through each texel + for (i = 0; i < sampleHeight; i++) + { + for (j = 0; j < sampleWidth; j++) + { kexVec3 c(0.0f, 0.0f, 0.0f); for (int k = 0; k < multisampleCount; k++) @@ -467,103 +467,103 @@ void kexLightmapBuilder::TraceSurface(surface_t *surface) c /= multisampleCount; - // if nothing at all was traced and color is completely black - // then this surface will not go through the extra rendering - // step in rendering the lightmap - if (c.x > 0.0f || c.y > 0.0f || c.z > 0.0f) - { - bShouldLookupTexture = true; - } + // if nothing at all was traced and color is completely black + // then this surface will not go through the extra rendering + // step in rendering the lightmap + if (c.x > 0.0f || c.y > 0.0f || c.z > 0.0f) + { + bShouldLookupTexture = true; + } kexMath::Clamp(c, 0, 1); colorSamples[i * 1024 + j] = c; } - } + } - // SVE redraws the scene for lightmaps, so for optimizations, - // tell the engine to ignore this surface if completely black - if(bShouldLookupTexture == false) - { - surface->lightmapNum = -1; - return; - } - else - { - int x = 0, y = 0; - int width = surface->lightmapDims[0]; - int height = surface->lightmapDims[1]; + // SVE redraws the scene for lightmaps, so for optimizations, + // tell the engine to ignore this surface if completely black + if (bShouldLookupTexture == false) + { + surface->lightmapNum = -1; + return; + } + else + { + int x = 0, y = 0; + int width = surface->lightmapDims[0]; + int height = surface->lightmapDims[1]; std::unique_lock lock(mutex); - // now that we know the width and height of this block, see if we got - // room for it in the light map texture. if not, then we must allocate - // a new texture - if(!MakeRoomForBlock(width, height, &x, &y, &surface->lightmapNum)) - { - // allocate a new texture for this block - NewTexture(); + // now that we know the width and height of this block, see if we got + // room for it in the light map texture. if not, then we must allocate + // a new texture + if (!MakeRoomForBlock(width, height, &x, &y, &surface->lightmapNum)) + { + // allocate a new texture for this block + NewTexture(); - if(!MakeRoomForBlock(width, height, &x, &y, &surface->lightmapNum)) - { + if (!MakeRoomForBlock(width, height, &x, &y, &surface->lightmapNum)) + { Error("Lightmap allocation failed\n"); - return; - } - } + return; + } + } lock.unlock(); - // calculate texture coordinates - for(i = 0; i < surface->numVerts; i++) - { - tDelta = surface->verts[i] - surface->bounds.min; - surface->lightmapCoords[i * 2 + 0] = - (tDelta.Dot(surface->textureCoords[0]) + x + 0.5f) / (float)textureWidth; - surface->lightmapCoords[i * 2 + 1] = - (tDelta.Dot(surface->textureCoords[1]) + y + 0.5f) / (float)textureHeight; - } + // calculate texture coordinates + for (i = 0; i < surface->numVerts; i++) + { + tDelta = surface->verts[i] - surface->bounds.min; + surface->lightmapCoords[i * 2 + 0] = + (tDelta.Dot(surface->textureCoords[0]) + x + 0.5f) / (float)textureWidth; + surface->lightmapCoords[i * 2 + 1] = + (tDelta.Dot(surface->textureCoords[1]) + y + 0.5f) / (float)textureHeight; + } - surface->lightmapOffs[0] = x; - surface->lightmapOffs[1] = y; - } + surface->lightmapOffs[0] = x; + surface->lightmapOffs[1] = y; + } std::unique_lock lock(mutex); - currentTexture = textures[surface->lightmapNum]; + currentTexture = textures[surface->lightmapNum]; lock.unlock(); - // store results to lightmap texture - for(i = 0; i < sampleHeight; i++) - { - for(j = 0; j < sampleWidth; j++) - { - // get texture offset - int offs = (((textureWidth * (i + surface->lightmapOffs[1])) + surface->lightmapOffs[0]) * 3); + // store results to lightmap texture + for (i = 0; i < sampleHeight; i++) + { + for (j = 0; j < sampleWidth; j++) + { + // get texture offset + int offs = (((textureWidth * (i + surface->lightmapOffs[1])) + surface->lightmapOffs[0]) * 3); - // convert RGB to bytes - currentTexture[offs + j * 3 + 0] = floatToHalf(colorSamples[i * 1024 + j].x); - currentTexture[offs + j * 3 + 1] = floatToHalf(colorSamples[i * 1024 + j].y); - currentTexture[offs + j * 3 + 2] = floatToHalf(colorSamples[i * 1024 + j].z); - } - } + // convert RGB to bytes + currentTexture[offs + j * 3 + 0] = floatToHalf(colorSamples[i * 1024 + j].x); + currentTexture[offs + j * 3 + 1] = floatToHalf(colorSamples[i * 1024 + j].y); + currentTexture[offs + j * 3 + 2] = floatToHalf(colorSamples[i * 1024 + j].z); + } + } } void kexLightmapBuilder::LightSurface(const int surfid) { - float remaining; - int numsurfs = surfaces.Length(); + float remaining; + int numsurfs = surfaces.Length(); - // TODO: this should NOT happen, but apparently, it can randomly occur - if(surfaces.Length() == 0) - { - return; - } + // TODO: this should NOT happen, but apparently, it can randomly occur + if (surfaces.Length() == 0) + { + return; + } - BuildSurfaceParams(surfaces[surfid]); - TraceSurface(surfaces[surfid]); + BuildSurfaceParams(surfaces[surfid]); + TraceSurface(surfaces[surfid]); std::unique_lock lock(mutex); int lastproc = processed * 100 / numsurfs; - processed++; + processed++; int curproc = processed * 100 / numsurfs; if (lastproc != curproc || processed == 1) { @@ -574,16 +574,16 @@ void kexLightmapBuilder::LightSurface(const int surfid) void kexLightmapBuilder::CreateLightmaps(FLevel &doomMap) { - map = &doomMap; + map = &doomMap; - printf("------------- Tracing surfaces -------------\n"); + printf("------------- Tracing surfaces -------------\n"); processed = 0; kexWorker::RunJob(surfaces.Length(), [=](int id) { LightSurface(id); }); - printf("Texels traced: %i \n\n", tracedTexels); + printf("Texels traced: %i \n\n", tracedTexels); } void kexLightmapBuilder::AddLightmapLump(FWadWriter &wadFile) @@ -701,29 +701,29 @@ void kexLightmapBuilder::AddLightmapLump(FWadWriter &wadFile) void kexLightmapBuilder::WriteTexturesToTGA() { - kexBinFile file; + kexBinFile file; - for(unsigned int i = 0; i < textures.Length(); i++) - { - file.Create(Va("lightmap_%02d.tga", i)); - file.Write16(0); - file.Write16(2); - file.Write16(0); - file.Write16(0); - file.Write16(0); - file.Write16(0); - file.Write16(textureWidth); - file.Write16(textureHeight); - file.Write16(24); + for (unsigned int i = 0; i < textures.Length(); i++) + { + file.Create(Va("lightmap_%02d.tga", i)); + file.Write16(0); + file.Write16(2); + file.Write16(0); + file.Write16(0); + file.Write16(0); + file.Write16(0); + file.Write16(textureWidth); + file.Write16(textureHeight); + file.Write16(24); - for(int j = 0; j < (textureWidth * textureHeight) * 3; j += 3) - { - file.Write8(textures[i][j+2]); - file.Write8(textures[i][j+1]); - file.Write8(textures[i][j+0]); - } - file.Close(); - } + for (int j = 0; j < (textureWidth * textureHeight) * 3; j += 3) + { + file.Write8(textures[i][j + 2]); + file.Write8(textures[i][j + 1]); + file.Write8(textures[i][j + 0]); + } + file.Close(); + } } void kexLightmapBuilder::WriteMeshToOBJ() diff --git a/src/lightmap/lightmap.h b/src/lightmap/lightmap.h index f3396cf..36a8550 100644 --- a/src/lightmap/lightmap.h +++ b/src/lightmap/lightmap.h @@ -38,39 +38,37 @@ class FWadWriter; class kexLightmapBuilder { public: - kexLightmapBuilder(); - ~kexLightmapBuilder(); + kexLightmapBuilder(); + ~kexLightmapBuilder(); - void BuildSurfaceParams(surface_t *surface); - void TraceSurface(surface_t *surface); - void CreateLightmaps(FLevel &doomMap); - void LightSurface(const int surfid); - void WriteTexturesToTGA(); - void WriteMeshToOBJ(); - void AddLightmapLump(FWadWriter &wadFile); + void BuildSurfaceParams(surface_t *surface); + void TraceSurface(surface_t *surface); + void CreateLightmaps(FLevel &doomMap); + void LightSurface(const int surfid); + void WriteTexturesToTGA(); + void WriteMeshToOBJ(); + void AddLightmapLump(FWadWriter &wadFile); - int samples; - float ambience; - int textureWidth; - int textureHeight; + int samples; + float ambience; + int textureWidth; + int textureHeight; - static const kexVec3 gridSize; + static const kexVec3 gridSize; private: - void NewTexture(); - bool MakeRoomForBlock(const int width, const int height, int *x, int *y, int *num); - kexBBox GetBoundsFromSurface(const surface_t *surface); - kexVec3 LightTexelSample(kexTrace &trace, const kexVec3 &origin, surface_t *surface); - bool EmitFromCeiling(kexTrace &trace, const surface_t *surface, const kexVec3 &origin, const kexVec3 &normal, kexVec3 &color); - void ExportTexelsToObjFile(FILE *f, const kexVec3 &org, int indices); - void WriteBlock(FILE *f, const int i, const kexVec3 &org, int indices, kexBBox &box); + void NewTexture(); + bool MakeRoomForBlock(const int width, const int height, int *x, int *y, int *num); + kexBBox GetBoundsFromSurface(const surface_t *surface); + kexVec3 LightTexelSample(kexTrace &trace, const kexVec3 &origin, surface_t *surface); + bool EmitFromCeiling(kexTrace &trace, const surface_t *surface, const kexVec3 &origin, const kexVec3 &normal, kexVec3 &color); - FLevel *map; - kexArray textures; - int **allocBlocks; - int numTextures; - int extraSamples; - int tracedTexels; + FLevel *map; + kexArray textures; + int **allocBlocks; + int numTextures; + int extraSamples; + int tracedTexels; std::mutex mutex; int processed = 0; diff --git a/src/lightmap/lightsurface.cpp b/src/lightmap/lightsurface.cpp index e66d3a2..3778075 100644 --- a/src/lightmap/lightsurface.cpp +++ b/src/lightmap/lightsurface.cpp @@ -47,313 +47,313 @@ kexLightSurface::~kexLightSurface() void kexLightSurface::Init(const surfaceLightDef &lightSurfaceDef, surface_t *surface, const bool bWall, const bool bNoCenterPoint) { - this->intensity = lightSurfaceDef.intensity; - this->distance = lightSurfaceDef.distance; - this->rgb = lightSurfaceDef.rgb; - this->surface = surface; - this->bWall = bWall; - this->bNoCenterPoint = bNoCenterPoint; + this->intensity = lightSurfaceDef.intensity; + this->distance = lightSurfaceDef.distance; + this->rgb = lightSurfaceDef.rgb; + this->surface = surface; + this->bWall = bWall; + this->bNoCenterPoint = bNoCenterPoint; } // Creates a single origin point if we're not intending on subdividing this light surface void kexLightSurface::CreateCenterOrigin() { - if(!bWall) - { - kexVec3 center; + if (!bWall) + { + kexVec3 center; - for(int i = 0; i < surface->numVerts; ++i) - { - center += surface->verts[i]; - } + for (int i = 0; i < surface->numVerts; ++i) + { + center += surface->verts[i]; + } - origins.Push(center / (float)surface->numVerts); - } - else - { - origins.Push(kexVec3((surface->verts[1].x + surface->verts[0].x) * 0.5f, - (surface->verts[1].y + surface->verts[0].y) * 0.5f, - (surface->verts[2].z + surface->verts[0].z) * 0.5f)); - } + origins.Push(center / (float)surface->numVerts); + } + else + { + origins.Push(kexVec3((surface->verts[1].x + surface->verts[0].x) * 0.5f, + (surface->verts[1].y + surface->verts[0].y) * 0.5f, + (surface->verts[2].z + surface->verts[0].z) * 0.5f)); + } } // 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) { - kexArray dists; - kexArray sides; + kexArray dists; + kexArray sides; - // determines what sides the vertices lies on - for(unsigned int i = 0; i < points.Length(); ++i) - { - float d = points[i].Dot(normal) - dist; + // determines what sides the vertices lies on + for (unsigned int i = 0; i < points.Length(); ++i) + { + float d = points[i].Dot(normal) - dist; - dists.Push(d); + dists.Push(d); - if(d > 0.1f) - { - sides.Push(1); // front - } - else if(d < -0.1f) - { - sides.Push(-1); // directly on the split plane - } - else - { - sides.Push(0); // back - } - } + if (d > 0.1f) + { + sides.Push(1); // front + } + else if (d < -0.1f) + { + sides.Push(-1); // directly on the split plane + } + else + { + sides.Push(0); // back + } + } - // add points - for(unsigned int i = 0; i < points.Length(); ++i) - { - int next; - float frac; - kexVec3 pt1, pt2, pt3; + // add points + for (unsigned int i = 0; i < points.Length(); ++i) + { + int next; + float frac; + kexVec3 pt1, pt2, pt3; - switch(sides[i]) - { - case -1: - backPoints->Push(points[i]); - break; + switch (sides[i]) + { + case -1: + backPoints->Push(points[i]); + break; - case 1: - frontPoints->Push(points[i]); - break; + case 1: + frontPoints->Push(points[i]); + break; - default: - frontPoints->Push(points[i]); - backPoints->Push(points[i]); + default: + frontPoints->Push(points[i]); + backPoints->Push(points[i]); - // point is on the split plane so no new split vertex is needed - continue; + // point is on the split plane so no new split vertex is needed + continue; - } + } - // check if the edge crosses the split plane - next = (i + 1) % points.Length(); + // check if the edge crosses the split plane + next = (i + 1) % points.Length(); - if(sides[next] == 0 || sides[next] == sides[i]) - { - // didn't cross - continue; - } + if (sides[next] == 0 || sides[next] == sides[i]) + { + // didn't cross + continue; + } - pt1 = points[i]; - pt2 = points[next]; + pt1 = points[i]; + pt2 = points[next]; - // insert a new point caused by the split - frac = dists[i] / (dists[i] - dists[next]); - pt3 = pt1.Lerp(pt2, frac); + // insert a new point caused by the split + frac = dists[i] / (dists[i] - dists[next]); + pt3 = pt1.Lerp(pt2, frac); - frontPoints->Push(pt3); - backPoints->Push(pt3); - } + frontPoints->Push(pt3); + backPoints->Push(pt3); + } } // Recursively divides the surface bool kexLightSurface::SubdivideRecursion(vertexBatch_t &surfPoints, float divide, kexArray &points) { - kexBBox bounds; - kexVec3 splitNormal; - float dist; - vertexBatch_t *frontPoints; - vertexBatch_t *backPoints; + kexBBox bounds; + kexVec3 splitNormal; + float dist; + vertexBatch_t *frontPoints; + vertexBatch_t *backPoints; - // get bounds from current set of points - for(unsigned int i = 0; i < surfPoints.Length(); ++i) - { - bounds.AddPoint(surfPoints[i]); - } + // get bounds from current set of points + for (unsigned int i = 0; i < surfPoints.Length(); ++i) + { + bounds.AddPoint(surfPoints[i]); + } - for(int i = 0; i < 3; ++i) - { - // check if its large enough to be divided - if((bounds.max[i] - bounds.min[i]) > divide) - { - splitNormal.Clear(); - splitNormal[i] = 1; + for (int i = 0; i < 3; ++i) + { + // check if its large enough to be divided + if ((bounds.max[i] - bounds.min[i]) > divide) + { + splitNormal.Clear(); + splitNormal[i] = 1; - dist = (bounds.max[i] + bounds.min[i]) * 0.5f; + dist = (bounds.max[i] + bounds.min[i]) * 0.5f; - frontPoints = new vertexBatch_t; - backPoints = new vertexBatch_t; + frontPoints = new vertexBatch_t; + backPoints = new vertexBatch_t; - // start clipping - Clip(surfPoints, splitNormal, dist, frontPoints, backPoints); + // start clipping + Clip(surfPoints, splitNormal, dist, frontPoints, backPoints); - if(!SubdivideRecursion(*frontPoints, divide, points)) - { - points.Push(frontPoints); - } - else - { - delete frontPoints; - } + if (!SubdivideRecursion(*frontPoints, divide, points)) + { + points.Push(frontPoints); + } + else + { + delete frontPoints; + } - if(!SubdivideRecursion(*backPoints, divide, points)) - { - points.Push(backPoints); - } - else - { - delete backPoints; - } + if (!SubdivideRecursion(*backPoints, divide, points)) + { + points.Push(backPoints); + } + else + { + delete backPoints; + } - return true; - } - } + return true; + } + } - return false; + return false; } void kexLightSurface::Subdivide(const float divide) { - kexArray points; - vertexBatch_t surfPoints; + kexArray points; + vertexBatch_t surfPoints; - for(int i = 0; i < surface->numVerts; ++i) - { - surfPoints.Push(surface->verts[i]); - } + for (int i = 0; i < surface->numVerts; ++i) + { + surfPoints.Push(surface->verts[i]); + } - SubdivideRecursion(surfPoints, divide, points); + SubdivideRecursion(surfPoints, divide, points); - // from each group of vertices caused by the split, begin - // creating a origin point based on the center of that group - for(unsigned int i = 0; i < points.Length(); ++i) - { - vertexBatch_t *vb = points[i]; - kexVec3 center; + // from each group of vertices caused by the split, begin + // creating a origin point based on the center of that group + for (unsigned int i = 0; i < points.Length(); ++i) + { + vertexBatch_t *vb = points[i]; + kexVec3 center; - for(unsigned int j = 0; j < vb->Length(); ++j) - { - center += (*vb)[j]; - } + for (unsigned int j = 0; j < vb->Length(); ++j) + { + center += (*vb)[j]; + } - origins.Push(center / (float)vb->Length()); - } + origins.Push(center / (float)vb->Length()); + } - for(unsigned int i = 0; i < points.Length(); ++i) - { - vertexBatch_t *vb = points[i]; + for (unsigned int i = 0; i < points.Length(); ++i) + { + vertexBatch_t *vb = points[i]; - vb->Empty(); - delete vb; - } + vb->Empty(); + delete vb; + } } bool kexLightSurface::TraceSurface(FLevel *doomMap, kexTrace &trace, const surface_t *surf, const kexVec3 &origin, float *dist) { - kexVec3 normal; - kexVec3 lnormal; - float curDist; + kexVec3 normal; + kexVec3 lnormal; + float curDist; - *dist = -M_INFINITY; + *dist = -M_INFINITY; - // light surface will always be fullbright - if(surf == surface) - { - *dist = Intensity(); - return true; - } + // light surface will always be fullbright + if (surf == surface) + { + *dist = Intensity(); + return true; + } - lnormal = surface->plane.Normal(); + lnormal = surface->plane.Normal(); - if(surf) - { - normal = surf->plane.Normal(); + if (surf) + { + normal = surf->plane.Normal(); - if(normal.Dot(lnormal) > 0) - { - // not facing the light surface - return false; - } - } - else - { - normal = kexVec3::vecUp; - } + if (normal.Dot(lnormal) > 0) + { + // not facing the light surface + return false; + } + } + else + { + normal = kexVec3::vecUp; + } - // we need to pick the closest sample point on the light surface. what really sucks is - // that we have to trace each one... which could really blow up the compile time - for(unsigned int i = 0; i < origins.Length(); ++i) - { + // we need to pick the closest sample point on the light surface. what really sucks is + // that we have to trace each one... which could really blow up the compile time + for (unsigned int i = 0; i < origins.Length(); ++i) + { kexVec3 center = origins[i]; - if(!bWall && origin.z > center.z) - { - // origin is not going to seen or traced by the light surface - // so don't even bother. this also fixes some bizzare light - // bleeding issues - continue; - } + if (!bWall && origin.z > center.z) + { + // origin is not going to seen or traced by the light surface + // so don't even bother. this also fixes some bizzare light + // bleeding issues + continue; + } - /*if(bWall) - { - angle = (origin - center).ToVec2().Normalize().Dot(lnormal.ToVec2()); - } - else - { - kexVec3 dir = (origin - center).Normalize(); + /*if(bWall) + { + angle = (origin - center).ToVec2().Normalize().Dot(lnormal.ToVec2()); + } + else + { + kexVec3 dir = (origin - center).Normalize(); - if(surf) - { - if(normal.Dot(dir) >= 0) - { - // not even facing the light surface - continue; - } - } + if(surf) + { + if(normal.Dot(dir) >= 0) + { + // not even facing the light surface + continue; + } + } - angle = dir.Dot(lnormal); - }*/ + angle = dir.Dot(lnormal); + }*/ - if(bWall) - { - if(origin.z >= surface->verts[0].z && origin.z <= surface->verts[2].z) - { - // since walls are always vertically straight, we can cheat a little by adjusting - // the sampling point height. this also allows us to do accurate light emitting - // while just using one sample point - center.z = origin.z; - } - } + if (bWall) + { + if (origin.z >= surface->verts[0].z && origin.z <= surface->verts[2].z) + { + // since walls are always vertically straight, we can cheat a little by adjusting + // the sampling point height. this also allows us to do accurate light emitting + // while just using one sample point + center.z = origin.z; + } + } - // trace the origin to the center of the light surface. nudge by the normals in - // case the start/end points are directly on or inside the surface - trace.Trace(center + lnormal, origin + normal); + // trace the origin to the center of the light surface. nudge by the normals in + // case the start/end points are directly on or inside the surface + trace.Trace(center + lnormal, origin + normal); - if(trace.fraction != 1) - { - // something is obstructing it - continue; - } + if (trace.fraction != 1) + { + // something is obstructing it + continue; + } - float d = origin.Distance(center); + float d = origin.Distance(center); curDist = 1.0f - d / (distance * 2.0f); // 2.0 because gzdoom's dynlights do this and we want them to match if (curDist < 0.0f) curDist = 0.0f; - if(curDist >= 1) - { - curDist = 1; + if (curDist >= 1) + { + curDist = 1; - // might get large unlit gaps near the surface. this looks a lot worse for - // non-wall light surfaces so just clamp to full bright and exit out. - if(!bWall) - { - *dist = 1; + // might get large unlit gaps near the surface. this looks a lot worse for + // non-wall light surfaces so just clamp to full bright and exit out. + if (!bWall) + { + *dist = 1; break; - } - } + } + } - if(curDist > *dist) - { - *dist = curDist; - } - } + if (curDist > *dist) + { + *dist = curDist; + } + } *dist *= Intensity(); - return *dist > 0; + return *dist > 0; } diff --git a/src/lightmap/lightsurface.h b/src/lightmap/lightsurface.h index d3081f3..3eb683d 100644 --- a/src/lightmap/lightsurface.h +++ b/src/lightmap/lightsurface.h @@ -36,31 +36,31 @@ class kexTrace; class kexLightSurface { public: - kexLightSurface(); - ~kexLightSurface(); + kexLightSurface(); + ~kexLightSurface(); - void Init(const surfaceLightDef &lightSurfaceDef, surface_t *surface, const bool bWall, const bool bNoCenterPoint); - void Subdivide(const float divide); - void CreateCenterOrigin(); - bool TraceSurface(FLevel *doomMap, kexTrace &trace, const surface_t *surface, const kexVec3 &origin, float *dist); + void Init(const surfaceLightDef &lightSurfaceDef, surface_t *surface, const bool bWall, const bool bNoCenterPoint); + void Subdivide(const float divide); + void CreateCenterOrigin(); + bool TraceSurface(FLevel *doomMap, kexTrace &trace, const surface_t *surface, const kexVec3 &origin, float *dist); - const float Distance() const { return distance; } - const float Intensity() const { return intensity; } - const kexVec3 GetRGB() const { return rgb; } - const bool IsAWall() const { return bWall; } - const bool NoCenterPoint() const { return bNoCenterPoint; } - const surface_t *Surface() const { return surface; } - const vertexBatch_t Origins() const { return origins; } + const float Distance() const { return distance; } + const float Intensity() const { return intensity; } + const kexVec3 GetRGB() const { return rgb; } + const bool IsAWall() const { return bWall; } + const bool NoCenterPoint() const { return bNoCenterPoint; } + const surface_t *Surface() const { return surface; } + const vertexBatch_t Origins() const { return origins; } private: - bool SubdivideRecursion(vertexBatch_t &surfPoints, float divide, kexArray &points); - void Clip(vertexBatch_t &points, const kexVec3 &normal, float dist, vertexBatch_t *frontPoints, vertexBatch_t *backPoints); + bool SubdivideRecursion(vertexBatch_t &surfPoints, float divide, kexArray &points); + void Clip(vertexBatch_t &points, const kexVec3 &normal, float dist, vertexBatch_t *frontPoints, vertexBatch_t *backPoints); - float distance; - float intensity; - kexVec3 rgb; - bool bWall; - bool bNoCenterPoint; - vertexBatch_t origins; - surface_t *surface; + float distance; + float intensity; + kexVec3 rgb; + bool bWall; + bool bNoCenterPoint; + vertexBatch_t origins; + surface_t *surface; }; diff --git a/src/lightmap/surfaces.cpp b/src/lightmap/surfaces.cpp index 8be9586..48d92bf 100644 --- a/src/lightmap/surfaces.cpp +++ b/src/lightmap/surfaces.cpp @@ -38,17 +38,17 @@ kexArray surfaces; static void CreateSideSurfaces(FLevel &doomMap, IntSideDef *side) { - surface_t *surf; - IntSector *front; - IntSector *back; + surface_t *surf; + IntSector *front; + IntSector *back; - front = doomMap.GetFrontSector(side); - back = doomMap.GetBackSector(side); + front = doomMap.GetFrontSector(side); + back = doomMap.GetBackSector(side); if (front->controlsector) return; - FloatVertex v1 = doomMap.GetSegVertex(side->line->v1); + FloatVertex v1 = doomMap.GetSegVertex(side->line->v1); FloatVertex v2 = doomMap.GetSegVertex(side->line->v2); if (side->line->sidenum[0] != (ptrdiff_t)(side - &doomMap.Sides[0])) @@ -61,199 +61,199 @@ static void CreateSideSurfaces(FLevel &doomMap, IntSideDef *side) float v2Top = front->ceilingplane.zAt(v2.x, v2.y); float v2Bottom = front->floorplane.zAt(v2.x, v2.y); - if(back) - { + if (back) + { float v1TopBack = back->ceilingplane.zAt(v1.x, v1.y); float v1BottomBack = back->floorplane.zAt(v1.x, v1.y); float v2TopBack = back->ceilingplane.zAt(v2.x, v2.y); float v2BottomBack = back->floorplane.zAt(v2.x, v2.y); - if (v1Top == v1TopBack && v1Bottom == v1BottomBack && v2Top == v2TopBack && v2Bottom == v2BottomBack) - { - return; - } + if (v1Top == v1TopBack && v1Bottom == v1BottomBack && v2Top == v2TopBack && v2Bottom == v2BottomBack) + { + return; + } - // bottom seg - if(v1Bottom < v1BottomBack || v2Bottom < v2BottomBack) - { - if(side->bottomtexture[0] != '-') - { - surf = (surface_t*)Mem_Calloc(sizeof(surface_t), hb_static); - surf->numVerts = 4; - surf->verts = (kexVec3*)Mem_Calloc(sizeof(kexVec3) * 4, hb_static); + // bottom seg + if (v1Bottom < v1BottomBack || v2Bottom < v2BottomBack) + { + if (side->bottomtexture[0] != '-') + { + surf = (surface_t*)Mem_Calloc(sizeof(surface_t), hb_static); + surf->numVerts = 4; + surf->verts = (kexVec3*)Mem_Calloc(sizeof(kexVec3) * 4, hb_static); - surf->verts[0].x = surf->verts[2].x = v1.x; - surf->verts[0].y = surf->verts[2].y = v1.y; - surf->verts[1].x = surf->verts[3].x = v2.x; - surf->verts[1].y = surf->verts[3].y = v2.y; + surf->verts[0].x = surf->verts[2].x = v1.x; + surf->verts[0].y = surf->verts[2].y = v1.y; + surf->verts[1].x = surf->verts[3].x = v2.x; + surf->verts[1].y = surf->verts[3].y = v2.y; surf->verts[0].z = v1Bottom; surf->verts[1].z = v2Bottom; surf->verts[2].z = v1BottomBack; surf->verts[3].z = v2BottomBack; - surf->plane.SetNormal(surf->verts[0], surf->verts[1], surf->verts[2]); - surf->plane.SetDistance(surf->verts[0]); - surf->type = ST_LOWERSIDE; - surf->typeIndex = side - &doomMap.Sides[0]; + surf->plane.SetNormal(surf->verts[0], surf->verts[1], surf->verts[2]); + surf->plane.SetDistance(surf->verts[0]); + surf->type = ST_LOWERSIDE; + surf->typeIndex = side - &doomMap.Sides[0]; - surfaces.Push(surf); - } + surfaces.Push(surf); + } v1Bottom = v1BottomBack; v2Bottom = v2BottomBack; - } + } - // top seg - if(v1Top > v1TopBack || v2Top > v2TopBack) - { - bool bSky = false; - int frontidx = front - &doomMap.Sectors[0]; - int backidx = back - &doomMap.Sectors[0]; + // top seg + if (v1Top > v1TopBack || v2Top > v2TopBack) + { + bool bSky = false; + int frontidx = front - &doomMap.Sectors[0]; + int backidx = back - &doomMap.Sectors[0]; - if(doomMap.bSkySectors[frontidx] && doomMap.bSkySectors[backidx]) - { - if(front->data.ceilingheight != back->data.ceilingheight && side->toptexture[0] == '-') - { - bSky = true; - } - } + if (doomMap.bSkySectors[frontidx] && doomMap.bSkySectors[backidx]) + { + if (front->data.ceilingheight != back->data.ceilingheight && side->toptexture[0] == '-') + { + bSky = true; + } + } - if(side->toptexture[0] != '-' || bSky) - { - surf = (surface_t*)Mem_Calloc(sizeof(surface_t), hb_static); - surf->numVerts = 4; - surf->verts = (kexVec3*)Mem_Calloc(sizeof(kexVec3) * 4, hb_static); + if (side->toptexture[0] != '-' || bSky) + { + surf = (surface_t*)Mem_Calloc(sizeof(surface_t), hb_static); + surf->numVerts = 4; + surf->verts = (kexVec3*)Mem_Calloc(sizeof(kexVec3) * 4, hb_static); - surf->verts[0].x = surf->verts[2].x = v1.x; - surf->verts[0].y = surf->verts[2].y = v1.y; - surf->verts[1].x = surf->verts[3].x = v2.x; - surf->verts[1].y = surf->verts[3].y = v2.y; + surf->verts[0].x = surf->verts[2].x = v1.x; + surf->verts[0].y = surf->verts[2].y = v1.y; + surf->verts[1].x = surf->verts[3].x = v2.x; + surf->verts[1].y = surf->verts[3].y = v2.y; surf->verts[0].z = v1TopBack; surf->verts[1].z = v2TopBack; surf->verts[2].z = v1Top; surf->verts[3].z = v2Top; - surf->plane.SetNormal(surf->verts[0], surf->verts[1], surf->verts[2]); - surf->plane.SetDistance(surf->verts[0]); - surf->type = ST_UPPERSIDE; + surf->plane.SetNormal(surf->verts[0], surf->verts[1], surf->verts[2]); + surf->plane.SetDistance(surf->verts[0]); + surf->type = ST_UPPERSIDE; surf->typeIndex = side - &doomMap.Sides[0]; - surf->bSky = bSky; + surf->bSky = bSky; - surfaces.Push(surf); - } + surfaces.Push(surf); + } v1Top = v1TopBack; v2Top = v2TopBack; - } - } + } + } - // middle seg - if(back == NULL) - { - surf = (surface_t*)Mem_Calloc(sizeof(surface_t), hb_static); - surf->numVerts = 4; - surf->verts = (kexVec3*)Mem_Calloc(sizeof(kexVec3) * 4, hb_static); + // middle seg + if (back == NULL) + { + surf = (surface_t*)Mem_Calloc(sizeof(surface_t), hb_static); + surf->numVerts = 4; + surf->verts = (kexVec3*)Mem_Calloc(sizeof(kexVec3) * 4, hb_static); - surf->verts[0].x = surf->verts[2].x = v1.x; - surf->verts[0].y = surf->verts[2].y = v1.y; - surf->verts[1].x = surf->verts[3].x = v2.x; - surf->verts[1].y = surf->verts[3].y = v2.y; + surf->verts[0].x = surf->verts[2].x = v1.x; + surf->verts[0].y = surf->verts[2].y = v1.y; + surf->verts[1].x = surf->verts[3].x = v2.x; + surf->verts[1].y = surf->verts[3].y = v2.y; surf->verts[0].z = v1Bottom; surf->verts[1].z = v2Bottom; surf->verts[2].z = v1Top; surf->verts[3].z = v2Top; - surf->plane.SetNormal(surf->verts[0], surf->verts[1], surf->verts[2]); - surf->plane.SetDistance(surf->verts[0]); - surf->type = ST_MIDDLESIDE; + surf->plane.SetNormal(surf->verts[0], surf->verts[1], surf->verts[2]); + surf->plane.SetDistance(surf->verts[0]); + surf->type = ST_MIDDLESIDE; surf->typeIndex = side - &doomMap.Sides[0]; - surfaces.Push(surf); - } + surfaces.Push(surf); + } } static void CreateSubsectorSurfaces(FLevel &doomMap) { - surface_t *surf; - IntSector *sector = NULL; - int i; - int j; + surface_t *surf; + IntSector *sector = NULL; + int i; + int j; - printf("------------- Building subsector surfaces -------------\n"); + printf("------------- Building subsector surfaces -------------\n"); - for(i = 0; i < doomMap.NumGLSubsectors; i++) - { - printf("subsectors: %i / %i\r", i+1, doomMap.NumGLSubsectors); + for (i = 0; i < doomMap.NumGLSubsectors; i++) + { + printf("subsectors: %i / %i\r", i + 1, doomMap.NumGLSubsectors); MapSubsectorEx *sub = &doomMap.GLSubsectors[i]; - if(sub->numlines < 3) - { - continue; - } + if (sub->numlines < 3) + { + continue; + } - sector = doomMap.GetSectorFromSubSector(sub); + sector = doomMap.GetSectorFromSubSector(sub); - // I will be NOT surprised if some users tries to do something stupid with - // sector hacks - if(sector == NULL) - { - Error("CreateSubsectorSurfaces: subsector %i has no sector\n", i); - return; - } + // I will be NOT surprised if some users tries to do something stupid with + // sector hacks + if (sector == NULL) + { + Error("CreateSubsectorSurfaces: subsector %i has no sector\n", i); + return; + } if (sector->controlsector) continue; - surf = (surface_t*)Mem_Calloc(sizeof(surface_t), hb_static); - surf->numVerts = sub->numlines; - surf->verts = (kexVec3*)Mem_Calloc(sizeof(kexVec3) * surf->numVerts, hb_static); + surf = (surface_t*)Mem_Calloc(sizeof(surface_t), hb_static); + surf->numVerts = sub->numlines; + surf->verts = (kexVec3*)Mem_Calloc(sizeof(kexVec3) * surf->numVerts, hb_static); - // floor verts - for(j = 0; j < surf->numVerts; j++) - { - MapSegGLEx *seg = &doomMap.GLSegs[sub->firstline + (surf->numVerts - 1) - j]; + // floor verts + for (j = 0; j < surf->numVerts; j++) + { + MapSegGLEx *seg = &doomMap.GLSegs[sub->firstline + (surf->numVerts - 1) - j]; FloatVertex v1 = doomMap.GetSegVertex(seg->v1); - surf->verts[j].x = v1.x; - surf->verts[j].y = v1.y; - surf->verts[j].z = sector->floorplane.zAt(surf->verts[j].x, surf->verts[j].y); - } + surf->verts[j].x = v1.x; + surf->verts[j].y = v1.y; + surf->verts[j].z = sector->floorplane.zAt(surf->verts[j].x, surf->verts[j].y); + } - surf->plane = sector->floorplane; - surf->type = ST_FLOOR; - surf->typeIndex = i; + surf->plane = sector->floorplane; + surf->type = ST_FLOOR; + surf->typeIndex = i; - surfaces.Push(surf); + surfaces.Push(surf); - surf = (surface_t*)Mem_Calloc(sizeof(surface_t), hb_static); - surf->numVerts = sub->numlines; - surf->verts = (kexVec3*)Mem_Calloc(sizeof(kexVec3) * surf->numVerts, hb_static); + surf = (surface_t*)Mem_Calloc(sizeof(surface_t), hb_static); + surf->numVerts = sub->numlines; + surf->verts = (kexVec3*)Mem_Calloc(sizeof(kexVec3) * surf->numVerts, hb_static); - if(doomMap.bSkySectors[sector-&doomMap.Sectors[0]]) - { - surf->bSky = true; - } + if (doomMap.bSkySectors[sector - &doomMap.Sectors[0]]) + { + surf->bSky = true; + } - // ceiling verts - for(j = 0; j < surf->numVerts; j++) - { + // ceiling verts + for (j = 0; j < surf->numVerts; j++) + { MapSegGLEx *seg = &doomMap.GLSegs[sub->firstline + j]; FloatVertex v1 = doomMap.GetSegVertex(seg->v1); - surf->verts[j].x = v1.x; - surf->verts[j].y = v1.y; - surf->verts[j].z = sector->ceilingplane.zAt(surf->verts[j].x, surf->verts[j].y); - } + surf->verts[j].x = v1.x; + surf->verts[j].y = v1.y; + surf->verts[j].z = sector->ceilingplane.zAt(surf->verts[j].x, surf->verts[j].y); + } - surf->plane = sector->ceilingplane; - surf->type = ST_CEILING; - surf->typeIndex = i; + surf->plane = sector->ceilingplane; + surf->type = ST_CEILING; + surf->typeIndex = i; - surfaces.Push(surf); - } + surfaces.Push(surf); + } - printf("\nLeaf surfaces: %i\n", surfaces.Length() - doomMap.NumGLSubsectors); + printf("\nLeaf surfaces: %i\n", surfaces.Length() - doomMap.NumGLSubsectors); } static bool IsDegenerate(const kexVec3 &v0, const kexVec3 &v1, const kexVec3 &v2) @@ -313,19 +313,19 @@ void CreateSurfaces(FLevel &doomMap) } } - printf("------------- Building side surfaces -------------\n"); + printf("------------- Building side surfaces -------------\n"); - for(unsigned int i = 0; i < doomMap.Sides.Size(); i++) - { + for (unsigned int i = 0; i < doomMap.Sides.Size(); i++) + { CreateSideSurfaces(doomMap, &doomMap.Sides[i]); - printf("sides: %i / %i\r", i+1, doomMap.Sides.Size()); - } + printf("sides: %i / %i\r", i + 1, doomMap.Sides.Size()); + } - printf("\nSide surfaces: %i\n", surfaces.Length()); + printf("\nSide surfaces: %i\n", surfaces.Length()); - CreateSubsectorSurfaces(doomMap); + CreateSubsectorSurfaces(doomMap); - printf("Surfaces total: %i\n\n", surfaces.Length()); + printf("Surfaces total: %i\n\n", surfaces.Length()); printf("Building collision mesh..\n\n"); diff --git a/src/lightmap/surfaces.h b/src/lightmap/surfaces.h index 8a5da02..af753c0 100644 --- a/src/lightmap/surfaces.h +++ b/src/lightmap/surfaces.h @@ -31,12 +31,12 @@ struct MapSubsectorEx; enum surfaceType_t { - ST_UNKNOWN = 0, - ST_MIDDLESIDE, - ST_UPPERSIDE, - ST_LOWERSIDE, - ST_CEILING, - ST_FLOOR + ST_UNKNOWN, + ST_MIDDLESIDE, + ST_UPPERSIDE, + ST_LOWERSIDE, + ST_CEILING, + ST_FLOOR }; typedef kexArray vertexBatch_t; @@ -46,20 +46,20 @@ typedef kexArray vertexBatch_t; struct surface_t { - kexPlane plane; - int lightmapNum; - int lightmapOffs[2]; - int lightmapDims[2]; - kexVec3 lightmapOrigin; - kexVec3 lightmapSteps[2]; - kexVec3 textureCoords[2]; - kexBBox bounds; - int numVerts; - kexVec3 *verts; - float *lightmapCoords; - surfaceType_t type; - int typeIndex; - bool bSky; + kexPlane plane; + int lightmapNum; + int lightmapOffs[2]; + int lightmapDims[2]; + kexVec3 lightmapOrigin; + kexVec3 lightmapSteps[2]; + kexVec3 textureCoords[2]; + kexBBox bounds; + int numVerts; + kexVec3 *verts; + float *lightmapCoords; + surfaceType_t type; + int typeIndex; + bool bSky; }; extern kexArray surfaces; diff --git a/src/lightmap/trace.cpp b/src/lightmap/trace.cpp index 93328c4..858a3b3 100644 --- a/src/lightmap/trace.cpp +++ b/src/lightmap/trace.cpp @@ -37,13 +37,13 @@ void kexTrace::Init(FLevel &doomMap) { - map = &doomMap; + map = &doomMap; } void kexTrace::Trace(const kexVec3 &startVec, const kexVec3 &endVec) { - start = startVec; - end = endVec; + start = startVec; + end = endVec; TraceHit hit = TriangleMeshShape::find_first_hit(map->CollisionMesh.get(), start, end); fraction = hit.fraction; diff --git a/src/lightmap/trace.h b/src/lightmap/trace.h index f4f44ca..9f78aff 100644 --- a/src/lightmap/trace.h +++ b/src/lightmap/trace.h @@ -32,14 +32,14 @@ struct FLevel; class kexTrace { public: - void Init(FLevel &doomMap); - void Trace(const kexVec3 &startVec, const kexVec3 &endVec); + void Init(FLevel &doomMap); + void Trace(const kexVec3 &startVec, const kexVec3 &endVec); - kexVec3 start; - kexVec3 end; - surface_t *hitSurface; - float fraction; + kexVec3 start; + kexVec3 end; + surface_t *hitSurface; + float fraction; private: - FLevel *map = nullptr; + FLevel *map = nullptr; };