refactor: refactor VxVector and its generator.

- refactor VxVector-like struct. split their declaration and implementatio because their implementation is too long. and occupy too much space in header.
- refactor VxVector struct generator. use jinja2 template engine, rather ran hand-written format string to make it is easy to read (although it still tough when first reading).
- add unary operator overloading for VxVector-like struct.
- add some VxMatrix functions which are essential to CKCamera.
- rename VxMatrix::ResetToIdentity to VxMatrix::SetIdentity to make it same as original Virtools SDK.
- the spaceship overloading with auto return value still may have bugs. please watch it carefully.
This commit is contained in:
2024-12-24 16:49:34 +08:00
parent 3eeb1f6cb6
commit 4bfc4782b5
15 changed files with 1199 additions and 644 deletions

View File

@ -157,7 +157,7 @@ namespace LibCmo::CK2::ObjImpls {
// read matrix
// reset
m_WorldMatrix.ResetToIdentity();
m_WorldMatrix.SetIdentity();
// force read as vector3
chunk->ReadStruct(reinterpret_cast<VxMath::VxVector3*>(&m_WorldMatrix[0]));
chunk->ReadStruct(reinterpret_cast<VxMath::VxVector3*>(&m_WorldMatrix[1]));

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

@ -573,7 +573,7 @@ namespace LibCmo::CK2::ObjImpls {
// get diff by distance
VxMath::VxVector3 diff = m_VertexNormal[vid] - generated[vid];
// abs the diff and add into accumulated diff
VxMath::NSVxVector::Abs(diff);
VxMath::NSVxVector::Absolute(diff);
accnml += diff;
}