Пример #1
0
        private static Vector closestVertexOnOBB(Vector p, RectangleParticle r)
        {
            Vector d = p - r.samp;
            Vector q = new Vector(r.samp.X, r.samp.Y);

            for (int i = 0; i < 2; i++)
            {
                float dist = d.Dot(r.axes[i]);

                if (dist >= 0) dist = r.extents(i);
                else if (dist < 0) dist = -r.extents(i);

                q += (r.axes[i] * dist);
            }
            return q;
        }
Пример #2
0
        private void setCorners(RectangleParticle r, int i)
        {
            float rx = r.curr.X;
            float ry = r.curr.Y;

            float ae0_x = r.axes[0].X * r.extents(0);
            float ae0_y = r.axes[0].Y * r.extents(0);
            float ae1_x = r.axes[1].X * r.extents(1);
            float ae1_y = r.axes[1].Y * r.extents(1);

            float emx = ae0_x - ae1_x;
            float emy = ae0_y - ae1_y;
            float epx = ae0_x + ae1_x;
            float epy = ae0_y + ae1_y;

            if (i == 0)
            {
                // 0 and 1
                rca.X = rx - epx;
                rca.Y = ry - epy;
                rcb.X = rx + emx;
                rcb.Y = ry + emy;

            }
            else if (i == 1)
            {
                // 1 and 2
                rca.X = rx + emx;
                rca.Y = ry + emy;
                rcb.X = rx + epx;
                rcb.Y = ry + epy;

            }
            else if (i == 2)
            {
                // 2 and 3
                rca.X = rx + epx;
                rca.Y = ry + epy;
                rcb.X = rx - emx;
                rcb.Y = ry - emy;

            }
            else if (i == 3)
            {
                // 3 and 0
                rca.X = rx - emx;
                rca.Y = ry - emy;
                rcb.X = rx - epx;
                rcb.Y = ry - epy;
            }
        }