Project a 3D point to 2D screen coordinates with perspective.
(
x: number,
y: number,
z: number,
)
| 2874 | |
| 2875 | /** Project a 3D point to 2D screen coordinates with perspective. */ |
| 2876 | private project3d( |
| 2877 | x: number, |
| 2878 | y: number, |
| 2879 | z: number, |
| 2880 | ): { px: number; py: number; scale: number; rz: number } { |
| 2881 | // X-axis tilt |
| 2882 | const cosT = Math.cos(this.mode3dTilt); |
| 2883 | const sinT = Math.sin(this.mode3dTilt); |
| 2884 | const ty = y * cosT - z * sinT; |
| 2885 | const tz = y * sinT + z * cosT; |
| 2886 | // Y-axis rotation |
| 2887 | const cosA = Math.cos(this.mode3dAngle); |
| 2888 | const sinA = Math.sin(this.mode3dAngle); |
| 2889 | const rx = x * cosA - tz * sinA; |
| 2890 | const rz = x * sinA + tz * cosA; |
| 2891 | // Perspective |
| 2892 | const scale = this.mode3dPerspectiveD / (this.mode3dPerspectiveD + rz); |
| 2893 | return { px: rx * scale, py: ty * scale, scale, rz }; |
| 2894 | } |
| 2895 | |
| 2896 | /** |
| 2897 | * Called from the Pixi ticker every frame when 3D mode is active. |