This commit is contained in:
2024-12-24 16:49:34 +08:00
parent 3eeb1f6cb6
commit 5219351df1
14 changed files with 945 additions and 109 deletions

View File

@ -3,4 +3,45 @@
namespace LibCmo::CK2::ObjImpls {
#pragma region Class Operations
CK_CAMERA_PROJECTION CKCamera::GetProjectionType() const {
return CK_CAMERA_PROJECTION();
}
void CKCamera::SetProjectionType(CK_CAMERA_PROJECTION proj) {}
CKFLOAT CKCamera::GetOrthographicZoom() const {
return CKFLOAT();
}
void CKCamera::SetOrthographicZoom(CKFLOAT zoom) {}
CKFLOAT CKCamera::GetFrontPlane() const {
return CKFLOAT();
}
CKFLOAT CKCamera::GetBackPlane() const {
return CKFLOAT();
}
CKFLOAT CKCamera::GetFov() const {
return CKFLOAT();
}
void CKCamera::SetFrontPlane(CKFLOAT front) {}
void CKCamera::SetBackPlane(CKFLOAT back) {}
void CKCamera::SetFov(CKFLOAT fov) {}
void CKCamera::GetAspectRatio(int& width, int& height) const {}
void CKCamera::SetAspectRatio(int width, int height) {}
void CKCamera::ComputeProjectionMatrix(VxMath::VxMatrix& mat) const {}
void CKCamera::ResetRoll() {}
void CKCamera::Roll(CKFLOAT angle) {}
CK3dEntity* CKCamera::GetTarget() const {
return nullptr;
}
void CKCamera::SetTarget(CK3dEntity* target) {}
#pragma endregion
}

View File

@ -131,7 +131,6 @@ namespace LibCmo::CK2::ObjImpls {
VxMath::VXLIGHT_TYPE CKLight::GetType() const {
return m_LightData.m_Type;
}
void CKLight::SetType(VxMath::VXLIGHT_TYPE light_type) {
m_LightData.m_Type = light_type;
}
@ -139,7 +138,6 @@ namespace LibCmo::CK2::ObjImpls {
const VxMath::VxColor& CKLight::GetColor() const {
return m_LightData.m_Diffuse;
}
void CKLight::SetColor(const VxMath::VxColor& c) {
m_LightData.m_Diffuse = c;
}
@ -147,23 +145,18 @@ namespace LibCmo::CK2::ObjImpls {
CKFLOAT CKLight::GetConstantAttenuation() const {
return m_LightData.m_Attenuation0;
}
CKFLOAT CKLight::GetLinearAttenuation() const {
return m_LightData.m_Attenuation1;
}
CKFLOAT CKLight::GetQuadraticAttenuation() const {
return m_LightData.m_Attenuation2;
}
void CKLight::SetConstantAttenuation(CKFLOAT value) {
m_LightData.m_Attenuation0 = value;
}
void CKLight::SetLinearAttenuation(CKFLOAT value) {
m_LightData.m_Attenuation1 = value;
}
void CKLight::SetQuadraticAttenuation(CKFLOAT value) {
m_LightData.m_Attenuation2 = value;
}
@ -171,7 +164,6 @@ namespace LibCmo::CK2::ObjImpls {
CKFLOAT CKLight::GetRange() const {
return m_LightData.m_Range;
}
void CKLight::SetRange(CKFLOAT value) {
m_LightData.m_Range = value;
}
@ -179,23 +171,18 @@ namespace LibCmo::CK2::ObjImpls {
CKFLOAT CKLight::GetHotSpot() const {
return m_LightData.m_InnerSpotCone;
}
CKFLOAT CKLight::GetFalloff() const {
return m_LightData.m_OuterSpotCone;
}
CKFLOAT CKLight::GetFalloffShape() const {
return m_LightData.m_Falloff;
}
void CKLight::SetHotSpot(CKFLOAT value) {
m_LightData.m_InnerSpotCone = value;
}
void CKLight::SetFalloff(CKFLOAT value) {
m_LightData.m_OuterSpotCone = value;
}
void CKLight::SetFalloffShape(CKFLOAT value) {
m_LightData.m_Falloff = value;
}
@ -203,7 +190,6 @@ namespace LibCmo::CK2::ObjImpls {
bool CKLight::GetActivity() const {
return YYCC::EnumHelper::Has(m_LightFlags, LightFlags::Active);
}
void CKLight::Active(bool active) {
if (active) {
YYCC::EnumHelper::Add(m_LightFlags, LightFlags::Active);
@ -215,7 +201,6 @@ namespace LibCmo::CK2::ObjImpls {
bool CKLight::GetSpecularFlag() const {
return YYCC::EnumHelper::Has(m_LightFlags, LightFlags::Specular);
}
void CKLight::SetSpecularFlag(bool specular) {
if (specular) {
YYCC::EnumHelper::Add(m_LightFlags, LightFlags::Specular);
@ -229,7 +214,6 @@ namespace LibCmo::CK2::ObjImpls {
// So it always return nullptr.
return nullptr;
}
void CKLight::SetTarget(CK3dEntity* target) {
// Normal light do not support target.
// So, do nothing.
@ -238,7 +222,6 @@ namespace LibCmo::CK2::ObjImpls {
CKFLOAT CKLight::GetLightPower() const {
return m_LightPower;
}
void CKLight::SetLightPower(CKFLOAT power) {
m_LightPower = power;
}

View File

@ -36,6 +36,7 @@ PRIVATE
CK2/ObjImpls/CKTargetCamera.cpp
# VxMath
VxMath/VxMemoryMappedFile.cpp
VxMath/VxTypes.cpp
VxMath/VxMath.cpp
# X Container
XContainer/XTypes.cpp

View File

@ -134,39 +134,4 @@ namespace LibCmo::VxMath {
#pragma endregion
#pragma region Patched
namespace NSVxVector {
float DotProduct(const VxVector2& lhs, const VxVector2& rhs) {
return lhs * rhs;
}
float DotProduct(const VxVector3& lhs, const VxVector3& rhs) {
return lhs * rhs;
}
float DotProduct(const VxVector4& lhs, const VxVector4& rhs) {
return lhs * rhs;
}
VxVector3 CrossProduct(const VxVector3& lhs, const VxVector3& rhs) {
return VxVector3(
lhs.y * rhs.z - lhs.z * rhs.y,
lhs.z * rhs.x - lhs.x * rhs.z,
lhs.x * rhs.y - lhs.y * rhs.x
);
}
void Abs(VxVector3& lhs) {
lhs.x = std::fabs(lhs.x);
lhs.y = std::fabs(lhs.y);
lhs.z = std::fabs(lhs.z);
}
}
#pragma endregion
}

View File

@ -95,56 +95,5 @@ namespace LibCmo::VxMath {
*/
void VxDoAlphaBlit(VxImageDescEx* dst_desc, const CKBYTE* AlphaValues);
// ========== Patch Section ==========
/**
* @brief The patch namespace for VxVector-like classes
* @details This namespace provides VxVector-like classes member functions which presented in original Virtools SDK.
* These functions are put in public namespace in original Virtools SDK.
* We just organise them into an unique namespace.
*/
namespace NSVxVector {
/**
* @brief Dot product 2 2d vectors.
* @param[in] lhs The left side vector of dot product symbol.
* @param[in] rhs The right side vector of dot product symbol.
* @return The float pointing result of dot product.
*/
CKFLOAT DotProduct(const VxVector2& lhs, const VxVector2& rhs);
/**
* @brief Dot product 2 3d vectors.
* @param[in] lhs The left side vector of dot product symbol.
* @param[in] rhs The right side vector of dot product symbol.
* @return The float pointing result of dot product.
*/
CKFLOAT DotProduct(const VxVector3& lhs, const VxVector3& rhs);
/**
* @brief Dot product 2 4d vectors.
* @param[in] lhs The left side vector of dot product symbol.
* @param[in] rhs The right side vector of dot product symbol.
* @return The float pointing result of dot product.
*/
CKFLOAT DotProduct(const VxVector4& lhs, const VxVector4& rhs);
/**
* @brief Cross product 2 3d vectors.
* @param[in] lhs The left side vector of cross product symbol.
* @param[in] rhs The right side vector of cross product symbol.
* @return The 3d vector result of cross product.
*/
VxVector3 CrossProduct(const VxVector3& lhs, const VxVector3& rhs);
/**
* @brief Set all factor in vector to its absolute value.
* @param[in,out] lhs The vector for processing.
* @remarks This function is rarely used.
* Please note this function is not calculate the absolute value of vector.
*/
void Abs(VxVector3& lhs);
}
}

59
LibCmo/VxMath/VxTypes.cpp Normal file
View File

@ -0,0 +1,59 @@
#include "VxTypes.hpp"
namespace LibCmo::VxMath {
#pragma region Patched
namespace NSVxVector {
float DotProduct(const VxVector2& lhs, const VxVector2& rhs) {
return lhs * rhs;
}
float DotProduct(const VxVector3& lhs, const VxVector3& rhs) {
return lhs * rhs;
}
float DotProduct(const VxVector4& lhs, const VxVector4& rhs) {
return lhs * rhs;
}
VxVector3 CrossProduct(const VxVector3& lhs, const VxVector3& rhs) {
return VxVector3(
lhs.y * rhs.z - lhs.z * rhs.y,
lhs.z * rhs.x - lhs.x * rhs.z,
lhs.x * rhs.y - lhs.y * rhs.x
);
}
void Abs(VxVector3& lhs) {
lhs.x = std::fabs(lhs.x);
lhs.y = std::fabs(lhs.y);
lhs.z = std::fabs(lhs.z);
}
}
namespace NSVxMatrix {
void Perspective(VxMatrix& mat, float Fov, float Aspect, float Near_plane, float Far_plane) {
}
void PerspectiveRect(VxMatrix& mat, float Left, float Right, float Top, float Bottom, float Near_plane, float Far_plane) {
}
void Orthographic(VxMatrix& mat, float Zoom, float Aspect, float Near_plane, float Far_plane) {
}
void OrthographicRect(VxMatrix& mat, float Left, float Right, float Top, float Bottom, float Near_plane, float Far_plane) {
}
}
#pragma endregion
}

View File

@ -23,7 +23,7 @@ namespace LibCmo::VxMath {
class VxMemoryMappedFile;
// Misc
// ========== Vector-like Definition ==========
/**
* @brief The representation of a Vector in 2 dimensions.
@ -403,6 +403,7 @@ namespace LibCmo::VxMath {
return a <=> rhs.a;
}
// ===== BEGIN USER CUSTOM =====
VxColor(CKFLOAT _r, CKFLOAT _g, CKFLOAT _b) : r(_r), g(_g), b(_b), a(1.0f) {}
void FromARGB(CKDWORD argb) {
a = ((argb & 0xFF000000) >> 24) / 255.0f;
@ -431,6 +432,7 @@ namespace LibCmo::VxMath {
if (a > 1.0f) a = 1.0f;
else if (a < 0.0f) a = 0.0f;
}
// ===== END USER CUSTOM =====
};
/**
@ -446,10 +448,6 @@ namespace LibCmo::VxMath {
VxMatrix() : m_Data() { ResetToIdentity(); }
VxMatrix(CKFLOAT m[4][4]) : m_Data() { std::memcpy(m_Data, m, sizeof(m_Data)); }
YYCC_DEF_CLS_COPY_MOVE(VxMatrix);
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;
}
VxVector4& operator[](size_t i) {
if (i >= 4) throw LogicException("Invalid index for VxMatrix::operator[].");
return *(reinterpret_cast<VxVector4*>(m_Data) + i);
@ -461,8 +459,20 @@ namespace LibCmo::VxMath {
bool operator==(const VxMatrix& rhs) const {
return std::memcmp(m_Data, rhs.m_Data, sizeof(m_Data)) == 0;
}
// ===== BEGIN USER CUSTOM =====
void ResetToIdentity() {
Clear();
m_Data[0][0] = m_Data[1][1] = m_Data[2][2] = m_Data[3][3] = 1.0f;
}
void Clear() {
std::memset(m_Data, 0, sizeof(m_Data));
}
// ===== END USER CUSTOM =====
};
// ========== Misc ==========
/**
* @brief Structure for storage of strided data.
* @tparam _Ty The data pointer type this class stored.
@ -698,4 +708,157 @@ namespace LibCmo::VxMath {
CKBYTE* m_Image; /**< A pointer points to current image in memory */
};
// ========== Patch Section ==========
/**
* @brief The patch namespace for VxVector-like classes
* @details This namespace provides VxVector-like classes member functions which presented in original Virtools SDK.
* These functions are put in public namespace in original Virtools SDK.
* We just organise them into an unique namespace.
*/
namespace NSVxVector {
/**
* @brief Dot product 2 2d vectors.
* @param[in] lhs The left side vector of dot product symbol.
* @param[in] rhs The right side vector of dot product symbol.
* @return The float pointing result of dot product.
*/
CKFLOAT DotProduct(const VxVector2& lhs, const VxVector2& rhs);
/**
* @brief Dot product 2 3d vectors.
* @param[in] lhs The left side vector of dot product symbol.
* @param[in] rhs The right side vector of dot product symbol.
* @return The float pointing result of dot product.
*/
CKFLOAT DotProduct(const VxVector3& lhs, const VxVector3& rhs);
/**
* @brief Dot product 2 4d vectors.
* @param[in] lhs The left side vector of dot product symbol.
* @param[in] rhs The right side vector of dot product symbol.
* @return The float pointing result of dot product.
*/
CKFLOAT DotProduct(const VxVector4& lhs, const VxVector4& rhs);
/**
* @brief Cross product 2 3d vectors.
* @param[in] lhs The left side vector of cross product symbol.
* @param[in] rhs The right side vector of cross product symbol.
* @return The 3d vector result of cross product.
*/
VxVector3 CrossProduct(const VxVector3& lhs, const VxVector3& rhs);
/**
* @brief Set all factor in vector to its absolute value.
* @param[in,out] lhs The vector for processing.
* @remarks This function is rarely used.
* Please note this function is not calculate the absolute value of vector.
*/
void Abs(VxVector3& lhs);
}
/**
* @brief The patch namespace for VxMatrix classes
* @details Like NXVxVector, these functions located in this namespace
* are exposed in public namespace in original Virtools SDK.
* And I re-organise them in there.
*/
namespace NSVxMatrix {
/**
* @brief Constructs a perspective projection matrix.
* @param[in] Fov Field of View.
* @param[in] Aspect Aspect ratio (Width/height)
* @param[in] Near_plane Distance of the near clipping plane.
* @param[in] Far_plane Distance of the far clipping plane.
* @remarks Sets Mat to
*
* A = Cos(Fov/2)/Sin(Fov/2)
* F = Far_plane
* N = Near_plane
*
* [ A 0 0 0]
* [ 0 A*Aspect 0 0]
* MAT= [ 0 0 F/F-N 1]
* [ 0 0 -F.N/F-N 0]
*
* @see PerspectiveRect, Orthographic, OrthographicRect
*/
void Perspective(VxMatrix& mat, float Fov, float Aspect, float Near_plane, float Far_plane);
/**
* @brief Constructs a perspective projection matrix given a view rectangle.
* @param[in] Left Left clipping plane value.
* @param[in] Right Right clipping plane value.
* @param[in] Top top clipping plane value.
* @param[in] Bottom bottom clipping plane value.
* @param[in] Near_plane Distance of the near clipping plane.
* @param[in] Far_plane Distance of the far clipping plane.
* @remarks Sets Mat to
*
* F = Far_plane
* N = Near_plane
* R = Right
* L = Left
* T = Top
* B = Bottom
*
* [ 2/(R-L) 0 0 0]
* [ 0 -2/(T-B) 0 0]
* MAT = [ 0 0 1/F-N 0]
* [ -(L+R)/(R-L) (T+B)/(T-B) -N/F-N 1]
*
* @see Perspective, Orthographic, OrthographicRect
*/
void PerspectiveRect(VxMatrix& mat, float Left, float Right, float Top, float Bottom, float Near_plane, float Far_plane);
/**
* @brief Constructs a orthographic projection matrix.
* @param[in] Zoom Zoom factor.
* @param[in] Aspect Aspect ratio (Width/height)
* @param[in] Near_plane Distance of the near clipping plane.
* @param[in] Far_plane Distance of the far clipping plane.
* @remarks Sets Mat to
*
* F = Far_plane
* N = Near_plane
*
* [ Zoom 0 0 0]
* [ 0 Zoom*Aspect 0 0]
* MAT = [ 0 0 1/F-N 0]
* [ 0 0 -N/F-N 1]
*
* @see Perspective, OrthographicRect
*/
void Orthographic(VxMatrix& mat, float Zoom, float Aspect, float Near_plane, float Far_plane);
/**
* @brief Constructs a orthographic projection matrix.
* @param[in] Left Left clipping plane value.
* @param[in] Right Right clipping plane value.
* @param[in] Top top clipping plane value.
* @param[in] Bottom bottom clipping plane value.
* @param[in] Near_plane Distance of the near clipping plane.
* @param[in] Far_plane Distance of the far clipping plane.
* @remarks Sets Mat to
*
* F = Far_plane
* N = Near_plane
* R = Right
* L = Left
* T = Top
* B = Bottom
*
* [ 2/(R-L) 0 0 0]
* [ 0 -2/(T-B) 0 0]
* MAT = [ 0 0 1/F-N 0]
* [ -(L+R)/(R-L) (T+B)/(T-B) -N/F-N 1]
*
* @see Perspective, Orthographic
*/
void OrthographicRect(VxMatrix& mat, float Left, float Right, float Top, float Bottom, float Near_plane, float Far_plane);
}
}