Just roughing physics
This commit is contained in:
27
src/dawn/scene/components/physics/2d/Ray2D.cpp
Normal file
27
src/dawn/scene/components/physics/2d/Ray2D.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Ray2D.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Ray2D::Ray2D(glm::vec2 pos, glm::vec2 dir) :
|
||||
position(pos),
|
||||
direction(dir)
|
||||
{
|
||||
}
|
||||
|
||||
bool_t Ray2D::intersects(struct Ray2D ray, glm::vec2 *out) {
|
||||
glm::vec2 j = this->position - ray.position;
|
||||
float_t f = -ray.direction.x * direction.y + direction.x * ray.direction.y;
|
||||
float_t s = (-direction.y * j.x + direction.x * j.y) / f;
|
||||
float_t t = (ray.direction.x * j.y - ray.direction.y * j.x) / f;
|
||||
if (s >= 0 && s <= 1 && t >= 0 && t <= 1) {
|
||||
*out = position + (t * direction);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
Reference in New Issue
Block a user