从零开发一个2D碰撞引擎1

定义形状
基础形状的定义:点,线段,射线,矩形,旋转矩形,三角形,圆,多边形
其中矩形,旋转矩形,三角形均可算作是多边形
具体形状类的实现:
//点的定义
public class Point
{
public float X { get; set; }
public float Y { get; set; }

public Point(float x, float y)
{
    X = x;
    Y = y;
}

}
//线段的定义
public class LineSegment
{
public Point StartPoint { get; set; } // 线段起点
public Point EndPoint { get; set; } // 线段终点

public LineSegment(Point startPoint, Point endPoint)
{
    StartPoint = startPoint;
    EndPoint = endPoint;
}

public float Length()
{
    float dx = EndPoint.X - StartPoint.X;
    float dy = EndPoint.Y - StartPoint.Y;

    return (float)Math.Sqrt(dx * dx + dy * dy);
}

}
//射线的定义
public class Ray
{

你可能感兴趣的:(2D物理,c#)