it's a range problem

This commit is contained in:
Lephenixnoir 2023-09-05 00:06:04 +02:00
parent 642c2e9877
commit 1fa16bf5f8
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
1 changed files with 10 additions and 3 deletions

View File

@ -224,13 +224,20 @@ bool Pixel_Perfect_Collision( SpriteLocator image1, SpriteLocator image2 )
/* NEW IMPLEMENTATION - TO TEST */
bool get_line_intersection( Vector2D p0, Vector2D p1, Vector2D p2, Vector2D p3, Vector2D *pr)
#include <num/vec.h>
bool get_line_intersection( Vector2D p0_n, Vector2D p1_n, Vector2D p2_n, Vector2D p3_n, Vector2D *pr)
{
Vector2D s1, s2;
using namespace libnum;
vec<float,2> p0((float)p0_n.x, (float)p0_n.y);
vec<float,2> p1((float)p1_n.x, (float)p1_n.y);
vec<float,2> p2((float)p2_n.x, (float)p2_n.y);
vec<float,2> p3((float)p3_n.x, (float)p3_n.y);
vec<float,2> s1, s2;
s1 = p1 - p0; s1 = p1 - p0;
s2 = p3 - p2; s2 = p3 - p2;
libnum::num s, t;
float s, t;
s = (-s1.y * (p0.x - p2.x) + s1.x * (p0.y - p2.y)) / (-s2.x * s1.y + s1.x * s2.y);
t = ( s2.x * (p0.y - p2.y) - s2.y * (p0.x - p2.x)) / (-s2.x * s1.y + s1.x * s2.y);