write some boring struct in VxTypes
This commit is contained in:
@ -9,6 +9,9 @@ namespace LibCmo::CK2::ObjImpls {
|
||||
* Because Virtools directly write a raw struct into file,
|
||||
* and our defines are different with Virtools.
|
||||
* So we need create a fake struct.
|
||||
* @remark
|
||||
* All pointers should translate to DWORD(32 bit) for platform independent.
|
||||
* Otherwise this struct may be corrupted in x64 platform because pointer is QWORD in x64.
|
||||
*/
|
||||
struct FakeBitmapProperties {
|
||||
CKINT m_Size;
|
||||
@ -50,10 +53,10 @@ namespace LibCmo::CK2::ObjImpls {
|
||||
CK2::CKWORD BytesPerColorEntry; ///< ColorMap Stride
|
||||
CK2::CKWORD ColorMapEntries; ///< If other than 0 image is palletized
|
||||
|
||||
CK2::CKBYTE* ColorMap; ///< Palette colors
|
||||
CK2::CKBYTE* Image; ///< Image
|
||||
/*CK2::CKBYTE**/CK2::CKDWORD ColorMap; ///< Palette colors
|
||||
/*CK2::CKBYTE**/CK2::CKDWORD Image; ///< Image
|
||||
}m_Format;
|
||||
void* m_Data;
|
||||
/*void**/CK2::CKDWORD m_Data;
|
||||
};
|
||||
|
||||
CKTexture::CKTexture(CKContext* ctx, CK_ID ckid, CKSTRING name) :
|
||||
|
@ -23,40 +23,262 @@ namespace LibCmo::VxMath {
|
||||
class VxMemoryMappedFile;
|
||||
|
||||
//---- Misc
|
||||
|
||||
/**
|
||||
* @brief Class representation of a Vector in 3 dimensions
|
||||
*/
|
||||
struct VxVector {
|
||||
float x, y, z;
|
||||
|
||||
VxVector() : x(0.0f), y(0.0f), z(0.0f) {}
|
||||
VxVector(float f) : x(f), y(f), z(f) {}
|
||||
VxVector(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
|
||||
VxVector(const float f[3]) : x(f[0]), y(f[1]), z(f[2]) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class representation of a Vector in 2 dimensions
|
||||
*/
|
||||
struct Vx2DVector {
|
||||
|
||||
struct VxVector2 {
|
||||
float x, y;
|
||||
|
||||
Vx2DVector() : x(0.0f), y(0.0f) {}
|
||||
Vx2DVector(float f) : x(f), y(f) {}
|
||||
Vx2DVector(float _x, float _y) : x(_x), y(_y) {}
|
||||
Vx2DVector(CK2::CKINT iX, CK2::CKINT iY) : x((float)iX), y((float)iY) {}
|
||||
Vx2DVector(const float f[2]) : x(f[0]), y(f[1]) {}
|
||||
VxVector2() : x(0.0f), y(0.0f) {}
|
||||
VxVector2(float _x, float _y) : x(_x), y(_y) {}
|
||||
LIBCMO_DEFAULT_COPY_MOVE(VxVector2);
|
||||
float& operator[](size_t i) {
|
||||
switch (i) {
|
||||
case 0: return x;
|
||||
case 1: return y;
|
||||
default: return x;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
VxVector2& operator*=(float rhs) {
|
||||
x *= rhs;
|
||||
y *= rhs;
|
||||
return *this;
|
||||
}
|
||||
friend VxVector2 operator*(const VxVector2& lhs, float rhs) {
|
||||
return VxVector2(lhs.x * rhs, lhs.y * rhs);
|
||||
}
|
||||
friend VxVector2 operator*(float lhs, const VxVector2& rhs) {
|
||||
return VxVector2(lhs * rhs.x, lhs * rhs.y);
|
||||
}
|
||||
VxVector2& operator/=(float rhs) {
|
||||
if (rhs == 0.0f) return *this;
|
||||
x /= rhs;
|
||||
y /= rhs;
|
||||
return *this;
|
||||
}
|
||||
friend VxVector2 operator/(const VxVector2& lhs, float rhs) {
|
||||
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);
|
||||
}
|
||||
bool operator!=(const VxVector2& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
struct VxVector3 {
|
||||
float x, y, z;
|
||||
VxVector3() : x(0.0f), y(0.0f), z(0.0f) {}
|
||||
VxVector3(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
|
||||
LIBCMO_DEFAULT_COPY_MOVE(VxVector3);
|
||||
float& operator[](size_t i) {
|
||||
switch (i) {
|
||||
case 0: return x;
|
||||
case 1: return y;
|
||||
case 2: return z;
|
||||
default: return x;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
VxVector3& operator*=(float rhs) {
|
||||
x *= rhs;
|
||||
y *= rhs;
|
||||
z *= rhs;
|
||||
return *this;
|
||||
}
|
||||
friend VxVector3 operator*(const VxVector3& lhs, float rhs) {
|
||||
return VxVector3(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs);
|
||||
}
|
||||
friend VxVector3 operator*(float lhs, const VxVector3& rhs) {
|
||||
return VxVector3(lhs * rhs.x, lhs * rhs.y, lhs * rhs.z);
|
||||
}
|
||||
VxVector3& operator/=(float rhs) {
|
||||
if (rhs == 0.0f) return *this;
|
||||
x /= rhs;
|
||||
y /= rhs;
|
||||
z /= rhs;
|
||||
return *this;
|
||||
}
|
||||
friend VxVector3 operator/(const VxVector3& lhs, float rhs) {
|
||||
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);
|
||||
}
|
||||
bool operator!=(const VxVector3& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
struct VxVector4 {
|
||||
float x, y, z, w;
|
||||
VxVector4() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {}
|
||||
VxVector4(float _x, float _y, float _z, float _w) : x(_x), y(_y), z(_z), w(_w) {}
|
||||
LIBCMO_DEFAULT_COPY_MOVE(VxVector4);
|
||||
float& operator[](size_t i) {
|
||||
switch (i) {
|
||||
case 0: return x;
|
||||
case 1: return y;
|
||||
case 2: return z;
|
||||
case 3: return w;
|
||||
default: return x;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
VxVector4& operator*=(float rhs) {
|
||||
x *= rhs;
|
||||
y *= rhs;
|
||||
z *= rhs;
|
||||
w *= rhs;
|
||||
return *this;
|
||||
}
|
||||
friend VxVector4 operator*(const VxVector4& lhs, float rhs) {
|
||||
return VxVector4(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs, lhs.w * rhs);
|
||||
}
|
||||
friend VxVector4 operator*(float lhs, const VxVector4& rhs) {
|
||||
return VxVector4(lhs * rhs.x, lhs * rhs.y, lhs * rhs.z, lhs * rhs.w);
|
||||
}
|
||||
VxVector4& operator/=(float rhs) {
|
||||
if (rhs == 0.0f) return *this;
|
||||
x /= rhs;
|
||||
y /= rhs;
|
||||
z /= rhs;
|
||||
w /= rhs;
|
||||
return *this;
|
||||
}
|
||||
friend VxVector4 operator/(const VxVector4& lhs, float rhs) {
|
||||
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);
|
||||
}
|
||||
bool operator!=(const VxVector4& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class representation of a Quaternion
|
||||
*/
|
||||
struct VxQuaternion {
|
||||
float x, y, z, w;
|
||||
VxQuaternion() : x(0.0f), y(0.0f), z(0.0f), w(1.0f) {} // set your custom init.
|
||||
VxQuaternion(float _x, float _y, float _z, float _w) : x(_x), y(_y), z(_z), w(_w) {}
|
||||
LIBCMO_DEFAULT_COPY_MOVE(VxQuaternion);
|
||||
float& operator[](size_t i) {
|
||||
switch (i) {
|
||||
case 0: return x;
|
||||
case 1: return y;
|
||||
case 2: return z;
|
||||
case 3: return w;
|
||||
default: return x;
|
||||
}
|
||||
}
|
||||
bool operator==(const VxQuaternion& rhs) const {
|
||||
return (x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w);
|
||||
}
|
||||
bool operator!=(const VxQuaternion& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
VxQuaternion() : x(0.0f), y(0.0f), z(0.0f), w(1.0f) {}
|
||||
VxQuaternion(float X, float Y, float Z, float W) : x(X), y(Y), z(Z), w(W) {}
|
||||
struct VxColor {
|
||||
float r, g, b, a;
|
||||
VxColor() : r(0.0f), g(0.0f), b(0.0f), a(1.0f) {} // set your custom init.
|
||||
VxColor(float _r, float _g, float _b, float _a) : r(_r), g(_g), b(_b), a(_a) {}
|
||||
VxColor(CK2::CKDWORD argb) {
|
||||
a = ((argb & 0xFF000000) >> 24) / 255.0f;
|
||||
r = ((argb & 0x00FF0000) >> 16) / 255.0f;
|
||||
g = ((argb & 0x0000FF00) >> 8) / 255.0f;
|
||||
b = ((argb & 0x000000FF) >> 0) / 255.0f;
|
||||
}
|
||||
LIBCMO_DEFAULT_COPY_MOVE(VxColor);
|
||||
CK2::CKDWORD ToARGB() const {
|
||||
CK2::CKDWORD argb = 0;
|
||||
argb |= static_cast<CK2::CKDWORD>(a * 255.0f);
|
||||
argb <<= 8;
|
||||
argb |= static_cast<CK2::CKDWORD>(r * 255.0f);
|
||||
argb <<= 8;
|
||||
argb |= static_cast<CK2::CKDWORD>(g * 255.0f);
|
||||
argb <<= 8;
|
||||
argb |= static_cast<CK2::CKDWORD>(b * 255.0f);
|
||||
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;
|
||||
else if (g < 0.0f) g= 0.0f;
|
||||
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;
|
||||
}
|
||||
float& operator[](size_t i) {
|
||||
switch (i) {
|
||||
case 0: return r;
|
||||
case 1: return g;
|
||||
case 2: return b;
|
||||
case 3: return a;
|
||||
default: return r;
|
||||
}
|
||||
}
|
||||
bool operator==(const VxColor& rhs) const {
|
||||
return (r == rhs.r && g == rhs.g && b == rhs.b && a == rhs.a);
|
||||
}
|
||||
bool operator!=(const VxColor& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
struct VxMatrix {
|
||||
@ -67,6 +289,18 @@ namespace LibCmo::VxMath {
|
||||
m_Data[0][0] = m_Data[1][1] = m_Data[2][2] = m_Data[3][3] = 1.0f;
|
||||
}
|
||||
VxMatrix(float m[4][4]) : m_Data() { std::memcpy(m_Data, m, sizeof(m_Data)); }
|
||||
LIBCMO_DEFAULT_COPY_MOVE(VxMatrix);
|
||||
|
||||
VxVector4& operator[](size_t i) {
|
||||
if (i >= 4) i = 0;
|
||||
return *(reinterpret_cast<VxVector4*>(m_Data) + i);
|
||||
}
|
||||
bool operator==(const VxMatrix& rhs) const {
|
||||
return std::memcmp(m_Data, rhs.m_Data, sizeof(m_Data)) == 0;
|
||||
}
|
||||
bool operator!=(const VxMatrix& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user