group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
EnergyTeslaArcEffect.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
7
8#include <array>
9#include <cstdint>
10#include <glm/glm.hpp>
11#include <vector>
12
15{
16public:
18 {
19 std::array<glm::vec3, 33> points{};
20 uint32_t count = 0;
21 };
22
23 void drive(uint32_t key,
24 glm::vec3 origin,
25 glm::vec3 guidePoint,
26 glm::vec3 hitPoint,
27 bool locked,
28 float lockStrength);
29 void debugPreview(glm::vec3 origin, glm::vec3 guidePoint, glm::vec3 hitPoint, bool locked, float lockStrength);
30 void debugPulse(glm::vec3 origin, glm::vec3 guidePoint, glm::vec3 hitPoint, bool locked, float lockStrength);
31 void update(float dt, glm::vec3 camForward);
32
33 [[nodiscard]] const ArcVertex* mainArcData() const { return mainArcVerts_.data(); }
34 [[nodiscard]] uint32_t mainArcCount() const { return static_cast<uint32_t>(mainArcVerts_.size()); }
35 [[nodiscard]] const ArcVertex* detailArcData() const { return detailArcVerts_.data(); }
36 [[nodiscard]] uint32_t detailArcCount() const { return static_cast<uint32_t>(detailArcVerts_.size()); }
37 [[nodiscard]] uint32_t arcCount() const { return mainArcCount() + detailArcCount(); }
38 [[nodiscard]] uint32_t activeBeamCount() const;
39
40 [[nodiscard]] static PathSample buildGuidePathForTest(glm::vec3 origin,
41 glm::vec3 guidePoint,
42 glm::vec3 hitPoint,
43 bool locked,
44 float lockStrength);
45
46private:
47 static constexpr int k_maxBeams = 8;
48 static constexpr int k_mainSegs = 32;
49 static constexpr int k_branchSegs = 7;
50 static constexpr int k_maxBranches = 8;
51 static constexpr int k_maxStrands = 3;
52 static constexpr float k_fadeTime = 0.08f;
53 static constexpr float k_branchRetime = 0.045f;
54
55 struct Branch
56 {
57 float tStart = 0.0f;
58 float length = 0.0f;
59 float angle = 0.0f;
60 float side = 0.0f;
61 float seed = 0.0f;
62 };
63
64 struct Beam
65 {
66 uint32_t key = 0;
67 bool active = false;
68 bool locked = false;
69 glm::vec3 origin{0.0f};
70 glm::vec3 guidePoint{0.0f};
71 glm::vec3 hitPoint{0.0f};
72 float lockStrength = 0.0f;
73 float displayedLock = 0.0f;
74 float age = 0.0f;
75 float time = 0.0f;
76 float seed = 0.0f;
77 float warpSeed = 0.0f;
78 float branchTimer = 0.0f;
79 bool drivenThisFrame = false;
80 std::array<Branch, k_maxBranches> branches{};
81 int branchCount = 0;
82 };
83
84 std::array<Beam, k_maxBeams> beams_{};
85 std::vector<ArcVertex> mainArcVerts_;
86 std::vector<ArcVertex> detailArcVerts_;
87 uint32_t debugPreviewKey_ = 0xEA10u;
88 uint32_t debugKey_ = 0xEA11u;
89
90 [[nodiscard]] static float hash01(uint32_t n);
91 [[nodiscard]] static float smooth01(float v);
92 [[nodiscard]] static glm::vec3 safeNormalize(glm::vec3 v, glm::vec3 fallback);
93 [[nodiscard]] static glm::vec3 cubic(glm::vec3 p0, glm::vec3 p1, glm::vec3 p2, glm::vec3 p3, float t);
94 [[nodiscard]] static PathSample buildGuidePath(glm::vec3 origin,
95 glm::vec3 guidePoint,
96 glm::vec3 hitPoint,
97 bool locked,
98 float lockStrength);
99
100 Beam* findOrAllocBeam(uint32_t key);
101 void rerandomizeBranches(Beam& beam);
102 void appendArcStrip(std::vector<ArcVertex>& out,
103 const std::vector<glm::vec3>& pts,
104 float radius,
105 glm::vec4 color,
106 glm::vec3 camForward);
107 void appendLayeredBolt(const std::vector<glm::vec3>& pts,
108 float fade,
109 float radiusScale,
110 bool primary,
111 glm::vec3 camForward);
112 void appendBranches(const Beam& beam,
113 const std::vector<glm::vec3>& mainPts,
114 glm::vec3 axisN,
115 glm::vec3 perp,
116 glm::vec3 perp2,
117 float len,
118 float fade,
119 glm::vec3 camForward);
120 void appendCorona(glm::vec3 center,
121 glm::vec3 axisN,
122 glm::vec3 perp,
123 glm::vec3 perp2,
124 float len,
125 float fade,
126 float seed,
127 bool targetCorona,
128 glm::vec3 camForward);
129 void appendEnergyBall(const Beam& beam,
130 glm::vec3 axisN,
131 glm::vec3 perp,
132 glm::vec3 perp2,
133 float len,
134 float fade,
135 glm::vec3 camForward);
136};
GPU-uploadable particle structs for all effect categories.
Continuous EnergyGun lightning built on the same ArcVertex path as Railgun.
Definition EnergyTeslaArcEffect.hpp:15
void appendArcStrip(std::vector< ArcVertex > &out, const std::vector< glm::vec3 > &pts, float radius, glm::vec4 color, glm::vec3 camForward)
Definition EnergyTeslaArcEffect.cpp:212
static constexpr int k_maxBranches
Definition EnergyTeslaArcEffect.hpp:50
static constexpr int k_maxStrands
Definition EnergyTeslaArcEffect.hpp:51
uint32_t activeBeamCount() const
Definition EnergyTeslaArcEffect.cpp:483
static constexpr int k_maxBeams
Definition EnergyTeslaArcEffect.hpp:47
std::vector< ArcVertex > detailArcVerts_
Definition EnergyTeslaArcEffect.hpp:86
void debugPreview(glm::vec3 origin, glm::vec3 guidePoint, glm::vec3 hitPoint, bool locked, float lockStrength)
Definition EnergyTeslaArcEffect.cpp:203
static PathSample buildGuidePath(glm::vec3 origin, glm::vec3 guidePoint, glm::vec3 hitPoint, bool locked, float lockStrength)
Definition EnergyTeslaArcEffect.cpp:92
Beam * findOrAllocBeam(uint32_t key)
Definition EnergyTeslaArcEffect.cpp:129
const ArcVertex * detailArcData() const
Definition EnergyTeslaArcEffect.hpp:35
uint32_t detailArcCount() const
Definition EnergyTeslaArcEffect.hpp:36
std::vector< ArcVertex > mainArcVerts_
Definition EnergyTeslaArcEffect.hpp:85
uint32_t debugKey_
Definition EnergyTeslaArcEffect.hpp:88
static PathSample buildGuidePathForTest(glm::vec3 origin, glm::vec3 guidePoint, glm::vec3 hitPoint, bool locked, float lockStrength)
Definition EnergyTeslaArcEffect.cpp:120
uint32_t debugPreviewKey_
Definition EnergyTeslaArcEffect.hpp:87
static constexpr int k_mainSegs
Definition EnergyTeslaArcEffect.hpp:48
static constexpr int k_branchSegs
Definition EnergyTeslaArcEffect.hpp:49
static glm::vec3 cubic(glm::vec3 p0, glm::vec3 p1, glm::vec3 p2, glm::vec3 p3, float t)
Definition EnergyTeslaArcEffect.cpp:86
static glm::vec3 safeNormalize(glm::vec3 v, glm::vec3 fallback)
Definition EnergyTeslaArcEffect.cpp:77
void appendBranches(const Beam &beam, const std::vector< glm::vec3 > &mainPts, glm::vec3 axisN, glm::vec3 perp, glm::vec3 perp2, float len, float fade, glm::vec3 camForward)
Definition EnergyTeslaArcEffect.cpp:261
static float hash01(uint32_t n)
Definition EnergyTeslaArcEffect.cpp:66
uint32_t mainArcCount() const
Definition EnergyTeslaArcEffect.hpp:34
static constexpr float k_fadeTime
Definition EnergyTeslaArcEffect.hpp:52
void appendLayeredBolt(const std::vector< glm::vec3 > &pts, float fade, float radiusScale, bool primary, glm::vec3 camForward)
Definition EnergyTeslaArcEffect.cpp:249
void rerandomizeBranches(Beam &beam)
Definition EnergyTeslaArcEffect.cpp:148
void drive(uint32_t key, glm::vec3 origin, glm::vec3 guidePoint, glm::vec3 hitPoint, bool locked, float lockStrength)
Definition EnergyTeslaArcEffect.cpp:167
const ArcVertex * mainArcData() const
Definition EnergyTeslaArcEffect.hpp:33
void appendEnergyBall(const Beam &beam, glm::vec3 axisN, glm::vec3 perp, glm::vec3 perp2, float len, float fade, glm::vec3 camForward)
Definition EnergyTeslaArcEffect.cpp:335
std::array< Beam, k_maxBeams > beams_
Definition EnergyTeslaArcEffect.hpp:84
uint32_t arcCount() const
Definition EnergyTeslaArcEffect.hpp:37
void appendCorona(glm::vec3 center, glm::vec3 axisN, glm::vec3 perp, glm::vec3 perp2, float len, float fade, float seed, bool targetCorona, glm::vec3 camForward)
Definition EnergyTeslaArcEffect.cpp:309
void debugPulse(glm::vec3 origin, glm::vec3 guidePoint, glm::vec3 hitPoint, bool locked, float lockStrength)
Definition EnergyTeslaArcEffect.cpp:194
static constexpr float k_branchRetime
Definition EnergyTeslaArcEffect.hpp:53
static float smooth01(float v)
Definition EnergyTeslaArcEffect.cpp:71
void update(float dt, glm::vec3 camForward)
Definition EnergyTeslaArcEffect.cpp:384
Lightning arc vertex (pre-expanded triangle strip, uploaded as flat stream).
Definition ParticleTypes.hpp:67
Definition EnergyTeslaArcEffect.hpp:65
bool drivenThisFrame
Definition EnergyTeslaArcEffect.hpp:79
float seed
Definition EnergyTeslaArcEffect.hpp:76
uint32_t key
Definition EnergyTeslaArcEffect.hpp:66
bool active
Definition EnergyTeslaArcEffect.hpp:67
glm::vec3 guidePoint
Definition EnergyTeslaArcEffect.hpp:70
float lockStrength
Definition EnergyTeslaArcEffect.hpp:72
float age
Definition EnergyTeslaArcEffect.hpp:74
float time
Definition EnergyTeslaArcEffect.hpp:75
bool locked
Definition EnergyTeslaArcEffect.hpp:68
int branchCount
Definition EnergyTeslaArcEffect.hpp:81
float branchTimer
Definition EnergyTeslaArcEffect.hpp:78
glm::vec3 origin
Definition EnergyTeslaArcEffect.hpp:69
std::array< Branch, k_maxBranches > branches
Definition EnergyTeslaArcEffect.hpp:80
float displayedLock
Definition EnergyTeslaArcEffect.hpp:73
glm::vec3 hitPoint
Definition EnergyTeslaArcEffect.hpp:71
float warpSeed
Definition EnergyTeslaArcEffect.hpp:77
Definition EnergyTeslaArcEffect.hpp:56
float side
Definition EnergyTeslaArcEffect.hpp:60
float tStart
Definition EnergyTeslaArcEffect.hpp:57
float seed
Definition EnergyTeslaArcEffect.hpp:61
float length
Definition EnergyTeslaArcEffect.hpp:58
float angle
Definition EnergyTeslaArcEffect.hpp:59
Definition EnergyTeslaArcEffect.hpp:18
std::array< glm::vec3, 33 > points
Definition EnergyTeslaArcEffect.hpp:19
uint32_t count
Definition EnergyTeslaArcEffect.hpp:20