simplification of Vector2D class

This commit is contained in:
Sylvain PILLOT 2023-05-24 20:28:55 +02:00
parent 0db32702c6
commit 2bfb17da99
3 changed files with 8 additions and 32 deletions

View File

@ -189,7 +189,7 @@ int Level::GetTileForeground( uint16_t x, uint16_t y )
// Compute the intersection Point between segments [AB] and [CD]
// if there is an intersection, return true and store the result into Point R
bool CollisionSegSeg( Point2D A, Point2D B, Vector2D N, Point2D C, Point2D D, Point2D *R )
bool CollisionSegSeg( Vector2D A, Vector2D B, Vector2D N, Vector2D C, Vector2D D, Vector2D *R )
{
Vector2D I, J;
@ -231,7 +231,7 @@ bool CollisionSegSeg( Point2D A, Point2D B, Vector2D N, Point2D C, Point2D D, Po
}
libnum::num32 ClosestPointOnSegment( Point2D A, Point2D B, Point2D P, Point2D *R )
libnum::num32 ClosestPointOnSegment( Vector2D A, Vector2D B, Vector2D P, Vector2D *R )
{
Vector2D AB;
AB.x = B.x - A.x;
@ -269,7 +269,7 @@ libnum::num32 ClosestPointOnSegment( Point2D A, Point2D B, Point2D P, Point2D *R
/*RETURN true if the player can go in the target position*/
bool Level::CanGo( void )
{
Point2D PlayerOrigin, PlayerTarget;
Vector2D PlayerOrigin, PlayerTarget;
PlayerOrigin.x = MyPlayer.currx;
PlayerOrigin.y = MyPlayer.curry;
@ -282,7 +282,7 @@ bool Level::CanGo( void )
for (unsigned int i=0; i<MyLevelBorders.size(); i++)
{
Point2D I;
Vector2D I;
// Detection de collision entre [A,B] et [Player.Curr, Player.Next]
if (CollisionSegSeg( MyLevelBorders[i]->A, MyLevelBorders[i]->B, MyLevelBorders[i]->N, PlayerOrigin, PlayerTarget, &I ))

View File

@ -56,7 +56,7 @@ Vector2D Vector2D::Clone( void )
return NewVector;
}
Vector2D Vector2D::MakeVector( Point2D A, Point2D B)
Vector2D Vector2D::MakeVector( Vector2D A, Vector2D B)
{
Vector2D NewVector( B.x-A.x, B.y-A.y );
return NewVector;

View File

@ -7,30 +7,6 @@
libnum::num32 sqrt_num32(libnum::num32 v);
class Point2D
{
public:
Point2D() {};
~Point2D() {};
libnum::num32 x;
libnum::num32 y;
};
class Circle
{
public:
Circle() {};
~Circle() {};
libnum::num32 x;
libnum::num32 y;
libnum::num32 r;
};
class Vector2D
{
@ -42,7 +18,7 @@ class Vector2D
~Vector2D();
Vector2D Clone( void );
Vector2D MakeVector( Point2D A, Point2D B);
Vector2D MakeVector( Vector2D A, Vector2D B);
void AddVectors( Vector2D a, Vector2D b );
void Add( Vector2D v, libnum::num32 scale );
@ -117,8 +93,8 @@ class Border
Border();
~Border();
Point2D A;
Point2D B;
Vector2D A;
Vector2D B;
Vector2D N;
uint16_t color;
};