Exemplo n.º 1
0
    public static void Draw <C>(SolidPrimitiveMsg message, Drawing3d drawing, Color color, GameObject origin = null)
        where C : ICoordinateSpace, new()
    {
        Vector3    originPosition = origin != null ? origin.transform.position : Vector3.zero;
        Quaternion originRotation = origin != null ? origin.transform.rotation : Quaternion.identity;

        switch (message.type)
        {
        case SolidPrimitiveMsg.BOX:
            drawing.DrawCuboid(
                originPosition,
                new Vector3 <C>(
                    (float)message.dimensions[SolidPrimitiveMsg.BOX_X] * 0.5f,
                    (float)message.dimensions[SolidPrimitiveMsg.BOX_Y] * 0.5f,
                    (float)message.dimensions[SolidPrimitiveMsg.BOX_Z] * 0.5f).toUnity,
                originRotation,
                color
                );
            break;

        case SolidPrimitiveMsg.SPHERE:
            drawing.DrawSphere(originPosition, color, (float)message.dimensions[SolidPrimitiveMsg.SPHERE_RADIUS]);
            break;

        case SolidPrimitiveMsg.CYLINDER:
            Vector3 cylinderAxis = originRotation * Vector3.up * (float)message.dimensions[SolidPrimitiveMsg.CYLINDER_HEIGHT] * 0.5f;
            drawing.DrawCylinder(originPosition - cylinderAxis, originPosition + cylinderAxis, color, (float)message.dimensions[SolidPrimitiveMsg.CYLINDER_RADIUS]);
            break;

        case SolidPrimitiveMsg.CONE:
            Vector3 coneAxis = originRotation * Vector3.up * (float)message.dimensions[SolidPrimitiveMsg.CONE_HEIGHT] * 0.5f;
            drawing.DrawCone(originPosition - coneAxis, originPosition + coneAxis, color, (float)message.dimensions[SolidPrimitiveMsg.CONE_RADIUS]);
            break;
        }
    }
    public static void Draw <C>(RangeMsg message, Drawing3d drawing, Color color, float size = 0.1f, bool drawUnityAxes = false)
        where C : ICoordinateSpace, new()
    {
        var     asin = Mathf.Asin(message.field_of_view);
        var     acos = Mathf.Acos(message.field_of_view);
        Color   col  = Color.HSVToRGB(Mathf.InverseLerp(message.min_range, message.max_range, message.range), 1, 1);
        Vector3 end  = new Vector3 <C>(message.range * acos, 0, message.range * asin).toUnity;

        drawing.DrawCone(end, Vector3.zero, col, Mathf.Rad2Deg * message.field_of_view / 2);
    }