CPP02/ex03/src/bsp.cpp
2025-03-27 16:15:11 +01:00

33 lines
1.4 KiB
C++

/* ************************************************************************** */
/* */
/* :::::::: */
/* bsp.cpp :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/03/27 16:01:44 by whaffman #+# #+# */
/* Updated: 2025/03/27 16:07:02 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "Point.hpp"
#include "Fixed.hpp"
#include "bsp.h"
Fixed crossproduct(Point a, Point b, Point c)
{
Fixed x1 = b.x() - a.x();
Fixed y1 = b.y() - a.y();
Fixed x2 = c.x() - a.x();
Fixed y2 = c.y() - a.y();
return (x1 * y2 - x2 * y1);
}
bool bsp(Point a, Point b, Point c, Point point)
{
Fixed res1 = crossproduct(a, b, point);
Fixed res2 = crossproduct(b, c, point);
Fixed res3 = crossproduct(c, a, point);
if ((res1 >= 0 && res2 >= 0 && res3 >= 0) || (res1 <= 0 && res2 <= 0 && res3 <= 0))
return true;
return false;
}