Skip to main content

AxisSpawnPlacer Class

Spawn placer that distributes entities evenly along an axis. More...

Declaration

class helios::engine::runtime::spawn::behavior::placements::AxisSpawnPlacer { ... }

Base class

classSpawnPlacer

Abstract interface for determining spawn positions. More...

Public Constructors Index

AxisSpawnPlacer (const helios::math::vec3f axis, const helios::math::vec3f origin)

Constructs an AxisSpawnPlacer with axis and origin. More...

Public Member Functions Index

helios::math::vec3fgetPosition (const helios::engine::ecs::EntityHandle &entityHandle, const helios::math::aabbf &gameObjectBounds, const helios::math::aabbf &environmentBounds, const SpawnPlanCursor &cursor, const SpawnContext &spawnContext) override

Calculates spawn position along the axis. More...

Private Member Attributes Index

helios::math::vec3faxis_

Normalized direction vector defining the spawn axis. More...

helios::math::vec3forigin_ {}

Starting point for entity placement. More...

Description

Spawn placer that distributes entities evenly along an axis.

AxisSpawnPlacer positions spawned entities along a normalized direction vector starting from an origin point. Entities are distributed evenly between the origin and the environment boundary intersection.

## Positioning Algorithm

1. Calculates where the axis intersects the environment bounds 2. Computes available length accounting for entity size 3. Distributes entities evenly along this length based on cursor position

## Use Cases

  • **Formation spawning:** Line formations of enemies
  • **Wave patterns:** Entities spawning along a direction
  • **Corridor spawning:** Entities placed along a path

## Usage

```cpp // Spawn entities along positive X-axis from origin auto placer = std::make_unique<AxisSpawnPlacer>( helios::math::vec3f{1.0f, 0.0f, 0.0f}, // axis (normalized) helios::math::vec3f{-100.0f, 0.0f, 0.0f} // origin );

// With 5 entities: evenly spaced from origin to right boundary ```

info

The axis vector must be normalized.

info

The origin must be within the environment bounds.

See Also

SpawnPlacer

See Also

DistributedSpawnPlacer

Definition at line 62 of file AxisSpawnPlacer.ixx.

Public Constructors

AxisSpawnPlacer()

helios::engine::runtime::spawn::behavior::placements::AxisSpawnPlacer::AxisSpawnPlacer (const helios::math::vec3f axis, const helios::math::vec3f origin)
inline explicit

Constructs an AxisSpawnPlacer with axis and origin.

Parameters
axis

Normalized direction vector for entity distribution.

origin

Starting point for the axis within environment bounds.

Precondition

`axis` must be normalized.

Definition at line 84 of file AxisSpawnPlacer.ixx.

84 explicit AxisSpawnPlacer(const helios::math::vec3f axis, const helios::math::vec3f origin)
85 : axis_(axis), origin_(origin) {
86 assert(axis.isNormalized() && "Axis must be normalized.");
87 }

Reference helios::math::vec3< T >::isNormalized.

Public Member Functions

getPosition()

helios::math::vec3f helios::engine::runtime::spawn::behavior::placements::AxisSpawnPlacer::getPosition (const helios::engine::ecs::EntityHandle & entityHandle, const helios::math::aabbf & gameObjectBounds, const helios::math::aabbf & environmentBounds, const SpawnPlanCursor & cursor, const SpawnContext & spawnContext)
inline virtual

Calculates spawn position along the axis.

Distributes entities evenly along the axis from origin to the environment boundary. Uses the cursor position to determine placement within the available range.

Parameters
guid

Unique identifier of the entity (unused).

gameObjectBounds

Bounding box of the entity being spawned.

environmentBounds

Bounding box of the spawn environment.

cursor

Current spawn batch cursor with position and count.

spawnContext

Context for the spawn operation (unused).

Returns

World position for the spawned entity.

Precondition

Origin must be within environment bounds.

Definition at line 106 of file AxisSpawnPlacer.ixx.

107 const helios::engine::ecs::EntityHandle& entityHandle,
108 const helios::math::aabbf& gameObjectBounds,
109 const helios::math::aabbf& environmentBounds,
110 const SpawnPlanCursor& cursor,
111 const SpawnContext& spawnContext
112 ) override {
113
114 assert(environmentBounds.contains(origin_) && "origin is not within bounding box");
115
116 const float top = environmentBounds.max()[1];
117 const float bottom = environmentBounds.min()[1];
118 const float left = environmentBounds.min()[0];
119 const float right = environmentBounds.max()[0];
120 const float near = environmentBounds.min()[2];
121 const float far = environmentBounds.max()[2];
122
123 const float height = std::abs(top - bottom);
124 const float width = std::abs(right - left);
125
126 float t_x = std::numeric_limits<float>::infinity();
127 if (axis_[0] < 0) {
128 t_x = ((left - origin_[0]) / axis_[0]);
129 } else if (axis_[0] > 0 ){
130 t_x = ((right - origin_[0]) / axis_[0]);
131 }
132
133 float t_y = std::numeric_limits<float>::infinity();
134 if (axis_[1] < 0) {
135 t_y = ((bottom - origin_[1]) / axis_[1]);
136 } else if (axis_[1] > 0 ){
137 t_y = ((top - origin_[1]) / axis_[1]);
138 }
139
140 float t_z =std::numeric_limits<float>::infinity();
141 if (axis_[2] < 0) {
142 t_z = ((near - origin_[2]) / axis_[2]);
143 } else if (axis_[2] > 0 ){
144 t_z = ((far - origin_[2]) / axis_[2]);
145 }
146
147 const auto t = std::min(std::min(t_x, t_y), t_z);
148
149 // compute the projection of the aaabb onto the direction vector.
150 // we use absolute values of the direction vector to make sure
151 // we effectively measure dimensions, not projections relative
152 // to the origin direction
153 const auto objectHalfSize = gameObjectBounds.size() * 0.5f;
154 const auto projection = objectHalfSize.dot(helios::math::vec3f{
155 std::abs(axis_[0]), std::abs(axis_[1]), std::abs(axis_[2])
156 });
157
158 float availableLength = t - projection;
159 availableLength = availableLength < 0 ? 0 : availableLength;
160
161 const auto pos = axis_ * availableLength *
162 (static_cast<float>(cursor.position)/static_cast<float>(
163 cursor.spawnCount > 0 ? cursor.spawnCount - 1 :1)
164 );
165
166
167 const auto center = gameObjectBounds.translate(
168 helios::math::vec3f{origin_[0] + pos[0], origin_[1] + pos[1], origin_[2] + pos[2]}
169 ).center();
170
171 return center;
172 }

References helios::math::aabb< T >::contains, helios::math::aabb< T >::max, helios::math::aabb< T >::min, helios::engine::runtime::spawn::types::SpawnPlanCursor::position, helios::math::aabb< T >::size, helios::engine::runtime::spawn::types::SpawnPlanCursor::spawnCount and helios::math::aabb< T >::translate.

Private Member Attributes

axis_

helios::math::vec3f helios::engine::runtime::spawn::behavior::placements::AxisSpawnPlacer::axis_

Normalized direction vector defining the spawn axis.

Definition at line 67 of file AxisSpawnPlacer.ixx.

origin_

helios::math::vec3f helios::engine::runtime::spawn::behavior::placements::AxisSpawnPlacer::origin_ {}

Starting point for entity placement.

Definition at line 72 of file AxisSpawnPlacer.ixx.

72 helios::math::vec3f origin_{};

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.