mirror of
https://github.com/Ladebeze66/cpp-partie-1.git
synced 2025-12-16 05:58:04 +01:00
35 lines
1.4 KiB
C++
35 lines
1.4 KiB
C++
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* bsp.cpp :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/12/27 21:59:43 by fgras-ca #+# #+# */
|
|
/* Updated: 2023/12/27 22:22:35 by fgras-ca ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "bsp.hpp"
|
|
|
|
float sign(Point p1, Point p2, Point p3)
|
|
{
|
|
Fixed result = (p1.getX() - p3.getX()) * (p2.getY() - p3.getY()) - (p2.getX() - p3.getX()) * (p1.getY() - p3.getY());
|
|
return (result.toFloat()); // Convertit le résultat Fixed en float
|
|
}
|
|
|
|
bool bsp(Point const a, Point const b, Point const c, Point const point)
|
|
{
|
|
float d1, d2, d3;
|
|
bool has_neg, has_pos;
|
|
|
|
d1 = sign(point, a, b);
|
|
d2 = sign(point, b, c);
|
|
d3 = sign(point, c, a);
|
|
|
|
has_neg = (d1 < 0) || (d2 < 0) || (d3 < 0);
|
|
has_pos = (d1 > 0) || (d2 > 0) || (d3 > 0);
|
|
|
|
return (!(has_neg && has_pos));
|
|
}
|