From fad2b8faab104647e9c0e4e64840e6b9be06d2d4 Mon Sep 17 00:00:00 2001 From: minggo Date: Wed, 6 Dec 2023 15:50:57 +0800 Subject: [PATCH] fix logic error in Vec3.rotateN() (#16564) --- cocos/core/math/vec3.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cocos/core/math/vec3.ts b/cocos/core/math/vec3.ts index 969ae9290a..fccc854449 100644 --- a/cocos/core/math/vec3.ts +++ b/cocos/core/math/vec3.ts @@ -388,7 +388,7 @@ export class Vec3 extends ValueType { * from normalized `from` to normalized `to`, * then scaled by linear interpolation of lengths from `from` to `to`. */ - public static slerp= ((): (out: Out, from: Readonly, to: Readonly, t: number) => Out => { + public static slerp = ((): (out: Out, from: Readonly, to: Readonly, t: number) => Out => { const cacheV1 = new Vec3(); const cacheV2 = new Vec3(); const cacheV3 = new Vec3(); @@ -668,7 +668,7 @@ export class Vec3 extends ValueType { const cos = Math.cos(a); const sin = Math.sin(a); - const rx = x * (nx * nx * (1.0 - cos) + cos) + y * (nx * ny * (1.0 - cos) - nx * sin) + z * (nx * nz * (1.0 - cos) + ny * sin); + const rx = x * (nx * nx * (1.0 - cos) + cos) + y * (nx * ny * (1.0 - cos) - nz * sin) + z * (nx * nz * (1.0 - cos) + ny * sin); const ry = x * (nx * ny * (1.0 - cos) + nz * sin) + y * (ny * ny * (1.0 - cos) + cos) + z * (ny * nz * (1.0 - cos) - nx * sin); const rz = x * (nx * nz * (1.0 - cos) - ny * sin) + y * (ny * nz * (1.0 - cos) + nx * sin) + z * (nz * nz * (1.0 - cos) + cos); @@ -1035,6 +1035,8 @@ export class Vec3 extends ValueType { * @param scalar scalar number */ public multiplyScalar (scalar: number): Vec3 { + // TODO: can not use cc.warn, or will cause circular dependency. + // eslint-disable-next-line no-console if (typeof scalar === 'object') { console.warn('should use Vec3.multiply for vector * vector operation'); } this.x *= scalar; this.y *= scalar; @@ -1048,6 +1050,8 @@ export class Vec3 extends ValueType { * @param other specified vector */ public multiply (other: Vec3): Vec3 { + // TODO: can not use cc.warn, or will cause circular dependency. + // eslint-disable-next-line no-console if (typeof other !== 'object') { console.warn('should use Vec3.scale for vector * scalar operation'); } this.x *= other.x; this.y *= other.y; @@ -1208,6 +1212,7 @@ export function v3 (other: Vec3): Vec3; export function v3 (x?: number, y?: number, z?: number): Vec3; export function v3 (x?: number | Vec3, y?: number, z?: number): Vec3 { + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument return new Vec3(x as any, y, z); }