Minor improvements to CScriptVisorFlare

Former-commit-id: e31200f62d
This commit is contained in:
Luke Street 2022-11-01 21:21:07 -04:00
parent 8498bd6e94
commit 5707a847da
5 changed files with 38 additions and 40 deletions

View File

@ -26,8 +26,6 @@ public:
mA = a; 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(float r, float g, float b, float a);
void Set(uchar r, uchar g, uchar b, uchar a = 255) { void Set(uchar r, uchar g, uchar b, uchar a = 255) {
mR = r; 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, float& a) const;
void Get(float& r, float& g, float& b) const; void Get(float& r, float& g, float& b) const;
void SetAlpha(float a) { // TODO check
mA = CCast::ToUint8(a * 255.f); 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 CColor Lerp(const CColor& a, const CColor& b, float t);
static uint Lerp(uint a, uint b, float t); static uint Lerp(uint a, uint b, float t);
@ -54,7 +52,8 @@ public:
uchar GetBlueu8() const { return mB; } uchar GetBlueu8() const { return mB; }
uchar GetAlphau8() const { return mA; } uchar GetAlphau8() const { return mA; }
ushort ToRGB5A3() const; 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; } uint GetColor_u32() const { return mRgba; }
static const CColor& Black(); static const CColor& Black();

View File

@ -17,8 +17,7 @@ public:
CAssetId c = kInvalidAssetId, CAssetId d = kInvalidAssetId, CAssetId c = kInvalidAssetId, CAssetId d = kInvalidAssetId,
CAssetId e = kInvalidAssetId, CAssetId f = kInvalidAssetId, CAssetId e = kInvalidAssetId, CAssetId f = kInvalidAssetId,
CAssetId g = kInvalidAssetId, CAssetId h = kInvalidAssetId) CAssetId g = kInvalidAssetId, CAssetId h = kInvalidAssetId)
: count(8) : count(8) {
{
data[0] = a; data[0] = a;
data[1] = b; data[1] = b;
data[2] = c; data[2] = c;
@ -33,9 +32,8 @@ public:
CPlasmaProjectile(const TToken< CWeaponDescription >& wDesc, const rstl::string& name, CPlasmaProjectile(const TToken< CWeaponDescription >& wDesc, const rstl::string& name,
EWeaponType wType, const CBeamInfo& bInfo, const CTransform4f& xf, EWeaponType wType, const CBeamInfo& bInfo, const CTransform4f& xf,
EMaterialTypes matType, const CDamageInfo& dInfo, TUniqueId uid, TAreaId aid, EMaterialTypes matType, const CDamageInfo& dInfo, TUniqueId uid, TAreaId aid,
TUniqueId owner, TUniqueId owner, const PlayerEffectResources& res, bool growingBeam,
EProjectileAttrib attribs);
const PlayerEffectResources& res, bool growingBeam, EProjectileAttrib attribs);
void Accept(IVisitor& visitor) override; void Accept(IVisitor& visitor) override;
void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) override; void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) override;

View File

@ -7,14 +7,8 @@ namespace rstl {
template < typename L, typename R > template < typename L, typename R >
class pair { class pair {
public: public:
inline pair() {} pair() {}
inline pair(const L& first, const R& second) : first(first), second(second) {} 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;
}
L first; L first;
R second; R second;

View File

@ -29,11 +29,11 @@ void CVector3f::PutTo(COutputStream& out) const {
} }
CVector3f CVector3f::Slerp(const CVector3f& a, const CVector3f& b, const CRelAngle& angle) { CVector3f CVector3f::Slerp(const CVector3f& a, const CVector3f& b, const CRelAngle& angle) {
CVector3f ab = CVector3f::Cross(a, b); CVector3f axb = CVector3f::Cross(a, b).AsNormalized();
CVector3f vec = CVector3f::Cross(ab.AsNormalized(), a); CVector3f crs = CVector3f::Cross(axb, a);
float sinAngle = sine(angle); float asin = sine(angle);
float cosAngle = cosine(angle); float acos = cosine(angle);
return cosAngle * a + vec * sinAngle; return acos * a + asin * crs;
} }
CVector3f& CVector3f::Normalize() { CVector3f& CVector3f::Normalize() {

View File

@ -135,7 +135,9 @@ void CVisorFlare::Render(const CVector3f& inPos, const CStateManager& mgr) const
if (!close_enough(x24_, 0.f, 1.0E-5f)) { if (!close_enough(x24_, 0.f, 1.0E-5f)) {
float acos = 0.f; float acos = 0.f;
if (!close_enough(x20_f3, 0.f, 1.0E-5f)) { 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()); CVector3f camDir(CVector3f(camFront.GetX(), camFront.GetY(), 0.f).AsNormalized());
acos = CMath::ArcCosineR(CVector3f::Dot(camDist, camDir)); acos = CMath::ArcCosineR(CVector3f::Dot(camDist, camDir));
if (camDist.GetX() * camDir.GetY() - camDir.GetX() * camDist.GetY() < 0.f) { 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 { void CVisorFlare::DrawDirect(const CColor& color, float f1, float f2) const {
// Giant TODO CColor kcolor = color;
// CColor kcolor = color; kcolor.SetAlpha(kcolor.GetAlpha() * x24_);
// kcolor.a() *= x24_; // TODO i think this is wrong CGX::SetTevKColor(GX_KCOLOR0, *reinterpret_cast< const GXColor* >(&kcolor));
GXColor gxColor;
CGX::SetTevKColor(GX_KCOLOR0, gxColor);
CGX::Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4); CGX::Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4);
// GXPosition3f32(f1 - f2, 0.f, f2 + f1); GXPosition3f32(f1 - f2, 0.f, f2 + f1);
// GXTexCoord2f32(0.f, 1.f); GXTexCoord2f32(0.f, 1.f);
// GXPosition3f32(f2 + f1, 0.f, f2 - f1); GXPosition3f32(f2 + f1, 0.f, f2 - f1);
// GXTexCoord2f32(1.f, 1.f); GXTexCoord2f32(1.f, 1.f);
// GXPosition3f32(-(f2 - f1), 0.f, -(f2 - f1)); GXPosition3f32(-(f2 - f1), 0.f, -(f2 - f1));
// GXTexCoord2f32(0.f, 0.f); GXTexCoord2f32(0.f, 0.f);
// GXPosition3f32(-f1 + f2, 0.f, -f2 - f1); GXPosition3f32(-f1 + f2, 0.f, -f2 - f1);
// GXTexCoord2f32(1.f, 0.f); GXTexCoord2f32(1.f, 0.f);
CGX::End(); 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 { void CVisorFlare::DrawStreamed(const CColor& color, float f1, float f2) const {
CGraphics::StreamBegin(kP_TriangleStrip); CGraphics::StreamBegin(kP_TriangleStrip);
float a = color.GetAlpha(); // TODO: incorrect CGraphics::StreamColor(ModulateAlpha(color, x24_));
CGraphics::StreamColor(CColor(color, a * x24_));
CGraphics::StreamTexcoord(0.f, 1.f); CGraphics::StreamTexcoord(0.f, 1.f);
CGraphics::StreamVertex(f1 - f2, 0.f, f2 + f1); CGraphics::StreamVertex(f1 - f2, 0.f, f2 + f1);
CGraphics::StreamTexcoord(1.f, 1.f); CGraphics::StreamTexcoord(1.f, 1.f);