Files
cocos4/cocos/core
James Chen d5e1bfa1a1 Fix wrong logic in Camera::screenToWorld function and remove Node._xxxCache properties to keep the same logic as web (#11693)
* Fix wrong logic in Carmea::screenToWorld function.

* [jsb] Remove Node._xxxCache properties. Keep the same logic as web.

In camera-component.ts

    public screenToWorld (screenPos: Vec3, out?: Vec3) {
        if (!out) { out = this.node.getWorldPosition(); }  // if out is null, getWorldPosition will return _worldPositionCache object
        if (this._camera) { this._camera.screenToWorld(out, screenPos); }
        return out;
    }

In user code, there may be something like this:

	const target = cameraCom.screenToWorld(pos); // target is _worldPositionCache object
        const dir = Vec3.subtract(new Vec3(), target, this.node.worldPosition).normalize(); // this.node.worldPosition also returns _worldPositionCache object because we define _pos like the following:

// node.jsb.ts

Object.defineProperty(nodeProto, '_pos', {
    configurable: true,
    enumerable: true,
    get (): Readonly<Vec3> {
        return this.getWorldPosition();
    }
});

nodeProto.getWorldPosition = function (out?: Vec3): Vec3 {
    const r = oldGetWorldPosition.call(this);
    if (out) {
        return Vec3.copy(out, r);
    }
    return Vec3.copy(this._worldPositionCache, r); // node.getWorldPosition() will return _worldPositionCache tool.
};

So the code [[[[ const dir = Vec3.subtract(new Vec3(), target, this.node.worldPosition).normalize(); ]]]] will replace target value since this.node.worldPosition getter  overrides the target value.
2022-06-24 18:30:59 +08:00
..
2021-07-23 11:26:55 +08:00
2022-05-17 11:56:06 +08:00
2022-05-17 11:56:06 +08:00
2022-06-22 16:49:50 +08:00
2022-05-17 11:56:06 +08:00
2022-04-20 18:47:53 +08:00
2022-05-17 11:56:06 +08:00
2022-06-02 21:03:17 +08:00
2022-05-17 11:56:06 +08:00