refactor project

This commit is contained in:
2023-09-16 18:31:25 +08:00
parent 8f960604ca
commit 1ddeeb3b68
41 changed files with 725 additions and 749 deletions

View File

@ -10,7 +10,7 @@ namespace LibCmo::VxMath {
@brief Pixel format types.
@see VxImageDesc2PixelFormat, VxPixelFormat2ImageDesc
*/
enum class VX_PIXELFORMAT : uint32_t {
enum class VX_PIXELFORMAT : CKDWORD {
UNKNOWN_PF = 0, /**< Unknown pixel format */
_32_ARGB8888 = 1, /**< 32-bit ARGB pixel format with alpha */
_32_RGB888 = 2, /**< 32-bit RGB pixel format without alpha */
@ -53,7 +53,7 @@ namespace LibCmo::VxMath {
+ Also used as value for CKRST_TSS_TEXTUREMAPBLEND texture stage state.
See Also: Using Materials,CKMaterial,CKTexture,CKMaterial::SetTextureBlendMode,CKRST_TSS_TEXTUREMAPBLEND.
*/
enum class VXTEXTURE_BLENDMODE : uint32_t {
enum class VXTEXTURE_BLENDMODE : CKDWORD {
VXTEXTUREBLEND_DECAL = 1UL, /**< Texture replace any material information */
VXTEXTUREBLEND_MODULATE = 2UL, /**< Texture and material are combine. Alpha information of the texture replace material alpha component. */
VXTEXTUREBLEND_DECALALPHA = 3UL, /**< Alpha information in the texture specify how material and texture are combined. Alpha information of the texture replace material alpha component. */
@ -75,7 +75,7 @@ namespace LibCmo::VxMath {
+ Also used as value for CKRST_TSS_MAGFILTER and CKRST_TSS_MINFILTER texture stage state.
See Also: Using Materials,CKMaterial,CKTexture,CKMaterial::SetTextureMagMode,CKMaterial::SetTextureMinMode,,CKRenderContext::SetTextureStageState
*/
enum class VXTEXTURE_FILTERMODE : uint32_t {
enum class VXTEXTURE_FILTERMODE : CKDWORD {
VXTEXTUREFILTER_NEAREST = 1UL, /**< No Filter */
VXTEXTUREFILTER_LINEAR = 2UL, /**< Bilinear Interpolation */
VXTEXTUREFILTER_MIPNEAREST = 3UL, /**< Mip mapping */
@ -100,7 +100,7 @@ namespace LibCmo::VxMath {
See Also: CKMaterial,CKTexture,CKMaterial::SetSourceBlend,CKMaterial::SetDestBlend,CKRenderContext::SetState,CKSprite::SetBlending,VXRENDERSTATE_SRCBLEND,VXRENDERSTATE_DESTBLEND
*/
enum class VXBLEND_MODE : uint32_t {
enum class VXBLEND_MODE : CKDWORD {
VXBLEND_ZERO = 1UL, /**< Blend factor is (0, 0, 0, 0). */
VXBLEND_ONE = 2UL, /**< Blend factor is (1, 1, 1, 1). */
VXBLEND_SRCCOLOR = 3UL, /**< Blend factor is (Rs, Gs, Bs, As). */
@ -125,7 +125,7 @@ namespace LibCmo::VxMath {
+ Also used as value for CKRST_TSS_ADDRESS texture stage state.
See Also: CKMaterial,CKTexture,CKRST_TSS_ADDRESS,CKRenderContext::SetTextureStageState
*/
enum class VXTEXTURE_ADDRESSMODE : uint32_t {
enum class VXTEXTURE_ADDRESSMODE : CKDWORD {
VXTEXTURE_ADDRESSWRAP = 1UL, /**< Default mesh wrap mode is used (see CKMesh::SetWrapMode) */
VXTEXTURE_ADDRESSMIRROR = 2UL, /**< Texture coordinates outside the range [0..1] are flipped evenly. */
VXTEXTURE_ADDRESSCLAMP = 3UL, /**< Texture coordinates greater than 1.0 are set to 1.0, and values less than 0.0 are set to 0.0. */
@ -140,7 +140,7 @@ namespace LibCmo::VxMath {
+ Also used as value for VXRENDERSTATE_FILLMODE render state.
See Also: CKMaterial::SetFillMode,VXRENDERSTATE_FILLMODE
*/
enum class VXFILL_MODE : uint32_t {
enum class VXFILL_MODE : CKDWORD {
VXFILL_POINT = 1UL, /**< Vertices rendering */
VXFILL_WIREFRAME = 2UL, /**< Edges rendering */
VXFILL_SOLID = 3UL, /**< Face rendering */
@ -154,7 +154,7 @@ namespace LibCmo::VxMath {
+ Also used as value for VXRENDERSTATE_SHADEMODE render state.
See Also: CKMaterial::SetShadeMode,VXRENDERSTATE_SHADEMODE
*/
enum class VXSHADE_MODE : uint32_t {
enum class VXSHADE_MODE : CKDWORD {
VXSHADE_FLAT = 1UL, /**< Flat Shading */
VXSHADE_GOURAUD = 2UL, /**< Gouraud Shading */
VXSHADE_PHONG = 3UL, /**< Phong Shading (Not yet supported by most implementation) */
@ -168,7 +168,7 @@ namespace LibCmo::VxMath {
+ The comparison function is used to compare the stencil,alpha or z reference value to a stencil,z or alpha entry.
See also: CKRenderContext::SetState,VXRENDERSTATETYPE,VXRENDERSTATE_ZFUNC,VXRENDERSTATE_ALPHAFUNC
*/
enum class VXCMPFUNC : uint32_t {
enum class VXCMPFUNC : CKDWORD {
VXCMP_NEVER = 1UL, /**< Always fail the test. */
VXCMP_LESS = 2UL, /**< Accept if value if less than current value. */
VXCMP_EQUAL = 3UL, /**< Accept if value if equal than current value. */
@ -190,7 +190,7 @@ namespace LibCmo::VxMath {
o Most of this effect are heavily hardware and device (DX8,DX7,etc..) dependant
See also: CKMaterial::SetEffect,CKMaterial::GetEffect,CKRenderManager::AddEffect
*/
enum class VX_EFFECT : uint32_t {
enum class VX_EFFECT : CKDWORD {
VXEFFECT_NONE = 0UL, /**< No Effect */
VXEFFECT_TEXGEN = 1UL, /**< Texture coordinate generation using current viewpoint as referential */
VXEFFECT_TEXGENREF = 2UL, /**< texture generation generation with an optionnal referential */
@ -212,7 +212,7 @@ namespace LibCmo::VxMath {
See Also: CK3dEntity::SetMoveableFlags
*/
enum class VX_MOVEABLE_FLAGS : uint32_t {
enum class VX_MOVEABLE_FLAGS : CKDWORD {
VX_MOVEABLE_PICKABLE = 0x00000001, /**< (User)If not set this entity cannot be returned by CKRenderContext::Pick() or CKRenderContext::RectPict() functions. */
VX_MOVEABLE_VISIBLE = 0x00000002, /**< (Engine) See CKObject::Show,CK3dEntity::IsVisible */
VX_MOVEABLE_UPTODATE = 0x00000004, /**< (Engine) Used to Notify change in the data of the entity. */
@ -244,7 +244,7 @@ namespace LibCmo::VxMath {
+ Most of this flags can be set or asked using the appropriate method of CKMesh (given between () in the members documentation).
See Also: CKMesh,CKMesh::SetFlags
*/
enum class VXMESH_FLAGS : uint32_t {
enum class VXMESH_FLAGS : CKDWORD {
VXMESH_BOUNDINGUPTODATE = 0x00000001, /**< If set the bounding box is up to date (internal). */
VXMESH_VISIBLE = 0x00000002, /**< If not set the mesh will not be rendered (CKMesh::Show) */
VXMESH_OPTIMIZED = 0x00000004, /**< Set by the render engine if the mesh is optimized for rendering. Unset it to force to recreate optimized structures (when changing materials or face organization ) (CKMesh::VertexMove) */
@ -277,7 +277,7 @@ namespace LibCmo::VxMath {
+ The VXMESH_LITMODE is used by CKMesh::SetLitMode to specify how lighting is done.
See Also: CKMaterial,CKMesh
*/
enum class VXMESH_LITMODE : uint32_t {
enum class VXMESH_LITMODE : CKDWORD {
VX_PRELITMESH = 0, /**< Lighting use color information store with vertices */
VX_LITMESH = 1, /**< Lighting is done by renderer using normals and face material information. */
};
@ -290,7 +290,7 @@ namespace LibCmo::VxMath {
an additional material channel.
See Also: CKMesh,CKMesh::AddChannel,CKMesh::IsChannelLit,CKMesh::IsChannelActive
*/
enum class VXCHANNEL_FLAGS : uint32_t {
enum class VXCHANNEL_FLAGS : CKDWORD {
VXCHANNEL_ACTIVE = 0x00000001, /**< This channel is active */
VXCHANNEL_SAMEUV = 0x00800000, /**< This channel should use the texture coordinates of the base mesh. */
VXCHANNEL_NOTLIT = 0x01000000, /**< Additionnal Material Channel should not be lit (some channels may not be rendered in one pass with this option) */
@ -307,7 +307,7 @@ namespace LibCmo::VxMath {
texture coordinates are interpolated.
See Also: Using Materials,CKMaterial,CKMesh::SetWrapMode.
*/
enum class VXTEXTURE_WRAPMODE : uint32_t {
enum class VXTEXTURE_WRAPMODE : CKDWORD {
VXTEXTUREWRAP_NONE = 0x00000000, /**< Flat texture addressing */
VXTEXTUREWRAP_U = 0x00000001, /**< Vertical cylinder mapping */
VXTEXTUREWRAP_V = 0x00000002, /**< Horizontal cylinder mapping */

View File

@ -1,21 +1,20 @@
#include "../VTImage.hpp"
#include "VxMath.hpp"
#include "stb_image.h"
#include "stb_image_resize.h"
namespace LibCmo::VxMath {
#pragma region Structure copying
void VxFillStructure(CK2::CKDWORD Count, void* Dst, CK2::CKDWORD Stride, CK2::CKDWORD SizeSrc, const void* Src) {
void VxFillStructure(CKDWORD Count, void* Dst, CKDWORD Stride, CKDWORD SizeSrc, const void* Src) {
VxCopyStructure(Count, Dst, Stride, SizeSrc, Src, SizeSrc);
}
void VxCopyStructure(CK2::CKDWORD Count, void* Dst, CK2::CKDWORD OutStride, CK2::CKDWORD SizeSrc, const void* Src, CK2::CKDWORD InStride) {
void VxCopyStructure(CKDWORD Count, void* Dst, CKDWORD OutStride, CKDWORD SizeSrc, const void* Src, CKDWORD InStride) {
if (Dst == nullptr || Src == nullptr) return;
char* cdst = reinterpret_cast<char*>(Dst);
const char* csrc = reinterpret_cast<const char*>(Src);
for (CK2::CKDWORD i = 0; i < Count; ++i) {
for (CKDWORD i = 0; i < Count; ++i) {
std::memcpy(cdst, csrc, SizeSrc);
cdst += OutStride;
csrc += InStride;
@ -57,9 +56,9 @@ namespace LibCmo::VxMath {
}
// copy and swap data by line
CK2::CKDWORD height = dst->GetHeight(),
CKDWORD height = dst->GetHeight(),
rowsize = VxImageDescEx::PixelSize * dst->GetWidth();
for (CK2::CKDWORD row = 0; row < height; ++row) {
for (CKDWORD row = 0; row < height; ++row) {
std::memcpy(
dst->GetMutableImage() + (row * rowsize),
origin->GetImage() + ((height - row - 1) * rowsize),
@ -68,10 +67,10 @@ namespace LibCmo::VxMath {
}
}
CK2::CKDWORD VxGetBitCount(CK2::CKDWORD dwMask) {
CKDWORD VxGetBitCount(CKDWORD dwMask) {
if (dwMask == 0u) return 0;
dwMask >>= VxGetBitShift(dwMask);
CK2::CKDWORD count = 0;
CKDWORD count = 0;
while ((dwMask & 1u) == 0u) {
dwMask >>= 1u;
++count;
@ -79,9 +78,9 @@ namespace LibCmo::VxMath {
return count;
}
CK2::CKDWORD VxGetBitShift(CK2::CKDWORD dwMask) {
CKDWORD VxGetBitShift(CKDWORD dwMask) {
if (dwMask == 0u) return 0;
CK2::CKDWORD count = 0;
CKDWORD count = 0;
while ((dwMask & 1u) != 0u) {
dwMask >>= 1u;
++count;
@ -89,7 +88,7 @@ namespace LibCmo::VxMath {
return count;
}
//CK2::CKDWORD VxScaleFactor(CK2::CKDWORD val, CK2::CKDWORD srcBitCount, CK2::CKDWORD dstBitCount) {
//CKDWORD VxScaleFactor(CKDWORD val, CKDWORD srcBitCount, CKDWORD dstBitCount) {
// if (srcBitCount == dstBitCount) return val;
// if (srcBitCount > dstBitCount) {
// return val >> (srcBitCount - dstBitCount);
@ -98,52 +97,29 @@ namespace LibCmo::VxMath {
// }
//}
void VxDoAlphaBlit(VxImageDescEx* dst_desc, CK2::CKBYTE AlphaValue) {
void VxDoAlphaBlit(VxImageDescEx* dst_desc, CKBYTE AlphaValue) {
if (dst_desc == nullptr) return;
CK2::CKDWORD* pixels = dst_desc->GetMutablePixels();
CK2::CKDWORD pixelcount = dst_desc->GetPixelCount();
CKDWORD* pixels = dst_desc->GetMutablePixels();
CKDWORD pixelcount = dst_desc->GetPixelCount();
for (CK2::CKDWORD i = 0; i < pixelcount; ++i) {
*pixels = (*pixels) & 0x00FFFFFF | (static_cast<CK2::CKDWORD>(AlphaValue) << 24);
for (CKDWORD i = 0; i < pixelcount; ++i) {
*pixels = (*pixels) & 0x00FFFFFF | (static_cast<CKDWORD>(AlphaValue) << 24);
++pixels;
}
//CK2::CKDWORD* pixels = dst_desc->GetPixels();
//CK2::CKDWORD pixelcount = dst_desc->GetPixelCount(),
// alphashift = VxGetBitShift(dst_desc->m_AlphaMask),
// alphacount = VxGetBitCount(dst_desc->m_AlphaMask);
//CK2::CKDWORD av = VxScaleFactor(AlphaValue, static_cast<CK2::CKDWORD>(sizeof(CK2::CKBYTE) * 8), alphacount) << alphashift;
//for (CK2::CKDWORD i = 0; i < pixelcount; ++i) {
// *pixels = (*pixels) & (~dst_desc->m_AlphaMask) | av;
// ++pixels;
//}
}
void VxDoAlphaBlit(VxImageDescEx* dst_desc, CK2::CKBYTE* AlphaValues) {
void VxDoAlphaBlit(VxImageDescEx* dst_desc, CKBYTE* AlphaValues) {
if (dst_desc == nullptr) return;
CK2::CKDWORD* pixels = dst_desc->GetMutablePixels();
CK2::CKDWORD pixelcount = dst_desc->GetPixelCount();
CKDWORD* pixels = dst_desc->GetMutablePixels();
CKDWORD pixelcount = dst_desc->GetPixelCount();
for (CK2::CKDWORD i = 0; i < pixelcount; ++i) {
*pixels = (*pixels) & 0x00FFFFFF | (static_cast<CK2::CKDWORD>(*AlphaValues) << 24);
for (CKDWORD i = 0; i < pixelcount; ++i) {
*pixels = (*pixels) & 0x00FFFFFF | (static_cast<CKDWORD>(*AlphaValues) << 24);
++pixels;
++AlphaValues;
}
//CK2::CKDWORD* pixels = dst_desc->GetPixels();
//CK2::CKDWORD pixelcount = dst_desc->GetPixelCount(),
// alphashift = VxGetBitShift(dst_desc->m_AlphaMask),
// alphacount = VxGetBitCount(dst_desc->m_AlphaMask);
//for (CK2::CKDWORD i = 0; i < pixelcount; ++i) {
// *pixels = (*pixels) & (~dst_desc->m_AlphaMask) | (VxScaleFactor(*AlphaValues, static_cast<CK2::CKDWORD>(sizeof(CK2::CKBYTE) * 8), alphacount) << alphashift);
// ++pixels;
// ++AlphaValues;
//}
}
#pragma endregion

View File

@ -1,4 +1,3 @@
#include "../VTUtils.hpp"
#include "../CK2/CKTypes.hpp"
#include "VxTypes.hpp"
@ -15,7 +14,7 @@ namespace LibCmo::VxMath {
* @param Src[in] Source buffer
* @remark This function can be used to initialized an array of structure when only some members should be modified.
*/
void VxFillStructure(CK2::CKDWORD Count, void* Dst, CK2::CKDWORD Stride, CK2::CKDWORD SizeSrc, const void* Src);
void VxFillStructure(CKDWORD Count, void* Dst, CKDWORD Stride, CKDWORD SizeSrc, const void* Src);
/**
* @brief copies an array of elements between two memory buffers.
* @param Count[in] Number of element to copy in the destination buffer
@ -26,7 +25,7 @@ namespace LibCmo::VxMath {
* @param InStride[in] Amount in bytes between each element in the source buffer
* @remark This function can be used to initialized an array of structure when only some members should be modified.
*/
void VxCopyStructure(CK2::CKDWORD Count, void* Dst, CK2::CKDWORD OutStride, CK2::CKDWORD SizeSrc, const void* Src, CK2::CKDWORD InStride);
void VxCopyStructure(CKDWORD Count, void* Dst, CKDWORD OutStride, CKDWORD SizeSrc, const void* Src, CKDWORD InStride);
// ========== Graphic Utilities ==========
@ -51,11 +50,11 @@ namespace LibCmo::VxMath {
/**
* @brief Counts number of bits to representing a value in dwMask
*/
CK2::CKDWORD VxGetBitCount(CK2::CKDWORD dwMask);
CKDWORD VxGetBitCount(CKDWORD dwMask);
/**
* @brief Counts number of bits to shift to acces a non zero value in dwMask.
*/
CK2::CKDWORD VxGetBitShift(CK2::CKDWORD dwMask);
CKDWORD VxGetBitShift(CKDWORD dwMask);
///**
// * @brief scale the integer to a new range.
@ -65,7 +64,7 @@ namespace LibCmo::VxMath {
// * @remark This function usually used in image color factor assign with mask.
// * @return The result integer.
//*/
//CK2::CKDWORD VxScaleFactor(CK2::CKDWORD val, CK2::CKDWORD srcBitCount, CK2::CKDWORD dstBitCount);
//CKDWORD VxScaleFactor(CKDWORD val, CKDWORD srcBitCount, CKDWORD dstBitCount);
/**
* @brief Sets the alpha component of an image.
@ -74,7 +73,7 @@ namespace LibCmo::VxMath {
* @param AlphaValue[in] A CKBYTE value containing the alpha value to set to the whole image
* @remark If the destination image does not have alpha information the function returns immediatly.
*/
void VxDoAlphaBlit(VxImageDescEx* dst_desc, CK2::CKBYTE AlphaValue);
void VxDoAlphaBlit(VxImageDescEx* dst_desc, CKBYTE AlphaValue);
/**
* @brief Sets the alpha component of an image.
* @remark The source image must be in a 32 bit ARGB8888 per pixel format.
@ -82,7 +81,7 @@ namespace LibCmo::VxMath {
* @param AlphaValues[in] A BYTE array containing the alpha values for each pixel. This array should be allocated to Width*Height bytes.
* @remark If the destination image does not have alpha information the function returns immediatly.
*/
void VxDoAlphaBlit(VxImageDescEx* dst_desc, CK2::CKBYTE* AlphaValues);
void VxDoAlphaBlit(VxImageDescEx* dst_desc, CKBYTE* AlphaValues);
}

View File

@ -46,7 +46,7 @@ namespace LibCmo::VxMath {
~VxMemoryMappedFile(void);
void* GetBase(void) { return this->m_pMemoryMappedFileBase; }
CK2::CKDWORD GetFileSize(void) { return static_cast<CK2::CKDWORD>(this->m_cbFile); }
CKDWORD GetFileSize(void) { return static_cast<CKDWORD>(this->m_cbFile); }
bool IsValid(void) { return this->m_bIsValid; }
};

View File

@ -25,11 +25,11 @@ namespace LibCmo::VxMath {
//---- Misc
struct VxVector2 {
float x, y;
CKFLOAT x, y;
VxVector2() : x(0.0f), y(0.0f) {}
VxVector2(float _x, float _y) : x(_x), y(_y) {}
VxVector2(CKFLOAT _x, CKFLOAT _y) : x(_x), y(_y) {}
LIBCMO_DEFAULT_COPY_MOVE(VxVector2);
float& operator[](size_t i) {
CKFLOAT& operator[](size_t i) {
switch (i) {
case 0: return x;
case 1: return y;
@ -52,24 +52,24 @@ namespace LibCmo::VxMath {
friend VxVector2 operator-(const VxVector2& lhs, const VxVector2& rhs) {
return VxVector2(lhs.x - rhs.x, lhs.y - rhs.y);
}
VxVector2& operator*=(float rhs) {
VxVector2& operator*=(CKFLOAT rhs) {
x *= rhs;
y *= rhs;
return *this;
}
friend VxVector2 operator*(const VxVector2& lhs, float rhs) {
friend VxVector2 operator*(const VxVector2& lhs, CKFLOAT rhs) {
return VxVector2(lhs.x * rhs, lhs.y * rhs);
}
friend VxVector2 operator*(float lhs, const VxVector2& rhs) {
friend VxVector2 operator*(CKFLOAT lhs, const VxVector2& rhs) {
return VxVector2(lhs * rhs.x, lhs * rhs.y);
}
VxVector2& operator/=(float rhs) {
VxVector2& operator/=(CKFLOAT rhs) {
if (rhs == 0.0f) return *this;
x /= rhs;
y /= rhs;
return *this;
}
friend VxVector2 operator/(const VxVector2& lhs, float rhs) {
friend VxVector2 operator/(const VxVector2& lhs, CKFLOAT rhs) {
if (rhs == 0.0f) return VxVector2(0.0f, 0.0f);
return VxVector2(lhs.x / rhs, lhs.y / rhs);
}
@ -82,11 +82,11 @@ namespace LibCmo::VxMath {
};
struct VxVector3 {
float x, y, z;
CKFLOAT 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) {}
VxVector3(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z) : x(_x), y(_y), z(_z) {}
LIBCMO_DEFAULT_COPY_MOVE(VxVector3);
float& operator[](size_t i) {
CKFLOAT& operator[](size_t i) {
switch (i) {
case 0: return x;
case 1: return y;
@ -112,26 +112,26 @@ namespace LibCmo::VxMath {
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) {
VxVector3& operator*=(CKFLOAT rhs) {
x *= rhs;
y *= rhs;
z *= rhs;
return *this;
}
friend VxVector3 operator*(const VxVector3& lhs, float rhs) {
friend VxVector3 operator*(const VxVector3& lhs, CKFLOAT rhs) {
return VxVector3(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs);
}
friend VxVector3 operator*(float lhs, const VxVector3& rhs) {
friend VxVector3 operator*(CKFLOAT lhs, const VxVector3& rhs) {
return VxVector3(lhs * rhs.x, lhs * rhs.y, lhs * rhs.z);
}
VxVector3& operator/=(float rhs) {
VxVector3& operator/=(CKFLOAT rhs) {
if (rhs == 0.0f) return *this;
x /= rhs;
y /= rhs;
z /= rhs;
return *this;
}
friend VxVector3 operator/(const VxVector3& lhs, float rhs) {
friend VxVector3 operator/(const VxVector3& lhs, CKFLOAT rhs) {
if (rhs == 0.0f) return VxVector3(0.0f, 0.0f, 0.0f);
return VxVector3(lhs.x / rhs, lhs.y / rhs, lhs.z / rhs);
}
@ -144,11 +144,11 @@ namespace LibCmo::VxMath {
};
struct VxVector4 {
float x, y, z, w;
CKFLOAT 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) {}
VxVector4(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z, CKFLOAT _w) : x(_x), y(_y), z(_z), w(_w) {}
LIBCMO_DEFAULT_COPY_MOVE(VxVector4);
float& operator[](size_t i) {
CKFLOAT& operator[](size_t i) {
switch (i) {
case 0: return x;
case 1: return y;
@ -177,20 +177,20 @@ namespace LibCmo::VxMath {
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) {
VxVector4& operator*=(CKFLOAT rhs) {
x *= rhs;
y *= rhs;
z *= rhs;
w *= rhs;
return *this;
}
friend VxVector4 operator*(const VxVector4& lhs, float rhs) {
friend VxVector4 operator*(const VxVector4& lhs, CKFLOAT rhs) {
return VxVector4(lhs.x * rhs, lhs.y * rhs, lhs.z * rhs, lhs.w * rhs);
}
friend VxVector4 operator*(float lhs, const VxVector4& rhs) {
friend VxVector4 operator*(CKFLOAT lhs, const VxVector4& rhs) {
return VxVector4(lhs * rhs.x, lhs * rhs.y, lhs * rhs.z, lhs * rhs.w);
}
VxVector4& operator/=(float rhs) {
VxVector4& operator/=(CKFLOAT rhs) {
if (rhs == 0.0f) return *this;
x /= rhs;
y /= rhs;
@ -198,7 +198,7 @@ namespace LibCmo::VxMath {
w /= rhs;
return *this;
}
friend VxVector4 operator/(const VxVector4& lhs, float rhs) {
friend VxVector4 operator/(const VxVector4& lhs, CKFLOAT 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);
}
@ -211,11 +211,11 @@ namespace LibCmo::VxMath {
};
struct VxQuaternion {
float x, y, z, w;
CKFLOAT 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) {}
VxQuaternion(CKFLOAT _x, CKFLOAT _y, CKFLOAT _z, CKFLOAT _w) : x(_x), y(_y), z(_z), w(_w) {}
LIBCMO_DEFAULT_COPY_MOVE(VxQuaternion);
float& operator[](size_t i) {
CKFLOAT& operator[](size_t i) {
switch (i) {
case 0: return x;
case 1: return y;
@ -233,26 +233,26 @@ namespace LibCmo::VxMath {
};
struct VxColor {
float r, g, b, a;
CKFLOAT 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) { FromARGB(argb); }
VxColor(CKFLOAT _r, CKFLOAT _g, CKFLOAT _b, CKFLOAT _a) : r(_r), g(_g), b(_b), a(_a) {}
VxColor(CKDWORD argb) { FromARGB(argb); }
LIBCMO_DEFAULT_COPY_MOVE(VxColor);
void FromARGB(CK2::CKDWORD argb) {
void FromARGB(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;
}
CK2::CKDWORD ToARGB() const {
CK2::CKDWORD argb = 0;
argb |= static_cast<CK2::CKDWORD>(a * 255.0f);
CKDWORD ToARGB() const {
CKDWORD argb = 0;
argb |= static_cast<CKDWORD>(a * 255.0f);
argb <<= 8;
argb |= static_cast<CK2::CKDWORD>(r * 255.0f);
argb |= static_cast<CKDWORD>(r * 255.0f);
argb <<= 8;
argb |= static_cast<CK2::CKDWORD>(g * 255.0f);
argb |= static_cast<CKDWORD>(g * 255.0f);
argb <<= 8;
argb |= static_cast<CK2::CKDWORD>(b * 255.0f);
argb |= static_cast<CKDWORD>(b * 255.0f);
return argb;
}
void Regulate() {
@ -265,7 +265,7 @@ namespace LibCmo::VxMath {
if (a > 1.0f) a = 1.0f;
else if (a < 0.0f) a = 0.0f;
}
float& operator[](size_t i) {
CKFLOAT& operator[](size_t i) {
switch (i) {
case 0: return r;
case 1: return g;
@ -283,13 +283,13 @@ namespace LibCmo::VxMath {
};
struct VxMatrix {
float m_Data[4][4];
CKFLOAT 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)); }
VxMatrix(CKFLOAT m[4][4]) : m_Data() { std::memcpy(m_Data, m, sizeof(m_Data)); }
LIBCMO_DEFAULT_COPY_MOVE(VxMatrix);
VxVector4& operator[](size_t i) {
@ -307,8 +307,8 @@ namespace LibCmo::VxMath {
template<class _Ty, std::enable_if_t<std::is_pointer_v<_Ty>, int> = 0>
class VxStridedData {
public:
VxStridedData(_Ty ptr, CK2::CKDWORD stride) :
m_Ptr(reinterpret_cast<CK2::CKBYTE*>(m_Ptr)),
VxStridedData(_Ty ptr, CKDWORD stride) :
m_Ptr(reinterpret_cast<CKBYTE*>(m_Ptr)),
m_Stride(stride)
{}
~VxStridedData() {}
@ -318,8 +318,8 @@ namespace LibCmo::VxMath {
}
private:
CK2::CKBYTE* m_Ptr;
CK2::CKDWORD m_Stride;
CKBYTE* m_Ptr;
CKDWORD m_Stride;
};
/**
@ -332,12 +332,12 @@ namespace LibCmo::VxMath {
*/
class VxImageDescEx {
public:
static constexpr CK2::CKDWORD ColorFactorSize = 1u;
static constexpr CK2::CKDWORD PixelSize = ColorFactorSize * 4u;
static constexpr CKDWORD ColorFactorSize = 1u;
static constexpr CKDWORD PixelSize = ColorFactorSize * 4u;
public:
VxImageDescEx() :
m_Width(0), m_Height(0), m_Image(nullptr) {}
VxImageDescEx(CK2::CKDWORD width, CK2::CKDWORD height) :
VxImageDescEx(CKDWORD width, CKDWORD height) :
m_Width(width), m_Height(height), m_Image(nullptr) {
CreateImage(width, height);
}
@ -382,13 +382,13 @@ namespace LibCmo::VxMath {
FreeImage();
}
void CreateImage(CK2::CKDWORD Width, CK2::CKDWORD Height) {
void CreateImage(CKDWORD Width, CKDWORD Height) {
FreeImage();
m_Width = Width;
m_Height = Height;
m_Image = new CK2::CKBYTE[GetImageSize()];
m_Image = new CKBYTE[GetImageSize()];
}
void CreateImage(CK2::CKDWORD Width, CK2::CKDWORD Height, void* dataptr) {
void CreateImage(CKDWORD Width, CKDWORD Height, void* dataptr) {
CreateImage(Width, Height);
std::memcpy(m_Image, dataptr, GetImageSize());
}
@ -401,30 +401,30 @@ namespace LibCmo::VxMath {
}
}
CK2::CKDWORD GetImageSize() const {
return static_cast<CK2::CKDWORD>(PixelSize * m_Width * m_Height);
CKDWORD GetImageSize() const {
return static_cast<CKDWORD>(PixelSize * m_Width * m_Height);
}
const CK2::CKBYTE* GetImage() const {
const CKBYTE* GetImage() const {
return m_Image;
}
CK2::CKBYTE* GetMutableImage() {
CKBYTE* GetMutableImage() {
return m_Image;
}
CK2::CKDWORD GetPixelCount() const {
return static_cast<CK2::CKDWORD>(m_Width * m_Height);
CKDWORD GetPixelCount() const {
return static_cast<CKDWORD>(m_Width * m_Height);
}
const CK2::CKDWORD* GetPixels() const {
return reinterpret_cast<CK2::CKDWORD*>(m_Image);
const CKDWORD* GetPixels() const {
return reinterpret_cast<CKDWORD*>(m_Image);
}
CK2::CKDWORD* GetMutablePixels() {
return reinterpret_cast<CK2::CKDWORD*>(m_Image);
CKDWORD* GetMutablePixels() {
return reinterpret_cast<CKDWORD*>(m_Image);
}
CK2::CKDWORD GetWidth() const {
CKDWORD GetWidth() const {
return m_Width;
}
CK2::CKDWORD GetHeight() const {
CKDWORD GetHeight() const {
return m_Height;
}
@ -448,15 +448,15 @@ namespace LibCmo::VxMath {
// }
//public:
// CK2::CKDWORD m_RedMask;
// CK2::CKDWORD m_GreenMask;
// CK2::CKDWORD m_BlueMask;
// CK2::CKDWORD m_AlphaMask;
// CKDWORD m_RedMask;
// CKDWORD m_GreenMask;
// CKDWORD m_BlueMask;
// CKDWORD m_AlphaMask;
protected:
CK2::CKDWORD m_Width; /**< Width in pixel of the image */
CK2::CKDWORD m_Height; /**< Height in pixel of the image */
CK2::CKBYTE* m_Image; /**< A pointer point to current processing image */
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 */
};
}