Exemplo n.º 1
0
        private static unsafe void DrawConvex(
            Collider *collider,
            ref PhysicsTransform worldTransform,
            ref PhysicsDebugStreamSystem.Context outputStream,
            Color colliderColor)
        {
            var convexCollider = (ConvexCollider *)collider;
            var vertexCount    = convexCollider->VertexCount;
            var vertices       = convexCollider->Vertices;
            var convexRadius   = convexCollider->m_ConvexHull.ConvexRadius;

            switch (collider->ColliderType)
            {
            case ColliderType.Box:
            case ColliderType.Polygon:
            {
                Assert.IsTrue(vertexCount >= 3, "ConvexCollider must have >= 3 vertices.");

                outputStream.Polygon(vertices, vertexCount, worldTransform, colliderColor);
                return;
            }

            case ColliderType.Circle:
            {
                Assert.AreEqual(1, vertexCount, "CircleCollider must have 1 vertex.");

                var position = PhysicsMath.mul(worldTransform, vertices[0]);
                outputStream.Circle(position, convexRadius, colliderColor);
                return;
            }

            case ColliderType.Capsule:
            {
                Assert.AreEqual(2, vertexCount, "CapsuleCollider must have 2 vertices.");

                var vertex0 = PhysicsMath.mul(worldTransform, vertices[0]);
                var vertex1 = PhysicsMath.mul(worldTransform, vertices[1]);
                var offset  = PhysicsMath.perp(math.normalizesafe(vertex1 - vertex0)) * new float2(convexRadius);

                // Side Edges.
                {
                    outputStream.Line(vertex0 - offset, vertex1 - offset, colliderColor);
                    outputStream.Line(vertex0 + offset, vertex1 + offset, colliderColor);
                }

                // End Caps.
                {
                    var startAngle = math.atan2(offset.y, offset.x);
                    var endAngle   = startAngle + math.PI;
                    outputStream.Arc(vertex0, convexRadius, startAngle, endAngle, colliderColor);
                    outputStream.Arc(vertex1, convexRadius, startAngle + math.PI, endAngle + math.PI, colliderColor);
                }

                return;
            }

            default:
                return;
            }
        }
Exemplo n.º 2
0
        public static unsafe void DrawCollider(
            Collider *collider,
            ref PhysicsTransform worldTransform,
            ref PhysicsDebugStreamSystem.Context outputStream,
            Color colliderColor)
        {
            switch (collider->CollisionType)
            {
            case CollisionType.Convex:
            {
                DrawConvex(collider, ref worldTransform, ref outputStream, colliderColor);
                return;
            }

            case CollisionType.Composite:
            {
                DrawComposite(collider, ref worldTransform, ref outputStream, colliderColor);
                return;
            }
            }
        }
Exemplo n.º 3
0
        private static unsafe void DrawComposite(
            Collider *collider,
            ref PhysicsTransform worldTransform,
            ref PhysicsDebugStreamSystem.Context outputStream,
            Color colliderColor)
        {
            switch (collider->ColliderType)
            {
            case ColliderType.Compound:
            {
                var compoundCollider = (PhysicsCompoundCollider *)collider;
                var children         = compoundCollider->Children;

                for (var i = 0; i < children.Length; ++i)
                {
                    ref PhysicsCompoundCollider.Child child = ref children[i];

                    var colliderWorldTransform = PhysicsMath.mul(worldTransform, child.CompoundFromChild);
                    DrawCollider(children[i].Collider, ref colliderWorldTransform, ref outputStream, colliderColor);
                }

                return;
            }
            }