]> git.seodisparate.com - jumpartifact.com_demo_0/commitdiff
Split off code into 3d_helpers function
authorStephen Seo <seo.disparate@gmail.com>
Thu, 24 Aug 2023 08:04:51 +0000 (17:04 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 24 Aug 2023 08:04:51 +0000 (17:04 +0900)
src/3d_helpers.cc
src/3d_helpers.h
src/electricity_effect.cc

index 0f98c11938264f38d668979a7eacdf34097349a6..9d17173f6501304de85129d644a0941b51f86087 100644 (file)
@@ -6,6 +6,9 @@
 // third party includes
 #include <raymath.h>
 
+// local includes
+#include "ems.h"
+
 Matrix get_identity_matrix() {
   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};
@@ -166,6 +169,18 @@ std::optional<Vector3> ray_to_plane(const Ray &ray, const Ray &plane) {
                  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) {
   return Vector3{a.x + b.x, a.y + b.y, a.z + b.z};
 }
index a407c01d73d6a139afc8f2db1df6792129e9d1b7..b4cfcd49622dbc3e8eeab3e6d462627edeb8e411 100644 (file)
@@ -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.
 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
 // weirdness regarding column-major matrices.
 // extern Vector4 operator*(const Matrix &m, const Vector4 &v);
index 699b422ce4bb33c87ae1c0194605d61718a3bf09..ea9435d9b198eb73477c1675668e230adf2d81ef 100644 (file)
@@ -80,13 +80,8 @@ bool ElectricityEffect::update(float dt) {
     if (Vector3Distance(cylinder.point, center) > radius) {
       cylinder.point =
           cylinder.point - cylinder.mdir * (dt * CYLINDER_MOVE_RATE);
-      Vector3 to_center = center - cylinder.point;
-      Vector3 perpendicular = Vector3Normalize(Vector3Perpendicular(to_center));
-      cylinder.mdir = Vector3Normalize(
-          to_center + Vector3RotateByAxisAngle(perpendicular,
-                                               Vector3Normalize(to_center),
-                                               call_js_get_random() * PI * 2) *
-                          (call_js_get_random() * radius));
+      cylinder.mdir =
+          from_edge_to_sphere_random(center, cylinder.point, radius);
     }
   }