Skip to content

Commit

Permalink
remove abs from rhw in transformMat4 (cocos#14483)
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyljl authored Mar 6, 2023
1 parent c963d5e commit e5fe41f
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cocos/2d/assembler/label/ttf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const ttf: IAssembler = {
const x = curData.x;
const y = curData.y;
let rhw = m.m03 * x + m.m07 * y + m.m15;
rhw = rhw ? Math.abs(1 / rhw) : 1;
rhw = rhw ? 1 / rhw : 1;

offset = i * stride;
vData[offset + 0] = (m.m00 * x + m.m04 * y + m.m12) * rhw;
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/assembler/sprite/bar-filled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export const barFilled: IAssembler = {
const x = local.x;
const y = local.y;
let rhw = m.m03 * x + m.m07 * y + m.m15;
rhw = rhw ? Math.abs(1 / rhw) : 1;
rhw = rhw ? 1 / rhw : 1;

offset = i * stride;
vData[offset] = (m.m00 * x + m.m04 * y + m.m12) * rhw;
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/assembler/sprite/radial-filled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ export const radialFilled: IAssembler = {
const x = vert.x;
const y = vert.y;
let rhw = m.m03 * x + m.m07 * y + m.m15;
rhw = rhw ? Math.abs(1 / rhw) : 1;
rhw = rhw ? 1 / rhw : 1;

vData[vertexOffset + 0] = (m.m00 * x + m.m04 * y + m.m12) * rhw;
vData[vertexOffset + 1] = (m.m01 * x + m.m05 * y + m.m13) * rhw;
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/assembler/sprite/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const simple: IAssembler = {
const x = curData.x;
const y = curData.y;
let rhw = m.m03 * x + m.m07 * y + m.m15;
rhw = rhw ? Math.abs(1 / rhw) : 1;
rhw = rhw ? 1 / rhw : 1;

offset = i * stride;
vData[offset + 0] = (m.m00 * x + m.m04 * y + m.m12) * rhw;
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/assembler/sprite/sliced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export const sliced: IAssembler = {
const x = colD.x;
const y = rowD.y;
let rhw = m.m03 * x + m.m07 * y + m.m15;
rhw = rhw ? Math.abs(1 / rhw) : 1;
rhw = rhw ? 1 / rhw : 1;

offset = (row * 4 + col) * stride;
vData[offset + 0] = (m.m00 * x + m.m04 * y + m.m12) * rhw;
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/assembler/sprite/tiled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export const tiled: IAssembler = {
const y = dataList[i].y;
const z = dataList[i].z;
let rhw = m.m03 * x + m.m07 * y + m.m11 * z + m.m15;
rhw = rhw ? Math.abs(1 / rhw) : 1;
rhw = rhw ? 1 / rhw : 1;

const offset = i * stride;
vData[offset] = (m.m00 * x + m.m04 * y + m.m08 * z + m.m12) * rhw;
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/assembler/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function fillMeshVertices3D (node: Node, renderer: IBatcher, renderData:
const x = vert.x;
const y = vert.y;
let rhw = m.m03 * x + m.m07 * y + m.m15;
rhw = rhw ? Math.abs(1 / rhw) : 1;
rhw = rhw ? 1 / rhw : 1;
vData[vertexOffset + 0] = (m.m00 * x + m.m04 * y + m.m12) * rhw;
vData[vertexOffset + 1] = (m.m01 * x + m.m05 * y + m.m13) * rhw;
vData[vertexOffset + 2] = (m.m02 * x + m.m06 * y + m.m14) * rhw;
Expand Down
8 changes: 2 additions & 6 deletions cocos/core/math/vec3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,7 @@ export class Vec3 extends ValueType {
const y = a.y;
const z = a.z;
let rhw = m.m03 * x + m.m07 * y + m.m11 * z + m.m15;
// Important note by stanley:
// Math.abs needs to be removed later, because the operation will generate a wrong homogeneous coordinate
rhw = rhw ? Math.abs(1 / rhw) : 1;
rhw = rhw ? 1 / rhw : 1;
out.x = (m.m00 * x + m.m04 * y + m.m08 * z + m.m12) * rhw;
out.y = (m.m01 * x + m.m05 * y + m.m09 * z + m.m13) * rhw;
out.z = (m.m02 * x + m.m06 * y + m.m10 * z + m.m14) * rhw;
Expand All @@ -474,9 +472,7 @@ export class Vec3 extends ValueType {
const y = a.y;
const z = a.z;
let rhw = m.m03 * x + m.m07 * y + m.m11 * z;
// Important note by stanley:
// Math.abs needs to be removed later, because the operation will generate a wrong homogeneous coordinate
rhw = rhw ? Math.abs(1 / rhw) : 1;
rhw = rhw ? 1 / rhw : 1;
out.x = (m.m00 * x + m.m04 * y + m.m08 * z) * rhw;
out.y = (m.m01 * x + m.m05 * y + m.m09 * z) * rhw;
out.z = (m.m02 * x + m.m06 * y + m.m10 * z) * rhw;
Expand Down
4 changes: 1 addition & 3 deletions native/cocos/math/Vec3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,7 @@ void Vec3::transformMat4Normal(const Vec3 &v, const Mat4 &m, Vec3 *dst) {
float y = v.y;
float z = v.z;
float rhw = m.m[3] * x + m.m[7] * y + m.m[11] * z;
// Important note by stanley:
// abs needs to be removed later, because the operation will generate a wrong homogeneous coordinate
rhw = rhw != 0.0F ? std::abs(1.0F / rhw) : 1.0F;
rhw = (rhw != 0.0F ? 1.0F / rhw : 1.0F);
dst->x = (m.m[0] * x + m.m[4] * y + m.m[8] * z) * rhw;
dst->y = (m.m[1] * x + m.m[5] * y + m.m[9] * z) * rhw;
dst->z = (m.m[2] * x + m.m[6] * y + m.m[10] * z) * rhw;
Expand Down

0 comments on commit e5fe41f

Please sign in to comment.