Split off code into 3d_helpers function
All checks were successful
Build and Publish WASM version of demo / Build-And-Deploy (push) Successful in 22s
All checks were successful
Build and Publish WASM version of demo / Build-And-Deploy (push) Successful in 22s
This commit is contained in:
parent
310fa33b01
commit
dd678f12ba
3 changed files with 20 additions and 7 deletions
|
@ -6,6 +6,9 @@
|
||||||
// third party includes
|
// third party includes
|
||||||
#include <raymath.h>
|
#include <raymath.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "ems.h"
|
||||||
|
|
||||||
Matrix get_identity_matrix() {
|
Matrix get_identity_matrix() {
|
||||||
return Matrix{1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F,
|
return Matrix{1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F,
|
||||||
0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F};
|
0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F};
|
||||||
|
@ -166,6 +169,18 @@ std::optional<Vector3> ray_to_plane(const Ray &ray, const Ray &plane) {
|
||||||
ray.position.z + ray.direction.z * amount};
|
ray.position.z + ray.direction.z * amount};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector3 from_edge_to_sphere_random(Vector3 center, Vector3 point,
|
||||||
|
float radius) {
|
||||||
|
Vector3 to_center = center - point;
|
||||||
|
Vector3 perpendicular = Vector3Normalize(Vector3Perpendicular(to_center));
|
||||||
|
|
||||||
|
return Vector3Normalize(
|
||||||
|
to_center + Vector3RotateByAxisAngle(perpendicular,
|
||||||
|
Vector3Normalize(to_center),
|
||||||
|
call_js_get_random() * PI * 2.0F) *
|
||||||
|
(call_js_get_random() * radius));
|
||||||
|
}
|
||||||
|
|
||||||
Vector3 operator+(const Vector3 &a, const Vector3 &b) {
|
Vector3 operator+(const Vector3 &a, const Vector3 &b) {
|
||||||
return Vector3{a.x + b.x, a.y + b.y, a.z + b.z};
|
return Vector3{a.x + b.x, a.y + b.y, a.z + b.z};
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,9 @@ extern bool ray_to_xz_plane(const Ray &ray, float &x_out, float &z_out);
|
||||||
/// plane.direction is plane normal, plane.position is position on plane.
|
/// plane.direction is plane normal, plane.position is position on plane.
|
||||||
extern std::optional<Vector3> ray_to_plane(const Ray &ray, const Ray &plane);
|
extern std::optional<Vector3> ray_to_plane(const Ray &ray, const Ray &plane);
|
||||||
|
|
||||||
|
extern Vector3 from_edge_to_sphere_random(Vector3 center, Vector3 point,
|
||||||
|
float radius);
|
||||||
|
|
||||||
// Unimplemented as this function isn't really needed and it exposes some
|
// Unimplemented as this function isn't really needed and it exposes some
|
||||||
// weirdness regarding column-major matrices.
|
// weirdness regarding column-major matrices.
|
||||||
// extern Vector4 operator*(const Matrix &m, const Vector4 &v);
|
// extern Vector4 operator*(const Matrix &m, const Vector4 &v);
|
||||||
|
|
|
@ -80,13 +80,8 @@ bool ElectricityEffect::update(float dt) {
|
||||||
if (Vector3Distance(cylinder.point, center) > radius) {
|
if (Vector3Distance(cylinder.point, center) > radius) {
|
||||||
cylinder.point =
|
cylinder.point =
|
||||||
cylinder.point - cylinder.mdir * (dt * CYLINDER_MOVE_RATE);
|
cylinder.point - cylinder.mdir * (dt * CYLINDER_MOVE_RATE);
|
||||||
Vector3 to_center = center - cylinder.point;
|
cylinder.mdir =
|
||||||
Vector3 perpendicular = Vector3Normalize(Vector3Perpendicular(to_center));
|
from_edge_to_sphere_random(center, cylinder.point, radius);
|
||||||
cylinder.mdir = Vector3Normalize(
|
|
||||||
to_center + Vector3RotateByAxisAngle(perpendicular,
|
|
||||||
Vector3Normalize(to_center),
|
|
||||||
call_js_get_random() * PI * 2) *
|
|
||||||
(call_js_get_random() * radius));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue