Moderátor: Moderátoři
if (ColisionRectangle.Intersects(Main.Bodies[i].ColisionRectangle))
t = (A.x - C.x)/(u.x – v.x)
A [2, 5]
B [10, 7]
C [5, 3]
D [7, 10]
t = (2 – 5) / (10 – 7);
t = -3 / 3 = -1;
t = (5 – 3) / (7 – 10);
t = 2 / -3 = -0,6666
public bool isLeft(Point a, Point b, Point c){
return ((b.x - a.x)*(c.y - a.y) - (b.y - a.y)*(c.x - a.x)) > 0;
}
public class CollisionLine
{
public Vector2 Origin;
public Vector2 Length;
public float X { get { return Length.X; } set { Length.X = value; } }
public float Y { get { return Length.Y; } set { Length.Y = value; } }
public CollisionLine(Vector2 originPoint, Vector2 lenght)
{
Origin = originPoint;
Length = lenght;
}
public bool Collides(CollisionLine colLine)
{
Vector2 A = colLine.Origin;
Vector2 B = colLine.Origin + colLine.Length;
Vector2 C = Origin;
int firstPoint = (int)((B.X - A.X) * (C.Y - A.Y) - (B.Y - A.Y) * (C.X - A.X));
C = Origin + Length;
int secondPoint = (int)((B.X - A.X) * (C.Y - A.Y) - (B.Y - A.Y) * (C.X - A.X));
A = Origin;
B = Origin + Length;
C = colLine.Origin;
int thirdPoint = (int)((B.X - A.X) * (C.Y - A.Y) - (B.Y - A.Y) * (C.X - A.X));
C = colLine.Origin + colLine.Length;
int fourthPoint = (int)((B.X - A.X) * (C.Y - A.Y) - (B.Y - A.Y) * (C.X - A.X));
if ((firstPoint == 0) || (secondPoint == 0))
{
if ((thirdPoint < 0) && (fourthPoint > 0))
return true;
else if ((thirdPoint > 0) && (fourthPoint < 0))
return true;
}
else if ((thirdPoint == 0) || (fourthPoint == 0))
{
if ((firstPoint < 0) && (secondPoint > 0))
return true;
else if ((firstPoint > 0) && (secondPoint < 0))
return true;
}
else if ((firstPoint < 0) && (secondPoint > 0))
{
if ((thirdPoint < 0) && (fourthPoint > 0))
return true;
else if ((thirdPoint > 0) && (fourthPoint < 0))
return true;
}
else if ((firstPoint > 0) && (secondPoint < 0))
{
if ((thirdPoint < 0) && (fourthPoint > 0))
return true;
else if ((thirdPoint > 0) && (fourthPoint < 0))
return true;
}
return false;
}
}
Zpět na Projekty ve všem ostatním
Uživatelé procházející toto fórum: Žádní registrovaní uživatelé a 0 návštevníků