Files
cocos4/native
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
..
2022-06-20 15:11:46 +08:00
2022-06-08 10:19:35 +08:00
2020-06-18 14:12:04 +08:00
2022-05-04 13:09:24 +08:00
2022-04-27 14:59:23 +08:00
2022-04-18 10:24:54 +08:00
2021-01-14 14:36:37 +08:00
2022-05-05 14:05:11 +08:00
2022-06-16 13:39:54 +08:00

cocos-engine native part

It is the native backend of Cocos Creator. It works on iOS, Android, macOS and Windows.

Coding format and coding style

The coding format file is .clang-format, and the coding style fomat file is .clang-tidy. Please use clang-format to format the codes and use clang-tidy to fix the coding style before commiting codes. See the linter auto-fix guide for more information.

Build Requirements

  • macOS 10.14+, Xcode 11.5+ to build mac games
  • with iOS 11.0+ to build iOS games
  • or Windows 7+, Visual Studio 2017 15.7+ / Visual Studio 2019 to build win64 games
  • NDK 18-21 is required to build Android games (22+ is not supported)
  • Cmake 3.8+ is required
  • use C++17, but can only use these C++17 features