// 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};
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};
}
/// 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);
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);
}
}