镜像代码调整

This commit is contained in:
fan 2023-06-16 14:08:04 +08:00
parent 59721814af
commit 3d8e203e9d
3 changed files with 40 additions and 53 deletions

View File

@ -1,9 +1,5 @@
import { Graphics, Point } from 'pixi.js';
// calculateMirrorPoint
import {
calculateDistanceFromPointToLine,
calculateMirrorPointBasedOnAxis,
} from 'src/jl-graphic';
import { Graphics } from 'pixi.js';
import { calculateMirrorPoint } from 'src/jl-graphic';
/**
*
* @param polygon
@ -49,45 +45,13 @@ export function drawArrow(
y: y - lineWidth / 2,
};
if (mirror) {
const throughPoint = new Point(trianglAcme.x, trianglAcme.y !== 0 ? 0 : 1);
triangleP1 = calculateMirrorPointBasedOnAxis(
trianglAcme,
throughPoint,
triangleP1,
calculateDistanceFromPointToLine(trianglAcme, throughPoint, triangleP1)
);
triangleP2 = calculateMirrorPointBasedOnAxis(
trianglAcme,
throughPoint,
triangleP2,
calculateDistanceFromPointToLine(trianglAcme, throughPoint, triangleP2)
);
lineP1 = calculateMirrorPointBasedOnAxis(
trianglAcme,
throughPoint,
lineP1,
calculateDistanceFromPointToLine(trianglAcme, throughPoint, lineP1)
);
lineP2 = calculateMirrorPointBasedOnAxis(
trianglAcme,
throughPoint,
lineP2,
calculateDistanceFromPointToLine(trianglAcme, throughPoint, lineP2)
);
lineP3 = calculateMirrorPointBasedOnAxis(
trianglAcme,
throughPoint,
lineP3,
calculateDistanceFromPointToLine(trianglAcme, throughPoint, lineP3)
);
lineP4 = calculateMirrorPointBasedOnAxis(
trianglAcme,
throughPoint,
lineP4,
calculateDistanceFromPointToLine(trianglAcme, throughPoint, lineP4)
);
triangleP1 = calculateMirrorPoint(trianglAcme, triangleP1);
triangleP2 = calculateMirrorPoint(trianglAcme, triangleP2);
lineP1 = calculateMirrorPoint(trianglAcme, lineP1);
lineP2 = calculateMirrorPoint(trianglAcme, lineP2);
lineP3 = calculateMirrorPoint(trianglAcme, lineP3);
lineP4 = calculateMirrorPoint(trianglAcme, lineP4);
}
console.log(triangleP1, triangleP2, lineP1, lineP2, lineP3, lineP4);
polygon.drawPolygon(
trianglAcme.x,
trianglAcme.y,

View File

@ -1,5 +1,6 @@
import { Container } from '@pixi/display';
import { Graphics } from 'pixi.js';
import { Graphics, Point } from 'pixi.js';
import { calculateMirrorPoint } from 'src/jl-graphic';
import { Lamp } from './Lamp';
export enum LampEnum {
@ -28,12 +29,16 @@ export class LampMainBody extends Container {
this.lampNum = lampNum;
this.removeChildren(0);
this.lampPost = new Graphics();
let lpp = new Point(lampConsts.levelLampPostLength, 0);
if (mirror) {
lpp = calculateMirrorPoint(new Point(0, 0), lpp);
}
this.lampPost
.lineStyle(lampConsts.postLineWidth, LampEnum.lampPostColor)
.moveTo(0, -lampConsts.verticalLampPostLength / 2)
.lineTo(0, lampConsts.verticalLampPostLength / 2)
.moveTo(0, 0)
.lineTo(lampConsts.levelLampPostLength * (mirror ? -1 : 1), 0);
.lineTo(lpp.x, lpp.y);
this.addChild(this.lampPost);
this.lamps = [];
@ -41,7 +46,11 @@ export class LampMainBody extends Container {
const lamp = new Lamp();
const radiusX =
(1 + i * 2) * lampConsts.lampRadius + lampConsts.levelLampPostLength;
lamp.paint(radiusX * (mirror ? -1 : 1), 0);
let lrp = new Point(radiusX, 0);
if (mirror) {
lrp = calculateMirrorPoint(new Point(0, 0), lrp);
}
lamp.paint(lrp.x, lrp.y);
this.addChild(lamp);
this.lamps.push(lamp);
}

View File

@ -1,10 +1,11 @@
import { Graphics } from 'pixi.js';
import { Graphics, Point } from 'pixi.js';
import {
GraphicData,
JlGraphic,
JlGraphicTemplate,
VectorText,
} from 'src/jl-graphic';
import { calculateMirrorPoint } from 'src/jl-graphic';
import { LampMainBody } from './LampMainBody';
import { drawArrow } from '../CommonGraphics';
@ -31,6 +32,7 @@ const signalConsts = {
fleetModeLength: 33,
fleetModeRadius: 10,
fleetModeLineWidth: 6,
humanControlRadius: 10,
};
export class Signal extends JlGraphic {
static Type = 'signal';
@ -58,10 +60,15 @@ export class Signal extends JlGraphic {
this.humanControl.clear();
this.humanControl.beginFill(SignalColorEnum.humanControlColor, 1);
if (this.humanControl.drawRegularPolygon) {
let hmp = new Point(-signalConsts.humanControlRadius, 0);
if (mirror) {
hmp = calculateMirrorPoint(new Point(0, 0), hmp);
}
console.log(hmp, 'hmp');
this.humanControl.drawRegularPolygon(
mirror ? 10 : -10,
0,
10,
hmp.x,
hmp.y,
signalConsts.humanControlRadius,
3,
(Math.PI / 2) * (mirror ? -1 : 1)
);
@ -69,10 +76,17 @@ export class Signal extends JlGraphic {
this.humanControl.endFill();
this.fleetMode.clear();
this.fleetMode.beginFill(SignalColorEnum.fleetModeColor, 1);
let lmp = new Point(
this.lampMainBody.width + signalConsts.fleetModeLength,
0
);
if (mirror) {
lmp = calculateMirrorPoint(new Point(0, 0), lmp);
}
console.log(lmp, 'hmp');
drawArrow(
this.fleetMode,
(this.lampMainBody.width + signalConsts.fleetModeLength) *
(mirror ? -1 : 1),
lmp.x,
0,
signalConsts.fleetModeLength,
signalConsts.fleetModeRadius,