Пример #1
0
 public SquareObject(Game game, Vector2 location, float height, float width, Brush color, float spacer) : base(game)
 {
     Location    = location;
     Height      = height;
     Width       = width;
     this.color  = color;
     collider    = new SquareCollider(Location, Width, Height);
     this.spacer = spacer;
 }
Пример #2
0
    static void DrawSquare(SquareCollider b, bool is_intersect)
    {
        Gizmos.color = is_intersect ? Color.green : Color.blue;
        Vector2[] points =
        {
            b.position + new Vector2(b.width.x / 2,  b.width.y / 2),
            b.position + new Vector2(b.width.x / 2,  -b.width.y / 2),
            b.position + new Vector2(-b.width.x / 2, -b.width.y / 2),
            b.position + new Vector2(-b.width.x / 2, b.width.y / 2),
        };

        Vector2[] rotated_points = new Vector2[4];
        Mat22     rot            = new Mat22(b.rotation);

        for (int i = 0; i < 4; i++)
        {
            points[i] = rot * (points[i] - b.position) + b.position;
        }

        for (int i = 0; i < 4; i++)
        {
            Gizmos.DrawLine(points[i], points[(i + 1) % 4]);
        }

        // oobb
        Gizmos.color = Color.red;
        Mat22   abs_rot = MathUtils.Abs(rot);
        Vector2 v       = abs_rot * (b.width);

        Vector2[] vec_aabb =
        {
            b.position + new Vector2(v.x / 2,  v.y / 2),
            b.position + new Vector2(v.x / 2,  -v.y / 2),
            b.position + new Vector2(-v.x / 2, -v.y / 2),
            b.position + new Vector2(-v.x / 2, v.y / 2),
        };

        for (int i = 0; i < 4; i++)
        {
            Gizmos.DrawLine(vec_aabb[i], vec_aabb[(i + 1) % 4]);
        }

        // normal(通过rotate来取出normal) 原理是:我们把初始法线值(0,1)旋转角度之后,得到的是col2,初始法线(1,0)旋转角度之后是col1
        //Gizmos.color = Color.green;
        //Gizmos.DrawLine(b.position, rot.col1+ b.position);
        //Gizmos.color = Color.yellow;
        //Gizmos.DrawLine(b.position, -rot.col1+ b.position);
        //Gizmos.DrawLine(b.position, rot.col2+ b.position);
        //Gizmos.DrawLine(b.position, -rot.col2+ b.position);
    }
Пример #3
0
    // Use this for initialization
    void Start()
    {
        for (int i = 0; i < OBJ_COUNT; i++)
        {
            squares[i] = new SquareCollider()
            {
                position = new Vector2(Random.Range(0, 10), Random.Range(0, 10)), rotation = Random.Range(0, 359), width = new Vector2(Random.Range(0.1f, 2), Random.Range(0.1f, 2))
            };
            circles[i] = new CircleCollider()
            {
                position = new Vector2(Random.Range(0, 10), Random.Range(0, 10)), radius = Random.Range(0.1f, 2)
            };
            rays[i] = new RayCollider()
            {
                p1 = new Vector2(Random.Range(0, 10), Random.Range(0, 10)), p2 = new Vector2(Random.Range(0, 10), Random.Range(0, 10))
            };
        }

        TestSqureCircle();
        TestSqureSqure();
        TestCircleCircle();
        TestRaySquare();
        TestRayCircle();
    }