<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Infinity Code Forum — Rotate clockwise Rect and Poly (OnlineMapsDrawingRect/Poly)]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=2302</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=2302&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Rotate clockwise Rect and Poly (OnlineMapsDrawingRect/Poly).]]></description>
		<lastBuildDate>Fri, 23 Aug 2024 19:42:04 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Rotate clockwise Rect and Poly (OnlineMapsDrawingRect/Poly)]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=9628#p9628</link>
			<description><![CDATA[<p>Hi.</p><p>I don&#039;t plan to add rotation to these objects.<br />Below is an example of how you can rotate polygons.<br />You can rotate rectangles by making it a polygon.</p><div class="codebox"><pre><code>using UnityEngine;

namespace InfinityCode.OnlineMapsSupport
{
    public class RotatePoly : MonoBehaviour
    {
        public OnlineMaps map;
        public float angle;

        private float _angle;
        private OnlineMapsVector2d[] originalPoints;
        private OnlineMapsDrawingPoly poly;

        private void Start()
        {
            if (map == null) map = OnlineMaps.instance;
        
            originalPoints = new[]
            {
                new OnlineMapsVector2d(0, 0),
                new OnlineMapsVector2d(10, 0),
                new OnlineMapsVector2d(10, 10),
                new OnlineMapsVector2d(0, 10)
            };

            OnlineMapsVector2d[] rotatedPoints = new OnlineMapsVector2d[originalPoints.Length];
            RotatedPoints(rotatedPoints);
        
            poly = new OnlineMapsDrawingPoly(rotatedPoints, Color.red, 2);
            map.drawingElementManager.Add(poly);
        }

        private void RotatedPoints(OnlineMapsVector2d[] rotatedPoints)
        {
            _angle = angle;
        
            float angleRad = Mathf.Repeat(angle, 360) * Mathf.Deg2Rad;
            OnlineMapsProjection projection = map.projection;
            double[] mercatorPoints = new double[originalPoints.Length * 2];

            double minX = double.MaxValue;
            double minY = double.MaxValue;
            double maxX = double.MinValue;
            double maxY = double.MinValue;

            for (int i = 0; i &lt; originalPoints.Length; i++)
            {
                OnlineMapsVector2d p = originalPoints[i];
                double x, y;
                projection.CoordinatesToTile(p.x, p.y, 0, out x, out y);
            
                mercatorPoints[i * 2] = x;
                mercatorPoints[i * 2 + 1] = y;
            
                if (x &lt; minX) minX = x;
                if (x &gt; maxX) maxX = x;
                if (y &lt; minY) minY = y;
                if (y &gt; maxY) maxY = y;
            }
        
            double cx = (minX + maxX) / 2;
            double cy = (minY + maxY) / 2;
        
            OnlineMapsVector2d rp = new OnlineMapsVector2d();
        
            for (int i = 0; i &lt; originalPoints.Length; i++)
            {
                double x = mercatorPoints[i * 2] - cx;
                double y = mercatorPoints[i * 2 + 1] - cy;
            
                double x2 = x * Mathf.Cos(angleRad) - y * Mathf.Sin(angleRad);
                double y2 = x * Mathf.Sin(angleRad) + y * Mathf.Cos(angleRad);
            
                x = x2 + cx;
                y = y2 + cy;
            
                projection.TileToCoordinates(x, y, 0, out rp.x, out rp.y);
                rotatedPoints[i] = rp;
            }
        }

        private void Update()
        {
            if (angle != _angle) UpdatePoints();
        }

        private void UpdatePoints()
        {
            OnlineMapsVector2d[] rotatedPoints = poly.points as OnlineMapsVector2d[];
            RotatedPoints(rotatedPoints);
            poly.points = rotatedPoints;
        }
    }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Fri, 23 Aug 2024 19:42:04 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=9628#p9628</guid>
		</item>
		<item>
			<title><![CDATA[Rotate clockwise Rect and Poly (OnlineMapsDrawingRect/Poly)]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=9622#p9622</link>
			<description><![CDATA[<p>Hi Alex,</p><p>great work on this Plugin!</p><p>Can you add a rotation function for both OnlineMapsDrawingElements please?</p><p>Many thanks!</p>]]></description>
			<author><![CDATA[null@example.com (A1)]]></author>
			<pubDate>Fri, 23 Aug 2024 08:12:02 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=9622#p9622</guid>
		</item>
	</channel>
</rss>
