2019-12-14 18:11:00 -05:00
|
|
|
import { Data, Location, Polygon } from "./Components";
|
|
|
|
import { Join } from "./Data";
|
|
|
|
|
|
|
|
export function TransformCx(cx: CanvasRenderingContext2D, location: Location, dt = 0) {
|
|
|
|
cx.translate(location.X + location.VX * dt, location.Y + location.VY * dt);
|
2020-01-19 02:08:25 -05:00
|
|
|
cx.rotate(location.Angle + location.VAngle * dt);
|
2019-12-14 18:11:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export function TfPolygon({points}: Polygon, {X, Y, Angle}: Location): Polygon {
|
|
|
|
const sin = Math.sin(Angle);
|
|
|
|
const cos = Math.cos(Angle);
|
2020-04-04 18:52:25 -04:00
|
|
|
const result = {points: new Array(points.length)};
|
2019-12-14 18:11:00 -05:00
|
|
|
for(let i = 0; i < points.length; i += 2) {
|
|
|
|
const x = points[i];
|
|
|
|
const y = points[i+1];
|
|
|
|
result.points[i] = x*cos - y*sin + X;
|
|
|
|
result.points[i+1] = x*sin + y*cos + Y;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function DumbMotion(data: Data, interval: number) {
|
2020-01-16 01:54:43 -05:00
|
|
|
Join(data, "location").forEach(([location]) => {
|
2019-12-14 18:11:00 -05:00
|
|
|
location.X += location.VX * interval;
|
|
|
|
location.Y += location.VY * interval;
|
|
|
|
location.Angle += location.VAngle * interval;
|
|
|
|
});
|
|
|
|
}
|