group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
HitscanEffect Class Reference

Hitscan energy beam using fBm (fractional Brownian motion) path deviation. More...

#include <HitscanEffect.hpp>

Collaboration diagram for HitscanEffect:
[legend]

Classes

struct  Branch
 A single forked branch diverging from the main arc. More...
struct  ReturnStroke
 A scheduled return stroke that re-randomises the arc path. More...
struct  BezierBeam
 State for a single active Bezier-spine beam. More...

Public Member Functions

void update (float dt, glm::vec3 camForward)
 Update all active beams, rebuilding arc vertex data each frame.
void spawn (glm::vec3 origin, glm::vec3 hitPos, WeaponType wt, glm::vec3 camForward)
 Fire a beam.
const ArcVertexarcData () const
 Get pointer to the arc vertex array for GPU upload.
uint32_t arcCount () const
 Get the number of arc vertices currently generated.
uint32_t activeBeamCount () const
 Get the number of active beams.
const HitscanBeambeamData () const
uint32_t beamCount () const

Private Member Functions

void appendArcStrip (const std::vector< glm::vec3 > &pts, float radius, glm::vec4 color, glm::vec3 camForward)
 Append a camera-facing triangle-strip ribbon to arcVerts_.

Static Private Member Functions

static glm::vec3 evalBezier (glm::vec3 p0, glm::vec3 p1, glm::vec3 p2, glm::vec3 p3, float t)
 Evaluate a cubic Bezier curve at parameter t.
static glm::vec3 evalBezierTangent (glm::vec3 p0, glm::vec3 p1, glm::vec3 p2, glm::vec3 p3, float t)
 Evaluate the tangent of a cubic Bezier curve at parameter t.
static void randomizeCP (glm::vec3 origin, glm::vec3 hitPos, glm::vec3 camForward, glm::vec3 &cp1, glm::vec3 &cp2)
 Randomize Bezier control points for a new arc shape.
static void rerandomizeBranches (BezierBeam &beam, glm::vec3 camForward)
 Re-randomize all branch parameters on a beam for flicker.

Private Attributes

BezierBeam beams_ [k_maxBeams] {}
std::vector< ArcVertexarcVerts_

Static Private Attributes

static constexpr int k_maxBeams = 4
static constexpr int k_bezierSegs = 32
 Samples along main arc.
static constexpr int k_branchSegs = 7
 Samples along each branch.
static constexpr int k_maxBranches = 5
static constexpr float k_beamLifetime = 0.22f
static constexpr float k_interpDuration = 0.08f
 Bezier morph time (s).

Detailed Description

Hitscan energy beam using fBm (fractional Brownian motion) path deviation.

Signal chain per frame: t [0,1] along Bezier spine -> optional domain warp -> 4-octave fBm (lacunarity~3, persistence~0.4) -> multiply by sin(t*pi) envelope (pinned at both endpoints) -> scale by baseAmplitude (16 % of beam length) -> apply perpendicular to Bezier tangent

Rendering: three concentric triangle-strip layers per arc (outer bloom halo, inner glow channel, white-hot core) rendered with additive blending, giving an HDR-like look without a post-process pass.

Temporal behaviour:

  • Smooth Bezier morph when a new shot is fired (80 ms interpolation).
  • Continuous fBm animation (each octave runs at 2x the speed of the one below).
  • 2-3 return strokes scheduled at 60/120/180 ms after the initial shot; each re-randomises the arc path and branches, simulating multi-strike behaviour.
  • Branches re-randomise every 45 ms for rapid flicker.

Member Function Documentation

◆ activeBeamCount()

uint32_t HitscanEffect::activeBeamCount ( ) const
nodiscard

Get the number of active beams.

Returns
Count of beams with active == true.

◆ appendArcStrip()

void HitscanEffect::appendArcStrip ( const std::vector< glm::vec3 > & pts,
float radius,
glm::vec4 color,
glm::vec3 camForward )
private

Append a camera-facing triangle-strip ribbon to arcVerts_.

Parameters
ptsSampled points along the arc segment.
radiusHalf-width of the ribbon strip.
colorRGBA color for all vertices in this strip.
camForwardCamera forward vector for billboard orientation.
Here is the caller graph for this function:

◆ arcCount()

uint32_t HitscanEffect::arcCount ( ) const
inlinenodiscard

Get the number of arc vertices currently generated.

Returns
Vertex count.

◆ arcData()

const ArcVertex * HitscanEffect::arcData ( ) const
inlinenodiscard

Get pointer to the arc vertex array for GPU upload.

Returns
Pointer to the first ArcVertex, or nullptr if empty.

◆ beamCount()

uint32_t HitscanEffect::beamCount ( ) const
inlinenodiscard

◆ beamData()

const HitscanBeam * HitscanEffect::beamData ( ) const
inlinenodiscard

◆ evalBezier()

glm::vec3 HitscanEffect::evalBezier ( glm::vec3 p0,
glm::vec3 p1,
glm::vec3 p2,
glm::vec3 p3,
float t )
staticprivate

Evaluate a cubic Bezier curve at parameter t.

Here is the caller graph for this function:

◆ evalBezierTangent()

glm::vec3 HitscanEffect::evalBezierTangent ( glm::vec3 p0,
glm::vec3 p1,
glm::vec3 p2,
glm::vec3 p3,
float t )
staticprivate

Evaluate the tangent of a cubic Bezier curve at parameter t.

Here is the caller graph for this function:

◆ randomizeCP()

void HitscanEffect::randomizeCP ( glm::vec3 origin,
glm::vec3 hitPos,
glm::vec3 camForward,
glm::vec3 & cp1,
glm::vec3 & cp2 )
staticprivate

Randomize Bezier control points for a new arc shape.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rerandomizeBranches()

void HitscanEffect::rerandomizeBranches ( BezierBeam & beam,
glm::vec3 camForward )
staticprivate

Re-randomize all branch parameters on a beam for flicker.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spawn()

void HitscanEffect::spawn ( glm::vec3 origin,
glm::vec3 hitPos,
WeaponType wt,
glm::vec3 camForward )

Fire a beam.

Consecutive shots on the same slot produce a smooth morph.

Parameters
originWorld-space beam start position.
hitPosWorld-space beam end position.
wtWeapon type (reserved for future per-weapon tuning).
camForwardCamera forward vector for control-point placement.
Here is the call graph for this function:

◆ update()

void HitscanEffect::update ( float dt,
glm::vec3 camForward )

Update all active beams, rebuilding arc vertex data each frame.

Parameters
dtFrame delta time in seconds.
camForwardCamera forward vector for billboard orientation.
Here is the call graph for this function:

Member Data Documentation

◆ arcVerts_

std::vector<ArcVertex> HitscanEffect::arcVerts_
private

◆ beams_

BezierBeam HitscanEffect::beams_[k_maxBeams] {}
private

◆ k_beamLifetime

float HitscanEffect::k_beamLifetime = 0.22f
staticconstexprprivate

◆ k_bezierSegs

int HitscanEffect::k_bezierSegs = 32
staticconstexprprivate

Samples along main arc.

◆ k_branchSegs

int HitscanEffect::k_branchSegs = 7
staticconstexprprivate

Samples along each branch.

◆ k_interpDuration

float HitscanEffect::k_interpDuration = 0.08f
staticconstexprprivate

Bezier morph time (s).

◆ k_maxBeams

int HitscanEffect::k_maxBeams = 4
staticconstexprprivate

◆ k_maxBranches

int HitscanEffect::k_maxBranches = 5
staticconstexprprivate

The documentation for this class was generated from the following files: