2023-08-22 15:30:26 +08:00
|
|
|
#pragma once
|
|
|
|
|
2023-09-05 22:23:05 +08:00
|
|
|
#include "../VTUtils.hpp"
|
|
|
|
#include "../CK2/CKTypes.hpp"
|
|
|
|
#include "VxEnums.hpp"
|
2023-08-22 15:30:26 +08:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cinttypes>
|
2023-09-19 15:20:40 +08:00
|
|
|
#include <cmath>
|
2023-08-22 15:30:26 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The VxMath part of LibCmo.
|
|
|
|
* These classes are prefixed with Vx in original Virtools SDK.
|
|
|
|
*/
|
|
|
|
namespace LibCmo::VxMath {
|
|
|
|
|
|
|
|
// ========== Type Definition ==========
|
|
|
|
|
|
|
|
|
|
|
|
// ========== Class List ==========
|
2024-08-17 20:43:27 +08:00
|
|
|
// Important classes
|
2023-08-22 15:30:26 +08:00
|
|
|
|
|
|
|
class VxMemoryMappedFile;
|
|
|
|
|
2024-08-17 20:43:27 +08:00
|
|
|
// Misc
|
2023-09-13 22:33:41 +08:00
|
|
|
struct VxVector2 {
|
2023-09-16 18:31:25 +08:00
|
|
|
CKFLOAT x, y;
|
2023-09-13 22:33:41 +08:00
|
|
|
VxVector2() : x(0.0f), y(0.0f) {}
|
2023-09-16 18:31:25 +08:00
|
|
|
VxVector2(CKFLOAT _x, CKFLOAT _y) : x(_x), y(_y) {}
|
2024-08-17 20:43:27 +08:00
|
|
|
YYCC_DEF_CLS_COPY_MOVE(VxVector2);
|
2023-09-16 18:31:25 +08:00
|
|
|
CKFLOAT& operator[](size_t i) {
|
2023-09-13 22:33:41 +08:00
|
|
|
switch (i) {
|
|
|
|
case 0: return x;
|
|
|
|
case 1: return y;
|
2024-08-17 20:43:27 +08:00
|
|
|
default: throw LogicException("Invalid index for VxVector2::operator[].");
|
2023-09-13 22:33:41 +08:00
|
|
|
}
|
2023-11-26 20:36:25 +08:00
|
|
|
}
|
|
|
|
const CKFLOAT& operator[](size_t i) const {
|
2023-09-19 15:20:40 +08:00
|
|
|
switch (i) {
|
|
|
|
case 0: return x;
|
|
|
|
case 1: return y;
|
2024-08-17 20:43:27 +08:00
|
|
|
default: throw LogicException("Invalid index for VxVector2::operator[].");
|
2023-09-19 15:20:40 +08:00
|
|
|
}
|
2023-09-13 22:33:41 +08:00
|
|
|
}
|
|
|
|
VxVector2& operator+=(const VxVector2& rhs) {
|
|
|
|
x += rhs.x;
|
|
|
|
y += rhs.y;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
friend VxVector2 operator+(const VxVector2& lhs, const VxVector2& rhs) {
|
|
|
|
return VxVector2(lhs.x + rhs.x, lhs.y + rhs.y);
|
|
|
|
}
|
|
|
|
VxVector2& operator-=(const VxVector2& rhs) {
|
|
|
|
x -= rhs.x;
|
|
|
|
y -= rhs.y;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
friend VxVector2 operator-(const VxVector2& lhs, const VxVector2& rhs) {
|
|
|
|
return VxVector2(lhs.x - rhs.x, lhs.y - rhs.y);
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
VxVector2& operator*=(CKFLOAT rhs) {
|
2023-09-13 22:33:41 +08:00
|
|
|
x *= rhs;
|
|
|
|
y *= rhs;
|
|
|
|
return *this;
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
friend VxVector2 operator*(const VxVector2& lhs, CKFLOAT rhs) {
|
2023-09-13 22:33:41 +08:00
|
|
|
return VxVector2(lhs.x * rhs, lhs.y * rhs);
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
friend VxVector2 operator*(CKFLOAT lhs, const VxVector2& rhs) {
|
2023-09-13 22:33:41 +08:00
|
|
|
return VxVector2(lhs * rhs.x, lhs * rhs.y);
|
|
|
|
}
|
2023-09-19 15:20:40 +08:00
|
|
|
friend CKFLOAT operator*(const VxVector2& lhs, const VxVector2& rhs) {
|
|
|
|
return (lhs.x * rhs.x + lhs.y * rhs.y);
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
VxVector2& operator/=(CKFLOAT rhs) {
|
2023-09-13 22:33:41 +08:00
|
|
|
if (rhs == 0.0f) return *this;
|
|
|
|
x /= rhs;
|
|
|
|
y /= rhs;
|
|
|
|
return *this;
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
friend VxVector2 operator/(const VxVector2& lhs, CKFLOAT rhs) {
|
2023-09-13 22:33:41 +08:00
|
|
|
if (rhs == 0.0f) return VxVector2(0.0f, 0.0f);
|
|
|
|
return VxVector2(lhs.x / rhs, lhs.y / rhs);
|
|
|
|
}
|
|
|
|
bool operator==(const VxVector2& rhs) const {
|
|
|
|
return (x == rhs.x && y == rhs.y);
|
|
|
|
}
|
2023-09-19 15:20:40 +08:00
|
|
|
CKFLOAT SquaredLength() const {
|
|
|
|
return (x * x + y * y);
|
|
|
|
}
|
|
|
|
CKFLOAT Length() const {
|
|
|
|
return std::sqrt(SquaredLength());
|
|
|
|
}
|
|
|
|
void Normalized() {
|
|
|
|
CKFLOAT len = Length();
|
|
|
|
if (len == 0.0f) return;
|
|
|
|
x /= len;
|
|
|
|
y /= len;
|
|
|
|
}
|
|
|
|
VxVector2 Normalize() const {
|
|
|
|
CKFLOAT len = Length();
|
|
|
|
if (len == 0.0f) return VxVector2();
|
|
|
|
return VxVector2(x / len, y / len);
|
|
|
|
}
|
2023-09-13 22:33:41 +08:00
|
|
|
};
|
2023-08-22 15:30:26 +08:00
|
|
|
|
2023-09-13 22:33:41 +08:00
|
|
|
struct VxVector3 {
|
2023-09-16 18:31:25 +08:00
|
|
|
CKFLOAT x, y, z;
|
2023-09-13 22:33:41 +08:00
|
|
|
VxVector3() : x(0.0f), y(0.0f), z(0.0f) {}
|
2023-09-16 18:31:25 +08:00
|
|
|
VxVector3(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z) : x(_x), y(_y), z(_z) {}
|
2024-08-17 20:43:27 +08:00
|
|
|
YYCC_DEF_CLS_COPY_MOVE(VxVector3);
|
2023-09-16 18:31:25 +08:00
|
|
|
CKFLOAT& operator[](size_t i) {
|
2023-09-13 22:33:41 +08:00
|
|
|
switch (i) {
|
|
|
|
case 0: return x;
|
|
|
|
case 1: return y;
|
|
|
|
case 2: return z;
|
2024-08-17 20:43:27 +08:00
|
|
|
default: throw LogicException("Invalid index for VxVector3::operator[].");
|
2023-09-13 22:33:41 +08:00
|
|
|
}
|
2023-11-26 20:36:25 +08:00
|
|
|
}
|
|
|
|
const CKFLOAT& operator[](size_t i) const {
|
2023-09-19 15:20:40 +08:00
|
|
|
switch (i) {
|
|
|
|
case 0: return x;
|
|
|
|
case 1: return y;
|
|
|
|
case 2: return z;
|
2024-08-17 20:43:27 +08:00
|
|
|
default: throw LogicException("Invalid index for VxVector3::operator[].");
|
2023-09-19 15:20:40 +08:00
|
|
|
}
|
2023-09-13 22:33:41 +08:00
|
|
|
}
|
|
|
|
VxVector3& operator+=(const VxVector3& rhs) {
|
|
|
|
x += rhs.x;
|
|
|
|
y += rhs.y;
|
|
|
|
z += rhs.z;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
friend VxVector3 operator+(const VxVector3& lhs, const VxVector3& rhs) {
|
|
|
|
return VxVector3(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z);
|
|
|
|
}
|
|
|
|
VxVector3& operator-=(const VxVector3& rhs) {
|
|
|
|
x -= rhs.x;
|
|
|
|
y -= rhs.y;
|
|
|
|
z -= rhs.z;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
friend VxVector3 operator-(const VxVector3& lhs, const VxVector3& rhs) {
|
|
|
|
return VxVector3(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z);
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
VxVector3& operator*=(CKFLOAT rhs) {
|
2023-09-13 22:33:41 +08:00
|
|
|
x *= rhs;
|
|
|
|
y *= rhs;
|
|
|
|
z *= rhs;
|
|
|
|
return *this;
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
friend VxVector3 operator*(const VxVector3& lhs, CKFLOAT rhs) {
|
2023-09-13 22:33:41 +08:00
|
|
|
return VxVector3(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs);
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
friend VxVector3 operator*(CKFLOAT lhs, const VxVector3& rhs) {
|
2023-09-13 22:33:41 +08:00
|
|
|
return VxVector3(lhs * rhs.x, lhs * rhs.y, lhs * rhs.z);
|
|
|
|
}
|
2023-09-19 15:20:40 +08:00
|
|
|
friend CKFLOAT operator*(const VxVector3& lhs, const VxVector3& rhs) {
|
|
|
|
return (lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z);
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
VxVector3& operator/=(CKFLOAT rhs) {
|
2023-09-13 22:33:41 +08:00
|
|
|
if (rhs == 0.0f) return *this;
|
|
|
|
x /= rhs;
|
|
|
|
y /= rhs;
|
|
|
|
z /= rhs;
|
|
|
|
return *this;
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
friend VxVector3 operator/(const VxVector3& lhs, CKFLOAT rhs) {
|
2023-09-13 22:33:41 +08:00
|
|
|
if (rhs == 0.0f) return VxVector3(0.0f, 0.0f, 0.0f);
|
|
|
|
return VxVector3(lhs.x / rhs, lhs.y / rhs, lhs.z / rhs);
|
|
|
|
}
|
|
|
|
bool operator==(const VxVector3& rhs) const {
|
|
|
|
return (x == rhs.x && y == rhs.y && z == rhs.z);
|
|
|
|
}
|
2023-09-19 15:20:40 +08:00
|
|
|
CKFLOAT SquaredLength() const {
|
|
|
|
return (x * x + y * y + z * z);
|
|
|
|
}
|
|
|
|
CKFLOAT Length() const {
|
|
|
|
return std::sqrt(SquaredLength());
|
|
|
|
}
|
|
|
|
void Normalized() {
|
|
|
|
CKFLOAT len = Length();
|
|
|
|
if (len == 0.0f) return;
|
|
|
|
x /= len;
|
|
|
|
y /= len;
|
|
|
|
z /= len;
|
|
|
|
}
|
|
|
|
VxVector3 Normalize() const {
|
|
|
|
CKFLOAT len = Length();
|
|
|
|
if (len == 0.0f) return VxVector3();
|
|
|
|
return VxVector3(x / len, y / len, z / len);
|
|
|
|
}
|
2023-08-22 15:30:26 +08:00
|
|
|
};
|
|
|
|
|
2023-09-13 22:33:41 +08:00
|
|
|
struct VxVector4 {
|
2023-09-16 18:31:25 +08:00
|
|
|
CKFLOAT x, y, z, w;
|
2023-09-13 22:33:41 +08:00
|
|
|
VxVector4() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {}
|
2023-09-16 18:31:25 +08:00
|
|
|
VxVector4(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z, CKFLOAT _w) : x(_x), y(_y), z(_z), w(_w) {}
|
2024-08-17 20:43:27 +08:00
|
|
|
YYCC_DEF_CLS_COPY_MOVE(VxVector4);
|
2023-09-16 18:31:25 +08:00
|
|
|
CKFLOAT& operator[](size_t i) {
|
2023-09-13 22:33:41 +08:00
|
|
|
switch (i) {
|
|
|
|
case 0: return x;
|
|
|
|
case 1: return y;
|
|
|
|
case 2: return z;
|
|
|
|
case 3: return w;
|
2024-08-17 20:43:27 +08:00
|
|
|
default: throw LogicException("Invalid index for VxVector4::operator[].");
|
2023-09-13 22:33:41 +08:00
|
|
|
}
|
2023-11-26 20:36:25 +08:00
|
|
|
}
|
|
|
|
const CKFLOAT& operator[](size_t i) const {
|
2023-09-19 15:20:40 +08:00
|
|
|
switch (i) {
|
|
|
|
case 0: return x;
|
|
|
|
case 1: return y;
|
|
|
|
case 2: return z;
|
|
|
|
case 3: return w;
|
2024-08-17 20:43:27 +08:00
|
|
|
default: throw LogicException("Invalid index for VxVector4::operator[].");
|
2023-09-19 15:20:40 +08:00
|
|
|
}
|
2023-09-13 22:33:41 +08:00
|
|
|
}
|
|
|
|
VxVector4& operator+=(const VxVector4& rhs) {
|
|
|
|
x += rhs.x;
|
|
|
|
y += rhs.y;
|
|
|
|
z += rhs.z;
|
|
|
|
w += rhs.w;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
friend VxVector4 operator+(const VxVector4& lhs, const VxVector4& rhs) {
|
|
|
|
return VxVector4(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z, lhs.w + rhs.w);
|
|
|
|
}
|
|
|
|
VxVector4& operator-=(const VxVector4& rhs) {
|
|
|
|
x -= rhs.x;
|
|
|
|
y -= rhs.y;
|
|
|
|
z -= rhs.z;
|
|
|
|
w -= rhs.w;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
friend VxVector4 operator-(const VxVector4& lhs, const VxVector4& rhs) {
|
|
|
|
return VxVector4(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z, lhs.w - rhs.w);
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
VxVector4& operator*=(CKFLOAT rhs) {
|
2023-09-13 22:33:41 +08:00
|
|
|
x *= rhs;
|
|
|
|
y *= rhs;
|
|
|
|
z *= rhs;
|
|
|
|
w *= rhs;
|
|
|
|
return *this;
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
friend VxVector4 operator*(const VxVector4& lhs, CKFLOAT rhs) {
|
2023-09-13 22:33:41 +08:00
|
|
|
return VxVector4(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs, lhs.w * rhs);
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
friend VxVector4 operator*(CKFLOAT lhs, const VxVector4& rhs) {
|
2023-09-13 22:33:41 +08:00
|
|
|
return VxVector4(lhs * rhs.x, lhs * rhs.y, lhs * rhs.z, lhs * rhs.w);
|
|
|
|
}
|
2023-09-19 15:20:40 +08:00
|
|
|
friend CKFLOAT operator*(const VxVector4& lhs, const VxVector4& rhs) {
|
|
|
|
return (lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z + lhs.w * rhs.w);
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
VxVector4& operator/=(CKFLOAT rhs) {
|
2023-09-13 22:33:41 +08:00
|
|
|
if (rhs == 0.0f) return *this;
|
|
|
|
x /= rhs;
|
|
|
|
y /= rhs;
|
|
|
|
z /= rhs;
|
|
|
|
w /= rhs;
|
|
|
|
return *this;
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
friend VxVector4 operator/(const VxVector4& lhs, CKFLOAT rhs) {
|
2023-09-13 22:33:41 +08:00
|
|
|
if (rhs == 0.0f) return VxVector4(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
return VxVector4(lhs.x / rhs, lhs.y / rhs, lhs.z / rhs, lhs.w / rhs);
|
|
|
|
}
|
|
|
|
bool operator==(const VxVector4& rhs) const {
|
|
|
|
return (x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w);
|
|
|
|
}
|
2023-09-19 15:20:40 +08:00
|
|
|
CKFLOAT SquaredLength() const {
|
|
|
|
return (x * x + y * y + z * z + w * w);
|
|
|
|
}
|
|
|
|
CKFLOAT Length() const {
|
|
|
|
return std::sqrt(SquaredLength());
|
|
|
|
}
|
|
|
|
void Normalized() {
|
|
|
|
CKFLOAT len = Length();
|
|
|
|
if (len == 0.0f) return;
|
|
|
|
x /= len;
|
|
|
|
y /= len;
|
|
|
|
z /= len;
|
|
|
|
w /= len;
|
|
|
|
}
|
|
|
|
VxVector4 Normalize() const {
|
|
|
|
CKFLOAT len = Length();
|
|
|
|
if (len == 0.0f) return VxVector4();
|
|
|
|
return VxVector4(x / len, y / len, z / len, w / len);
|
|
|
|
}
|
2023-08-22 15:30:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct VxQuaternion {
|
2023-09-16 18:31:25 +08:00
|
|
|
CKFLOAT x, y, z, w;
|
2024-08-17 20:43:27 +08:00
|
|
|
VxQuaternion() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {} // set your custom init.
|
2023-09-16 18:31:25 +08:00
|
|
|
VxQuaternion(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z, CKFLOAT _w) : x(_x), y(_y), z(_z), w(_w) {}
|
2024-08-17 20:43:27 +08:00
|
|
|
YYCC_DEF_CLS_COPY_MOVE(VxQuaternion);
|
2023-09-16 18:31:25 +08:00
|
|
|
CKFLOAT& operator[](size_t i) {
|
2023-09-13 22:33:41 +08:00
|
|
|
switch (i) {
|
|
|
|
case 0: return x;
|
|
|
|
case 1: return y;
|
|
|
|
case 2: return z;
|
|
|
|
case 3: return w;
|
2024-08-17 20:43:27 +08:00
|
|
|
default: throw LogicException("Invalid index for VxQuaternion::operator[].");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const CKFLOAT& operator[](size_t i) const {
|
|
|
|
switch (i) {
|
|
|
|
case 0: return x;
|
|
|
|
case 1: return y;
|
|
|
|
case 2: return z;
|
|
|
|
case 3: return w;
|
|
|
|
default: throw LogicException("Invalid index for VxQuaternion::operator[].");
|
2023-09-13 22:33:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
bool operator==(const VxQuaternion& rhs) const {
|
|
|
|
return (x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w);
|
|
|
|
}
|
|
|
|
};
|
2023-08-22 15:30:26 +08:00
|
|
|
|
2023-09-13 22:33:41 +08:00
|
|
|
struct VxColor {
|
2023-09-16 18:31:25 +08:00
|
|
|
CKFLOAT r, g, b, a;
|
2024-08-17 20:43:27 +08:00
|
|
|
VxColor() : r(0.0f), g(0.0f), b(0.0f), a(0.0f) {} // set your custom init.
|
2023-09-16 18:31:25 +08:00
|
|
|
VxColor(CKFLOAT _r, CKFLOAT _g, CKFLOAT _b, CKFLOAT _a) : r(_r), g(_g), b(_b), a(_a) {}
|
|
|
|
VxColor(CKDWORD argb) { FromARGB(argb); }
|
2024-08-17 20:43:27 +08:00
|
|
|
YYCC_DEF_CLS_COPY_MOVE(VxColor);
|
2023-09-16 18:31:25 +08:00
|
|
|
void FromARGB(CKDWORD argb) {
|
2023-09-13 22:33:41 +08:00
|
|
|
a = ((argb & 0xFF000000) >> 24) / 255.0f;
|
|
|
|
r = ((argb & 0x00FF0000) >> 16) / 255.0f;
|
|
|
|
g = ((argb & 0x0000FF00) >> 8) / 255.0f;
|
|
|
|
b = ((argb & 0x000000FF) >> 0) / 255.0f;
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
CKDWORD ToARGB() const {
|
|
|
|
CKDWORD argb = 0;
|
|
|
|
argb |= static_cast<CKDWORD>(a * 255.0f);
|
2023-09-13 22:33:41 +08:00
|
|
|
argb <<= 8;
|
2023-09-16 18:31:25 +08:00
|
|
|
argb |= static_cast<CKDWORD>(r * 255.0f);
|
2023-09-13 22:33:41 +08:00
|
|
|
argb <<= 8;
|
2023-09-16 18:31:25 +08:00
|
|
|
argb |= static_cast<CKDWORD>(g * 255.0f);
|
2023-09-13 22:33:41 +08:00
|
|
|
argb <<= 8;
|
2023-09-16 18:31:25 +08:00
|
|
|
argb |= static_cast<CKDWORD>(b * 255.0f);
|
2023-09-13 22:33:41 +08:00
|
|
|
return argb;
|
|
|
|
}
|
|
|
|
void Regulate() {
|
|
|
|
if (r > 1.0f) r = 1.0f;
|
|
|
|
else if (r < 0.0f) r = 0.0f;
|
|
|
|
if (g > 1.0f) g = 1.0f;
|
2023-09-19 15:20:40 +08:00
|
|
|
else if (g < 0.0f) g = 0.0f;
|
2023-09-13 22:33:41 +08:00
|
|
|
if (b > 1.0f) b = 1.0f;
|
|
|
|
else if (b < 0.0f) b = 0.0f;
|
|
|
|
if (a > 1.0f) a = 1.0f;
|
|
|
|
else if (a < 0.0f) a = 0.0f;
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
CKFLOAT& operator[](size_t i) {
|
2023-09-13 22:33:41 +08:00
|
|
|
switch (i) {
|
|
|
|
case 0: return r;
|
|
|
|
case 1: return g;
|
|
|
|
case 2: return b;
|
|
|
|
case 3: return a;
|
2024-08-17 20:43:27 +08:00
|
|
|
default: throw LogicException("Invalid index for VxColor::operator[].");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const CKFLOAT& operator[](size_t i) const {
|
|
|
|
switch (i) {
|
|
|
|
case 0: return r;
|
|
|
|
case 1: return g;
|
|
|
|
case 2: return b;
|
|
|
|
case 3: return a;
|
|
|
|
default: throw LogicException("Invalid index for VxColor::operator[].");
|
2023-09-13 22:33:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
bool operator==(const VxColor& rhs) const {
|
|
|
|
return (r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a);
|
|
|
|
}
|
2023-08-22 15:30:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct VxMatrix {
|
2023-09-16 18:31:25 +08:00
|
|
|
CKFLOAT m_Data[4][4];
|
2024-08-17 20:43:27 +08:00
|
|
|
VxMatrix() : m_Data() { ResetToIdentity(); }
|
2023-09-16 18:31:25 +08:00
|
|
|
VxMatrix(CKFLOAT m[4][4]) : m_Data() { std::memcpy(m_Data, m, sizeof(m_Data)); }
|
2024-08-17 20:43:27 +08:00
|
|
|
YYCC_DEF_CLS_COPY_MOVE(VxMatrix);
|
2023-09-19 22:32:07 +08:00
|
|
|
void ResetToIdentity() {
|
|
|
|
std::memset(m_Data, 0, sizeof(m_Data));
|
|
|
|
m_Data[0][0] = m_Data[1][1] = m_Data[2][2] = m_Data[3][3] = 1.0f;
|
|
|
|
}
|
2023-09-13 22:33:41 +08:00
|
|
|
VxVector4& operator[](size_t i) {
|
2024-08-17 20:43:27 +08:00
|
|
|
if (i >= 4) throw LogicException("Invalid index for VxMatrix::operator[].");
|
2023-09-13 22:33:41 +08:00
|
|
|
return *(reinterpret_cast<VxVector4*>(m_Data) + i);
|
|
|
|
}
|
2023-09-19 22:32:07 +08:00
|
|
|
const VxVector4& operator[](size_t i) const {
|
2024-08-17 20:43:27 +08:00
|
|
|
if (i >= 4) throw LogicException("Invalid index for VxMatrix::operator[].");
|
2023-09-19 22:32:07 +08:00
|
|
|
return *(reinterpret_cast<const VxVector4*>(m_Data) + i);
|
|
|
|
}
|
2023-09-13 22:33:41 +08:00
|
|
|
bool operator==(const VxMatrix& rhs) const {
|
|
|
|
return std::memcmp(m_Data, rhs.m_Data, sizeof(m_Data)) == 0;
|
|
|
|
}
|
2023-08-22 15:30:26 +08:00
|
|
|
};
|
|
|
|
|
2023-09-15 16:15:07 +08:00
|
|
|
template<class _Ty, std::enable_if_t<std::is_pointer_v<_Ty>, int> = 0>
|
|
|
|
class VxStridedData {
|
|
|
|
public:
|
2023-09-16 18:31:25 +08:00
|
|
|
VxStridedData(_Ty ptr, CKDWORD stride) :
|
2023-09-20 10:49:32 +08:00
|
|
|
m_Ptr(reinterpret_cast<CKBYTE*>(ptr)),
|
2023-09-19 15:20:40 +08:00
|
|
|
m_Stride(stride) {}
|
2023-09-15 16:15:07 +08:00
|
|
|
~VxStridedData() {}
|
|
|
|
|
|
|
|
_Ty operator[](size_t idx) {
|
|
|
|
return reinterpret_cast<_Ty>(m_Ptr + (m_Stride * idx));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2023-09-16 18:31:25 +08:00
|
|
|
CKBYTE* m_Ptr;
|
|
|
|
CKDWORD m_Stride;
|
2023-09-15 16:15:07 +08:00
|
|
|
};
|
|
|
|
|
2023-08-22 15:30:26 +08:00
|
|
|
/**
|
2023-09-07 16:27:41 +08:00
|
|
|
* VxImageDescEx describe the height, width,
|
|
|
|
* and etc for image.
|
|
|
|
* Also it hold a pointer to raw image data.
|
2023-09-11 14:39:07 +08:00
|
|
|
* The image data must be 32bit ARGB8888 format.
|
2023-09-07 16:27:41 +08:00
|
|
|
* Thus the size of Image must be 4 * Width * Height.
|
2023-09-12 20:49:19 +08:00
|
|
|
* And the image buffer must is in B, G, R, A order because little endian.
|
2023-08-22 15:30:26 +08:00
|
|
|
*/
|
2023-09-07 16:27:41 +08:00
|
|
|
class VxImageDescEx {
|
2023-09-12 20:49:19 +08:00
|
|
|
public:
|
2023-09-16 18:31:25 +08:00
|
|
|
static constexpr CKDWORD ColorFactorSize = 1u;
|
|
|
|
static constexpr CKDWORD PixelSize = ColorFactorSize * 4u;
|
2023-09-07 16:27:41 +08:00
|
|
|
public:
|
2023-09-11 14:39:07 +08:00
|
|
|
VxImageDescEx() :
|
|
|
|
m_Width(0), m_Height(0), m_Image(nullptr) {}
|
2023-09-16 18:31:25 +08:00
|
|
|
VxImageDescEx(CKDWORD width, CKDWORD height) :
|
2023-09-11 14:39:07 +08:00
|
|
|
m_Width(width), m_Height(height), m_Image(nullptr) {
|
|
|
|
CreateImage(width, height);
|
2023-09-07 16:27:41 +08:00
|
|
|
}
|
2023-09-10 21:33:43 +08:00
|
|
|
VxImageDescEx(const VxImageDescEx& rhs) :
|
2023-09-11 14:39:07 +08:00
|
|
|
m_Width(rhs.m_Width), m_Height(rhs.m_Height), m_Image(nullptr) {
|
2023-09-10 21:33:43 +08:00
|
|
|
// copy image
|
2023-09-11 14:39:07 +08:00
|
|
|
if (rhs.m_Image != nullptr) {
|
|
|
|
CreateImage(rhs.m_Width, rhs.m_Height, rhs.m_Image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VxImageDescEx(VxImageDescEx&& rhs) :
|
|
|
|
m_Width(rhs.m_Width), m_Height(rhs.m_Height), m_Image(rhs.m_Image) {
|
|
|
|
// move image
|
|
|
|
rhs.m_Height = 0;
|
|
|
|
rhs.m_Width = 0;
|
|
|
|
rhs.m_Image = nullptr;
|
|
|
|
}
|
|
|
|
VxImageDescEx& operator=(const VxImageDescEx& rhs) {
|
|
|
|
FreeImage();
|
|
|
|
|
|
|
|
m_Width = rhs.m_Width;
|
|
|
|
m_Height = rhs.m_Height;
|
|
|
|
if (rhs.m_Image != nullptr) {
|
|
|
|
CreateImage(rhs.m_Width, rhs.m_Height, rhs.m_Image);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
VxImageDescEx& operator=(VxImageDescEx&& rhs) {
|
|
|
|
FreeImage();
|
|
|
|
|
|
|
|
m_Height = rhs.m_Height;
|
|
|
|
m_Width = rhs.m_Width;
|
|
|
|
m_Image = rhs.m_Image;
|
|
|
|
rhs.m_Height = 0;
|
|
|
|
rhs.m_Width = 0;
|
|
|
|
rhs.m_Image = nullptr;
|
|
|
|
|
|
|
|
return *this;
|
2023-09-10 21:33:43 +08:00
|
|
|
}
|
2023-09-07 16:27:41 +08:00
|
|
|
~VxImageDescEx() {
|
2023-09-11 14:39:07 +08:00
|
|
|
FreeImage();
|
|
|
|
}
|
|
|
|
|
2023-09-16 18:31:25 +08:00
|
|
|
void CreateImage(CKDWORD Width, CKDWORD Height) {
|
2023-09-11 14:39:07 +08:00
|
|
|
FreeImage();
|
|
|
|
m_Width = Width;
|
|
|
|
m_Height = Height;
|
2023-09-16 18:31:25 +08:00
|
|
|
m_Image = new CKBYTE[GetImageSize()];
|
2023-09-11 14:39:07 +08:00
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
void CreateImage(CKDWORD Width, CKDWORD Height, void* dataptr) {
|
2023-09-11 14:39:07 +08:00
|
|
|
CreateImage(Width, Height);
|
|
|
|
std::memcpy(m_Image, dataptr, GetImageSize());
|
|
|
|
}
|
|
|
|
void FreeImage() {
|
|
|
|
m_Width = 0;
|
|
|
|
m_Height = 0;
|
|
|
|
if (m_Image != nullptr) {
|
|
|
|
delete[] m_Image;
|
|
|
|
m_Image = nullptr;
|
|
|
|
}
|
2023-09-07 16:27:41 +08:00
|
|
|
}
|
|
|
|
|
2023-09-16 18:31:25 +08:00
|
|
|
CKDWORD GetImageSize() const {
|
|
|
|
return static_cast<CKDWORD>(PixelSize * m_Width * m_Height);
|
2023-09-07 16:27:41 +08:00
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
const CKBYTE* GetImage() const {
|
2023-09-07 21:57:48 +08:00
|
|
|
return m_Image;
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
CKBYTE* GetMutableImage() {
|
2023-09-07 16:27:41 +08:00
|
|
|
return m_Image;
|
2023-09-05 22:23:05 +08:00
|
|
|
}
|
|
|
|
|
2023-09-16 18:31:25 +08:00
|
|
|
CKDWORD GetPixelCount() const {
|
|
|
|
return static_cast<CKDWORD>(m_Width * m_Height);
|
2023-09-05 22:23:05 +08:00
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
const CKDWORD* GetPixels() const {
|
|
|
|
return reinterpret_cast<CKDWORD*>(m_Image);
|
2023-09-07 21:57:48 +08:00
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
CKDWORD* GetMutablePixels() {
|
|
|
|
return reinterpret_cast<CKDWORD*>(m_Image);
|
2023-09-05 22:23:05 +08:00
|
|
|
}
|
2023-08-22 15:30:26 +08:00
|
|
|
|
2023-09-16 18:31:25 +08:00
|
|
|
CKDWORD GetWidth() const {
|
2023-09-07 16:27:41 +08:00
|
|
|
return m_Width;
|
|
|
|
}
|
2023-09-16 18:31:25 +08:00
|
|
|
CKDWORD GetHeight() const {
|
2023-09-07 16:27:41 +08:00
|
|
|
return m_Height;
|
|
|
|
}
|
|
|
|
|
2023-09-11 14:39:07 +08:00
|
|
|
bool IsValid() const {
|
|
|
|
return (
|
|
|
|
m_Width != 0u &&
|
|
|
|
m_Height != 0u &&
|
|
|
|
m_Image != nullptr
|
2023-09-19 15:20:40 +08:00
|
|
|
);
|
2023-09-11 14:39:07 +08:00
|
|
|
}
|
2023-09-07 16:27:41 +08:00
|
|
|
bool IsHWEqual(const VxImageDescEx& rhs) const {
|
|
|
|
return (m_Width == rhs.m_Width && m_Height == rhs.m_Height);
|
|
|
|
}
|
2023-09-11 14:39:07 +08:00
|
|
|
// bool IsMaskEqual(const VxImageDescEx& rhs) const {
|
2024-08-17 20:43:27 +08:00
|
|
|
// return (
|
|
|
|
// m_RedMask == rhs.m_RedMask &&
|
|
|
|
// m_GreenMask == rhs.m_GreenMask &&
|
|
|
|
// m_BlueMask == rhs.m_BlueMask &&
|
|
|
|
// m_AlphaMask == rhs.m_AlphaMask
|
|
|
|
// );
|
|
|
|
// }
|
2023-09-07 16:27:41 +08:00
|
|
|
|
2024-08-17 20:43:27 +08:00
|
|
|
//public:
|
|
|
|
// CKDWORD m_RedMask;
|
|
|
|
// CKDWORD m_GreenMask;
|
|
|
|
// CKDWORD m_BlueMask;
|
|
|
|
// CKDWORD m_AlphaMask;
|
2023-09-07 16:27:41 +08:00
|
|
|
|
|
|
|
protected:
|
2023-09-16 18:31:25 +08:00
|
|
|
CKDWORD m_Width; /**< Width in pixel of the image */
|
|
|
|
CKDWORD m_Height; /**< Height in pixel of the image */
|
|
|
|
CKBYTE* m_Image; /**< A pointer point to current processing image */
|
2023-08-22 15:30:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|