Example #1
0
        private static void Draw(CharacterController controller)
        {
            SceneObject so = controller.SceneObject;

            Quaternion rotation = Quaternion.FromToRotation(Vector3.YAxis, controller.Up);

            // Rotate around origin
            Matrix4 rotMatrix = Matrix4.TRS(Vector3.Zero, rotation, Vector3.One);

            Gizmos.Color     = Color.Green;
            Gizmos.Transform = Matrix4.TRS(so.Position, so.Rotation, Vector3.One) * rotMatrix;

            Vector3 scale        = so.Scale;
            float   scaledHeight = controller.Height * 2.0f * scale.y;
            float   scaledRadius = controller.Radius * MathEx.Max(scale.x, scale.z);

            Gizmos.DrawWireCapsule(Vector3.Zero, scaledHeight, scaledRadius);
        }
        private static void DrawCapsuleCollider(CapsuleCollider collider)
        {
            SceneObject so = collider.SceneObject;

            Vector3    offset   = collider.Center;
            Quaternion rotation = Quaternion.FromToRotation(Vector3.YAxis, collider.Normal);

            // Rotate around origin
            Matrix4 rotMatrix = Matrix4.TRS(offset, Quaternion.Identity, Vector3.One) *
                                Matrix4.TRS(Vector3.Zero, rotation, Vector3.One) *
                                Matrix4.TRS(-offset, Quaternion.Identity, Vector3.One);

            Gizmos.Color     = Color.Green;
            Gizmos.Transform = Matrix4.TRS(so.Position, so.Rotation, Vector3.One) * rotMatrix;

            Vector3 scale        = so.Scale;
            float   scaledHeight = collider.HalfHeight * 2.0f * scale.y;
            float   scaledRadius = collider.Radius * MathEx.Max(scale.x, scale.z);

            Gizmos.DrawWireCapsule(offset * scale, scaledHeight, scaledRadius);
        }