Minor fixes to 3d_helpers.cc
All checks were successful
Build and Publish WASM version of demo / Build-And-Deploy (push) Successful in 17s
All checks were successful
Build and Publish WASM version of demo / Build-And-Deploy (push) Successful in 17s
This commit is contained in:
parent
ff03f30809
commit
d4850f99bb
1 changed files with 7 additions and 2 deletions
|
@ -127,7 +127,7 @@ Matrix operator*(const Matrix &a, const Matrix &b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ray_to_xz_plane(const Ray &ray, float &x_out, float &z_out) {
|
bool ray_to_xz_plane(const Ray &ray, float &x_out, float &z_out) {
|
||||||
if (ray.direction.y == 0.0F) {
|
if (FloatEquals(ray.direction.y, 0.0F)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// y = 0 -> amount to set ray.dir to set ray.pos to zero
|
// y = 0 -> amount to set ray.dir to set ray.pos to zero
|
||||||
|
@ -147,7 +147,7 @@ bool ray_to_xz_plane(const Ray &ray, float &x_out, float &z_out) {
|
||||||
std::optional<Vector3> ray_to_plane(const Ray &ray, const Ray &plane) {
|
std::optional<Vector3> ray_to_plane(const Ray &ray, const Ray &plane) {
|
||||||
// Ray dir and plane normal.
|
// Ray dir and plane normal.
|
||||||
float rd_pn = Vector3DotProduct(ray.direction, plane.direction);
|
float rd_pn = Vector3DotProduct(ray.direction, plane.direction);
|
||||||
if (rd_pn == 0.0F) {
|
if (FloatEquals(rd_pn, 0.0F)) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,6 +155,11 @@ std::optional<Vector3> ray_to_plane(const Ray &ray, const Ray &plane) {
|
||||||
Vector3DotProduct(ray.position, plane.direction)) /
|
Vector3DotProduct(ray.position, plane.direction)) /
|
||||||
rd_pn;
|
rd_pn;
|
||||||
|
|
||||||
|
// Negative amount means collision in opposite direction of ray.
|
||||||
|
if (amount < 0.0F) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
// Amount * ray_dir + ray_pos == plane intersection.
|
// Amount * ray_dir + ray_pos == plane intersection.
|
||||||
return Vector3{ray.position.x + ray.direction.x * amount,
|
return Vector3{ray.position.x + ray.direction.x * amount,
|
||||||
ray.position.y + ray.direction.y * amount,
|
ray.position.y + ray.direction.y * amount,
|
||||||
|
|
Loading…
Reference in a new issue