From 5707a847da1ee0fba2f0040d1c6d3232042e7629 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Tue, 1 Nov 2022 21:21:07 -0400 Subject: [PATCH] Minor improvements to CScriptVisorFlare Former-commit-id: e31200f62d709f33ad9a257be84ccb97550d3b20 --- include/Kyoto/Graphics/CColor.hpp | 11 +++--- .../Weapons/CPlasmaProjectile.hpp | 8 ++-- include/rstl/pair.hpp | 10 +---- src/Kyoto/Math/CVector3f.cpp | 10 ++--- src/MetroidPrime/CVisorFlare.cpp | 39 +++++++++++-------- 5 files changed, 38 insertions(+), 40 deletions(-) diff --git a/include/Kyoto/Graphics/CColor.hpp b/include/Kyoto/Graphics/CColor.hpp index 52bdcb0b..b34c5ceb 100644 --- a/include/Kyoto/Graphics/CColor.hpp +++ b/include/Kyoto/Graphics/CColor.hpp @@ -26,8 +26,6 @@ public: mA = a; } - CColor(CColor rgb, float a) : mRgba((rgb.GetColor_u32() & 0xffffff00) | CCast::ToUint8(a * 255.f)) {} - void Set(float r, float g, float b, float a); void Set(uchar r, uchar g, uchar b, uchar a = 255) { mR = r; @@ -37,9 +35,9 @@ public: } void Get(float& r, float& g, float& b, float& a) const; void Get(float& r, float& g, float& b) const; - void SetAlpha(float a) { - mA = CCast::ToUint8(a * 255.f); - } + // TODO check + void SetAlpha(float a) { mA = CCast::ToUint8(a * 255.f); } + void SetAlpha(uchar a) { mRgba = (mRgba & ~0xff) | a; } static CColor Lerp(const CColor& a, const CColor& b, float t); static uint Lerp(uint a, uint b, float t); @@ -54,7 +52,8 @@ public: uchar GetBlueu8() const { return mB; } uchar GetAlphau8() const { return mA; } ushort ToRGB5A3() const; - GXColor ToGX(uint); + // TODO check + static GXColor ToGX(uint c) { return *reinterpret_cast< const GXColor* >(&c); } uint GetColor_u32() const { return mRgba; } static const CColor& Black(); diff --git a/include/MetroidPrime/Weapons/CPlasmaProjectile.hpp b/include/MetroidPrime/Weapons/CPlasmaProjectile.hpp index b851d164..4cefb204 100644 --- a/include/MetroidPrime/Weapons/CPlasmaProjectile.hpp +++ b/include/MetroidPrime/Weapons/CPlasmaProjectile.hpp @@ -17,8 +17,7 @@ public: CAssetId c = kInvalidAssetId, CAssetId d = kInvalidAssetId, CAssetId e = kInvalidAssetId, CAssetId f = kInvalidAssetId, CAssetId g = kInvalidAssetId, CAssetId h = kInvalidAssetId) - : count(8) - { + : count(8) { data[0] = a; data[1] = b; data[2] = c; @@ -33,9 +32,8 @@ public: CPlasmaProjectile(const TToken< CWeaponDescription >& wDesc, const rstl::string& name, EWeaponType wType, const CBeamInfo& bInfo, const CTransform4f& xf, EMaterialTypes matType, const CDamageInfo& dInfo, TUniqueId uid, TAreaId aid, - TUniqueId owner, - - const PlayerEffectResources& res, bool growingBeam, EProjectileAttrib attribs); + TUniqueId owner, const PlayerEffectResources& res, bool growingBeam, + EProjectileAttrib attribs); void Accept(IVisitor& visitor) override; void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) override; diff --git a/include/rstl/pair.hpp b/include/rstl/pair.hpp index 44187ff2..cd4be389 100644 --- a/include/rstl/pair.hpp +++ b/include/rstl/pair.hpp @@ -7,14 +7,8 @@ namespace rstl { template < typename L, typename R > class pair { public: - inline pair() {} - inline pair(const L& first, const R& second) : first(first), second(second) {} - - inline pair& operator=(const pair& other) { - first = other.first; - second = other.second; - return *this; - } + pair() {} + pair(const L& first, const R& second) : first(first), second(second) {} L first; R second; diff --git a/src/Kyoto/Math/CVector3f.cpp b/src/Kyoto/Math/CVector3f.cpp index 17734a0a..4b456f83 100644 --- a/src/Kyoto/Math/CVector3f.cpp +++ b/src/Kyoto/Math/CVector3f.cpp @@ -29,11 +29,11 @@ void CVector3f::PutTo(COutputStream& out) const { } CVector3f CVector3f::Slerp(const CVector3f& a, const CVector3f& b, const CRelAngle& angle) { - CVector3f ab = CVector3f::Cross(a, b); - CVector3f vec = CVector3f::Cross(ab.AsNormalized(), a); - float sinAngle = sine(angle); - float cosAngle = cosine(angle); - return cosAngle * a + vec * sinAngle; + CVector3f axb = CVector3f::Cross(a, b).AsNormalized(); + CVector3f crs = CVector3f::Cross(axb, a); + float asin = sine(angle); + float acos = cosine(angle); + return acos * a + asin * crs; } CVector3f& CVector3f::Normalize() { diff --git a/src/MetroidPrime/CVisorFlare.cpp b/src/MetroidPrime/CVisorFlare.cpp index 5a8cb9e6..e8d6bb3f 100644 --- a/src/MetroidPrime/CVisorFlare.cpp +++ b/src/MetroidPrime/CVisorFlare.cpp @@ -135,7 +135,9 @@ void CVisorFlare::Render(const CVector3f& inPos, const CStateManager& mgr) const if (!close_enough(x24_, 0.f, 1.0E-5f)) { float acos = 0.f; if (!close_enough(x20_f3, 0.f, 1.0E-5f)) { - CVector3f camDist(CVector3f(inPosCopy.GetX() - camPos.GetX(), inPosCopy.GetY() - camPos.GetY(), 0.f).AsNormalized()); + CVector3f camDist( + CVector3f(inPosCopy.GetX() - camPos.GetX(), inPosCopy.GetY() - camPos.GetY(), 0.f) + .AsNormalized()); CVector3f camDir(CVector3f(camFront.GetX(), camFront.GetY(), 0.f).AsNormalized()); acos = CMath::ArcCosineR(CVector3f::Dot(camDist, camDir)); if (camDist.GetX() * camDir.GetY() - camDir.GetX() * camDist.GetY() < 0.f) { @@ -179,27 +181,32 @@ void CVisorFlare::Render(const CVector3f& inPos, const CStateManager& mgr) const } void CVisorFlare::DrawDirect(const CColor& color, float f1, float f2) const { - // Giant TODO - // CColor kcolor = color; - // kcolor.a() *= x24_; // TODO i think this is wrong - GXColor gxColor; - CGX::SetTevKColor(GX_KCOLOR0, gxColor); + CColor kcolor = color; + kcolor.SetAlpha(kcolor.GetAlpha() * x24_); + CGX::SetTevKColor(GX_KCOLOR0, *reinterpret_cast< const GXColor* >(&kcolor)); CGX::Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4); - // GXPosition3f32(f1 - f2, 0.f, f2 + f1); - // GXTexCoord2f32(0.f, 1.f); - // GXPosition3f32(f2 + f1, 0.f, f2 - f1); - // GXTexCoord2f32(1.f, 1.f); - // GXPosition3f32(-(f2 - f1), 0.f, -(f2 - f1)); - // GXTexCoord2f32(0.f, 0.f); - // GXPosition3f32(-f1 + f2, 0.f, -f2 - f1); - // GXTexCoord2f32(1.f, 0.f); + GXPosition3f32(f1 - f2, 0.f, f2 + f1); + GXTexCoord2f32(0.f, 1.f); + GXPosition3f32(f2 + f1, 0.f, f2 - f1); + GXTexCoord2f32(1.f, 1.f); + GXPosition3f32(-(f2 - f1), 0.f, -(f2 - f1)); + GXTexCoord2f32(0.f, 0.f); + GXPosition3f32(-f1 + f2, 0.f, -f2 - f1); + GXTexCoord2f32(1.f, 0.f); CGX::End(); } +// fake but close +static inline CColor ModulateAlpha(const CColor& color, float alphaMod) { + uchar a = CCast::ToUint8(static_cast< float >(color.GetAlphau8()) * alphaMod); + CColor result = color; + result.SetAlpha(a); + return result; +} + void CVisorFlare::DrawStreamed(const CColor& color, float f1, float f2) const { CGraphics::StreamBegin(kP_TriangleStrip); - float a = color.GetAlpha(); // TODO: incorrect - CGraphics::StreamColor(CColor(color, a * x24_)); + CGraphics::StreamColor(ModulateAlpha(color, x24_)); CGraphics::StreamTexcoord(0.f, 1.f); CGraphics::StreamVertex(f1 - f2, 0.f, f2 + f1); CGraphics::StreamTexcoord(1.f, 1.f);