diff --git a/SQCSim-common/bullet.cpp b/SQCSim-common/bullet.cpp index c06c9e7..52824d5 100644 --- a/SQCSim-common/bullet.cpp +++ b/SQCSim-common/bullet.cpp @@ -30,3 +30,7 @@ void Bullet::Transpose(int& x, int& z) { m_startpos.x -= x * CHUNK_SIZE_X; m_startpos.z -= z * CHUNK_SIZE_Z; } + +Vector3f& Bullet::getPos() { + return m_currentpos; +} diff --git a/SQCSim-common/bullet.h b/SQCSim-common/bullet.h index de2e14c..599eab6 100644 --- a/SQCSim-common/bullet.h +++ b/SQCSim-common/bullet.h @@ -12,6 +12,7 @@ public: bool Update(World* world, float elapsedtime); void Transpose(int& x, int& z); + Vector3f& getPos(); private: Vector3f m_startpos; diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h index 968b71d..0342359 100644 --- a/SQCSim-common/define.h +++ b/SQCSim-common/define.h @@ -11,7 +11,7 @@ #define CHUNK_SIZE_Y 64 #define CHUNK_SIZE_Z 4 #define MAX_SELECTION_DISTANCE 5 -#define SEED 12345 +#define SEED 0 #define COUNTDOWN 300 #define WORLD_SIZE_X 64 diff --git a/SQCSim-common/netprotocol.cpp b/SQCSim-common/netprotocol.cpp index d7f7675..b692201 100644 --- a/SQCSim-common/netprotocol.cpp +++ b/SQCSim-common/netprotocol.cpp @@ -13,7 +13,26 @@ void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) { } void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) { + *buf[0] = netprot::PACKET_TYPE::TEAMINF; + size_t namesize = std::strlen(tinfo->name) + 1; + + memcpy(*buf + 1, &tinfo->name, namesize); + uint64_t tid = tinfo->id; + uint8_t tid8[sizeof(uint64_t)] = { + (tid >> 56) & 0xFF, + (tid >> 48) & 0xFF, + (tid >> 40) & 0xFF, + (tid >> 32) & 0xFF, + (tid >> 24) & 0xFF, + (tid >> 16) & 0xFF, + (tid >> 8) & 0xFF, + tid & 0xFF + }; + + memcpy(*buf + namesize + 2, tid8, sizeof(uint64_t)); + + *buflen = namesize + sizeof(uint64_t) + 2; } void netprot::Serialize(LoginInfo* linfo, char* buf[], uint32_t* buflen) { @@ -54,7 +73,40 @@ void netprot::Serialize(LoginInfo* linfo, char* buf[], uint32_t* buflen) { } void netprot::Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen) { + *buf[0] = netprot::PACKET_TYPE::PLAYINF; + size_t namesize = std::strlen(pinfo->name) + 1; + + memcpy(*buf + 1, &pinfo->name, namesize); + uint64_t id = pinfo->id; + uint8_t id8[sizeof(uint64_t)] = { + (id >> 56) & 0xFF, + (id >> 48) & 0xFF, + (id >> 40) & 0xFF, + (id >> 32) & 0xFF, + (id >> 24) & 0xFF, + (id >> 16) & 0xFF, + (id >> 8) & 0xFF, + id & 0xFF + }; + + memcpy(*buf + namesize + 2, id8, sizeof(uint64_t)); + + uint64_t tid = pinfo->tid; + uint8_t tid8[sizeof(uint64_t)] = { + (tid >> 56) & 0xFF, + (tid >> 48) & 0xFF, + (tid >> 40) & 0xFF, + (tid >> 32) & 0xFF, + (tid >> 24) & 0xFF, + (tid >> 16) & 0xFF, + (tid >> 8) & 0xFF, + tid & 0xFF + }; + + memcpy(*buf + namesize + 2 + sizeof(uint64_t), tid8, sizeof(uint64_t)); + + *buflen = namesize + sizeof(uint64_t) * 2 + 2; } void netprot::Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen) { @@ -106,11 +158,67 @@ void netprot::Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen) { } void netprot::Serialize(Chat* chat, char* buf[], uint32_t* buflen) { + *buf[0] = netprot::PACKET_TYPE::CHAT; + uint64_t src = chat->src_id; + uint8_t src8[sizeof(uint64_t)] = { + (src >> 56) & 0xFF, + (src >> 48) & 0xFF, + (src >> 40) & 0xFF, + (src >> 32) & 0xFF, + (src >> 24) & 0xFF, + (src >> 16) & 0xFF, + (src >> 8) & 0xFF, + src & 0xFF + }; + + memcpy(*buf + 1, src8, sizeof(uint64_t)); + + uint64_t dst = chat->dest_id; + uint8_t dst8[sizeof(uint64_t)] = { + (dst >> 56) & 0xFF, + (dst >> 48) & 0xFF, + (dst >> 40) & 0xFF, + (dst >> 32) & 0xFF, + (dst >> 24) & 0xFF, + (dst >> 16) & 0xFF, + (dst >> 8) & 0xFF, + dst & 0xFF + }; + + memcpy(*buf + 1 + sizeof(uint64_t), dst8, sizeof(uint64_t)); + + uint64_t dstteam = chat->dest_id; + uint8_t dstt8[sizeof(uint64_t)] = { + (dstteam >> 56) & 0xFF, + (dstteam >> 48) & 0xFF, + (dstteam >> 40) & 0xFF, + (dstteam >> 32) & 0xFF, + (dstteam >> 24) & 0xFF, + (dstteam >> 16) & 0xFF, + (dstteam >> 8) & 0xFF, + dstteam & 0xFF + }; + + memcpy(*buf + 1 + sizeof(uint64_t) * 2, dstt8, sizeof(uint64_t)); + + size_t messize = std::strlen(chat->mess) + 1; + + memcpy(*buf + 1 + sizeof(uint64_t) * 3, &chat->mess, messize); + + *buflen = messize + sizeof(uint64_t) * 3 + 2; } void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) { - + *buf[0] = netprot::PACKET_TYPE::ERRLOG; + + size_t messize = std::strlen(errlog->mess) + 1; + + memcpy(*buf + 1, &errlog->mess, messize); + + memcpy(*buf + 1 + messize, &errlog->is_fatal, sizeof(bool)); + + *buflen = messize + sizeof(bool) + 1; } @@ -128,11 +236,33 @@ bool netprot::Deserialize(Sync* sync, char* buf, const uint32_t buflen) { } bool netprot::Deserialize(TeamInfo* tinfo, char* buf, const uint32_t buflen) { - return false; + if (buflen <= sizeof(LoginInfo)) + return false; + + size_t namesize = std::strlen(buf) + 1; + + if (namesize > 32) + return false; + + memcpy(&tinfo->name, &buf[1], namesize); + + uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; + memcpy(diff, &buf[namesize + 1], sizeof(uint64_t)); + tinfo->id = + (uint64_t)diff[0] << 56 | + (uint64_t)diff[1] << 48 | + (uint64_t)diff[2] << 40 | + (uint64_t)diff[3] << 32 | + (uint64_t)diff[4] << 24 | + (uint64_t)diff[5] << 16 | + (uint64_t)diff[6] << 8 | + (uint64_t)diff[7]; + + return true; } bool netprot::Deserialize(LoginInfo* linfo, char* buf, const uint32_t buflen) { - if (buflen < sizeof(LoginInfo) + 3) + if (buflen <= sizeof(LoginInfo)) return false; size_t namesize = std::strlen(buf) + 1; @@ -169,11 +299,44 @@ bool netprot::Deserialize(LoginInfo* linfo, char* buf, const uint32_t buflen) { } bool netprot::Deserialize(PlayerInfo* pinfo, char* buf, const uint32_t buflen) { - return false; + if (buflen <= sizeof(PlayerInfo)) + return false; + + size_t namesize = std::strlen(buf) + 1; + + if (namesize > 32) + return false; + + memcpy(&pinfo->name, &buf[1], namesize); + + uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; + memcpy(diff, &buf[namesize + 1], sizeof(uint64_t)); + pinfo->id = + (uint64_t)diff[0] << 56 | + (uint64_t)diff[1] << 48 | + (uint64_t)diff[2] << 40 | + (uint64_t)diff[3] << 32 | + (uint64_t)diff[4] << 24 | + (uint64_t)diff[5] << 16 | + (uint64_t)diff[6] << 8 | + (uint64_t)diff[7]; + + memcpy(diff, &buf[namesize + sizeof(uint64_t) + 1], sizeof(uint64_t)); + pinfo->tid = + (uint64_t)diff[0] << 56 | + (uint64_t)diff[1] << 48 | + (uint64_t)diff[2] << 40 | + (uint64_t)diff[3] << 32 | + (uint64_t)diff[4] << 24 | + (uint64_t)diff[5] << 16 | + (uint64_t)diff[6] << 8 | + (uint64_t)diff[7]; + + return true; } bool netprot::Deserialize(GameInfo* ginfo, char* buf, const uint32_t buflen) { - if (buflen < sizeof(GameInfo) + 1) + if (buflen <= sizeof(GameInfo)) return false; uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; @@ -214,11 +377,67 @@ bool netprot::Deserialize(GameInfo* ginfo, char* buf, const uint32_t buflen) { } bool netprot::Deserialize(Chat* chat, char* buf, const uint32_t buflen) { - return false; + if (buflen <= sizeof(Chat)) + return false; + + uint8_t src[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; + memcpy(src, &buf[1], sizeof(uint64_t)); + chat->src_id = + (uint64_t)src[0] << 56 | + (uint64_t)src[1] << 48 | + (uint64_t)src[2] << 40 | + (uint64_t)src[3] << 32 | + (uint64_t)src[4] << 24 | + (uint64_t)src[5] << 16 | + (uint64_t)src[6] << 8 | + (uint64_t)src[7]; + + uint8_t dst[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; + memcpy(dst, &buf[1 + sizeof(uint64_t)], sizeof(uint64_t)); + chat->dest_id = + (uint64_t)dst[0] << 56 | + (uint64_t)dst[1] << 48 | + (uint64_t)dst[2] << 40 | + (uint64_t)dst[3] << 32 | + (uint64_t)dst[4] << 24 | + (uint64_t)dst[5] << 16 | + (uint64_t)dst[6] << 8 | + (uint64_t)dst[7]; + + uint8_t dstt[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 }; + memcpy(dstt, &buf[1 + sizeof(uint64_t) * 2], sizeof(uint64_t)); + chat->dest_team_id = + (uint64_t)dstt[0] << 56 | + (uint64_t)dstt[1] << 48 | + (uint64_t)dstt[2] << 40 | + (uint64_t)dstt[3] << 32 | + (uint64_t)dstt[4] << 24 | + (uint64_t)dstt[5] << 16 | + (uint64_t)dstt[6] << 8 | + (uint64_t)dstt[7]; + + size_t messsize = std::strlen(buf + sizeof(uint64_t) * 3) + 1; + + if (messsize > 140) + return false; + + memcpy(&chat->mess, &buf[1 + sizeof(uint64_t) * 3], messsize); + return true; } bool netprot::Deserialize(ErrorLog* errlog, char* buf, const uint32_t buflen) { - return false; + if (buflen <= sizeof(ErrorLog)) + return false; + + size_t messsize = std::strlen(buf) + 1; + + if (messsize > 140) + return false; + + memcpy(&errlog->mess, &buf[1], messsize); + memcpy(&errlog->is_fatal, &buf[1 + messsize], sizeof(bool)); + + return true; } netprot::PacketType netprot::getType(char* buf, const uint32_t buflen) { diff --git a/SQCSim-common/netprotocol.h b/SQCSim-common/netprotocol.h index 3e237f7..7f93349 100644 --- a/SQCSim-common/netprotocol.h +++ b/SQCSim-common/netprotocol.h @@ -18,9 +18,26 @@ namespace netprot { LAST_PACK }; + struct Keys { + bool forward, + backward, + left, + right, + jump, + shoot; + }; + + struct States { + bool jumping, + shooting, + hit, + powerup; + }; + struct Input { // cli -> srv UDP ~frame Timestamp timestamp; - uint8_t keys; // 0bFBLRJS__ bit-packing de bool. + uint64_t sid = 0; + Keys keys; // 0bFBLRJS__ bit-packing de bool. Vector3f direction; }; @@ -28,8 +45,8 @@ namespace netprot { Timestamp timestamp; uint64_t id = 0; Vector3f position, - direction; - uint8_t states; // 0bJSH_____ bit-packing de bool. + direction; + States states; // 0bJSH_____ bit-packing de bool. }; struct Sync { // srv -> cli TCP ~second diff --git a/SQCSim2021/SQCSim2021.vcxproj b/SQCSim2021/SQCSim2021.vcxproj index 9cac270..005bcc5 100644 --- a/SQCSim2021/SQCSim2021.vcxproj +++ b/SQCSim2021/SQCSim2021.vcxproj @@ -19,18 +19,13 @@ - - - - - @@ -43,14 +38,12 @@ - - diff --git a/SQCSim2021/SQCSim2021.vcxproj.filters b/SQCSim2021/SQCSim2021.vcxproj.filters index 60aa0a8..ec7b7d6 100644 --- a/SQCSim2021/SQCSim2021.vcxproj.filters +++ b/SQCSim2021/SQCSim2021.vcxproj.filters @@ -11,12 +11,6 @@ - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - Fichiers d%27en-tête @@ -26,12 +20,6 @@ Fichiers d%27en-tête - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - Fichiers d%27en-tête @@ -44,15 +32,9 @@ Fichiers d%27en-tête - - Fichiers d%27en-tête - Fichiers d%27en-tête - - Fichiers d%27en-tête - Fichiers d%27en-tête @@ -65,20 +47,20 @@ Fichiers d%27en-tête - - Fichiers d%27en-tête - - - Fichiers d%27en-tête - Fichiers d%27en-tête + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + + + Fichiers d%27en-tête + - - Fichiers sources - Fichiers sources @@ -103,9 +85,6 @@ Fichiers sources - - Fichiers sources - Fichiers sources @@ -121,14 +100,14 @@ Fichiers sources - - Fichiers sources - - - Fichiers sources - Fichiers sources + + Fichiers sources + + + Fichiers sources + \ No newline at end of file diff --git a/SQCSim2021/array2d.h b/SQCSim2021/array2d.h deleted file mode 100644 index 7451365..0000000 --- a/SQCSim2021/array2d.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef ARRAY2D_H__ -#define ARRAY2D_H__ - -#include "define.h" - -template -class Array2d { - public: - Array2d(int x, int y); - ~Array2d(); - Array2d(const Array2d& array); - - void Set(int x, int y, T type); - T Get(int x, int y) const; - T Remove(int x, int y); - - void Reset(T type); - - private: - int m_x, m_y; - T* m_array; - - int To1dIndex(int x, int y) const; -}; - -template -Array2d::Array2d(int x, int y) : m_x(x), m_y(y) { m_array = new T[m_x * m_y]; } - -template -Array2d::~Array2d() { delete[] m_array; } - -template -Array2d::Array2d(const Array2d& array) : m_x(array.m_x), m_y(array.m_y) { - m_array = new T[m_x * m_y]; - for (int i = 0; i < m_x * m_y; ++i) - m_array[i] = array.m_array[i]; -} - -template -void Array2d::Set(int x, int y, T type) { m_array[To1dIndex(x, y)] = type; } - -template -T Array2d::Get(int x, int y) const { return m_array[To1dIndex(x, y)]; } - -template -T Array2d::Remove(int x, int y) { - T thing = std::move(m_array[To1dIndex(x, y)]); - m_array[To1dIndex(x, y)] = nullptr; - return thing; -} - -template -void Array2d::Reset(T type) { - for (int i = 0; i < m_x * m_y; ++i) - m_array[i] = type; -} - -template -int Array2d::To1dIndex(int x, int y) const { return x + (y * m_x); } - -#endif // ARRAY2D_H__ diff --git a/SQCSim2021/array3d.h b/SQCSim2021/array3d.h deleted file mode 100644 index 97603ef..0000000 --- a/SQCSim2021/array3d.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef ARRAY3D_H__ -#define ARRAY3D_H__ - -#include "define.h" - -template -class Array3d { - public: - Array3d(int x, int y, int z); - ~Array3d(); - Array3d(const Array3d& array); - - void Set(int x, int y, int z, T type); - T Get(int x, int y, int z) const; - - void Reset(T type); - - private: - int m_x, m_y, m_z; - T* m_array; - - int To1dIndex(int x, int y, int z) const; -}; - -template -Array3d::Array3d(int x, int y, int z) : m_x(x), m_y(y), m_z(z) { m_array = new T[m_x * m_y * m_z]; } - -template -Array3d::~Array3d() { delete[] m_array; } - -template -Array3d::Array3d(const Array3d& array) : m_x(array.m_x), m_y(array.m_y), m_z(array.m_z) { - m_array = new T[m_x * m_y * m_z]; - for (int i = 0; i < m_x * m_y * m_z; ++i) - m_array[i] = array.m_array[i]; -} - -template -void Array3d::Set(int x, int y, int z, T type) { - m_array[To1dIndex(x, y, z)] = type; -} - -template -T Array3d::Get(int x, int y, int z) const { return m_array[To1dIndex(x, y, z)]; } - -template -void Array3d::Reset(T type) { - for (int i = 0; i < m_x * m_y * m_z; ++i) - m_array[i] = type; -} - -template -int Array3d::To1dIndex(int x, int y, int z) const { return x + (z * m_x) + (y * m_z * m_x); } - -#endif // ARRAY3D_H__ diff --git a/SQCSim2021/blockinfo.cpp b/SQCSim2021/blockinfo.cpp deleted file mode 100644 index 1e42825..0000000 --- a/SQCSim2021/blockinfo.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "blockinfo.h" -#include - -BlockInfo::BlockInfo(BlockType type, const std::string& name, float u, float v, float s, int dur) : m_type(type), m_name(name), m_u(u), m_v(v), m_s(s), m_durability(dur) -{ -} - -BlockInfo::~BlockInfo() -{ -} - -BlockType BlockInfo::GetType() const -{ - return m_type; -} - -void BlockInfo::SetDurability(int durability) -{ - m_durability = durability; -} - -int BlockInfo::GetDurability() const -{ - return m_durability; -} - -void BlockInfo::GetTexture(float& u, float& v, float& s) -{ - u = m_u; - v = m_v; - s = m_s; -} - -void BlockInfo::Show() const -{ - std::cout << "Type: " << m_type << std::endl; - std::cout << "Nom: " << m_name << std::endl; - std::cout << "Durabilite: " << m_durability << std::endl; - std::cout << "Coordonnees Texture: " << m_u << ", " << m_v << ", " << m_s << std::endl; -} - - diff --git a/SQCSim2021/blockinfo.h b/SQCSim2021/blockinfo.h deleted file mode 100644 index 8a2afe7..0000000 --- a/SQCSim2021/blockinfo.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef BLOCKINFO_H__ -#define BLOCKINFO_H__ - -#include -#include "define.h" - -class BlockInfo -{ - public: - BlockInfo(BlockType type, const std::string& name, float u, float v, float s, int dur); - ~BlockInfo(); - - BlockType GetType() const; - - void SetDurability(int durability); - int GetDurability() const; - - void GetTexture(float& u, float& v, float& s); - - void Show() const; - - private: - BlockType m_type; - float m_u; - float m_v; - float m_s; - std::string m_name; - int m_durability; - -}; - -#endif // BLOCKINFO_H__ diff --git a/SQCSim2021/chunk.h b/SQCSim2021/chunk.h index 2ce15e8..995b3f6 100644 --- a/SQCSim2021/chunk.h +++ b/SQCSim2021/chunk.h @@ -1,11 +1,11 @@ #ifndef CHUNK_H__ #define CHUNK_H__ #include "define.h" -#include "array3d.h" -#include "array2d.h" +#include "../SQCSim-common/array2d.h" +#include "../SQCSim-common/array3d.h" +#include "../SQCSim-common/blockinfo.h" +#include "../SQCSim-common/opensimplex.h" #include "vertexbuffer.h" -#include "blockinfo.h" -#include "opensimplex.h" class World; diff --git a/SQCSim2021/connector.h b/SQCSim2021/connector.h index 166c07b..297be6f 100644 --- a/SQCSim2021/connector.h +++ b/SQCSim2021/connector.h @@ -1,9 +1,9 @@ #ifndef CONNECTOR_H__ #define CONNECTOR_H__ -#include "define.h" -#include "../SQCSim-common/netprotocol.h" #include +#include "../SQCSim-common/netprotocol.h" +#include "define.h" class Connector { public: diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index a20a720..5f21e66 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -46,7 +46,7 @@ void Engine::Init() { for (int x = 0; x < MAX_BULLETS; ++x) m_bullets[x] = nullptr; - uint64_t seed = 0; + uint64_t seed = SEED; std::string playname = "La Chienne à Jacques"; if (NETWORK_TEST) { // Test connexion réseau. if (!m_conn.Init()) { diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index 5ce52ec..5220cf8 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -3,7 +3,10 @@ #include #include +#include "../SQCSim-common/array2d.h" +#include "../SQCSim-common/blockinfo.h" #include "define.h" +#include "bullet.h" #include "openglcontext.h" #include "texture.h" #include "transformation.h" @@ -13,10 +16,7 @@ #include "skybox.h" #include "audio.h" #include "textureatlas.h" -#include "blockinfo.h" -#include "array2d.h" #include "world.h" -#include "bullet.h" #include "connector.h" class Engine : public OpenglContext { diff --git a/SQCSim2021/matrix4.h b/SQCSim2021/matrix4.h deleted file mode 100644 index bf5ac5b..0000000 --- a/SQCSim2021/matrix4.h +++ /dev/null @@ -1,571 +0,0 @@ -#ifndef MATRIX4_H__ -#define MATRIX4_H__ - -#include -#include -#include - -#include "define.h" -#include "../SQCSim-common/vector3.h" - -#ifndef M_PI -#define M_PI 3.14159265f -#endif - -#define DEGTORAD(x) ((x * M_PI) / 180.f) -#define RADTODEG(x) ((180.f * x) / M_PI) - -template -class Matrix4 -{ - public: - typedef T Type; - - public: - static const Matrix4 ZERO; - static const Matrix4 IDENTITY; - - public: - Matrix4(); - Matrix4(const T& v); - Matrix4(const Matrix4& m); - Matrix4(const T& m_11, const T& m_12, const T& m_13, const T& m_14, - const T& m_21, const T& m_22, const T& m_23, const T& m_24, - const T& m_31, const T& m_32, const T& m_33, const T& m_34, - const T& m_41, const T& m_42, const T& m_43, const T& m_44); - - const T& Get11() const; - const T& Get12() const; - const T& Get13() const; - const T& Get14() const; - const T& Get21() const; - const T& Get22() const; - const T& Get23() const; - const T& Get24() const; - const T& Get31() const; - const T& Get32() const; - const T& Get33() const; - const T& Get34() const; - const T& Get41() const; - const T& Get42() const; - const T& Get43() const; - const T& Get44() const; - - Matrix4& operator=(const Matrix4& m); - - Matrix4 operator+(const Matrix4& m) const; - const Matrix4& operator+=(const Matrix4& m); - - Matrix4 operator-(const Matrix4& m) const; - Matrix4 operator-() const; - const Matrix4& operator-=(const Matrix4& m); - - Matrix4 operator*(const Matrix4& m) const; - Matrix4 operator*(const T& v) const; - const Matrix4& operator*=(const Matrix4& m); - const Matrix4& operator*=(const T& v); - - Matrix4 operator/(const T& v) const; - const Matrix4& operator/=(const T& v); - - bool operator==(const Matrix4& m) const; - bool operator!=(const Matrix4& m) const; - - void SetZero(); - void SetIdentity(); - void SetPerspectiveProjection(const T& fov, const T& aspect, const T& nearPlane, const T& farPlane); - void SetOrthographicProjection(const T& left, const T& right, const T& bottom, const T& top, const T& nearPlane, const T& farPlane); - - void SetLookAt(const Vector3& eyePosition, const Vector3& lookAtPosition, Vector3 upVector = Vector3(T(0), T(1), T(0))); - - bool IsZero() const; - bool IsIdentity() const; - - void ApplyTranslation(const T& x, const T& y, const T& z); - void ApplyRotation(const T& angle, const T& x, const T& y, const T& z); - void ApplyScale(const T& x, const T& y, const T& z); - - Vector3 GetTranslation() const; - - const T* GetInternalValues() const; - T* GetInternalValues(); - std::string ToString(const std::string& lineBegin = "|", const std::string& lineEnd = "|\n") const; - - private: - union { - // column-major matrix - struct - { - T m_11, m_21, m_31, m_41, m_12, m_22, m_32, m_42, m_13, m_23, m_33, m_43, m_14, m_24, m_34, m_44; - }; - T m_values[16]; - }; -}; - -typedef Matrix4 Matrix4i; -typedef Matrix4 Matrix4f; -typedef Matrix4 Matrix4d; - -template -const Matrix4 Matrix4::ZERO = Matrix4(0); - -template -const Matrix4 Matrix4::IDENTITY = Matrix4( - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1); - - template -std::ostream& operator<<(std::ostream& out, const Matrix4& m) -{ - out << m.ToString(); - return out; -} - - template -Matrix4::Matrix4() -{ - // Leave matrix uninitialized -} - - template -Matrix4::Matrix4(const T& v) -{ - for(int i = 0; i < 16; ++i) - m_values[i] = v; -} - - template -Matrix4::Matrix4(const Matrix4& m) -{ - for(int i = 0; i < 16; ++i) - m_values[i] = m.m_values[i]; -} - - template -Matrix4::Matrix4(const T& m_11, const T& m_12, const T& m_13, const T& m_14, - const T& m_21, const T& m_22, const T& m_23, const T& m_24, - const T& m_31, const T& m_32, const T& m_33, const T& m_34, - const T& m_41, const T& m_42, const T& m_43, const T& m_44) -{ - this->m_11 = m_11; - this->m_12 = m_12; - this->m_13 = m_13; - this->m_14 = m_14; - this->m_21 = m_21; - this->m_22 = m_22; - this->m_23 = m_23; - this->m_24 = m_24; - this->m_31 = m_31; - this->m_32 = m_32; - this->m_33 = m_33; - this->m_34 = m_34; - this->m_41 = m_41; - this->m_42 = m_42; - this->m_43 = m_43; - this->m_44 = m_44; -} - -template -const T& Matrix4::Get11() const -{ - return m_11; -} - -template -const T& Matrix4::Get12() const -{ - return m_12; -} - -template -const T& Matrix4::Get13() const -{ - return m_13; -} - -template -const T& Matrix4::Get14() const -{ - return m_14; -} - -template -const T& Matrix4::Get21() const -{ - return m_21; -} - -template -const T& Matrix4::Get22() const -{ - return m_22; -} - -template -const T& Matrix4::Get23() const -{ - return m_23; -} - -template -const T& Matrix4::Get24() const -{ - return m_24; -} - -template -const T& Matrix4::Get31() const -{ - return m_31; -} - -template -const T& Matrix4::Get32() const -{ - return m_32; -} - -template -const T& Matrix4::Get33() const -{ - return m_33; -} - -template -const T& Matrix4::Get34() const -{ - return m_34; -} - -template -const T& Matrix4::Get41() const -{ - return m_41; -} - -template -const T& Matrix4::Get42() const -{ - return m_42; -} - -template -const T& Matrix4::Get43() const -{ - return m_43; -} - -template -const T& Matrix4::Get44() const -{ - return m_44; -} - - template -Matrix4& Matrix4::operator=(const Matrix4& m) -{ - if(this != &m) - { - for(int i = 0; i < 16; ++i) - m_values[i] = m.m_values[i]; - } - - return *this; -} - -template -Matrix4 Matrix4::operator+(const Matrix4& m) const -{ - return Matrix4( - m_11 + m.m_11, m_12 + m.m_12, m_13 + m.m_13, m_14 + m.m_14, - m_21 + m.m_21, m_22 + m.m_22, m_23 + m.m_23, m_24 + m.m_24, - m_31 + m.m_31, m_32 + m.m_32, m_33 + m.m_33, m_34 + m.m_34, - m_41 + m.m_41, m_42 + m.m_42, m_43 + m.m_43, m_44 + m.m_44); -} - - template -const Matrix4& Matrix4::operator+=(const Matrix4& m) -{ - *this = *this + m; - return *this; -} - -template -Matrix4 Matrix4::operator-(const Matrix4& m) const -{ - return Matrix4( - m_11 - m.m_11, m_12 - m.m_12, m_13 - m.m_13, m_14 - m.m_14, - m_21 - m.m_21, m_22 - m.m_22, m_23 - m.m_23, m_24 - m.m_24, - m_31 - m.m_31, m_32 - m.m_32, m_33 - m.m_33, m_34 - m.m_34, - m_41 - m.m_41, m_42 - m.m_42, m_43 - m.m_43, m_44 - m.m_44); -} - -template -Matrix4 Matrix4::operator-() const -{ - return Matrix4( - -m_11, -m_12, -m_13, -m_14, - -m_21, -m_22, -m_23, -m_24, - -m_31, -m_32, -m_33, -m_34, - -m_41, -m_42, -m_43, -m_44); -} - - template -const Matrix4& Matrix4::operator-=(const Matrix4& m) -{ - *this = *this - m; - return *this; -} - -template -Matrix4 Matrix4::operator*(const Matrix4& m) const -{ - return Matrix4( - m_11 * m.m_11 + m_12 * m.m_21 + m_13 * m.m_31 + m_14 * m.m_41, - m_11 * m.m_12 + m_12 * m.m_22 + m_13 * m.m_32 + m_14 * m.m_42, - m_11 * m.m_13 + m_12 * m.m_23 + m_13 * m.m_33 + m_14 * m.m_43, - m_11 * m.m_14 + m_12 * m.m_24 + m_13 * m.m_34 + m_14 * m.m_44, - - m_21 * m.m_11 + m_22 * m.m_21 + m_23 * m.m_31 + m_24 * m.m_41, - m_21 * m.m_12 + m_22 * m.m_22 + m_23 * m.m_32 + m_24 * m.m_42, - m_21 * m.m_13 + m_22 * m.m_23 + m_23 * m.m_33 + m_24 * m.m_43, - m_21 * m.m_14 + m_22 * m.m_24 + m_23 * m.m_34 + m_24 * m.m_44, - - m_31 * m.m_11 + m_32 * m.m_21 + m_33 * m.m_31 + m_34 * m.m_41, - m_31 * m.m_12 + m_32 * m.m_22 + m_33 * m.m_32 + m_34 * m.m_42, - m_31 * m.m_13 + m_32 * m.m_23 + m_33 * m.m_33 + m_34 * m.m_43, - m_31 * m.m_14 + m_32 * m.m_24 + m_33 * m.m_34 + m_34 * m.m_44, - - m_41 * m.m_11 + m_42 * m.m_21 + m_43 * m.m_31 + m_44 * m.m_41, - m_41 * m.m_12 + m_42 * m.m_22 + m_43 * m.m_32 + m_44 * m.m_42, - m_41 * m.m_13 + m_42 * m.m_23 + m_43 * m.m_33 + m_44 * m.m_43, - m_41 * m.m_14 + m_42 * m.m_24 + m_43 * m.m_34 + m_44 * m.m_44); -} - -template -Matrix4 Matrix4::operator*(const T& v) const -{ - return Matrix4( - m_11 * v, m_12 * v, m_13 * v, m_14 * v, - m_21 * v, m_22 * v, m_23 * v, m_24 * v, - m_31 * v, m_32 * v, m_33 * v, m_34 * v, - m_41 * v, m_42 * v, m_43 * v, m_44 * v); -} - - template -const Matrix4& Matrix4::operator*=(const Matrix4& m) -{ - *this = *this * m; - return *this; -} - - template -const Matrix4& Matrix4::operator*=(const T& v) -{ - *this = *this * v; - return *this; -} - -template -Matrix4 Matrix4::operator/(const T& v) const -{ - return Matrix4( - m_11 / v, m_12 / v, m_13 / v, m_14 / v, - m_21 / v, m_22 / v, m_23 / v, m_24 / v, - m_31 / v, m_32 / v, m_33 / v, m_34 / v, - m_41 / v, m_42 / v, m_43 / v, m_44 / v); -} - - template -const Matrix4& Matrix4::operator/=(const T& v) -{ - *this = *this / v; - return *this; -} - -template -bool Matrix4::operator==(const Matrix4& m) const -{ - for(int i = 0; i < 16; ++i) - if(m_values[i] != m.m_values[i]) - return false; - - return true; -} - -template -bool Matrix4::operator!=(const Matrix4& m) const -{ - return !(*this == m); -} - - template -void Matrix4::SetZero() -{ - *this = ZERO; -} - - template -void Matrix4::SetIdentity() -{ - *this = IDENTITY; -} - - template -void Matrix4::SetPerspectiveProjection(const T& fov, const T& aspect, const T& nearPlane, const T& farPlane) -{ - const float h = T(1) / tan(fov * T(M_PI / 360.f)); - T negDepth = nearPlane - farPlane; - - SetZero(); - - m_11 = h / aspect; - m_22 = h; - m_33 = (farPlane + nearPlane) / negDepth; - m_34 = T(2) * (nearPlane * farPlane) / negDepth; - m_43 = -T(1); -} - - template -void Matrix4::SetOrthographicProjection(const T& left, const T& right, const T& bottom, const T& top, const T& nearPlane, const T& farPlane) -{ - m_11 = T(2) / (right - left); - m_12 = T(0); - m_13 = T(0); - m_14 = -(right + left) / (right - left); - - m_21 = T(0); - m_22 = T(2) / (top - bottom); - m_23 = T(0); - m_24 = -(top + bottom) / (top - bottom); - - m_31 = T(0); - m_32 = T(0); - m_33 = -T(2) / (farPlane - nearPlane); - m_34 = -(farPlane + nearPlane) / (farPlane - nearPlane); - - m_41 = T(0); - m_42 = T(0); - m_43 = T(0); - m_44 = T(1); -} - - template -void Matrix4::SetLookAt(const Vector3& eyePosition, const Vector3& lookAtPosition, Vector3 upVector) -{ - Vector3f L = lookAtPosition - eyePosition; - L.Normalize(); - - upVector.Normalize(); - Vector3f S = L.Cross(upVector); - S.Normalize(); - - Vector3f U = S.Cross(L); - - Matrix4 M; - M.m_11 = S.x; - M.m_12 = S.y; - M.m_13 = S.z; - M.m_14 = 0; - - M.m_21 = U.x; - M.m_22 = U.y; - M.m_23 = U.z; - M.m_24 = 0; - - M.m_31 = -L.x; - M.m_32 = -L.y; - M.m_33 = -L.z; - M.m_34 = 0; - - M.m_41 = 0; - M.m_42 = 0; - M.m_43 = 0; - M.m_44 = 1.f; - - SetIdentity(); - *this *= M; - ApplyTranslation(-eyePosition.x, -eyePosition.y, -eyePosition.z); -} - - template -void Matrix4::ApplyTranslation(const T& x, const T& y, const T& z) -{ - Matrix4 tmp( - 1, 0, 0, x, - 0, 1, 0, y, - 0, 0, 1, z, - 0, 0, 0, 1); - - *this *= tmp; -} - - template -void Matrix4::ApplyRotation(const T& angle, const T& x, const T& y, const T& z) -{ - // TODO axis (x, y, z) must be normalized... - - T s = sin(DEGTORAD(angle)); - T c = cos(DEGTORAD(angle)); - T ic = T(1) - c; - - Matrix4 tmp( - x * x * ic + c, y * x * ic + (z * s), z * x * ic - (y * s), 0, - x * y * ic - (z * s), y * y * ic + c, z * y * ic + (x * s), 0, - x * z * ic + (y * s), y * z * ic - (x * s), z * z * ic + c, 0, - 0, 0, 0, 1); - - *this *= tmp; -} - - template -void Matrix4::ApplyScale(const T& x, const T& y, const T& z) -{ - Matrix4 tmp( - x, 0, 0, 0, - 0, y, 0, 0, - 0, 0, z, 0, - 0, 0, 0, 1); - - *this *= tmp; -} - -template -Vector3 Matrix4::GetTranslation() const -{ - // NOTE: Works only if the matrix doesn't contains scale information (only rotation and translation) - // Reference: http://www.gamedev.net/topic/397751-how-to-get-camera-position/ - T x = -(m_11 * m_14 + m_21 * m_24 + m_31 * m_34); - T y = -(m_12 * m_14 + m_22 * m_24 + m_32 * m_34); - T z = -(m_13 * m_14 + m_23 * m_24 + m_33 * m_34); - - return Vector3(x, y, z); -} - - template -T* Matrix4::GetInternalValues() -{ - return m_values; -} - -template -const T* Matrix4::GetInternalValues() const -{ - return m_values; -} - -template -std::string Matrix4::ToString(const std::string& lineBegin, const std::string& lineEnd) const -{ - std::ostringstream ss; - ss << lineBegin << m_11 << " " << m_12 << " " << m_13 << " " << m_14 << lineEnd; - ss << lineBegin << m_21 << " " << m_22 << " " << m_23 << " " << m_24 << lineEnd; - ss << lineBegin << m_31 << " " << m_32 << " " << m_33 << " " << m_34 << lineEnd; - ss << lineBegin << m_41 << " " << m_42 << " " << m_43 << " " << m_44 << lineEnd; - - return ss.str(); -} - -#endif // MATRIX4_H__ diff --git a/SQCSim2021/opensimplex.cpp b/SQCSim2021/opensimplex.cpp deleted file mode 100644 index a64d31f..0000000 --- a/SQCSim2021/opensimplex.cpp +++ /dev/null @@ -1,2542 +0,0 @@ -#include "opensimplex.h" - -#include -namespace OpenSimplexNoise -{ - using namespace std; - - Noise::Noise() - : m_stretch2d(-0.211324865405187) //(1/Math.sqrt(2+1)-1)/2; - , m_squish2d(0.366025403784439) //(Math.sqrt(2+1)-1)/2; - , m_stretch3d(-1.0 / 6) //(1/Math.sqrt(3+1)-1)/3; - , m_squish3d(1.0 / 3) //(Math.sqrt(3+1)-1)/3; - , m_stretch4d(-0.138196601125011) //(1/Math.sqrt(4+1)-1)/4; - , m_squish4d(0.309016994374947) //(Math.sqrt(4+1)-1)/4; - , m_norm2d(47) - , m_norm3d(103) - , m_norm4d(30) - , m_defaultSeed(0) - , m_perm{0} - , m_permGradIndex3d{0} - , m_gradients2d{ 5, 2, 2, 5, - -5, 2, -2, 5, - 5, -2, 2, -5, - -5, -2, -2, -5, } - , m_gradients3d{-11, 4, 4, -4, 11, 4, -4, 4, 11, - 11, 4, 4, 4, 11, 4, 4, 4, 11, - -11, -4, 4, -4, -11, 4, -4, -4, 11, - 11, -4, 4, 4, -11, 4, 4, -4, 11, - -11, 4, -4, -4, 11, -4, -4, 4, -11, - 11, 4, -4, 4, 11, -4, 4, 4, -11, - -11, -4, -4, -4, -11, -4, -4, -4, -11, - 11, -4, -4, 4, -11, -4, 4, -4, -11, } - , m_gradients4d{ 3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3, - -3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3, - 3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3, - -3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3, 1, -1, -1, 1, 3, - 3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3, - -3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3, - 3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3, - -3, -1, -1, 1, -1, -3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3, - 3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3, - -3, 1, 1, -1, -1, 3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3, - 3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3, - -3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3, - 3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3, - -3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3, - 3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3, -1, 1, -1, -1, -3, - -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3, } - { - } - - Noise::Noise(int64_t seed) - : Noise() - { - short source[256]; - for (short i = 0; i < 256; i++) - { - source[i] = i; - } - seed = seed * 6364136223846793005l + 1442695040888963407l; - seed = seed * 6364136223846793005l + 1442695040888963407l; - seed = seed * 6364136223846793005l + 1442695040888963407l; - for (int i = 255; i >= 0; i--) - { - seed = seed * 6364136223846793005l + 1442695040888963407l; - int r = static_cast((seed + 31) % (i + 1)); - if (r < 0) - { - r += (i + 1); - } - m_perm[i] = source[r]; - m_permGradIndex3d[i] = static_cast((m_perm[i] % (m_gradients3d.size() / 3)) * 3); - source[r] = source[i]; - } - } - - double Noise::eval(double x, double y) const - { - //Place input coordinates onto grid. - double stretchOffset = (x + y) * m_stretch2d; - double xs = x + stretchOffset; - double ys = y + stretchOffset; - - //Floor to get grid coordinates of rhombus (stretched square) super-cell origin. - int xsb = static_cast(floor(xs)); - int ysb = static_cast(floor(ys)); - - //Skew out to get actual coordinates of rhombus origin. We'll need these later. - double squishOffset = (xsb + ysb) * m_squish2d; - double xb = xsb + squishOffset; - double yb = ysb + squishOffset; - - //Compute grid coordinates relative to rhombus origin. - double xins = xs - xsb; - double yins = ys - ysb; - - //Sum those together to get a value that determines which region we're in. - double inSum = xins + yins; - - //Positions relative to origin point. - double dx0 = x - xb; - double dy0 = y - yb; - - //We'll be defining these inside the next block and using them afterwards. - double dx_ext, dy_ext; - int xsv_ext, ysv_ext; - - double value = 0; - - //Contribution (1,0) - double dx1 = dx0 - 1 - m_squish2d; - double dy1 = dy0 - 0 - m_squish2d; - double attn1 = 2 - dx1 * dx1 - dy1 * dy1; - if (attn1 > 0) - { - attn1 *= attn1; - value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, dx1, dy1); - } - - //Contribution (0,1) - double dx2 = dx0 - 0 - m_squish2d; - double dy2 = dy0 - 1 - m_squish2d; - double attn2 = 2 - dx2 * dx2 - dy2 * dy2; - if (attn2 > 0) - { - attn2 *= attn2; - value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, dx2, dy2); - } - - if (inSum <= 1) - { //We're inside the triangle (2-Simplex) at (0,0) - double zins = 1 - inSum; - if (zins > xins || zins > yins) - { //(0,0) is one of the closest two triangular vertices - if (xins > yins) - { - xsv_ext = xsb + 1; - ysv_ext = ysb - 1; - dx_ext = dx0 - 1; - dy_ext = dy0 + 1; - } - else - { - xsv_ext = xsb - 1; - ysv_ext = ysb + 1; - dx_ext = dx0 + 1; - dy_ext = dy0 - 1; - } - } - else - { //(1,0) and (0,1) are the closest two vertices. - xsv_ext = xsb + 1; - ysv_ext = ysb + 1; - dx_ext = dx0 - 1 - 2 * m_squish2d; - dy_ext = dy0 - 1 - 2 * m_squish2d; - } - } - else - { //We're inside the triangle (2-Simplex) at (1,1) - double zins = 2 - inSum; - if (zins < xins || zins < yins) - { //(0,0) is one of the closest two triangular vertices - if (xins > yins) - { - xsv_ext = xsb + 2; - ysv_ext = ysb + 0; - dx_ext = dx0 - 2 - 2 * m_squish2d; - dy_ext = dy0 + 0 - 2 * m_squish2d; - } - else - { - xsv_ext = xsb + 0; - ysv_ext = ysb + 2; - dx_ext = dx0 + 0 - 2 * m_squish2d; - dy_ext = dy0 - 2 - 2 * m_squish2d; - } - } - else - { //(1,0) and (0,1) are the closest two vertices. - dx_ext = dx0; - dy_ext = dy0; - xsv_ext = xsb; - ysv_ext = ysb; - } - xsb += 1; - ysb += 1; - dx0 = dx0 - 1 - 2 * m_squish2d; - dy0 = dy0 - 1 - 2 * m_squish2d; - } - - //Contribution (0,0) or (1,1) - double attn0 = 2 - dx0 * dx0 - dy0 * dy0; - if (attn0 > 0) - { - attn0 *= attn0; - value += attn0 * attn0 * extrapolate(xsb, ysb, dx0, dy0); - } - - //Extra Vertex - double attn_ext = 2 - dx_ext * dx_ext - dy_ext * dy_ext; - if (attn_ext > 0) - { - attn_ext *= attn_ext; - value += attn_ext * attn_ext * extrapolate(xsv_ext, ysv_ext, dx_ext, dy_ext); - } - - return value / m_norm2d; - } - - double Noise::eval(double x, double y, double z) const - { - //Place input coordinates on simplectic honeycomb. - double stretchOffset = (x + y + z) * m_stretch3d; - double xs = x + stretchOffset; - double ys = y + stretchOffset; - double zs = z + stretchOffset; - - //static_cast(floor to get simplectic honeycomb coordinates of rhombohedron (stretched cube) super-cell origin. - int xsb = static_cast(floor(xs)); - int ysb = static_cast(floor(ys)); - int zsb = static_cast(floor(zs)); - - //Skew out to get actual coordinates of rhombohedron origin. We'll need these later. - double squishOffset = (xsb + ysb + zsb) * m_squish3d; - double xb = xsb + squishOffset; - double yb = ysb + squishOffset; - double zb = zsb + squishOffset; - - //Compute simplectic honeycomb coordinates relative to rhombohedral origin. - double xins = xs - xsb; - double yins = ys - ysb; - double zins = zs - zsb; - - //Sum those together to get a value that determines which region we're in. - double inSum = xins + yins + zins; - - //Positions relative to origin point. - double dx0 = x - xb; - double dy0 = y - yb; - double dz0 = z - zb; - - //We'll be defining these inside the next block and using them afterwards. - double dx_ext0, dy_ext0, dz_ext0; - double dx_ext1, dy_ext1, dz_ext1; - int xsv_ext0, ysv_ext0, zsv_ext0; - int xsv_ext1, ysv_ext1, zsv_ext1; - - double value = 0; - if (inSum <= 1) - { //We're inside the tetrahedron (3-Simplex) at (0,0,0) - -//Determine which two of (0,0,1), (0,1,0), (1,0,0) are closest. - char aPoint = 0x01; - double aScore = xins; - char bPoint = 0x02; - double bScore = yins; - if (aScore >= bScore && zins > bScore) - { - bScore = zins; - bPoint = 0x04; - } - else if (aScore < bScore && zins > aScore) - { - aScore = zins; - aPoint = 0x04; - } - - //Now we determine the two lattice points not part of the tetrahedron that may contribute. - //This depends on the closest two tetrahedral vertices, including (0,0,0) - double wins = 1 - inSum; - if (wins > aScore || wins > bScore) - { //(0,0,0) is one of the closest two tetrahedral vertices. - char c = (bScore > aScore ? bPoint : aPoint); //Our other closest vertex is the closest out of a and b. - - if ((c & 0x01) == 0) - { - xsv_ext0 = xsb - 1; - xsv_ext1 = xsb; - dx_ext0 = dx0 + 1; - dx_ext1 = dx0; - } - else - { - xsv_ext0 = xsv_ext1 = xsb + 1; - dx_ext0 = dx_ext1 = dx0 - 1; - } - - if ((c & 0x02) == 0) - { - ysv_ext0 = ysv_ext1 = ysb; - dy_ext0 = dy_ext1 = dy0; - if ((c & 0x01) == 0) - { - ysv_ext1 -= 1; - dy_ext1 += 1; - } - else - { - ysv_ext0 -= 1; - dy_ext0 += 1; - } - } - else - { - ysv_ext0 = ysv_ext1 = ysb + 1; - dy_ext0 = dy_ext1 = dy0 - 1; - } - - if ((c & 0x04) == 0) - { - zsv_ext0 = zsb; - zsv_ext1 = zsb - 1; - dz_ext0 = dz0; - dz_ext1 = dz0 + 1; - } - else - { - zsv_ext0 = zsv_ext1 = zsb + 1; - dz_ext0 = dz_ext1 = dz0 - 1; - } - } - else - { //(0,0,0) is not one of the closest two tetrahedral vertices. - char c = static_cast(aPoint | bPoint); //Our two extra vertices are determined by the closest two. - - if ((c & 0x01) == 0) - { - xsv_ext0 = xsb; - xsv_ext1 = xsb - 1; - dx_ext0 = dx0 - 2 * m_squish3d; - dx_ext1 = dx0 + 1 - m_squish3d; - } - else - { - xsv_ext0 = xsv_ext1 = xsb + 1; - dx_ext0 = dx0 - 1 - 2 * m_squish3d; - dx_ext1 = dx0 - 1 - m_squish3d; - } - - if ((c & 0x02) == 0) - { - ysv_ext0 = ysb; - ysv_ext1 = ysb - 1; - dy_ext0 = dy0 - 2 * m_squish3d; - dy_ext1 = dy0 + 1 - m_squish3d; - } - else - { - ysv_ext0 = ysv_ext1 = ysb + 1; - dy_ext0 = dy0 - 1 - 2 * m_squish3d; - dy_ext1 = dy0 - 1 - m_squish3d; - } - - if ((c & 0x04) == 0) - { - zsv_ext0 = zsb; - zsv_ext1 = zsb - 1; - dz_ext0 = dz0 - 2 * m_squish3d; - dz_ext1 = dz0 + 1 - m_squish3d; - } - else - { - zsv_ext0 = zsv_ext1 = zsb + 1; - dz_ext0 = dz0 - 1 - 2 * m_squish3d; - dz_ext1 = dz0 - 1 - m_squish3d; - } - } - - //Contribution (0,0,0) - double attn0 = 2 - dx0 * dx0 - dy0 * dy0 - dz0 * dz0; - if (attn0 > 0) - { - attn0 *= attn0; - value += attn0 * attn0 * extrapolate(xsb + 0, ysb + 0, zsb + 0, dx0, dy0, dz0); - } - - //Contribution (1,0,0) - double dx1 = dx0 - 1 - m_squish3d; - double dy1 = dy0 - 0 - m_squish3d; - double dz1 = dz0 - 0 - m_squish3d; - double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1; - if (attn1 > 0) - { - attn1 *= attn1; - value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, zsb + 0, dx1, dy1, dz1); - } - - //Contribution (0,1,0) - double dx2 = dx0 - 0 - m_squish3d; - double dy2 = dy0 - 1 - m_squish3d; - double dz2 = dz1; - double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2; - if (attn2 > 0) - { - attn2 *= attn2; - value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, zsb + 0, dx2, dy2, dz2); - } - - //Contribution (0,0,1) - double dx3 = dx2; - double dy3 = dy1; - double dz3 = dz0 - 1 - m_squish3d; - double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3; - if (attn3 > 0) - { - attn3 *= attn3; - value += attn3 * attn3 * extrapolate(xsb + 0, ysb + 0, zsb + 1, dx3, dy3, dz3); - } - } - else if (inSum >= 2) - { //We're inside the tetrahedron (3-Simplex) at (1,1,1) - -//Determine which two tetrahedral vertices are the closest, out of (1,1,0), (1,0,1), (0,1,1) but not (1,1,1). - char aPoint = 0x06; - double aScore = xins; - char bPoint = 0x05; - double bScore = yins; - if (aScore <= bScore && zins < bScore) - { - bScore = zins; - bPoint = 0x03; - } - else if (aScore > bScore && zins < aScore) - { - aScore = zins; - aPoint = 0x03; - } - - //Now we determine the two lattice points not part of the tetrahedron that may contribute. - //This depends on the closest two tetrahedral vertices, including (1,1,1) - double wins = 3 - inSum; - if (wins < aScore || wins < bScore) - { //(1,1,1) is one of the closest two tetrahedral vertices. - char c = (bScore < aScore ? bPoint : aPoint); //Our other closest vertex is the closest out of a and b. - - if ((c & 0x01) != 0) - { - xsv_ext0 = xsb + 2; - xsv_ext1 = xsb + 1; - dx_ext0 = dx0 - 2 - 3 * m_squish3d; - dx_ext1 = dx0 - 1 - 3 * m_squish3d; - } - else - { - xsv_ext0 = xsv_ext1 = xsb; - dx_ext0 = dx_ext1 = dx0 - 3 * m_squish3d; - } - - if ((c & 0x02) != 0) - { - ysv_ext0 = ysv_ext1 = ysb + 1; - dy_ext0 = dy_ext1 = dy0 - 1 - 3 * m_squish3d; - if ((c & 0x01) != 0) - { - ysv_ext1 += 1; - dy_ext1 -= 1; - } - else - { - ysv_ext0 += 1; - dy_ext0 -= 1; - } - } - else - { - ysv_ext0 = ysv_ext1 = ysb; - dy_ext0 = dy_ext1 = dy0 - 3 * m_squish3d; - } - - if ((c & 0x04) != 0) - { - zsv_ext0 = zsb + 1; - zsv_ext1 = zsb + 2; - dz_ext0 = dz0 - 1 - 3 * m_squish3d; - dz_ext1 = dz0 - 2 - 3 * m_squish3d; - } - else - { - zsv_ext0 = zsv_ext1 = zsb; - dz_ext0 = dz_ext1 = dz0 - 3 * m_squish3d; - } - } - else - { //(1,1,1) is not one of the closest two tetrahedral vertices. - char c = static_cast(aPoint & bPoint); //Our two extra vertices are determined by the closest two. - - if ((c & 0x01) != 0) - { - xsv_ext0 = xsb + 1; - xsv_ext1 = xsb + 2; - dx_ext0 = dx0 - 1 - m_squish3d; - dx_ext1 = dx0 - 2 - 2 * m_squish3d; - } - else - { - xsv_ext0 = xsv_ext1 = xsb; - dx_ext0 = dx0 - m_squish3d; - dx_ext1 = dx0 - 2 * m_squish3d; - } - - if ((c & 0x02) != 0) - { - ysv_ext0 = ysb + 1; - ysv_ext1 = ysb + 2; - dy_ext0 = dy0 - 1 - m_squish3d; - dy_ext1 = dy0 - 2 - 2 * m_squish3d; - } - else - { - ysv_ext0 = ysv_ext1 = ysb; - dy_ext0 = dy0 - m_squish3d; - dy_ext1 = dy0 - 2 * m_squish3d; - } - - if ((c & 0x04) != 0) - { - zsv_ext0 = zsb + 1; - zsv_ext1 = zsb + 2; - dz_ext0 = dz0 - 1 - m_squish3d; - dz_ext1 = dz0 - 2 - 2 * m_squish3d; - } - else - { - zsv_ext0 = zsv_ext1 = zsb; - dz_ext0 = dz0 - m_squish3d; - dz_ext1 = dz0 - 2 * m_squish3d; - } - } - - //Contribution (1,1,0) - double dx3 = dx0 - 1 - 2 * m_squish3d; - double dy3 = dy0 - 1 - 2 * m_squish3d; - double dz3 = dz0 - 0 - 2 * m_squish3d; - double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3; - if (attn3 > 0) - { - attn3 *= attn3; - value += attn3 * attn3 * extrapolate(xsb + 1, ysb + 1, zsb + 0, dx3, dy3, dz3); - } - - //Contribution (1,0,1) - double dx2 = dx3; - double dy2 = dy0 - 0 - 2 * m_squish3d; - double dz2 = dz0 - 1 - 2 * m_squish3d; - double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2; - if (attn2 > 0) - { - attn2 *= attn2; - value += attn2 * attn2 * extrapolate(xsb + 1, ysb + 0, zsb + 1, dx2, dy2, dz2); - } - - //Contribution (0,1,1) - double dx1 = dx0 - 0 - 2 * m_squish3d; - double dy1 = dy3; - double dz1 = dz2; - double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1; - if (attn1 > 0) - { - attn1 *= attn1; - value += attn1 * attn1 * extrapolate(xsb + 0, ysb + 1, zsb + 1, dx1, dy1, dz1); - } - - //Contribution (1,1,1) - dx0 = dx0 - 1 - 3 * m_squish3d; - dy0 = dy0 - 1 - 3 * m_squish3d; - dz0 = dz0 - 1 - 3 * m_squish3d; - double attn0 = 2 - dx0 * dx0 - dy0 * dy0 - dz0 * dz0; - if (attn0 > 0) - { - attn0 *= attn0; - value += attn0 * attn0 * extrapolate(xsb + 1, ysb + 1, zsb + 1, dx0, dy0, dz0); - } - } - else - { //We're inside the octahedron (Rectified 3-Simplex) in between. - double aScore; - char aPoint; - bool aIsFurtherSide; - double bScore; - char bPoint; - bool bIsFurtherSide; - - //Decide between point (0,0,1) and (1,1,0) as closest - double p1 = xins + yins; - if (p1 > 1) - { - aScore = p1 - 1; - aPoint = 0x03; - aIsFurtherSide = true; - } - else - { - aScore = 1 - p1; - aPoint = 0x04; - aIsFurtherSide = false; - } - - //Decide between point (0,1,0) and (1,0,1) as closest - double p2 = xins + zins; - if (p2 > 1) - { - bScore = p2 - 1; - bPoint = 0x05; - bIsFurtherSide = true; - } - else - { - bScore = 1 - p2; - bPoint = 0x02; - bIsFurtherSide = false; - } - - //The closest out of the two (1,0,0) and (0,1,1) will replace the furthest out of the two decided above, if closer. - double p3 = yins + zins; - if (p3 > 1) - { - double score = p3 - 1; - if (aScore <= bScore && aScore < score) - { - aScore = score; - aPoint = 0x06; - aIsFurtherSide = true; - } - else if (aScore > bScore && bScore < score) - { - bScore = score; - bPoint = 0x06; - bIsFurtherSide = true; - } - } - else - { - double score = 1 - p3; - if (aScore <= bScore && aScore < score) - { - aScore = score; - aPoint = 0x01; - aIsFurtherSide = false; - } - else if (aScore > bScore && bScore < score) - { - bScore = score; - bPoint = 0x01; - bIsFurtherSide = false; - } - } - - //Where each of the two closest points are determines how the extra two vertices are calculated. - if (aIsFurtherSide == bIsFurtherSide) - { - if (aIsFurtherSide) - { //Both closest points on (1,1,1) side - -//One of the two extra points is (1,1,1) - dx_ext0 = dx0 - 1 - 3 * m_squish3d; - dy_ext0 = dy0 - 1 - 3 * m_squish3d; - dz_ext0 = dz0 - 1 - 3 * m_squish3d; - xsv_ext0 = xsb + 1; - ysv_ext0 = ysb + 1; - zsv_ext0 = zsb + 1; - - //Other extra point is based on the shared axis. - char c = static_cast(aPoint & bPoint); - if ((c & 0x01) != 0) - { - dx_ext1 = dx0 - 2 - 2 * m_squish3d; - dy_ext1 = dy0 - 2 * m_squish3d; - dz_ext1 = dz0 - 2 * m_squish3d; - xsv_ext1 = xsb + 2; - ysv_ext1 = ysb; - zsv_ext1 = zsb; - } - else if ((c & 0x02) != 0) - { - dx_ext1 = dx0 - 2 * m_squish3d; - dy_ext1 = dy0 - 2 - 2 * m_squish3d; - dz_ext1 = dz0 - 2 * m_squish3d; - xsv_ext1 = xsb; - ysv_ext1 = ysb + 2; - zsv_ext1 = zsb; - } - else - { - dx_ext1 = dx0 - 2 * m_squish3d; - dy_ext1 = dy0 - 2 * m_squish3d; - dz_ext1 = dz0 - 2 - 2 * m_squish3d; - xsv_ext1 = xsb; - ysv_ext1 = ysb; - zsv_ext1 = zsb + 2; - } - } - else - {//Both closest points on (0,0,0) side - - //One of the two extra points is (0,0,0) - dx_ext0 = dx0; - dy_ext0 = dy0; - dz_ext0 = dz0; - xsv_ext0 = xsb; - ysv_ext0 = ysb; - zsv_ext0 = zsb; - - //Other extra point is based on the omitted axis. - char c = static_cast(aPoint | bPoint); - if ((c & 0x01) == 0) - { - dx_ext1 = dx0 + 1 - m_squish3d; - dy_ext1 = dy0 - 1 - m_squish3d; - dz_ext1 = dz0 - 1 - m_squish3d; - xsv_ext1 = xsb - 1; - ysv_ext1 = ysb + 1; - zsv_ext1 = zsb + 1; - } - else if ((c & 0x02) == 0) - { - dx_ext1 = dx0 - 1 - m_squish3d; - dy_ext1 = dy0 + 1 - m_squish3d; - dz_ext1 = dz0 - 1 - m_squish3d; - xsv_ext1 = xsb + 1; - ysv_ext1 = ysb - 1; - zsv_ext1 = zsb + 1; - } - else - { - dx_ext1 = dx0 - 1 - m_squish3d; - dy_ext1 = dy0 - 1 - m_squish3d; - dz_ext1 = dz0 + 1 - m_squish3d; - xsv_ext1 = xsb + 1; - ysv_ext1 = ysb + 1; - zsv_ext1 = zsb - 1; - } - } - } - else - { //One point on (0,0,0) side, one point on (1,1,1) side - char c1, c2; - if (aIsFurtherSide) - { - c1 = aPoint; - c2 = bPoint; - } - else - { - c1 = bPoint; - c2 = aPoint; - } - - //One contribution is a permutation of (1,1,-1) - if ((c1 & 0x01) == 0) - { - dx_ext0 = dx0 + 1 - m_squish3d; - dy_ext0 = dy0 - 1 - m_squish3d; - dz_ext0 = dz0 - 1 - m_squish3d; - xsv_ext0 = xsb - 1; - ysv_ext0 = ysb + 1; - zsv_ext0 = zsb + 1; - } - else if ((c1 & 0x02) == 0) - { - dx_ext0 = dx0 - 1 - m_squish3d; - dy_ext0 = dy0 + 1 - m_squish3d; - dz_ext0 = dz0 - 1 - m_squish3d; - xsv_ext0 = xsb + 1; - ysv_ext0 = ysb - 1; - zsv_ext0 = zsb + 1; - } - else - { - dx_ext0 = dx0 - 1 - m_squish3d; - dy_ext0 = dy0 - 1 - m_squish3d; - dz_ext0 = dz0 + 1 - m_squish3d; - xsv_ext0 = xsb + 1; - ysv_ext0 = ysb + 1; - zsv_ext0 = zsb - 1; - } - - //One contribution is a permutation of (0,0,2) - dx_ext1 = dx0 - 2 * m_squish3d; - dy_ext1 = dy0 - 2 * m_squish3d; - dz_ext1 = dz0 - 2 * m_squish3d; - xsv_ext1 = xsb; - ysv_ext1 = ysb; - zsv_ext1 = zsb; - if ((c2 & 0x01) != 0) - { - dx_ext1 -= 2; - xsv_ext1 += 2; - } - else if ((c2 & 0x02) != 0) - { - dy_ext1 -= 2; - ysv_ext1 += 2; - } - else - { - dz_ext1 -= 2; - zsv_ext1 += 2; - } - } - - //Contribution (1,0,0) - double dx1 = dx0 - 1 - m_squish3d; - double dy1 = dy0 - 0 - m_squish3d; - double dz1 = dz0 - 0 - m_squish3d; - double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1; - if (attn1 > 0) - { - attn1 *= attn1; - value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, zsb + 0, dx1, dy1, dz1); - } - - //Contribution (0,1,0) - double dx2 = dx0 - 0 - m_squish3d; - double dy2 = dy0 - 1 - m_squish3d; - double dz2 = dz1; - double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2; - if (attn2 > 0) - { - attn2 *= attn2; - value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, zsb + 0, dx2, dy2, dz2); - } - - //Contribution (0,0,1) - double dx3 = dx2; - double dy3 = dy1; - double dz3 = dz0 - 1 - m_squish3d; - double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3; - if (attn3 > 0) - { - attn3 *= attn3; - value += attn3 * attn3 * extrapolate(xsb + 0, ysb + 0, zsb + 1, dx3, dy3, dz3); - } - - //Contribution (1,1,0) - double dx4 = dx0 - 1 - 2 * m_squish3d; - double dy4 = dy0 - 1 - 2 * m_squish3d; - double dz4 = dz0 - 0 - 2 * m_squish3d; - double attn4 = 2 - dx4 * dx4 - dy4 * dy4 - dz4 * dz4; - if (attn4 > 0) - { - attn4 *= attn4; - value += attn4 * attn4 * extrapolate(xsb + 1, ysb + 1, zsb + 0, dx4, dy4, dz4); - } - - //Contribution (1,0,1) - double dx5 = dx4; - double dy5 = dy0 - 0 - 2 * m_squish3d; - double dz5 = dz0 - 1 - 2 * m_squish3d; - double attn5 = 2 - dx5 * dx5 - dy5 * dy5 - dz5 * dz5; - if (attn5 > 0) - { - attn5 *= attn5; - value += attn5 * attn5 * extrapolate(xsb + 1, ysb + 0, zsb + 1, dx5, dy5, dz5); - } - - //Contribution (0,1,1) - double dx6 = dx0 - 0 - 2 * m_squish3d; - double dy6 = dy4; - double dz6 = dz5; - double attn6 = 2 - dx6 * dx6 - dy6 * dy6 - dz6 * dz6; - if (attn6 > 0) - { - attn6 *= attn6; - value += attn6 * attn6 * extrapolate(xsb + 0, ysb + 1, zsb + 1, dx6, dy6, dz6); - } - } - - //First extra vertex - double attn_ext0 = 2 - dx_ext0 * dx_ext0 - dy_ext0 * dy_ext0 - dz_ext0 * dz_ext0; - if (attn_ext0 > 0) - { - attn_ext0 *= attn_ext0; - value += attn_ext0 * attn_ext0 * extrapolate(xsv_ext0, ysv_ext0, zsv_ext0, dx_ext0, dy_ext0, dz_ext0); - } - - //Second extra vertex - double attn_ext1 = 2 - dx_ext1 * dx_ext1 - dy_ext1 * dy_ext1 - dz_ext1 * dz_ext1; - if (attn_ext1 > 0) - { - attn_ext1 *= attn_ext1; - value += attn_ext1 * attn_ext1 * extrapolate(xsv_ext1, ysv_ext1, zsv_ext1, dx_ext1, dy_ext1, dz_ext1); - } - - return value / m_norm3d; - } - - double Noise::eval(double x, double y, double z, double w) const - { - //Place input coordinates on simplectic honeycomb. - double stretchOffset = (x + y + z + w) * m_stretch4d; - double xs = x + stretchOffset; - double ys = y + stretchOffset; - double zs = z + stretchOffset; - double ws = w + stretchOffset; - - //static_cast(floor to get simplectic honeycomb coordinates of rhombo-hypercube super-cell origin. - int xsb = static_cast(floor(xs)); - int ysb = static_cast(floor(ys)); - int zsb = static_cast(floor(zs)); - int wsb = static_cast(floor(ws)); - - //Skew out to get actual coordinates of stretched rhombo-hypercube origin. We'll need these later. - double squishOffset = (xsb + ysb + zsb + wsb) * m_squish4d; - double xb = xsb + squishOffset; - double yb = ysb + squishOffset; - double zb = zsb + squishOffset; - double wb = wsb + squishOffset; - - //Compute simplectic honeycomb coordinates relative to rhombo-hypercube origin. - double xins = xs - xsb; - double yins = ys - ysb; - double zins = zs - zsb; - double wins = ws - wsb; - - //Sum those together to get a value that determines which region we're in. - double inSum = xins + yins + zins + wins; - - //Positions relative to origin point. - double dx0 = x - xb; - double dy0 = y - yb; - double dz0 = z - zb; - double dw0 = w - wb; - - //We'll be defining these inside the next block and using them afterwards. - double dx_ext0, dy_ext0, dz_ext0, dw_ext0; - double dx_ext1, dy_ext1, dz_ext1, dw_ext1; - double dx_ext2, dy_ext2, dz_ext2, dw_ext2; - int xsv_ext0, ysv_ext0, zsv_ext0, wsv_ext0; - int xsv_ext1, ysv_ext1, zsv_ext1, wsv_ext1; - int xsv_ext2, ysv_ext2, zsv_ext2, wsv_ext2; - - double value = 0; - if (inSum <= 1) - { //We're inside the pentachoron (4-Simplex) at (0,0,0,0) - -//Determine which two of (0,0,0,1), (0,0,1,0), (0,1,0,0), (1,0,0,0) are closest. - char aPoint = 0x01; - double aScore = xins; - char bPoint = 0x02; - double bScore = yins; - if (aScore >= bScore && zins > bScore) - { - bScore = zins; - bPoint = 0x04; - } - else if (aScore < bScore && zins > aScore) - { - aScore = zins; - aPoint = 0x04; - } - if (aScore >= bScore && wins > bScore) - { - bScore = wins; - bPoint = 0x08; - } - else if (aScore < bScore && wins > aScore) - { - aScore = wins; - aPoint = 0x08; - } - - //Now we determine the three lattice points not part of the pentachoron that may contribute. - //This depends on the closest two pentachoron vertices, including (0,0,0,0) - double uins = 1 - inSum; - if (uins > aScore || uins > bScore) - { //(0,0,0,0) is one of the closest two pentachoron vertices. - char c = (bScore > aScore ? bPoint : aPoint); //Our other closest vertex is the closest out of a and b. - if ((c & 0x01) == 0) - { - xsv_ext0 = xsb - 1; - xsv_ext1 = xsv_ext2 = xsb; - dx_ext0 = dx0 + 1; - dx_ext1 = dx_ext2 = dx0; - } - else - { - xsv_ext0 = xsv_ext1 = xsv_ext2 = xsb + 1; - dx_ext0 = dx_ext1 = dx_ext2 = dx0 - 1; - } - - if ((c & 0x02) == 0) - { - ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb; - dy_ext0 = dy_ext1 = dy_ext2 = dy0; - if ((c & 0x01) == 0x01) - { - ysv_ext0 -= 1; - dy_ext0 += 1; - } - else - { - ysv_ext1 -= 1; - dy_ext1 += 1; - } - } - else - { - ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb + 1; - dy_ext0 = dy_ext1 = dy_ext2 = dy0 - 1; - } - - if ((c & 0x04) == 0) - { - zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb; - dz_ext0 = dz_ext1 = dz_ext2 = dz0; - if ((c & 0x03) != 0) - { - if ((c & 0x03) == 0x03) - { - zsv_ext0 -= 1; - dz_ext0 += 1; - } - else - { - zsv_ext1 -= 1; - dz_ext1 += 1; - } - } - else - { - zsv_ext2 -= 1; - dz_ext2 += 1; - } - } - else - { - zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb + 1; - dz_ext0 = dz_ext1 = dz_ext2 = dz0 - 1; - } - - if ((c & 0x08) == 0) - { - wsv_ext0 = wsv_ext1 = wsb; - wsv_ext2 = wsb - 1; - dw_ext0 = dw_ext1 = dw0; - dw_ext2 = dw0 + 1; - } - else - { - wsv_ext0 = wsv_ext1 = wsv_ext2 = wsb + 1; - dw_ext0 = dw_ext1 = dw_ext2 = dw0 - 1; - } - } - else - { //(0,0,0,0) is not one of the closest two pentachoron vertices. - char c = static_cast(aPoint | bPoint); //Our three extra vertices are determined by the closest two. - - if ((c & 0x01) == 0) - { - xsv_ext0 = xsv_ext2 = xsb; - xsv_ext1 = xsb - 1; - dx_ext0 = dx0 - 2 * m_squish4d; - dx_ext1 = dx0 + 1 - m_squish4d; - dx_ext2 = dx0 - m_squish4d; - } - else - { - xsv_ext0 = xsv_ext1 = xsv_ext2 = xsb + 1; - dx_ext0 = dx0 - 1 - 2 * m_squish4d; - dx_ext1 = dx_ext2 = dx0 - 1 - m_squish4d; - } - - if ((c & 0x02) == 0) - { - ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb; - dy_ext0 = dy0 - 2 * m_squish4d; - dy_ext1 = dy_ext2 = dy0 - m_squish4d; - if ((c & 0x01) == 0x01) - { - ysv_ext1 -= 1; - dy_ext1 += 1; - } - else - { - ysv_ext2 -= 1; - dy_ext2 += 1; - } - } - else - { - ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb + 1; - dy_ext0 = dy0 - 1 - 2 * m_squish4d; - dy_ext1 = dy_ext2 = dy0 - 1 - m_squish4d; - } - - if ((c & 0x04) == 0) - { - zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb; - dz_ext0 = dz0 - 2 * m_squish4d; - dz_ext1 = dz_ext2 = dz0 - m_squish4d; - if ((c & 0x03) == 0x03) - { - zsv_ext1 -= 1; - dz_ext1 += 1; - } - else - { - zsv_ext2 -= 1; - dz_ext2 += 1; - } - } - else - { - zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb + 1; - dz_ext0 = dz0 - 1 - 2 * m_squish4d; - dz_ext1 = dz_ext2 = dz0 - 1 - m_squish4d; - } - - if ((c & 0x08) == 0) - { - wsv_ext0 = wsv_ext1 = wsb; - wsv_ext2 = wsb - 1; - dw_ext0 = dw0 - 2 * m_squish4d; - dw_ext1 = dw0 - m_squish4d; - dw_ext2 = dw0 + 1 - m_squish4d; - } - else - { - wsv_ext0 = wsv_ext1 = wsv_ext2 = wsb + 1; - dw_ext0 = dw0 - 1 - 2 * m_squish4d; - dw_ext1 = dw_ext2 = dw0 - 1 - m_squish4d; - } - } - - //Contribution (0,0,0,0) - double attn0 = 2 - dx0 * dx0 - dy0 * dy0 - dz0 * dz0 - dw0 * dw0; - if (attn0 > 0) - { - attn0 *= attn0; - value += attn0 * attn0 * extrapolate(xsb + 0, ysb + 0, zsb + 0, wsb + 0, dx0, dy0, dz0, dw0); - } - - //Contribution (1,0,0,0) - double dx1 = dx0 - 1 - m_squish4d; - double dy1 = dy0 - 0 - m_squish4d; - double dz1 = dz0 - 0 - m_squish4d; - double dw1 = dw0 - 0 - m_squish4d; - double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1 - dw1 * dw1; - if (attn1 > 0) - { - attn1 *= attn1; - value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, zsb + 0, wsb + 0, dx1, dy1, dz1, dw1); - } - - //Contribution (0,1,0,0) - double dx2 = dx0 - 0 - m_squish4d; - double dy2 = dy0 - 1 - m_squish4d; - double dz2 = dz1; - double dw2 = dw1; - double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2 - dw2 * dw2; - if (attn2 > 0) - { - attn2 *= attn2; - value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, zsb + 0, wsb + 0, dx2, dy2, dz2, dw2); - } - - //Contribution (0,0,1,0) - double dx3 = dx2; - double dy3 = dy1; - double dz3 = dz0 - 1 - m_squish4d; - double dw3 = dw1; - double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3 - dw3 * dw3; - if (attn3 > 0) - { - attn3 *= attn3; - value += attn3 * attn3 * extrapolate(xsb + 0, ysb + 0, zsb + 1, wsb + 0, dx3, dy3, dz3, dw3); - } - - //Contribution (0,0,0,1) - double dx4 = dx2; - double dy4 = dy1; - double dz4 = dz1; - double dw4 = dw0 - 1 - m_squish4d; - double attn4 = 2 - dx4 * dx4 - dy4 * dy4 - dz4 * dz4 - dw4 * dw4; - if (attn4 > 0) - { - attn4 *= attn4; - value += attn4 * attn4 * extrapolate(xsb + 0, ysb + 0, zsb + 0, wsb + 1, dx4, dy4, dz4, dw4); - } - } - else if (inSum >= 3) - { //We're inside the pentachoron (4-Simplex) at (1,1,1,1) -//Determine which two of (1,1,1,0), (1,1,0,1), (1,0,1,1), (0,1,1,1) are closest. - char aPoint = 0x0E; - double aScore = xins; - char bPoint = 0x0D; - double bScore = yins; - if (aScore <= bScore && zins < bScore) - { - bScore = zins; - bPoint = 0x0B; - } - else if (aScore > bScore && zins < aScore) - { - aScore = zins; - aPoint = 0x0B; - } - if (aScore <= bScore && wins < bScore) - { - bScore = wins; - bPoint = 0x07; - } - else if (aScore > bScore && wins < aScore) - { - aScore = wins; - aPoint = 0x07; - } - - //Now we determine the three lattice points not part of the pentachoron that may contribute. - //This depends on the closest two pentachoron vertices, including (0,0,0,0) - double uins = 4 - inSum; - if (uins < aScore || uins < bScore) - { //(1,1,1,1) is one of the closest two pentachoron vertices. - char c = (bScore < aScore ? bPoint : aPoint); //Our other closest vertex is the closest out of a and b. - - if ((c & 0x01) != 0) - { - xsv_ext0 = xsb + 2; - xsv_ext1 = xsv_ext2 = xsb + 1; - dx_ext0 = dx0 - 2 - 4 * m_squish4d; - dx_ext1 = dx_ext2 = dx0 - 1 - 4 * m_squish4d; - } - else - { - xsv_ext0 = xsv_ext1 = xsv_ext2 = xsb; - dx_ext0 = dx_ext1 = dx_ext2 = dx0 - 4 * m_squish4d; - } - - if ((c & 0x02) != 0) - { - ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb + 1; - dy_ext0 = dy_ext1 = dy_ext2 = dy0 - 1 - 4 * m_squish4d; - if ((c & 0x01) != 0) - { - ysv_ext1 += 1; - dy_ext1 -= 1; - } - else - { - ysv_ext0 += 1; - dy_ext0 -= 1; - } - } - else - { - ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb; - dy_ext0 = dy_ext1 = dy_ext2 = dy0 - 4 * m_squish4d; - } - - if ((c & 0x04) != 0) - { - zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb + 1; - dz_ext0 = dz_ext1 = dz_ext2 = dz0 - 1 - 4 * m_squish4d; - if ((c & 0x03) != 0x03) - { - if ((c & 0x03) == 0) - { - zsv_ext0 += 1; - dz_ext0 -= 1; - } - else - { - zsv_ext1 += 1; - dz_ext1 -= 1; - } - } - else - { - zsv_ext2 += 1; - dz_ext2 -= 1; - } - } - else - { - zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb; - dz_ext0 = dz_ext1 = dz_ext2 = dz0 - 4 * m_squish4d; - } - - if ((c & 0x08) != 0) - { - wsv_ext0 = wsv_ext1 = wsb + 1; - wsv_ext2 = wsb + 2; - dw_ext0 = dw_ext1 = dw0 - 1 - 4 * m_squish4d; - dw_ext2 = dw0 - 2 - 4 * m_squish4d; - } - else - { - wsv_ext0 = wsv_ext1 = wsv_ext2 = wsb; - dw_ext0 = dw_ext1 = dw_ext2 = dw0 - 4 * m_squish4d; - } - } - else - { //(1,1,1,1) is not one of the closest two pentachoron vertices. - char c = static_cast(aPoint & bPoint); //Our three extra vertices are determined by the closest two. - - if ((c & 0x01) != 0) - { - xsv_ext0 = xsv_ext2 = xsb + 1; - xsv_ext1 = xsb + 2; - dx_ext0 = dx0 - 1 - 2 * m_squish4d; - dx_ext1 = dx0 - 2 - 3 * m_squish4d; - dx_ext2 = dx0 - 1 - 3 * m_squish4d; - } - else - { - xsv_ext0 = xsv_ext1 = xsv_ext2 = xsb; - dx_ext0 = dx0 - 2 * m_squish4d; - dx_ext1 = dx_ext2 = dx0 - 3 * m_squish4d; - } - - if ((c & 0x02) != 0) - { - ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb + 1; - dy_ext0 = dy0 - 1 - 2 * m_squish4d; - dy_ext1 = dy_ext2 = dy0 - 1 - 3 * m_squish4d; - if ((c & 0x01) != 0) - { - ysv_ext2 += 1; - dy_ext2 -= 1; - } - else - { - ysv_ext1 += 1; - dy_ext1 -= 1; - } - } - else - { - ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb; - dy_ext0 = dy0 - 2 * m_squish4d; - dy_ext1 = dy_ext2 = dy0 - 3 * m_squish4d; - } - - if ((c & 0x04) != 0) - { - zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb + 1; - dz_ext0 = dz0 - 1 - 2 * m_squish4d; - dz_ext1 = dz_ext2 = dz0 - 1 - 3 * m_squish4d; - if ((c & 0x03) != 0) - { - zsv_ext2 += 1; - dz_ext2 -= 1; - } - else - { - zsv_ext1 += 1; - dz_ext1 -= 1; - } - } - else - { - zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb; - dz_ext0 = dz0 - 2 * m_squish4d; - dz_ext1 = dz_ext2 = dz0 - 3 * m_squish4d; - } - - if ((c & 0x08) != 0) - { - wsv_ext0 = wsv_ext1 = wsb + 1; - wsv_ext2 = wsb + 2; - dw_ext0 = dw0 - 1 - 2 * m_squish4d; - dw_ext1 = dw0 - 1 - 3 * m_squish4d; - dw_ext2 = dw0 - 2 - 3 * m_squish4d; - } - else - { - wsv_ext0 = wsv_ext1 = wsv_ext2 = wsb; - dw_ext0 = dw0 - 2 * m_squish4d; - dw_ext1 = dw_ext2 = dw0 - 3 * m_squish4d; - } - } - - //Contribution (1,1,1,0) - double dx4 = dx0 - 1 - 3 * m_squish4d; - double dy4 = dy0 - 1 - 3 * m_squish4d; - double dz4 = dz0 - 1 - 3 * m_squish4d; - double dw4 = dw0 - 3 * m_squish4d; - double attn4 = 2 - dx4 * dx4 - dy4 * dy4 - dz4 * dz4 - dw4 * dw4; - if (attn4 > 0) - { - attn4 *= attn4; - value += attn4 * attn4 * extrapolate(xsb + 1, ysb + 1, zsb + 1, wsb + 0, dx4, dy4, dz4, dw4); - } - - //Contribution (1,1,0,1) - double dx3 = dx4; - double dy3 = dy4; - double dz3 = dz0 - 3 * m_squish4d; - double dw3 = dw0 - 1 - 3 * m_squish4d; - double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3 - dw3 * dw3; - if (attn3 > 0) - { - attn3 *= attn3; - value += attn3 * attn3 * extrapolate(xsb + 1, ysb + 1, zsb + 0, wsb + 1, dx3, dy3, dz3, dw3); - } - - //Contribution (1,0,1,1) - double dx2 = dx4; - double dy2 = dy0 - 3 * m_squish4d; - double dz2 = dz4; - double dw2 = dw3; - double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2 - dw2 * dw2; - if (attn2 > 0) - { - attn2 *= attn2; - value += attn2 * attn2 * extrapolate(xsb + 1, ysb + 0, zsb + 1, wsb + 1, dx2, dy2, dz2, dw2); - } - - //Contribution (0,1,1,1) - double dx1 = dx0 - 3 * m_squish4d; - double dz1 = dz4; - double dy1 = dy4; - double dw1 = dw3; - double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1 - dw1 * dw1; - if (attn1 > 0) - { - attn1 *= attn1; - value += attn1 * attn1 * extrapolate(xsb + 0, ysb + 1, zsb + 1, wsb + 1, dx1, dy1, dz1, dw1); - } - - //Contribution (1,1,1,1) - dx0 = dx0 - 1 - 4 * m_squish4d; - dy0 = dy0 - 1 - 4 * m_squish4d; - dz0 = dz0 - 1 - 4 * m_squish4d; - dw0 = dw0 - 1 - 4 * m_squish4d; - double attn0 = 2 - dx0 * dx0 - dy0 * dy0 - dz0 * dz0 - dw0 * dw0; - if (attn0 > 0) - { - attn0 *= attn0; - value += attn0 * attn0 * extrapolate(xsb + 1, ysb + 1, zsb + 1, wsb + 1, dx0, dy0, dz0, dw0); - } - } - else if (inSum <= 2) - { //We're inside the first dispentachoron (Rectified 4-Simplex) - double aScore; - char aPoint; - bool aIsBiggerSide = true; - double bScore; - char bPoint; - bool bIsBiggerSide = true; - - //Decide between (1,1,0,0) and (0,0,1,1) - if (xins + yins > zins + wins) - { - aScore = xins + yins; - aPoint = 0x03; - } - else - { - aScore = zins + wins; - aPoint = 0x0C; - } - - //Decide between (1,0,1,0) and (0,1,0,1) - if (xins + zins > yins + wins) - { - bScore = xins + zins; - bPoint = 0x05; - } - else - { - bScore = yins + wins; - bPoint = 0x0A; - } - - //Closer between (1,0,0,1) and (0,1,1,0) will replace the further of a and b, if closer. - if (xins + wins > yins + zins) - { - double score = xins + wins; - if (aScore >= bScore && score > bScore) - { - bScore = score; - bPoint = 0x09; - } - else if (aScore < bScore && score > aScore) - { - aScore = score; - aPoint = 0x09; - } - } - else - { - double score = yins + zins; - if (aScore >= bScore && score > bScore) - { - bScore = score; - bPoint = 0x06; - } - else if (aScore < bScore && score > aScore) - { - aScore = score; - aPoint = 0x06; - } - } - - //Decide if (1,0,0,0) is closer. - double p1 = 2 - inSum + xins; - if (aScore >= bScore && p1 > bScore) - { - bScore = p1; - bPoint = 0x01; - bIsBiggerSide = false; - } - else if (aScore < bScore && p1 > aScore) - { - aScore = p1; - aPoint = 0x01; - aIsBiggerSide = false; - } - - //Decide if (0,1,0,0) is closer. - double p2 = 2 - inSum + yins; - if (aScore >= bScore && p2 > bScore) - { - bScore = p2; - bPoint = 0x02; - bIsBiggerSide = false; - } - else if (aScore < bScore && p2 > aScore) - { - aScore = p2; - aPoint = 0x02; - aIsBiggerSide = false; - } - - //Decide if (0,0,1,0) is closer. - double p3 = 2 - inSum + zins; - if (aScore >= bScore && p3 > bScore) - { - bScore = p3; - bPoint = 0x04; - bIsBiggerSide = false; - } - else if (aScore < bScore && p3 > aScore) - { - aScore = p3; - aPoint = 0x04; - aIsBiggerSide = false; - } - - //Decide if (0,0,0,1) is closer. - double p4 = 2 - inSum + wins; - if (aScore >= bScore && p4 > bScore) - { - bScore = p4; - bPoint = 0x08; - bIsBiggerSide = false; - } - else if (aScore < bScore && p4 > aScore) - { - aScore = p4; - aPoint = 0x08; - aIsBiggerSide = false; - } - - //Where each of the two closest points are determines how the extra three vertices are calculated. - if (aIsBiggerSide == bIsBiggerSide) - { - if (aIsBiggerSide) - { //Both closest points on the bigger side - char c1 = static_cast(aPoint | bPoint); - char c2 = static_cast(aPoint & bPoint); - if ((c1 & 0x01) == 0) - { - xsv_ext0 = xsb; - xsv_ext1 = xsb - 1; - dx_ext0 = dx0 - 3 * m_squish4d; - dx_ext1 = dx0 + 1 - 2 * m_squish4d; - } - else - { - xsv_ext0 = xsv_ext1 = xsb + 1; - dx_ext0 = dx0 - 1 - 3 * m_squish4d; - dx_ext1 = dx0 - 1 - 2 * m_squish4d; - } - - if ((c1 & 0x02) == 0) - { - ysv_ext0 = ysb; - ysv_ext1 = ysb - 1; - dy_ext0 = dy0 - 3 * m_squish4d; - dy_ext1 = dy0 + 1 - 2 * m_squish4d; - } - else - { - ysv_ext0 = ysv_ext1 = ysb + 1; - dy_ext0 = dy0 - 1 - 3 * m_squish4d; - dy_ext1 = dy0 - 1 - 2 * m_squish4d; - } - - if ((c1 & 0x04) == 0) - { - zsv_ext0 = zsb; - zsv_ext1 = zsb - 1; - dz_ext0 = dz0 - 3 * m_squish4d; - dz_ext1 = dz0 + 1 - 2 * m_squish4d; - } - else - { - zsv_ext0 = zsv_ext1 = zsb + 1; - dz_ext0 = dz0 - 1 - 3 * m_squish4d; - dz_ext1 = dz0 - 1 - 2 * m_squish4d; - } - - if ((c1 & 0x08) == 0) - { - wsv_ext0 = wsb; - wsv_ext1 = wsb - 1; - dw_ext0 = dw0 - 3 * m_squish4d; - dw_ext1 = dw0 + 1 - 2 * m_squish4d; - } - else - { - wsv_ext0 = wsv_ext1 = wsb + 1; - dw_ext0 = dw0 - 1 - 3 * m_squish4d; - dw_ext1 = dw0 - 1 - 2 * m_squish4d; - } - - //One combination is a permutation of (0,0,0,2) based on c2 - xsv_ext2 = xsb; - ysv_ext2 = ysb; - zsv_ext2 = zsb; - wsv_ext2 = wsb; - dx_ext2 = dx0 - 2 * m_squish4d; - dy_ext2 = dy0 - 2 * m_squish4d; - dz_ext2 = dz0 - 2 * m_squish4d; - dw_ext2 = dw0 - 2 * m_squish4d; - if ((c2 & 0x01) != 0) - { - xsv_ext2 += 2; - dx_ext2 -= 2; - } - else if ((c2 & 0x02) != 0) - { - ysv_ext2 += 2; - dy_ext2 -= 2; - } - else if ((c2 & 0x04) != 0) - { - zsv_ext2 += 2; - dz_ext2 -= 2; - } - else - { - wsv_ext2 += 2; - dw_ext2 -= 2; - } - - } - else - { //Both closest points on the smaller side - //One of the two extra points is (0,0,0,0) - xsv_ext2 = xsb; - ysv_ext2 = ysb; - zsv_ext2 = zsb; - wsv_ext2 = wsb; - dx_ext2 = dx0; - dy_ext2 = dy0; - dz_ext2 = dz0; - dw_ext2 = dw0; - - //Other two points are based on the omitted axes. - char c = static_cast(aPoint | bPoint); - - if ((c & 0x01) == 0) - { - xsv_ext0 = xsb - 1; - xsv_ext1 = xsb; - dx_ext0 = dx0 + 1 - m_squish4d; - dx_ext1 = dx0 - m_squish4d; - } - else - { - xsv_ext0 = xsv_ext1 = xsb + 1; - dx_ext0 = dx_ext1 = dx0 - 1 - m_squish4d; - } - - if ((c & 0x02) == 0) - { - ysv_ext0 = ysv_ext1 = ysb; - dy_ext0 = dy_ext1 = dy0 - m_squish4d; - if ((c & 0x01) == 0x01) - { - ysv_ext0 -= 1; - dy_ext0 += 1; - } - else - { - ysv_ext1 -= 1; - dy_ext1 += 1; - } - } - else - { - ysv_ext0 = ysv_ext1 = ysb + 1; - dy_ext0 = dy_ext1 = dy0 - 1 - m_squish4d; - } - - if ((c & 0x04) == 0) - { - zsv_ext0 = zsv_ext1 = zsb; - dz_ext0 = dz_ext1 = dz0 - m_squish4d; - if ((c & 0x03) == 0x03) - { - zsv_ext0 -= 1; - dz_ext0 += 1; - } - else - { - zsv_ext1 -= 1; - dz_ext1 += 1; - } - } - else - { - zsv_ext0 = zsv_ext1 = zsb + 1; - dz_ext0 = dz_ext1 = dz0 - 1 - m_squish4d; - } - - if ((c & 0x08) == 0) - { - wsv_ext0 = wsb; - wsv_ext1 = wsb - 1; - dw_ext0 = dw0 - m_squish4d; - dw_ext1 = dw0 + 1 - m_squish4d; - } - else - { - wsv_ext0 = wsv_ext1 = wsb + 1; - dw_ext0 = dw_ext1 = dw0 - 1 - m_squish4d; - } - - } - } - else - { //One point on each "side" - char c1, c2; - if (aIsBiggerSide) - { - c1 = aPoint; - c2 = bPoint; - } - else - { - c1 = bPoint; - c2 = aPoint; - } - - //Two contributions are the bigger-sided point with each 0 replaced with -1. - if ((c1 & 0x01) == 0) - { - xsv_ext0 = xsb - 1; - xsv_ext1 = xsb; - dx_ext0 = dx0 + 1 - m_squish4d; - dx_ext1 = dx0 - m_squish4d; - } - else - { - xsv_ext0 = xsv_ext1 = xsb + 1; - dx_ext0 = dx_ext1 = dx0 - 1 - m_squish4d; - } - - if ((c1 & 0x02) == 0) - { - ysv_ext0 = ysv_ext1 = ysb; - dy_ext0 = dy_ext1 = dy0 - m_squish4d; - if ((c1 & 0x01) == 0x01) - { - ysv_ext0 -= 1; - dy_ext0 += 1; - } - else - { - ysv_ext1 -= 1; - dy_ext1 += 1; - } - } - else - { - ysv_ext0 = ysv_ext1 = ysb + 1; - dy_ext0 = dy_ext1 = dy0 - 1 - m_squish4d; - } - - if ((c1 & 0x04) == 0) - { - zsv_ext0 = zsv_ext1 = zsb; - dz_ext0 = dz_ext1 = dz0 - m_squish4d; - if ((c1 & 0x03) == 0x03) - { - zsv_ext0 -= 1; - dz_ext0 += 1; - } - else - { - zsv_ext1 -= 1; - dz_ext1 += 1; - } - } - else - { - zsv_ext0 = zsv_ext1 = zsb + 1; - dz_ext0 = dz_ext1 = dz0 - 1 - m_squish4d; - } - - if ((c1 & 0x08) == 0) - { - wsv_ext0 = wsb; - wsv_ext1 = wsb - 1; - dw_ext0 = dw0 - m_squish4d; - dw_ext1 = dw0 + 1 - m_squish4d; - } - else - { - wsv_ext0 = wsv_ext1 = wsb + 1; - dw_ext0 = dw_ext1 = dw0 - 1 - m_squish4d; - } - - //One contribution is a permutation of (0,0,0,2) based on the smaller-sided point - xsv_ext2 = xsb; - ysv_ext2 = ysb; - zsv_ext2 = zsb; - wsv_ext2 = wsb; - dx_ext2 = dx0 - 2 * m_squish4d; - dy_ext2 = dy0 - 2 * m_squish4d; - dz_ext2 = dz0 - 2 * m_squish4d; - dw_ext2 = dw0 - 2 * m_squish4d; - if ((c2 & 0x01) != 0) - { - xsv_ext2 += 2; - dx_ext2 -= 2; - } - else if ((c2 & 0x02) != 0) - { - ysv_ext2 += 2; - dy_ext2 -= 2; - } - else if ((c2 & 0x04) != 0) - { - zsv_ext2 += 2; - dz_ext2 -= 2; - } - else - { - wsv_ext2 += 2; - dw_ext2 -= 2; - } - } - - //Contribution (1,0,0,0) - double dx1 = dx0 - 1 - m_squish4d; - double dy1 = dy0 - 0 - m_squish4d; - double dz1 = dz0 - 0 - m_squish4d; - double dw1 = dw0 - 0 - m_squish4d; - double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1 - dw1 * dw1; - if (attn1 > 0) - { - attn1 *= attn1; - value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, zsb + 0, wsb + 0, dx1, dy1, dz1, dw1); - } - - //Contribution (0,1,0,0) - double dx2 = dx0 - 0 - m_squish4d; - double dy2 = dy0 - 1 - m_squish4d; - double dz2 = dz1; - double dw2 = dw1; - double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2 - dw2 * dw2; - if (attn2 > 0) - { - attn2 *= attn2; - value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, zsb + 0, wsb + 0, dx2, dy2, dz2, dw2); - } - - //Contribution (0,0,1,0) - double dx3 = dx2; - double dy3 = dy1; - double dz3 = dz0 - 1 - m_squish4d; - double dw3 = dw1; - double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3 - dw3 * dw3; - if (attn3 > 0) - { - attn3 *= attn3; - value += attn3 * attn3 * extrapolate(xsb + 0, ysb + 0, zsb + 1, wsb + 0, dx3, dy3, dz3, dw3); - } - - //Contribution (0,0,0,1) - double dx4 = dx2; - double dy4 = dy1; - double dz4 = dz1; - double dw4 = dw0 - 1 - m_squish4d; - double attn4 = 2 - dx4 * dx4 - dy4 * dy4 - dz4 * dz4 - dw4 * dw4; - if (attn4 > 0) - { - attn4 *= attn4; - value += attn4 * attn4 * extrapolate(xsb + 0, ysb + 0, zsb + 0, wsb + 1, dx4, dy4, dz4, dw4); - } - - //Contribution (1,1,0,0) - double dx5 = dx0 - 1 - 2 * m_squish4d; - double dy5 = dy0 - 1 - 2 * m_squish4d; - double dz5 = dz0 - 0 - 2 * m_squish4d; - double dw5 = dw0 - 0 - 2 * m_squish4d; - double attn5 = 2 - dx5 * dx5 - dy5 * dy5 - dz5 * dz5 - dw5 * dw5; - if (attn5 > 0) - { - attn5 *= attn5; - value += attn5 * attn5 * extrapolate(xsb + 1, ysb + 1, zsb + 0, wsb + 0, dx5, dy5, dz5, dw5); - } - - //Contribution (1,0,1,0) - double dx6 = dx0 - 1 - 2 * m_squish4d; - double dy6 = dy0 - 0 - 2 * m_squish4d; - double dz6 = dz0 - 1 - 2 * m_squish4d; - double dw6 = dw0 - 0 - 2 * m_squish4d; - double attn6 = 2 - dx6 * dx6 - dy6 * dy6 - dz6 * dz6 - dw6 * dw6; - if (attn6 > 0) - { - attn6 *= attn6; - value += attn6 * attn6 * extrapolate(xsb + 1, ysb + 0, zsb + 1, wsb + 0, dx6, dy6, dz6, dw6); - } - - //Contribution (1,0,0,1) - double dx7 = dx0 - 1 - 2 * m_squish4d; - double dy7 = dy0 - 0 - 2 * m_squish4d; - double dz7 = dz0 - 0 - 2 * m_squish4d; - double dw7 = dw0 - 1 - 2 * m_squish4d; - double attn7 = 2 - dx7 * dx7 - dy7 * dy7 - dz7 * dz7 - dw7 * dw7; - if (attn7 > 0) - { - attn7 *= attn7; - value += attn7 * attn7 * extrapolate(xsb + 1, ysb + 0, zsb + 0, wsb + 1, dx7, dy7, dz7, dw7); - } - - //Contribution (0,1,1,0) - double dx8 = dx0 - 0 - 2 * m_squish4d; - double dy8 = dy0 - 1 - 2 * m_squish4d; - double dz8 = dz0 - 1 - 2 * m_squish4d; - double dw8 = dw0 - 0 - 2 * m_squish4d; - double attn8 = 2 - dx8 * dx8 - dy8 * dy8 - dz8 * dz8 - dw8 * dw8; - if (attn8 > 0) - { - attn8 *= attn8; - value += attn8 * attn8 * extrapolate(xsb + 0, ysb + 1, zsb + 1, wsb + 0, dx8, dy8, dz8, dw8); - } - - //Contribution (0,1,0,1) - double dx9 = dx0 - 0 - 2 * m_squish4d; - double dy9 = dy0 - 1 - 2 * m_squish4d; - double dz9 = dz0 - 0 - 2 * m_squish4d; - double dw9 = dw0 - 1 - 2 * m_squish4d; - double attn9 = 2 - dx9 * dx9 - dy9 * dy9 - dz9 * dz9 - dw9 * dw9; - if (attn9 > 0) - { - attn9 *= attn9; - value += attn9 * attn9 * extrapolate(xsb + 0, ysb + 1, zsb + 0, wsb + 1, dx9, dy9, dz9, dw9); - } - - //Contribution (0,0,1,1) - double dx10 = dx0 - 0 - 2 * m_squish4d; - double dy10 = dy0 - 0 - 2 * m_squish4d; - double dz10 = dz0 - 1 - 2 * m_squish4d; - double dw10 = dw0 - 1 - 2 * m_squish4d; - double attn10 = 2 - dx10 * dx10 - dy10 * dy10 - dz10 * dz10 - dw10 * dw10; - if (attn10 > 0) - { - attn10 *= attn10; - value += attn10 * attn10 * extrapolate(xsb + 0, ysb + 0, zsb + 1, wsb + 1, dx10, dy10, dz10, dw10); - } - } - else - { //We're inside the second dispentachoron (Rectified 4-Simplex) - double aScore; - char aPoint; - bool aIsBiggerSide = true; - double bScore; - char bPoint; - bool bIsBiggerSide = true; - - //Decide between (0,0,1,1) and (1,1,0,0) - if (xins + yins < zins + wins) - { - aScore = xins + yins; - aPoint = 0x0C; - } - else - { - aScore = zins + wins; - aPoint = 0x03; - } - - //Decide between (0,1,0,1) and (1,0,1,0) - if (xins + zins < yins + wins) - { - bScore = xins + zins; - bPoint = 0x0A; - } - else - { - bScore = yins + wins; - bPoint = 0x05; - } - - //Closer between (0,1,1,0) and (1,0,0,1) will replace the further of a and b, if closer. - if (xins + wins < yins + zins) - { - double score = xins + wins; - if (aScore <= bScore && score < bScore) - { - bScore = score; - bPoint = 0x06; - } - else if (aScore > bScore && score < aScore) - { - aScore = score; - aPoint = 0x06; - } - } - else - { - double score = yins + zins; - if (aScore <= bScore && score < bScore) - { - bScore = score; - bPoint = 0x09; - } - else if (aScore > bScore && score < aScore) - { - aScore = score; - aPoint = 0x09; - } - } - - //Decide if (0,1,1,1) is closer. - double p1 = 3 - inSum + xins; - if (aScore <= bScore && p1 < bScore) - { - bScore = p1; - bPoint = 0x0E; - bIsBiggerSide = false; - } - else if (aScore > bScore && p1 < aScore) - { - aScore = p1; - aPoint = 0x0E; - aIsBiggerSide = false; - } - - //Decide if (1,0,1,1) is closer. - double p2 = 3 - inSum + yins; - if (aScore <= bScore && p2 < bScore) - { - bScore = p2; - bPoint = 0x0D; - bIsBiggerSide = false; - } - else if (aScore > bScore && p2 < aScore) - { - aScore = p2; - aPoint = 0x0D; - aIsBiggerSide = false; - } - - //Decide if (1,1,0,1) is closer. - double p3 = 3 - inSum + zins; - if (aScore <= bScore && p3 < bScore) - { - bScore = p3; - bPoint = 0x0B; - bIsBiggerSide = false; - } - else if (aScore > bScore && p3 < aScore) - { - aScore = p3; - aPoint = 0x0B; - aIsBiggerSide = false; - } - - //Decide if (1,1,1,0) is closer. - double p4 = 3 - inSum + wins; - if (aScore <= bScore && p4 < bScore) - { - bScore = p4; - bPoint = 0x07; - bIsBiggerSide = false; - } - else if (aScore > bScore && p4 < aScore) - { - aScore = p4; - aPoint = 0x07; - aIsBiggerSide = false; - } - - //Where each of the two closest points are determines how the extra three vertices are calculated. - if (aIsBiggerSide == bIsBiggerSide) - { - if (aIsBiggerSide) - { //Both closest points on the bigger side - char c1 = static_cast(aPoint & bPoint); - char c2 = static_cast(aPoint | bPoint); - - //Two contributions are permutations of (0,0,0,1) and (0,0,0,2) based on c1 - xsv_ext0 = xsv_ext1 = xsb; - ysv_ext0 = ysv_ext1 = ysb; - zsv_ext0 = zsv_ext1 = zsb; - wsv_ext0 = wsv_ext1 = wsb; - dx_ext0 = dx0 - m_squish4d; - dy_ext0 = dy0 - m_squish4d; - dz_ext0 = dz0 - m_squish4d; - dw_ext0 = dw0 - m_squish4d; - dx_ext1 = dx0 - 2 * m_squish4d; - dy_ext1 = dy0 - 2 * m_squish4d; - dz_ext1 = dz0 - 2 * m_squish4d; - dw_ext1 = dw0 - 2 * m_squish4d; - if ((c1 & 0x01) != 0) - { - xsv_ext0 += 1; - dx_ext0 -= 1; - xsv_ext1 += 2; - dx_ext1 -= 2; - } - else if ((c1 & 0x02) != 0) - { - ysv_ext0 += 1; - dy_ext0 -= 1; - ysv_ext1 += 2; - dy_ext1 -= 2; - } - else if ((c1 & 0x04) != 0) - { - zsv_ext0 += 1; - dz_ext0 -= 1; - zsv_ext1 += 2; - dz_ext1 -= 2; - } - else - { - wsv_ext0 += 1; - dw_ext0 -= 1; - wsv_ext1 += 2; - dw_ext1 -= 2; - } - - //One contribution is a permutation of (1,1,1,-1) based on c2 - xsv_ext2 = xsb + 1; - ysv_ext2 = ysb + 1; - zsv_ext2 = zsb + 1; - wsv_ext2 = wsb + 1; - dx_ext2 = dx0 - 1 - 2 * m_squish4d; - dy_ext2 = dy0 - 1 - 2 * m_squish4d; - dz_ext2 = dz0 - 1 - 2 * m_squish4d; - dw_ext2 = dw0 - 1 - 2 * m_squish4d; - if ((c2 & 0x01) == 0) - { - xsv_ext2 -= 2; - dx_ext2 += 2; - } - else if ((c2 & 0x02) == 0) - { - ysv_ext2 -= 2; - dy_ext2 += 2; - } - else if ((c2 & 0x04) == 0) - { - zsv_ext2 -= 2; - dz_ext2 += 2; - } - else - { - wsv_ext2 -= 2; - dw_ext2 += 2; - } - } - else - { //Both closest points on the smaller side - //One of the two extra points is (1,1,1,1) - xsv_ext2 = xsb + 1; - ysv_ext2 = ysb + 1; - zsv_ext2 = zsb + 1; - wsv_ext2 = wsb + 1; - dx_ext2 = dx0 - 1 - 4 * m_squish4d; - dy_ext2 = dy0 - 1 - 4 * m_squish4d; - dz_ext2 = dz0 - 1 - 4 * m_squish4d; - dw_ext2 = dw0 - 1 - 4 * m_squish4d; - - //Other two points are based on the shared axes. - char c = static_cast(aPoint & bPoint); - - if ((c & 0x01) != 0) - { - xsv_ext0 = xsb + 2; - xsv_ext1 = xsb + 1; - dx_ext0 = dx0 - 2 - 3 * m_squish4d; - dx_ext1 = dx0 - 1 - 3 * m_squish4d; - } - else - { - xsv_ext0 = xsv_ext1 = xsb; - dx_ext0 = dx_ext1 = dx0 - 3 * m_squish4d; - } - - if ((c & 0x02) != 0) - { - ysv_ext0 = ysv_ext1 = ysb + 1; - dy_ext0 = dy_ext1 = dy0 - 1 - 3 * m_squish4d; - if ((c & 0x01) == 0) - { - ysv_ext0 += 1; - dy_ext0 -= 1; - } - else - { - ysv_ext1 += 1; - dy_ext1 -= 1; - } - } - else - { - ysv_ext0 = ysv_ext1 = ysb; - dy_ext0 = dy_ext1 = dy0 - 3 * m_squish4d; - } - - if ((c & 0x04) != 0) - { - zsv_ext0 = zsv_ext1 = zsb + 1; - dz_ext0 = dz_ext1 = dz0 - 1 - 3 * m_squish4d; - if ((c & 0x03) == 0) - { - zsv_ext0 += 1; - dz_ext0 -= 1; - } - else - { - zsv_ext1 += 1; - dz_ext1 -= 1; - } - } - else - { - zsv_ext0 = zsv_ext1 = zsb; - dz_ext0 = dz_ext1 = dz0 - 3 * m_squish4d; - } - - if ((c & 0x08) != 0) - { - wsv_ext0 = wsb + 1; - wsv_ext1 = wsb + 2; - dw_ext0 = dw0 - 1 - 3 * m_squish4d; - dw_ext1 = dw0 - 2 - 3 * m_squish4d; - } - else - { - wsv_ext0 = wsv_ext1 = wsb; - dw_ext0 = dw_ext1 = dw0 - 3 * m_squish4d; - } - } - } - else - { //One point on each "side" - char c1, c2; - if (aIsBiggerSide) - { - c1 = aPoint; - c2 = bPoint; - } - else - { - c1 = bPoint; - c2 = aPoint; - } - - //Two contributions are the bigger-sided point with each 1 replaced with 2. - if ((c1 & 0x01) != 0) - { - xsv_ext0 = xsb + 2; - xsv_ext1 = xsb + 1; - dx_ext0 = dx0 - 2 - 3 * m_squish4d; - dx_ext1 = dx0 - 1 - 3 * m_squish4d; - } - else - { - xsv_ext0 = xsv_ext1 = xsb; - dx_ext0 = dx_ext1 = dx0 - 3 * m_squish4d; - } - - if ((c1 & 0x02) != 0) - { - ysv_ext0 = ysv_ext1 = ysb + 1; - dy_ext0 = dy_ext1 = dy0 - 1 - 3 * m_squish4d; - if ((c1 & 0x01) == 0) - { - ysv_ext0 += 1; - dy_ext0 -= 1; - } - else - { - ysv_ext1 += 1; - dy_ext1 -= 1; - } - } - else - { - ysv_ext0 = ysv_ext1 = ysb; - dy_ext0 = dy_ext1 = dy0 - 3 * m_squish4d; - } - - if ((c1 & 0x04) != 0) - { - zsv_ext0 = zsv_ext1 = zsb + 1; - dz_ext0 = dz_ext1 = dz0 - 1 - 3 * m_squish4d; - if ((c1 & 0x03) == 0) - { - zsv_ext0 += 1; - dz_ext0 -= 1; - } - else - { - zsv_ext1 += 1; - dz_ext1 -= 1; - } - } - else - { - zsv_ext0 = zsv_ext1 = zsb; - dz_ext0 = dz_ext1 = dz0 - 3 * m_squish4d; - } - - if ((c1 & 0x08) != 0) - { - wsv_ext0 = wsb + 1; - wsv_ext1 = wsb + 2; - dw_ext0 = dw0 - 1 - 3 * m_squish4d; - dw_ext1 = dw0 - 2 - 3 * m_squish4d; - } - else - { - wsv_ext0 = wsv_ext1 = wsb; - dw_ext0 = dw_ext1 = dw0 - 3 * m_squish4d; - } - - //One contribution is a permutation of (1,1,1,-1) based on the smaller-sided point - xsv_ext2 = xsb + 1; - ysv_ext2 = ysb + 1; - zsv_ext2 = zsb + 1; - wsv_ext2 = wsb + 1; - dx_ext2 = dx0 - 1 - 2 * m_squish4d; - dy_ext2 = dy0 - 1 - 2 * m_squish4d; - dz_ext2 = dz0 - 1 - 2 * m_squish4d; - dw_ext2 = dw0 - 1 - 2 * m_squish4d; - if ((c2 & 0x01) == 0) - { - xsv_ext2 -= 2; - dx_ext2 += 2; - } - else if ((c2 & 0x02) == 0) - { - ysv_ext2 -= 2; - dy_ext2 += 2; - } - else if ((c2 & 0x04) == 0) - { - zsv_ext2 -= 2; - dz_ext2 += 2; - } - else - { - wsv_ext2 -= 2; - dw_ext2 += 2; - } - } - - //Contribution (1,1,1,0) - double dx4 = dx0 - 1 - 3 * m_squish4d; - double dy4 = dy0 - 1 - 3 * m_squish4d; - double dz4 = dz0 - 1 - 3 * m_squish4d; - double dw4 = dw0 - 3 * m_squish4d; - double attn4 = 2 - dx4 * dx4 - dy4 * dy4 - dz4 * dz4 - dw4 * dw4; - if (attn4 > 0) - { - attn4 *= attn4; - value += attn4 * attn4 * extrapolate(xsb + 1, ysb + 1, zsb + 1, wsb + 0, dx4, dy4, dz4, dw4); - } - - //Contribution (1,1,0,1) - double dx3 = dx4; - double dy3 = dy4; - double dz3 = dz0 - 3 * m_squish4d; - double dw3 = dw0 - 1 - 3 * m_squish4d; - double attn3 = 2 - dx3 * dx3 - dy3 * dy3 - dz3 * dz3 - dw3 * dw3; - if (attn3 > 0) - { - attn3 *= attn3; - value += attn3 * attn3 * extrapolate(xsb + 1, ysb + 1, zsb + 0, wsb + 1, dx3, dy3, dz3, dw3); - } - - //Contribution (1,0,1,1) - double dx2 = dx4; - double dy2 = dy0 - 3 * m_squish4d; - double dz2 = dz4; - double dw2 = dw3; - double attn2 = 2 - dx2 * dx2 - dy2 * dy2 - dz2 * dz2 - dw2 * dw2; - if (attn2 > 0) - { - attn2 *= attn2; - value += attn2 * attn2 * extrapolate(xsb + 1, ysb + 0, zsb + 1, wsb + 1, dx2, dy2, dz2, dw2); - } - - //Contribution (0,1,1,1) - double dx1 = dx0 - 3 * m_squish4d; - double dz1 = dz4; - double dy1 = dy4; - double dw1 = dw3; - double attn1 = 2 - dx1 * dx1 - dy1 * dy1 - dz1 * dz1 - dw1 * dw1; - if (attn1 > 0) - { - attn1 *= attn1; - value += attn1 * attn1 * extrapolate(xsb + 0, ysb + 1, zsb + 1, wsb + 1, dx1, dy1, dz1, dw1); - } - - //Contribution (1,1,0,0) - double dx5 = dx0 - 1 - 2 * m_squish4d; - double dy5 = dy0 - 1 - 2 * m_squish4d; - double dz5 = dz0 - 0 - 2 * m_squish4d; - double dw5 = dw0 - 0 - 2 * m_squish4d; - double attn5 = 2 - dx5 * dx5 - dy5 * dy5 - dz5 * dz5 - dw5 * dw5; - if (attn5 > 0) - { - attn5 *= attn5; - value += attn5 * attn5 * extrapolate(xsb + 1, ysb + 1, zsb + 0, wsb + 0, dx5, dy5, dz5, dw5); - } - - //Contribution (1,0,1,0) - double dx6 = dx0 - 1 - 2 * m_squish4d; - double dy6 = dy0 - 0 - 2 * m_squish4d; - double dz6 = dz0 - 1 - 2 * m_squish4d; - double dw6 = dw0 - 0 - 2 * m_squish4d; - double attn6 = 2 - dx6 * dx6 - dy6 * dy6 - dz6 * dz6 - dw6 * dw6; - if (attn6 > 0) - { - attn6 *= attn6; - value += attn6 * attn6 * extrapolate(xsb + 1, ysb + 0, zsb + 1, wsb + 0, dx6, dy6, dz6, dw6); - } - - //Contribution (1,0,0,1) - double dx7 = dx0 - 1 - 2 * m_squish4d; - double dy7 = dy0 - 0 - 2 * m_squish4d; - double dz7 = dz0 - 0 - 2 * m_squish4d; - double dw7 = dw0 - 1 - 2 * m_squish4d; - double attn7 = 2 - dx7 * dx7 - dy7 * dy7 - dz7 * dz7 - dw7 * dw7; - if (attn7 > 0) - { - attn7 *= attn7; - value += attn7 * attn7 * extrapolate(xsb + 1, ysb + 0, zsb + 0, wsb + 1, dx7, dy7, dz7, dw7); - } - - //Contribution (0,1,1,0) - double dx8 = dx0 - 0 - 2 * m_squish4d; - double dy8 = dy0 - 1 - 2 * m_squish4d; - double dz8 = dz0 - 1 - 2 * m_squish4d; - double dw8 = dw0 - 0 - 2 * m_squish4d; - double attn8 = 2 - dx8 * dx8 - dy8 * dy8 - dz8 * dz8 - dw8 * dw8; - if (attn8 > 0) - { - attn8 *= attn8; - value += attn8 * attn8 * extrapolate(xsb + 0, ysb + 1, zsb + 1, wsb + 0, dx8, dy8, dz8, dw8); - } - - //Contribution (0,1,0,1) - double dx9 = dx0 - 0 - 2 * m_squish4d; - double dy9 = dy0 - 1 - 2 * m_squish4d; - double dz9 = dz0 - 0 - 2 * m_squish4d; - double dw9 = dw0 - 1 - 2 * m_squish4d; - double attn9 = 2 - dx9 * dx9 - dy9 * dy9 - dz9 * dz9 - dw9 * dw9; - if (attn9 > 0) - { - attn9 *= attn9; - value += attn9 * attn9 * extrapolate(xsb + 0, ysb + 1, zsb + 0, wsb + 1, dx9, dy9, dz9, dw9); - } - - //Contribution (0,0,1,1) - double dx10 = dx0 - 0 - 2 * m_squish4d; - double dy10 = dy0 - 0 - 2 * m_squish4d; - double dz10 = dz0 - 1 - 2 * m_squish4d; - double dw10 = dw0 - 1 - 2 * m_squish4d; - double attn10 = 2 - dx10 * dx10 - dy10 * dy10 - dz10 * dz10 - dw10 * dw10; - if (attn10 > 0) - { - attn10 *= attn10; - value += attn10 * attn10 * extrapolate(xsb + 0, ysb + 0, zsb + 1, wsb + 1, dx10, dy10, dz10, dw10); - } - } - - //First extra vertex - double attn_ext0 = 2 - dx_ext0 * dx_ext0 - dy_ext0 * dy_ext0 - dz_ext0 * dz_ext0 - dw_ext0 * dw_ext0; - if (attn_ext0 > 0) - { - attn_ext0 *= attn_ext0; - value += attn_ext0 * attn_ext0 * extrapolate(xsv_ext0, ysv_ext0, zsv_ext0, wsv_ext0, dx_ext0, dy_ext0, dz_ext0, dw_ext0); - } - - //Second extra vertex - double attn_ext1 = 2 - dx_ext1 * dx_ext1 - dy_ext1 * dy_ext1 - dz_ext1 * dz_ext1 - dw_ext1 * dw_ext1; - if (attn_ext1 > 0) - { - attn_ext1 *= attn_ext1; - value += attn_ext1 * attn_ext1 * extrapolate(xsv_ext1, ysv_ext1, zsv_ext1, wsv_ext1, dx_ext1, dy_ext1, dz_ext1, dw_ext1); - } - - //Third extra vertex - double attn_ext2 = 2 - dx_ext2 * dx_ext2 - dy_ext2 * dy_ext2 - dz_ext2 * dz_ext2 - dw_ext2 * dw_ext2; - if (attn_ext2 > 0) - { - attn_ext2 *= attn_ext2; - value += attn_ext2 * attn_ext2 * extrapolate(xsv_ext2, ysv_ext2, zsv_ext2, wsv_ext2, dx_ext2, dy_ext2, dz_ext2, dw_ext2); - } - - return value / m_norm4d; - } - - double Noise::extrapolate(int xsb, int ysb, double dx, double dy) const - { - int index = m_perm[(m_perm[xsb & 0xFF] + ysb) & 0xFF] & 0x0E; - return m_gradients2d[index] * dx - + m_gradients2d[index + 1] * dy; - } - - double Noise::extrapolate(int xsb, int ysb, int zsb, double dx, double dy, double dz) const - { - int index = m_permGradIndex3d[(m_perm[(m_perm[xsb & 0xFF] + ysb) & 0xFF] + zsb) & 0xFF]; - return m_gradients3d[index] * dx - + m_gradients3d[index + 1] * dy - + m_gradients3d[index + 2] * dz; - } - - double Noise::extrapolate(int xsb, int ysb, int zsb, int wsb, double dx, double dy, double dz, double dw) const - { - int index = m_perm[(m_perm[(m_perm[(m_perm[xsb & 0xFF] + ysb) & 0xFF] + zsb) & 0xFF] + wsb) & 0xFF] & 0xFC; - return m_gradients4d[index] * dx - + m_gradients4d[index + 1] * dy - + m_gradients4d[index + 2] * dz - + m_gradients4d[index + 3] * dw; - } - -} \ No newline at end of file diff --git a/SQCSim2021/opensimplex.h b/SQCSim2021/opensimplex.h deleted file mode 100644 index 4b1b1f4..0000000 --- a/SQCSim2021/opensimplex.h +++ /dev/null @@ -1,51 +0,0 @@ -/** - Open Simple Noise for C++ - - Port to C++ from https://gist.github.com/KdotJPG/b1270127455a94ac5d19 - by Rickard Lundberg, 2019. -*/ -#ifndef _OPENSIMPLEX_H__ -#define _OPENSIMPLEX_H__ - -#include -#include - -namespace OpenSimplexNoise -{ - class Noise - { - public: - Noise(); - Noise(int64_t seed); - //2D Open Simplex Noise. - double eval(const double x, const double y) const; - //3D Open Simplex Noise. - double eval(double x, double y, double z) const; - //4D Open Simplex Noise. - double eval(double x, double y, double z, double w) const; - private: - const double m_stretch2d; - const double m_squish2d; - const double m_stretch3d; - const double m_squish3d; - const double m_stretch4d; - const double m_squish4d; - - const double m_norm2d; - const double m_norm3d; - const double m_norm4d; - - const long m_defaultSeed; - - std::array m_perm; - std::array m_permGradIndex3d; - std::array m_gradients2d; - std::array m_gradients3d; - std::array m_gradients4d; - double extrapolate(int xsb, int ysb, double dx, double dy) const; - double extrapolate(int xsb, int ysb, int zsb, double dx, double dy, double dz) const; - double extrapolate(int xsb, int ysb, int zsb, int wsb, double dx, double dy, double dz, double dw) const; - }; -} - -#endif // _OPENSIMPLEX_H__ \ No newline at end of file diff --git a/SQCSim2021/player.h b/SQCSim2021/player.h index 239b550..d8f46f3 100644 --- a/SQCSim2021/player.h +++ b/SQCSim2021/player.h @@ -1,5 +1,5 @@ -#ifndef _PLAYER_H__ -#define _PLAYER_H__ +#ifndef CLI_PLAYER_H__ +#define CLI_PLAYER_H__ #include "../SQCSim-common/vector3.h" #include "transformation.h" #include "audio.h" diff --git a/SQCSim2021/transformation.h b/SQCSim2021/transformation.h index 764a781..72e0690 100644 --- a/SQCSim2021/transformation.h +++ b/SQCSim2021/transformation.h @@ -1,9 +1,10 @@ #ifndef TRANSFORMATION_H__ #define TRANSFORMATION_H__ -#include "matrix4.h" -#include "../SQCSim-common/vector3.h" #include +#include "../SQCSim-common/matrix4.h" +#include "../SQCSim-common/vector3.h" +#include "define.h" class Transformation { diff --git a/SQCSim2021/vertexbuffer.h b/SQCSim2021/vertexbuffer.h index b44f8f8..845eefe 100644 --- a/SQCSim2021/vertexbuffer.h +++ b/SQCSim2021/vertexbuffer.h @@ -1,8 +1,8 @@ #ifndef VERTEXBUFFER_H__ #define VERTEXBUFFER_H__ -#include "define.h" #include +#include "define.h" class VertexBuffer { diff --git a/SQCSim2021/world.h b/SQCSim2021/world.h index 486e2d2..d2b0dc1 100644 --- a/SQCSim2021/world.h +++ b/SQCSim2021/world.h @@ -5,14 +5,14 @@ #include #include #include -#include "define.h" -#include "chunk.h" -#include "array2d.h" #include "../SQCSim-common/vector3.h" +#include "../SQCSim-common/array2d.h" +#include "bullet.h" +#include "define.h" #include "player.h" +#include "chunk.h" #include "transformation.h" #include "shader.h" -#include "bullet.h" #include "textureatlas.h" class Chunk;