Skip to content

Commit

Permalink
Fix instance selection rectangle not being flipped properly (#6971)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementPasteau authored Sep 18, 2024
1 parent 82158f7 commit 27b71b0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import * as THREE from 'three';
import { shouldBeHandledByPinch } from '../PinchHandler';
import { makeDoubleClickable } from './PixiDoubleClickEvent';
import Rectangle from '../../Utils/Rectangle'; // TODO (3D): add support for zMin/zMax/depth.
import { rotatePolygon, type Polygon } from '../../Utils/PolygonHelper';
import {
flipPolygon,
rotatePolygon,
type Polygon,
} from '../../Utils/PolygonHelper';
import Rendered3DInstance from '../../ObjectsRendering/Renderers/Rendered3DInstance';
const gd: libGDevelop = global.gd;

Expand Down Expand Up @@ -310,7 +314,9 @@ export default class LayerRenderer {

getInstanceAABB(instance: gdInitialInstance, bounds: Rectangle): Rectangle {
const angle = (instance.getAngle() * Math.PI) / 180;
if (angle === 0) {
const isFlippedX = instance.isFlippedX();
const isFlippedY = instance.isFlippedY();
if (angle === 0 && !isFlippedX && !isFlippedY) {
return this.getUnrotatedInstanceAABB(instance, bounds);
}

Expand Down Expand Up @@ -352,6 +358,7 @@ export default class LayerRenderer {
centerY = (rotatedRectangle[0][1] + rotatedRectangle[2][1]) / 2;
}

flipPolygon(rotatedRectangle, centerX, centerY, isFlippedX, isFlippedY);
rotatePolygon(rotatedRectangle, centerX, centerY, angle);
}

Expand Down
13 changes: 13 additions & 0 deletions newIDE/app/src/Utils/PolygonHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,16 @@ export function rotatePolygon(
vertices[i][1] = centerY - x * sina + y * cosa;
}
}

export function flipPolygon(
vertices: Polygon,
centerX: number,
centerY: number,
flipX: boolean,
flipY: boolean
): void {
for (let i = 0, len = vertices.length; i < len; ++i) {
vertices[i][0] = flipX ? 2 * centerX - vertices[i][0] : vertices[i][0];
vertices[i][1] = flipY ? 2 * centerY - vertices[i][1] : vertices[i][1];
}
}

0 comments on commit 27b71b0

Please sign in to comment.