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 61 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 83 of file AxisSpawnPlacer.ixx.

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

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 105 of file AxisSpawnPlacer.ixx.

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

References helios::math::aabb< T >::contains, helios::math::aabb< T >::max, helios::math::aabb< T >::min, helios::engine::runtime::spawn::SpawnPlanCursor::position, helios::math::aabb< T >::size, helios::engine::runtime::spawn::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 66 of file AxisSpawnPlacer.ixx.

origin_

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

Starting point for entity placement.

Definition at line 71 of file AxisSpawnPlacer.ixx.

71 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.