mirror of https://github.com/AxioDL/metaforce.git
Particle, map and line renderer fixes
This commit is contained in:
parent
a2da358fd3
commit
29dad50cca
|
@ -183,9 +183,9 @@ struct RELifetimePercent : IRealElement
|
|||
struct RESineWave : IRealElement
|
||||
{
|
||||
AT_DECL_DNA_YAML
|
||||
RealElementFactory magnitude;
|
||||
RealElementFactory linearAngle;
|
||||
RealElementFactory constantAngle;
|
||||
RealElementFactory frequency;
|
||||
RealElementFactory amplitude;
|
||||
RealElementFactory phase;
|
||||
const char* ClassID() const {return "SINE";}
|
||||
};
|
||||
|
||||
|
|
|
@ -59,8 +59,8 @@ void CMapArea::PostConstruct()
|
|||
m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, m_verts.data(), 16, m_verts.size());
|
||||
m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, index.data(), 4, index.size());
|
||||
|
||||
/* Only the map universe specifies Always; it draws a maximum of 133 instances */
|
||||
size_t instCount = (xc_visibilityMode == EVisMode::Always) ? 133 : 1;
|
||||
/* Only the map universe specifies Always; it draws a maximum of 1016 instances */
|
||||
size_t instCount = (xc_visibilityMode == EVisMode::Always) ? 1024 : 1;
|
||||
|
||||
for (u32 i = 0 ; i<x30_surfaceCount ; ++i)
|
||||
{
|
||||
|
|
|
@ -93,7 +93,7 @@ void CMapUniverse::Draw(const CMapUniverseDrawParms& parms, const zeus::CVector3
|
|||
std::sort(sortInfos.begin(), sortInfos.end(),
|
||||
[](const CMapObjectSortInfo& a, const CMapObjectSortInfo& b)
|
||||
{
|
||||
return a.GetZDistance() < b.GetZDistance();
|
||||
return a.GetZDistance() > b.GetZDistance();
|
||||
});
|
||||
|
||||
int lastWldIdx = -1;
|
||||
|
|
|
@ -39,13 +39,11 @@ CLineRenderer::CLineRenderer(boo::IGraphicsDataFactory::Context& ctx,
|
|||
switch (mode)
|
||||
{
|
||||
case EPrimitiveMode::Lines:
|
||||
maxTriVerts = maxVerts * 3;
|
||||
break;
|
||||
case EPrimitiveMode::LineStrip:
|
||||
maxTriVerts = maxVerts * 2;
|
||||
maxTriVerts = maxVerts * 4;
|
||||
break;
|
||||
case EPrimitiveMode::LineLoop:
|
||||
maxTriVerts = maxVerts * 2 + 2;
|
||||
maxTriVerts = maxVerts * 4 + 4;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -75,13 +73,11 @@ CLineRenderer::CLineRenderer(EPrimitiveMode mode, u32 maxVerts,
|
|||
switch (mode)
|
||||
{
|
||||
case EPrimitiveMode::Lines:
|
||||
maxTriVerts = maxVerts * 3;
|
||||
break;
|
||||
case EPrimitiveMode::LineStrip:
|
||||
maxTriVerts = maxVerts * 2;
|
||||
maxTriVerts = maxVerts * 4;
|
||||
break;
|
||||
case EPrimitiveMode::LineLoop:
|
||||
maxTriVerts = maxVerts * 2 + 2;
|
||||
maxTriVerts = maxVerts * 4 + 4;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -102,18 +98,17 @@ CLineRenderer::CLineRenderer(EPrimitiveMode mode, u32 maxVerts,
|
|||
rstl::reserved_vector<CLineRenderer::SDrawVertTex, 1024> CLineRenderer::g_StaticLineVertsTex = {};
|
||||
rstl::reserved_vector<CLineRenderer::SDrawVertNoTex, 1024> CLineRenderer::g_StaticLineVertsNoTex = {};
|
||||
|
||||
static zeus::CVector2f IntersectLines(const zeus::CVector2f& pa1, const zeus::CVector2f& pa2,
|
||||
const zeus::CVector2f& pb1, const zeus::CVector2f& pb2)
|
||||
static bool IntersectLines(const zeus::CVector2f& pa1, const zeus::CVector2f& pa2,
|
||||
const zeus::CVector2f& pb1, const zeus::CVector2f& pb2,
|
||||
zeus::CVector3f& intersect)
|
||||
{
|
||||
zeus::CVector2f pa1mpa2 = pa1 - pa2;
|
||||
zeus::CVector2f pb1mpb2 = pb1 - pb2;
|
||||
float denom = pa1mpa2.x * pb1mpb2.y - pa1mpa2.y * pb1mpb2.x;
|
||||
if (denom < 0.01f)
|
||||
return pa2;
|
||||
float numt1 = pa1.x * pa2.y - pa1.y * pa2.x;
|
||||
float numt2 = pb1.x * pb2.y - pb1.y * pb2.x;
|
||||
return {(numt1 * pb1mpb2.x - pa1mpa2.x * numt2) / denom,
|
||||
(numt1 * pb1mpb2.y - pa1mpa2.y * numt2) / denom};
|
||||
float det = (pa1.x - pa2.x) * (pb1.y - pb2.y) - (pa1.y - pa2.y) * (pb1.x - pb2.x);
|
||||
if (std::fabs(det) < 0.01f)
|
||||
return false;
|
||||
float c0 = pa1.x * pa2.y - pa1.y * pa2.x;
|
||||
float c1 = pb1.x * pb2.y - pb1.y * pb2.x;
|
||||
intersect = (c0 * (pb1 - pb2) - c1 * (pa1 - pa2)) / det;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CLineRenderer::Reset()
|
||||
|
@ -186,17 +181,33 @@ void CLineRenderer::AddVertex(const zeus::CVector3f& position, const zeus::CColo
|
|||
}
|
||||
else
|
||||
{
|
||||
zeus::CVector3f intersect1 = IntersectLines(m_lastPos2.toVec2f() + dva, m_lastPos.toVec2f() + dva,
|
||||
m_lastPos.toVec2f() + dvb, projPt.toVec2f() + dvb);
|
||||
zeus::CVector3f intersect1;
|
||||
bool good1 = IntersectLines(m_lastPos2.toVec2f() + dva, m_lastPos.toVec2f() + dva,
|
||||
m_lastPos.toVec2f() + dvb, projPt.toVec2f() + dvb, intersect1);
|
||||
if ((intersect1.toVec2f() - m_lastPos.toVec2f()).magnitude() > m_lastWidth * 4.f)
|
||||
good1 = false;
|
||||
|
||||
zeus::CVector3f intersect2;
|
||||
bool good2 = IntersectLines(m_lastPos2.toVec2f() - dva, m_lastPos.toVec2f() - dva,
|
||||
m_lastPos.toVec2f() - dvb, projPt.toVec2f() - dvb, intersect2);
|
||||
if ((intersect2.toVec2f() - m_lastPos.toVec2f()).magnitude() > m_lastWidth * 4.f)
|
||||
good2 = false;
|
||||
|
||||
if (good1 && good2)
|
||||
{
|
||||
intersect1.z = m_lastPos.z;
|
||||
|
||||
zeus::CVector3f intersect2 = IntersectLines(m_lastPos2.toVec2f() - dva, m_lastPos.toVec2f() - dva,
|
||||
m_lastPos.toVec2f() - dvb, projPt.toVec2f() - dvb);
|
||||
intersect2.z = m_lastPos.z;
|
||||
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor, m_lastUV});
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor, m_lastUV});
|
||||
}
|
||||
else
|
||||
{
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor, m_lastUV});
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor, m_lastUV});
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor, m_lastUV});
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor, m_lastUV});
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -217,17 +228,33 @@ void CLineRenderer::AddVertex(const zeus::CVector3f& position, const zeus::CColo
|
|||
}
|
||||
else
|
||||
{
|
||||
zeus::CVector3f intersect1 = IntersectLines(m_lastPos2.toVec2f() + dva, m_lastPos.toVec2f() + dva,
|
||||
m_lastPos.toVec2f() + dvb, projPt.toVec2f() + dvb);
|
||||
zeus::CVector3f intersect1;
|
||||
bool good1 = IntersectLines(m_lastPos2.toVec2f() + dva, m_lastPos.toVec2f() + dva,
|
||||
m_lastPos.toVec2f() + dvb, projPt.toVec2f() + dvb, intersect1);
|
||||
if ((intersect1.toVec2f() - m_lastPos.toVec2f()).magnitude() > m_lastWidth * 4.f)
|
||||
good1 = false;
|
||||
|
||||
zeus::CVector3f intersect2;
|
||||
bool good2 = IntersectLines(m_lastPos2.toVec2f() - dva, m_lastPos.toVec2f() - dva,
|
||||
m_lastPos.toVec2f() - dvb, projPt.toVec2f() - dvb, intersect2);
|
||||
if ((intersect2.toVec2f() - m_lastPos.toVec2f()).magnitude() > m_lastWidth * 4.f)
|
||||
good2 = false;
|
||||
|
||||
if (good1 && good2)
|
||||
{
|
||||
intersect1.z = m_lastPos.z;
|
||||
|
||||
zeus::CVector3f intersect2 = IntersectLines(m_lastPos2.toVec2f() - dva, m_lastPos.toVec2f() - dva,
|
||||
m_lastPos.toVec2f() - dvb, projPt.toVec2f() - dvb);
|
||||
intersect2.z = m_lastPos.z;
|
||||
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor});
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor});
|
||||
}
|
||||
else
|
||||
{
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor});
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor});
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor});
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (m_nextVert == 1)
|
||||
|
@ -277,24 +304,52 @@ void CLineRenderer::Render(const zeus::CColor& moduColor)
|
|||
dvb = dvb.normalized().perpendicularVector() * m_lastWidth;
|
||||
dvb.x /= CGraphics::g_ProjAspect;
|
||||
|
||||
zeus::CVector3f intersect1 = IntersectLines(m_lastPos2.toVec2f() + dva, m_lastPos.toVec2f() + dva,
|
||||
m_lastPos.toVec2f() + dvb, m_firstPos.toVec2f() + dvb);
|
||||
intersect1.z = m_lastPos.z;
|
||||
zeus::CVector3f intersect1;
|
||||
bool good1 = IntersectLines(m_lastPos2.toVec2f() + dva, m_lastPos.toVec2f() + dva,
|
||||
m_lastPos.toVec2f() + dvb, m_firstPos.toVec2f() + dvb, intersect1);
|
||||
if ((intersect1.toVec2f() - m_lastPos.toVec2f()).magnitude() > m_lastWidth * 4.f)
|
||||
good1 = false;
|
||||
|
||||
zeus::CVector3f intersect2 = IntersectLines(m_lastPos2.toVec2f() - dva, m_lastPos.toVec2f() - dva,
|
||||
m_lastPos.toVec2f() - dvb, m_firstPos.toVec2f() - dvb);
|
||||
intersect2.z = m_lastPos.z;
|
||||
zeus::CVector3f intersect2;
|
||||
bool good2 = IntersectLines(m_lastPos2.toVec2f() - dva, m_lastPos.toVec2f() - dva,
|
||||
m_lastPos.toVec2f() - dvb, m_firstPos.toVec2f() - dvb, intersect2);
|
||||
if ((intersect2.toVec2f() - m_lastPos.toVec2f()).magnitude() > m_lastWidth * 4.f)
|
||||
good2 = false;
|
||||
|
||||
if (m_textured)
|
||||
{
|
||||
if (good1 && good2)
|
||||
{
|
||||
intersect1.z = m_lastPos.z;
|
||||
intersect2.z = m_lastPos.z;
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor, m_lastUV});
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor, m_lastUV});
|
||||
}
|
||||
else
|
||||
{
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor, m_lastUV});
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor, m_lastUV});
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor, m_lastUV});
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor, m_lastUV});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (good1 && good2)
|
||||
{
|
||||
intersect1.z = m_lastPos.z;
|
||||
intersect2.z = m_lastPos.z;
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor});
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor});
|
||||
}
|
||||
else
|
||||
{
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor});
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor});
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor});
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor});
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
zeus::CVector2f dva = (m_firstPos - m_lastPos).toVec2f();
|
||||
|
@ -309,23 +364,51 @@ void CLineRenderer::Render(const zeus::CColor& moduColor)
|
|||
dvb = dvb.normalized().perpendicularVector() * m_firstWidth;
|
||||
dvb.x /= CGraphics::g_ProjAspect;
|
||||
|
||||
zeus::CVector3f intersect1 = IntersectLines(m_lastPos.toVec2f() + dva, m_firstPos.toVec2f() + dva,
|
||||
m_firstPos.toVec2f() + dvb, m_secondPos.toVec2f() + dvb);
|
||||
intersect1.z = m_firstPos.z;
|
||||
zeus::CVector3f intersect1;
|
||||
bool good1 = IntersectLines(m_lastPos.toVec2f() + dva, m_firstPos.toVec2f() + dva,
|
||||
m_firstPos.toVec2f() + dvb, m_secondPos.toVec2f() + dvb, intersect1);
|
||||
if ((intersect1.toVec2f() - m_firstPos.toVec2f()).magnitude() > m_firstWidth * 4.f)
|
||||
good1 = false;
|
||||
|
||||
zeus::CVector3f intersect2 = IntersectLines(m_lastPos.toVec2f() - dva, m_firstPos.toVec2f() - dva,
|
||||
m_firstPos.toVec2f() - dvb, m_secondPos.toVec2f() - dvb);
|
||||
intersect2.z = m_firstPos.z;
|
||||
zeus::CVector3f intersect2;
|
||||
bool good2 = IntersectLines(m_lastPos.toVec2f() - dva, m_firstPos.toVec2f() - dva,
|
||||
m_firstPos.toVec2f() - dvb, m_secondPos.toVec2f() - dvb, intersect2);
|
||||
if ((intersect2.toVec2f() - m_firstPos.toVec2f()).magnitude() > m_firstWidth * 4.f)
|
||||
good2 = false;
|
||||
|
||||
if (m_textured)
|
||||
{
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect1, m_firstW), m_firstColor, m_firstUV});
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect2, m_firstW), m_firstColor, m_firstUV});
|
||||
if (good1 && good2)
|
||||
{
|
||||
intersect1.z = m_firstPos.z;
|
||||
intersect2.z = m_firstPos.z;
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor, m_lastUV});
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor, m_lastUV});
|
||||
}
|
||||
else
|
||||
{
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect1, m_firstW), m_firstColor});
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect2, m_firstW), m_firstColor});
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dva, m_lastW), m_lastColor, m_lastUV});
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dva, m_lastW), m_lastColor, m_lastUV});
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dvb, m_lastW), m_lastColor, m_lastUV});
|
||||
g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dvb, m_lastW), m_lastColor, m_lastUV});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (good1 && good2)
|
||||
{
|
||||
intersect1.z = m_firstPos.z;
|
||||
intersect2.z = m_firstPos.z;
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor});
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor});
|
||||
}
|
||||
else
|
||||
{
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dva, m_lastW), m_lastColor});
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dva, m_lastW), m_lastColor});
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dvb, m_lastW), m_lastColor});
|
||||
g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dvb, m_lastW), m_lastColor});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -193,10 +193,10 @@ bool CRELifetimePercent::GetValue(int frame, float& valOut) const
|
|||
bool CRESineWave::GetValue(int frame, float& valOut) const
|
||||
{
|
||||
float a, b, c;
|
||||
x4_magnitude->GetValue(frame, a);
|
||||
x8_linearFrame->GetValue(frame, b);
|
||||
xc_constantFrame->GetValue(frame, c);
|
||||
valOut = std::sin(zeus::degToRad(frame * b + c)) * a;
|
||||
x4_frequency->GetValue(frame, a);
|
||||
x8_amplitude->GetValue(frame, b);
|
||||
xc_phase->GetValue(frame, c);
|
||||
valOut = std::sin(zeus::degToRad(frame * a + c)) * b;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -146,13 +146,13 @@ public:
|
|||
|
||||
class CRESineWave : public CRealElement
|
||||
{
|
||||
std::unique_ptr<CRealElement> x4_magnitude;
|
||||
std::unique_ptr<CRealElement> x8_linearFrame;
|
||||
std::unique_ptr<CRealElement> xc_constantFrame;
|
||||
std::unique_ptr<CRealElement> x4_frequency;
|
||||
std::unique_ptr<CRealElement> x8_amplitude;
|
||||
std::unique_ptr<CRealElement> xc_phase;
|
||||
public:
|
||||
CRESineWave(std::unique_ptr<CRealElement>&& a, std::unique_ptr<CRealElement>&& b,
|
||||
std::unique_ptr<CRealElement>&& c)
|
||||
: x4_magnitude(std::move(a)), x8_linearFrame(std::move(b)), xc_constantFrame(std::move(c)) {}
|
||||
: x4_frequency(std::move(a)), x8_amplitude(std::move(b)), xc_phase(std::move(c)) {}
|
||||
bool GetValue(int frame, float& valOut) const;
|
||||
};
|
||||
|
||||
|
|
|
@ -64,6 +64,11 @@ public:
|
|||
void Render(const CStateManager&) const;
|
||||
void Think(float, CStateManager&);
|
||||
bool CanRenderUnsorted(const CStateManager&) const { return false; }
|
||||
void SetActive(bool active)
|
||||
{
|
||||
CActor::SetActive(active);
|
||||
xe7_29_drawEnabled = true;
|
||||
}
|
||||
void CalculateRenderBounds();
|
||||
zeus::CAABox GetSortingBounds(const CStateManager&) const;
|
||||
bool AreBothSystemsDeleteable();
|
||||
|
|
Loading…
Reference in New Issue