mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-09 03:58:19 +03:00
Organise
This commit is contained in:
parent
6a44e7487e
commit
72b769bdad
2 changed files with 35 additions and 34 deletions
|
@ -20,36 +20,7 @@ namespace TEN::Effects::ElectricArc
|
||||||
|
|
||||||
// BIG TODO: Make a family of Bezier, B-Spline, and Catmull-Rom curve classes.
|
// BIG TODO: Make a family of Bezier, B-Spline, and Catmull-Rom curve classes.
|
||||||
|
|
||||||
// 4-point Catmull-Rom spline interpolation.
|
// More standard version. Adopt this in place of the one below.
|
||||||
// Function takes reference to array of knots and
|
|
||||||
// calculates using subset of 4 determined alpha value.
|
|
||||||
static Vector3 ElectricArcSpline(const std::array<Vector3, ELECTRIC_ARC_KNOTS_SIZE>& knots, float alpha)
|
|
||||||
{
|
|
||||||
alpha *= ELECTRIC_ARC_KNOTS_SIZE - 3;
|
|
||||||
|
|
||||||
int span = alpha;
|
|
||||||
if (span >= (ELECTRIC_ARC_KNOTS_SIZE - 3))
|
|
||||||
span = ELECTRIC_ARC_KNOTS_SIZE - 4;
|
|
||||||
|
|
||||||
float alphaNorm = alpha - span; // What?
|
|
||||||
|
|
||||||
// Determine subset of 4 knots.
|
|
||||||
const auto& knot0 = knots[span];
|
|
||||||
const auto& knot1 = knots[span + 1];
|
|
||||||
const auto& knot2 = knots[span + 2];
|
|
||||||
const auto& knot3 = knots[span + 3];
|
|
||||||
|
|
||||||
auto point1 = knot1 + (knot1 / 2) - (knot2 / 2) - knot2 + (knot3 / 2) + ((-knot0 - Vector3::One) / 2);
|
|
||||||
auto ret = point1 * alphaNorm;
|
|
||||||
auto point2 = ret + Vector3(2.0f) * knot2 - 2 * knot1 - (knot1 / 2) - (knot3 / 2) + knot0;
|
|
||||||
ret = point2 * alphaNorm;
|
|
||||||
auto point3 = ret + (knot2 / 2) + ((-knot0 - Vector3::One) / 2);
|
|
||||||
ret = point3 * alphaNorm;
|
|
||||||
|
|
||||||
return (ret + knot1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// More standard version. Adopt this in place of the above.
|
|
||||||
static Vector3 CatmullRomSpline(float alpha, const std::array<Vector3, 4>& knots)
|
static Vector3 CatmullRomSpline(float alpha, const std::array<Vector3, 4>& knots)
|
||||||
{
|
{
|
||||||
auto point1 = knots[1] + ((knots[2] - knots[0]) * (1 / 6.0f));
|
auto point1 = knots[1] + ((knots[2] - knots[0]) * (1 / 6.0f));
|
||||||
|
@ -63,6 +34,35 @@ namespace TEN::Effects::ElectricArc
|
||||||
return spline;
|
return spline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 4-point Catmull-Rom spline interpolation.
|
||||||
|
// Function takes reference to array of knots and
|
||||||
|
// calculates using subset of 4 determined alpha value.
|
||||||
|
static Vector3 ElectricArcSpline(const std::array<Vector3, ELECTRIC_ARC_KNOTS_SIZE>& knots, float alpha)
|
||||||
|
{
|
||||||
|
alpha *= ELECTRIC_ARC_KNOTS_SIZE - 3;
|
||||||
|
|
||||||
|
int span = alpha;
|
||||||
|
if (span >= (ELECTRIC_ARC_KNOTS_SIZE - 3))
|
||||||
|
span = ELECTRIC_ARC_KNOTS_SIZE - 4;
|
||||||
|
|
||||||
|
float something = alpha - span;
|
||||||
|
|
||||||
|
// Determine subset of 4 knots.
|
||||||
|
const auto& knot0 = knots[span];
|
||||||
|
const auto& knot1 = knots[span + 1];
|
||||||
|
const auto& knot2 = knots[span + 2];
|
||||||
|
const auto& knot3 = knots[span + 3];
|
||||||
|
|
||||||
|
auto point1 = knot1 + (knot1 / 2) - (knot2 / 2) - knot2 + (knot3 / 2) + ((-knot0 - Vector3::One) / 2);
|
||||||
|
auto ret = point1 * something;
|
||||||
|
auto point2 = ret + Vector3(2.0f) * knot2 - 2 * knot1 - (knot1 / 2) - (knot3 / 2) + knot0;
|
||||||
|
ret = point2 * something;
|
||||||
|
auto point3 = ret + (knot2 / 2) + ((-knot0 - Vector3::One) / 2);
|
||||||
|
ret = point3 * something;
|
||||||
|
|
||||||
|
return (ret + knot1);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Pass const Vector4& for color.
|
// TODO: Pass const Vector4& for color.
|
||||||
void SpawnElectricArc(const Vector3& origin, const Vector3& target, float amplitude, byte r, byte g, byte b, float life, int flags, float width, unsigned int numSegments)
|
void SpawnElectricArc(const Vector3& origin, const Vector3& target, float amplitude, byte r, byte g, byte b, float life, int flags, float width, unsigned int numSegments)
|
||||||
{
|
{
|
||||||
|
@ -167,6 +167,7 @@ namespace TEN::Effects::ElectricArc
|
||||||
void UpdateHelicalLasers()
|
void UpdateHelicalLasers()
|
||||||
{
|
{
|
||||||
static constexpr auto LIFE_START_FADING = HELICAL_LASER_LIFE_MAX / 2;
|
static constexpr auto LIFE_START_FADING = HELICAL_LASER_LIFE_MAX / 2;
|
||||||
|
static constexpr auto LENGTH_LERP_ALPHA = 0.25f;
|
||||||
|
|
||||||
// No active effects; return early.
|
// No active effects; return early.
|
||||||
if (HelicalLasers.empty())
|
if (HelicalLasers.empty())
|
||||||
|
@ -180,7 +181,7 @@ namespace TEN::Effects::ElectricArc
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Update length.
|
// Update length.
|
||||||
laser.Length = Lerp(laser.Length, laser.LengthEnd, 0.25f);
|
laser.Length = Lerp(laser.Length, laser.LengthEnd, LENGTH_LERP_ALPHA);
|
||||||
|
|
||||||
// Update radius.
|
// Update radius.
|
||||||
laser.Radius += 1 / 8.0f;
|
laser.Radius += 1 / 8.0f;
|
||||||
|
@ -216,7 +217,7 @@ namespace TEN::Effects::ElectricArc
|
||||||
arc.life -= 2.0f;
|
arc.life -= 2.0f;
|
||||||
if (arc.life > 0.0f)
|
if (arc.life > 0.0f)
|
||||||
{
|
{
|
||||||
// TODO: Find a better way for this.
|
// TODO: Find a better way to do this.
|
||||||
auto* posPtr = (Vector3*)&arc.pos2;
|
auto* posPtr = (Vector3*)&arc.pos2;
|
||||||
for (auto& interpPos : arc.interpolation)
|
for (auto& interpPos : arc.interpolation)
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,7 +44,7 @@ extern Particle Particles[MAX_PARTICLES];
|
||||||
extern SPLASH_STRUCT Splashes[MAX_SPLASHES];
|
extern SPLASH_STRUCT Splashes[MAX_SPLASHES];
|
||||||
extern RIPPLE_STRUCT Ripples[MAX_RIPPLES];
|
extern RIPPLE_STRUCT Ripples[MAX_RIPPLES];
|
||||||
|
|
||||||
// TODO: EnemyBites must be eradicated and kept directly in object structs or passed to gunflash functions!
|
// TODO: EnemyBites must be eradicated and kept directly in object structs or passed to gunflash functions.
|
||||||
|
|
||||||
BiteInfo EnemyBites[12] =
|
BiteInfo EnemyBites[12] =
|
||||||
{
|
{
|
||||||
|
@ -136,7 +136,7 @@ namespace TEN::Renderer
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ElectricArcKnots[0] = arc.pos1;
|
ElectricArcKnots[0] = arc.pos1;
|
||||||
memcpy(&ElectricArcKnots[1], &arc, 48); // TODO: This is wrong.
|
memcpy(&ElectricArcKnots[1], &arc, 48); // TODO: This should be wrong, but it still works??
|
||||||
ElectricArcKnots[5] = arc.pos4;
|
ElectricArcKnots[5] = arc.pos4;
|
||||||
|
|
||||||
for (int j = 0; j < ElectricArcKnots.size(); j++)
|
for (int j = 0; j < ElectricArcKnots.size(); j++)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue