Rotate ground-units as in the campaign miz

This implements a logic to rotate groups which are generated from templates like the origin (ground unit) which was placed by the campaign designer
This commit is contained in:
RndName
2022-01-17 20:31:49 +01:00
parent 5febcdd4e4
commit daf4704fe7
4 changed files with 42 additions and 17 deletions

View File

@@ -1,5 +1,7 @@
from __future__ import annotations
import math
from dcs import Point
from game.utils import Heading
@@ -16,3 +18,12 @@ class PointWithHeading(Point):
p.y = point.y
p.heading = heading
return p
def rotate(self, origin: Point, heading: Heading) -> None:
"""Rotates the Point by a given angle clockwise around the origin"""
ox, oy = origin.x, origin.y
px, py = self.x, self.y
radians = heading.radians
self.x = ox + math.cos(radians) * (px - ox) - math.sin(radians) * (py - oy)
self.y = oy + math.sin(radians) * (px - ox) + math.cos(radians) * (py - oy)