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>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The VxMath part of LibCmo.
|
|
|
|
* These classes are prefixed with Vx in original Virtools SDK.
|
|
|
|
*/
|
|
|
|
namespace LibCmo::VxMath {
|
|
|
|
|
|
|
|
// ========== Type Definition ==========
|
|
|
|
|
|
|
|
|
|
|
|
// ========== Class List ==========
|
|
|
|
//--- Important classes
|
|
|
|
|
|
|
|
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 {
|
|
|
|
float x, y;
|
|
|
|
|
|
|
|
Vx2DVector() : x(0.0f), y(0.0f) {}
|
|
|
|
Vx2DVector(float f) : x(f), y(f) {}
|
2023-08-25 21:57:22 +08:00
|
|
|
Vx2DVector(float _x, float _y) : x(_x), y(_y) {}
|
2023-08-22 15:30:26 +08:00
|
|
|
Vx2DVector(CK2::CKINT iX, CK2::CKINT iY) : x((float)iX), y((float)iY) {}
|
|
|
|
Vx2DVector(const float f[2]) : x(f[0]), y(f[1]) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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) {}
|
|
|
|
VxQuaternion(float X, float Y, float Z, float W) : x(X), y(Y), z(Z), w(W) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VxMatrix {
|
|
|
|
float m_Data[4][4];
|
|
|
|
|
|
|
|
VxMatrix() : m_Data() {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
VxMatrix(float m[4][4]) : m_Data() { std::memcpy(m_Data, m, sizeof(m_Data)); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Enhanced Image description
|
|
|
|
* @remark The VxImageDescEx holds basically an VxImageDesc with additionnal support for
|
|
|
|
* Colormap, Image pointer and is ready for future enhancements.
|
|
|
|
*/
|
|
|
|
struct VxImageDescEx {
|
2023-09-05 22:23:05 +08:00
|
|
|
VX_PIXELFORMAT Flags; /**< Reserved for special formats (such as compressed ) 0 otherwise */
|
2023-08-22 15:30:26 +08:00
|
|
|
|
2023-09-05 22:23:05 +08:00
|
|
|
CK2::CKDWORD Width; /**< Width in pixel of the image */
|
|
|
|
CK2::CKDWORD Height; /**< Height in pixel of the image */
|
2023-08-22 15:30:26 +08:00
|
|
|
union {
|
2023-09-05 22:23:05 +08:00
|
|
|
CK2::CKDWORD BytesPerLine; /**< Pitch (width in bytes) of the image */
|
|
|
|
CK2::CKDWORD TotalImageSize; /**< For compressed image (DXT1...) the total size of the image */
|
2023-08-22 15:30:26 +08:00
|
|
|
};
|
2023-09-05 22:23:05 +08:00
|
|
|
CK2::CKINT BitsPerPixel; /**< Number of bits per pixel */
|
2023-08-22 15:30:26 +08:00
|
|
|
union {
|
2023-09-05 22:23:05 +08:00
|
|
|
CK2::CKDWORD RedMask; /**< Mask for Red component */
|
|
|
|
CK2::CKDWORD BumpDuMask; /**< Mask for Bump Du component */
|
2023-08-22 15:30:26 +08:00
|
|
|
};
|
|
|
|
union {
|
2023-09-05 22:23:05 +08:00
|
|
|
CK2::CKDWORD GreenMask; /**< Mask for Green component */
|
|
|
|
CK2::CKDWORD BumpDvMask; /**< Mask for Bump Dv component */
|
2023-08-22 15:30:26 +08:00
|
|
|
};
|
|
|
|
union {
|
2023-09-05 22:23:05 +08:00
|
|
|
CK2::CKDWORD BlueMask; /**< Mask for Blue component */
|
|
|
|
CK2::CKDWORD BumpLumMask; /**< Mask for Luminance component */
|
2023-08-22 15:30:26 +08:00
|
|
|
|
|
|
|
};
|
2023-09-05 22:23:05 +08:00
|
|
|
CK2::CKDWORD AlphaMask; /**< Mask for Alpha component */
|
|
|
|
|
|
|
|
CK2::CKWORD BytesPerColorEntry; /**< ColorMap Stride */
|
|
|
|
CK2::CKWORD ColorMapEntries; /**< If other than 0 image is palletized */
|
|
|
|
|
|
|
|
CK2::CKBYTE* ColorMap; /**< Palette colors */
|
|
|
|
CK2::CKBYTE* Image; /**< Image */
|
2023-08-22 15:30:26 +08:00
|
|
|
|
2023-09-05 22:23:05 +08:00
|
|
|
bool HasAlpha() {
|
|
|
|
return (AlphaMask == 0 || Flags >= VX_PIXELFORMAT::_DXT1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const VxImageDescEx& rhs) const {
|
|
|
|
return (
|
|
|
|
Height == rhs.Height && Width == rhs.Width &&
|
|
|
|
BitsPerPixel == rhs.BitsPerPixel && BytesPerLine == rhs.BytesPerLine &&
|
|
|
|
RedMask == rhs.RedMask && GreenMask == rhs.GreenMask && BlueMask == rhs.BlueMask && AlphaMask == rhs.AlphaMask &&
|
|
|
|
BytesPerColorEntry == rhs.BytesPerColorEntry && ColorMapEntries == rhs.ColorMapEntries
|
|
|
|
);
|
|
|
|
}
|
|
|
|
bool operator!=(const VxImageDescEx& rhs) const {
|
|
|
|
return !((*this) == rhs);
|
|
|
|
}
|
2023-08-22 15:30:26 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|