Topic: Rotate OnlineMapsDrawingRect

Hi is there any way to rotate a Rectangle on the map?

eg. rotate the Rectangle by 45 degrees.

Re: Rotate OnlineMapsDrawingRect

Hi.

No, you can't rotate the rectangle. Use OnlineMapsDrawingPoly instead.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Rotate OnlineMapsDrawingRect

Thank you Alex.

Re: Rotate OnlineMapsDrawingRect

Thank you Alex.

5

Re: Rotate OnlineMapsDrawingRect

Do you have a function to rotate clockwise a OnlineMapsDrawingPoly ?

Re: Rotate OnlineMapsDrawingRect

I noticed that for OnlineMapsDrawingLine has an option for  followRelief = true, which it works great on 3D terrain.

Is there any possibility to make OnlineMapsDrawingRect and OnlineMapsDrawingPoly follow Relief?
I couldn't find any similar function in API Reference.

thanks

7 (edited by savvas_6 2024-08-23 14:11:50)

Re: Rotate OnlineMapsDrawingRect

Hi A1.

Try the following code to rotate the Line.

using System.Collections.Generic;
using UnityEngine;

public class LineRotator
{
    public static void RotateLine(OnlineMapsDrawingLine line, Vector2 pivot, float angleDegrees)
    {
        // Convert the rotation angle from degrees to radians
        float angleRadians = angleDegrees * Mathf.Deg2Rad;

        // Get the list of original points from the line
        List<Vector2> originalPoints = line.points;

        // Create a list to store the rotated points
        List<Vector2> rotatedPoints = new List<Vector2>();

        // Calculate the sine and cosine of the rotation angle
        float cosTheta = Mathf.Cos(angleRadians);
        float sinTheta = Mathf.Sin(angleRadians);

        // Iterate over each point and apply the rotation
        foreach (Vector2 point in originalPoints)
        {
            // Translate the point to the origin (pivot as the origin)
            float translatedX = point.x - pivot.x;
            float translatedY = point.y - pivot.y;

            // Apply the rotation matrix
            float rotatedX = translatedX * cosTheta - translatedY * sinTheta;
            float rotatedY = translatedX * sinTheta + translatedY * cosTheta;

            // Translate the point back
            rotatedX += pivot.x;
            rotatedY += pivot.y;

            // Add the rotated point to the new points list
            rotatedPoints.Add(new Vector2(rotatedX, rotatedY));
        }

        // Update the line's points with the rotated points
        line.points = rotatedPoints;

        // Refresh the map to reflect the changes
        OnlineMaps.instance.Redraw();
    }
}

8

Re: Rotate OnlineMapsDrawingRect

@savvas_6 Thanks. This works for me.