ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
VectorField2D Class Reference

A class for managing and rendering 2D vector fields. More...

#include <VectorField2D.h>

Inheritance diagram for VectorField2D:
Collaboration diagram for VectorField2D:

Public Member Functions

 VectorField2D (uint16_t x, uint16_t y)
 Constructs a 2D vector field with specified dimensions.
 
 ~VectorField2D ()
 Destructor for the VectorField2D class.
 
void Boundary ()
 Applies boundary conditions to the vector field.
 
void Diffuse (float viscosity, float dt)
 Performs diffusion on the vector field.
 
void Advect (float dt)
 Advances the vector field using advection.
 
void SineField (float ratio, float period, float amplitude)
 Creates a sine wave effect in the vector field.
 
void StepField (float ratio, float period, float intensity)
 Creates a stepped pattern effect in the vector field.
 
void MovingSquareField (float ratio, float period, float intensity)
 Creates a moving square pattern in the vector field.
 
void SpiralField (float ratio, float period, float amplitude)
 Creates a spiral pattern in the vector field.
 
void ObjectField (Object3D *object, float intensity)
 Generates a field effect based on a 3D object's position and shape.
 
uint16_t GetCountX ()
 Retrieves the number of vectors along the X-axis.
 
uint16_t GetCountY ()
 Retrieves the number of vectors along the Y-axis.
 
void RenderDensity ()
 Renders the density values of the vector field.
 
void RenderVector ()
 Renders the vector field as arrows.
 
void SetSize (float sizeX, float sizeY)
 Sets the size of the vector field.
 
void SetPosition (float posX, float posY)
 Sets the position of the vector field.
 
void SetRotation (float rotation)
 Sets the rotation of the vector field.
 
uint32_t GetVectorAtPosition (float x, float y, bool &inBounds)
 Retrieves the vector at a specific position in the field.
 
RGBColor GetRGB (const Vector3D &position, const Vector3D &normal, const Vector3D &uvw) override
 Retrieves the RGB color corresponding to a position in the field.
 
- Public Member Functions inherited from Material
virtual ~Material ()=default
 Virtual destructor for proper cleanup in derived classes.
 

Private Attributes

int8_tvecXP
 X-component of previous vectors.
 
int8_tvecYP
 Y-component of previous vectors.
 
int8_tvecDP
 Density of previous vectors.
 
int8_tvecX
 X-component of current vectors.
 
int8_tvecY
 Y-component of current vectors.
 
int8_tvecD
 Density of current vectors.
 
Vector2D size
 Size of the vector field.
 
Vector2D position
 Position of the vector field.
 
const uint16_t countX
 Number of vectors along the X-axis.
 
const uint16_t countY
 Number of vectors along the Y-axis.
 
float rotation = 0.0f
 Rotation of the field in degrees.
 
bool density = false
 Indicates if the field should render density values.
 

Additional Inherited Members

- Public Types inherited from Material
enum  Method {
  Base , Add , Subtract , Multiply ,
  Divide , Darken , Lighten , Screen ,
  Overlay , SoftLight , Replace , EfficientMask ,
  Bypass
}
 Defines blending methods for combining colors. More...
 

Detailed Description

A class for managing and rendering 2D vector fields.

Definition at line 24 of file VectorField2D.h.

Constructor & Destructor Documentation

◆ VectorField2D()

Constructs a 2D vector field with specified dimensions.

Parameters
xNumber of vectors along the X-axis.
yNumber of vectors along the Y-axis.

Definition at line 3 of file VectorField2D.cpp.

References vecD, vecDP, vecX, vecXP, vecY, and vecYP.

◆ ~VectorField2D()

Destructor for the VectorField2D class.

Definition at line 13 of file VectorField2D.cpp.

References vecD, vecDP, vecX, vecXP, vecY, and vecYP.

Member Function Documentation

◆ Advect()

void Advect ( float  dt)

Advances the vector field using advection.

Parameters
dtThe time step for advection.

Definition at line 51 of file VectorField2D.cpp.

References Mathematics::Constrain(), countX, countY, vecD, vecDP, vecX, and vecY.

Referenced by VectorFieldAnimation::Update().

◆ Boundary()

void Boundary ( )

Applies boundary conditions to the vector field.

Definition at line 22 of file VectorField2D.cpp.

◆ Diffuse()

void Diffuse ( float  viscosity,
float  dt 
)

Performs diffusion on the vector field.

Parameters
viscosityThe viscosity of the field.
dtThe time step for diffusion.

Definition at line 26 of file VectorField2D.cpp.

References Mathematics::Constrain(), countX, countY, vecD, and vecDP.

Referenced by VectorFieldAnimation::Update().

◆ GetCountX()

uint16_t GetCountX ( )

Retrieves the number of vectors along the X-axis.

Returns
The count of vectors along the X-axis.

Definition at line 217 of file VectorField2D.cpp.

References countX.

◆ GetCountY()

uint16_t GetCountY ( )

Retrieves the number of vectors along the Y-axis.

Returns
The count of vectors along the Y-axis.

Definition at line 221 of file VectorField2D.cpp.

References countY.

◆ GetRGB()

RGBColor GetRGB ( const Vector3D position,
const Vector3D normal,
const Vector3D uvw 
)
overridevirtual

Retrieves the RGB color corresponding to a position in the field.

Parameters
positionThe 3D position in the field.
normalThe normal vector at the position.
uvwUVW coordinates at the position.
Returns
The RGB color at the specified position.

Implements Material.

Definition at line 291 of file VectorField2D.cpp.

References GetVectorAtPosition(), size, Vector2D::X, Vector3D::X, Vector2D::Y, and Vector3D::Y.

◆ GetVectorAtPosition()

uint32_t GetVectorAtPosition ( float  x,
float  y,
bool inBounds 
)

Retrieves the vector at a specific position in the field.

Parameters
xThe X-coordinate of the position.
yThe Y-coordinate of the position.
inBoundsOutput parameter indicating if the position is within bounds.
Returns
A packed integer representing the vector components and density.

Definition at line 247 of file VectorField2D.cpp.

References Mathematics::BilinearInterpolation(), countX, countY, Mathematics::IsClose(), Mathematics::Map(), position, Vector2D::Rotate(), rotation, size, vecD, Vector2D::X, and Vector2D::Y.

Referenced by GetRGB().

◆ MovingSquareField()

void MovingSquareField ( float  ratio,
float  period,
float  intensity 
)

Creates a moving square pattern in the vector field.

Parameters
ratioThe frequency multiplier.
periodThe period of the movement.
intensityThe intensity of the movement.

Definition at line 129 of file VectorField2D.cpp.

References Mathematics::Constrain(), countX, countY, Mathematics::MPI, size, vecD, Vector2D::X, and Vector2D::Y.

◆ ObjectField()

void ObjectField ( Object3D object,
float  intensity 
)

Generates a field effect based on a 3D object's position and shape.

Parameters
objectPointer to the 3D object.
intensityThe intensity of the effect.

Definition at line 167 of file VectorField2D.cpp.

References Mathematics::Constrain(), countX, countY, Object3D::GetTriangleGroup(), ITriangleGroup::GetTriangles(), size, vecD, vecX, vecY, Vector2D::X, and Vector2D::Y.

Referenced by VectorFieldAnimation::Update().

◆ RenderDensity()

void RenderDensity ( )

Renders the density values of the vector field.

Definition at line 225 of file VectorField2D.cpp.

References density.

Referenced by VectorFieldAnimation::Update().

◆ RenderVector()

void RenderVector ( )

Renders the vector field as arrows.

Definition at line 229 of file VectorField2D.cpp.

References density.

◆ SetPosition()

void SetPosition ( float  posX,
float  posY 
)

Sets the position of the vector field.

Parameters
posXThe X-coordinate of the position.
posYThe Y-coordinate of the position.

Definition at line 238 of file VectorField2D.cpp.

References position, Vector2D::X, and Vector2D::Y.

Referenced by VectorFieldAnimation::Update().

◆ SetRotation()

void SetRotation ( float  rotation)

Sets the rotation of the vector field.

Parameters
rotationThe rotation angle in degrees.

Definition at line 243 of file VectorField2D.cpp.

References rotation.

◆ SetSize()

void SetSize ( float  sizeX,
float  sizeY 
)

Sets the size of the vector field.

Parameters
sizeXThe width of the field.
sizeYThe height of the field.

Definition at line 233 of file VectorField2D.cpp.

References size, Vector2D::X, and Vector2D::Y.

Referenced by VectorFieldAnimation::Update().

◆ SineField()

void SineField ( float  ratio,
float  period,
float  amplitude 
)

Creates a sine wave effect in the vector field.

Parameters
ratioThe frequency multiplier.
periodThe period of the sine wave.
amplitudeThe amplitude of the sine wave.

Definition at line 93 of file VectorField2D.cpp.

References Mathematics::Constrain(), countX, countY, size, vecD, vecX, vecY, Vector2D::X, and Vector2D::Y.

◆ SpiralField()

void SpiralField ( float  ratio,
float  period,
float  amplitude 
)

Creates a spiral pattern in the vector field.

Parameters
ratioThe frequency multiplier.
periodThe period of the spiral.
amplitudeThe amplitude of the spiral.

Definition at line 151 of file VectorField2D.cpp.

References Mathematics::Constrain(), countX, countY, size, vecX, vecY, Vector2D::X, and Vector2D::Y.

◆ StepField()

void StepField ( float  ratio,
float  period,
float  intensity 
)

Creates a stepped pattern effect in the vector field.

Parameters
ratioThe frequency multiplier.
periodThe period of the steps.
intensityThe intensity of the steps.

Definition at line 108 of file VectorField2D.cpp.

References Mathematics::Constrain(), countX, countY, Mathematics::MPI, size, vecD, vecX, vecY, Vector2D::X, and Vector2D::Y.

Member Data Documentation

◆ countX

const uint16_t countX
private

Number of vectors along the X-axis.

Definition at line 35 of file VectorField2D.h.

Referenced by Advect(), Diffuse(), GetCountX(), GetVectorAtPosition(), MovingSquareField(), ObjectField(), SineField(), SpiralField(), and StepField().

◆ countY

const uint16_t countY
private

Number of vectors along the Y-axis.

Definition at line 36 of file VectorField2D.h.

Referenced by Advect(), Diffuse(), GetCountY(), GetVectorAtPosition(), MovingSquareField(), ObjectField(), SineField(), SpiralField(), and StepField().

◆ density

bool density = false
private

Indicates if the field should render density values.

Definition at line 38 of file VectorField2D.h.

Referenced by RenderDensity(), and RenderVector().

◆ position

Vector2D position
private

Position of the vector field.

Definition at line 34 of file VectorField2D.h.

Referenced by GetVectorAtPosition(), and SetPosition().

◆ rotation

float rotation = 0.0f
private

Rotation of the field in degrees.

Definition at line 37 of file VectorField2D.h.

Referenced by GetVectorAtPosition(), and SetRotation().

◆ size

Vector2D size
private

Size of the vector field.

Definition at line 33 of file VectorField2D.h.

Referenced by GetRGB(), GetVectorAtPosition(), MovingSquareField(), ObjectField(), SetSize(), SineField(), SpiralField(), and StepField().

◆ vecD

int8_t* vecD
private

Density of current vectors.

Definition at line 31 of file VectorField2D.h.

Referenced by Advect(), Diffuse(), GetVectorAtPosition(), MovingSquareField(), ObjectField(), SineField(), StepField(), VectorField2D(), and ~VectorField2D().

◆ vecDP

int8_t* vecDP
private

Density of previous vectors.

Definition at line 28 of file VectorField2D.h.

Referenced by Advect(), Diffuse(), VectorField2D(), and ~VectorField2D().

◆ vecX

int8_t* vecX
private

X-component of current vectors.

Definition at line 29 of file VectorField2D.h.

Referenced by Advect(), ObjectField(), SineField(), SpiralField(), StepField(), VectorField2D(), and ~VectorField2D().

◆ vecXP

int8_t* vecXP
private

X-component of previous vectors.

Definition at line 26 of file VectorField2D.h.

Referenced by VectorField2D(), and ~VectorField2D().

◆ vecY

int8_t* vecY
private

Y-component of current vectors.

Definition at line 30 of file VectorField2D.h.

Referenced by Advect(), ObjectField(), SineField(), SpiralField(), StepField(), VectorField2D(), and ~VectorField2D().

◆ vecYP

int8_t* vecYP
private

Y-component of previous vectors.

Definition at line 27 of file VectorField2D.h.

Referenced by VectorField2D(), and ~VectorField2D().


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