Rework electricity effect "line" generation
All checks were successful
Build and Publish WASM version of demo / Build-And-Deploy (push) Successful in 23s
All checks were successful
Build and Publish WASM version of demo / Build-And-Deploy (push) Successful in 23s
This commit is contained in:
parent
d7351f9e3b
commit
bfa1e31305
4 changed files with 25 additions and 47 deletions
|
@ -1,5 +1,8 @@
|
||||||
#include "electricity_effect.h"
|
#include "electricity_effect.h"
|
||||||
|
|
||||||
|
// standard library includes
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
// third party includes
|
// third party includes
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
#include <raymath.h>
|
#include <raymath.h>
|
||||||
|
@ -18,54 +21,28 @@ ElectricityEffect::ElectricityEffect(Vector3 center, float radius,
|
||||||
cylinders.reserve(line_count);
|
cylinders.reserve(line_count);
|
||||||
|
|
||||||
// Generate cylinders.
|
// Generate cylinders.
|
||||||
int sub_count = 0;
|
std::queue<Vector3> positions;
|
||||||
Vector3 dir, pos;
|
Vector3 next, dir;
|
||||||
for (; line_count > 0; --line_count) {
|
for (unsigned int idx = 0; idx < CYLINDER_SPLIT_COUNT; ++idx) {
|
||||||
if (sub_count == 0) {
|
positions.push(center);
|
||||||
dir.x = call_js_get_random() * 2.0F - 1.0F;
|
}
|
||||||
dir.y = call_js_get_random() * 2.0F - 1.0F;
|
while (line_count-- > 0 && !positions.empty()) {
|
||||||
dir.z = call_js_get_random() * 2.0F - 1.0F;
|
next = positions.front();
|
||||||
|
positions.pop();
|
||||||
|
|
||||||
dir = Vector3Normalize(dir);
|
dir = Vector3Normalize(Vector3{call_js_get_random() * 2.0F - 1.0F,
|
||||||
|
call_js_get_random() * 2.0F - 1.0F,
|
||||||
|
call_js_get_random() * 2.0F - 1.0F});
|
||||||
|
|
||||||
pos = center + dir * (radius * 0.7F);
|
auto coll = GetRayCollisionSphere(Ray{.position = next, .direction = dir},
|
||||||
|
center, radius);
|
||||||
|
|
||||||
dir.x = call_js_get_random() * 2.0F - 1.0F;
|
cylinders.push_back(Cylinder{.start = next, .end = coll.point});
|
||||||
dir.y = call_js_get_random() * 2.0F - 1.0F;
|
|
||||||
dir.z = call_js_get_random() * 2.0F - 1.0F;
|
|
||||||
|
|
||||||
dir = Vector3Normalize(dir);
|
dir = Vector3Normalize(center - coll.point);
|
||||||
|
coll.point = coll.point + dir * (radius * CYLINDER_EDGE_OFFSET);
|
||||||
auto coll = GetRayCollisionSphere(
|
for (unsigned int idx = 0; idx < CYLINDER_SPLIT_COUNT; ++idx) {
|
||||||
Ray{.position = center, .direction = dir}, center, radius);
|
positions.push(coll.point);
|
||||||
|
|
||||||
cylinders.push_back(Cylinder{.start = pos, .end = coll.point});
|
|
||||||
|
|
||||||
pos = coll.point;
|
|
||||||
} else {
|
|
||||||
dir = Vector3Normalize(center - pos);
|
|
||||||
|
|
||||||
pos = pos + dir * (radius * CYLINDER_EDGE_OFFSET);
|
|
||||||
|
|
||||||
for (unsigned int idx = 0; idx < CYLINDER_SPLIT_COUNT; ++idx) {
|
|
||||||
dir.x = call_js_get_random() * 2.0F - 1.0F;
|
|
||||||
dir.y = call_js_get_random() * 2.0F - 1.0F;
|
|
||||||
dir.z = call_js_get_random() * 2.0F - 1.0F;
|
|
||||||
|
|
||||||
dir = Vector3Normalize(dir);
|
|
||||||
|
|
||||||
auto coll = GetRayCollisionSphere(
|
|
||||||
Ray{.position = pos, .direction = dir}, center, radius);
|
|
||||||
|
|
||||||
cylinders.push_back(Cylinder{.start = pos, .end = coll.point});
|
|
||||||
|
|
||||||
if (idx == CYLINDER_SPLIT_COUNT - 1) {
|
|
||||||
pos = coll.point;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (++sub_count >= CYLINDER_SUB_COUNT_MAX) {
|
|
||||||
sub_count = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
// third party includes
|
// third party includes
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
|
||||||
constexpr int CYLINDER_SUB_COUNT_MAX = 3;
|
|
||||||
constexpr int CYLINDER_SPLIT_COUNT = 3;
|
constexpr int CYLINDER_SPLIT_COUNT = 3;
|
||||||
constexpr int CYLINDER_SIDES = 3;
|
constexpr int CYLINDER_SIDES = 3;
|
||||||
constexpr float CYLINDER_MAX_RADIUS = 0.03F;
|
constexpr float CYLINDER_MAX_RADIUS = 0.03F;
|
||||||
|
|
|
@ -101,8 +101,8 @@ bool TRunnerScreen::update(float dt, bool is_resized) {
|
||||||
if (walker_hack_success && controlled_walker_idx.has_value()) {
|
if (walker_hack_success && controlled_walker_idx.has_value()) {
|
||||||
walkers[controlled_walker_idx.value()].set_player_controlled(true);
|
walkers[controlled_walker_idx.value()].set_player_controlled(true);
|
||||||
electricityEffects.push_back(ElectricityEffect(
|
electricityEffects.push_back(ElectricityEffect(
|
||||||
walkers[controlled_walker_idx.value()].get_body_pos(), 1.7F, 15,
|
walkers[controlled_walker_idx.value()].get_body_pos(), 1.7F,
|
||||||
1.0F));
|
ELECTRICITY_EFFECT_LINE_COUNT, 1.0F));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
controlled_walker_idx.reset();
|
controlled_walker_idx.reset();
|
||||||
|
|
|
@ -29,6 +29,8 @@ constexpr float SURFACE_RESET_TIME = 4.0F;
|
||||||
constexpr float SURFACE_RESET_TIME_TRI_DRAW = 3.0F;
|
constexpr float SURFACE_RESET_TIME_TRI_DRAW = 3.0F;
|
||||||
constexpr float SURFACE_RESET_Y_OFFSET = 40.0F;
|
constexpr float SURFACE_RESET_Y_OFFSET = 40.0F;
|
||||||
|
|
||||||
|
constexpr int ELECTRICITY_EFFECT_LINE_COUNT = 50;
|
||||||
|
|
||||||
class TRunnerScreen : public Screen {
|
class TRunnerScreen : public Screen {
|
||||||
public:
|
public:
|
||||||
struct SurfaceUnit {
|
struct SurfaceUnit {
|
||||||
|
|
Loading…
Reference in a new issue