mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
4bc2739786
* Vmath (#4895) * vmath refactor * value-type API change * vmath change update * conflict fix * value types change * translate modify (#4917) * value types bug fixed (#4940) * playground update (#4946) * bug fixed * bug fixed * bug fixed * bug fix * util modify * create remove & ccenum rename * export by cc.math * Rename value-types to math * util funtion deprecated warn * value-types change * color test fix * color API change
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
/**
|
|
* @category pipeline
|
|
*/
|
|
|
|
import { CameraComponent, UITransformComponent } from '../3d';
|
|
import { Vec3 } from '../core/math';
|
|
import { Node } from '../scene-graph';
|
|
|
|
const _temp_vec3_1 = new Vec3();
|
|
|
|
/**
|
|
* @en
|
|
* Conversion of non-UI nodes to UI Node (Local) Space coordinate system.
|
|
* @zh
|
|
* 非 UI 节点转换到 UI 节点(局部) 空间坐标系。
|
|
* @param mainCamera 主相机。
|
|
* @param wpos 世界空间位置。
|
|
* @param uiNode UI节点。
|
|
* @param out 返回局部坐标。
|
|
*/
|
|
export function WorldNode3DToLocalNodeUI (mainCamera: CameraComponent, wpos: Vec3, uiNode: Node, out?: Vec3) {
|
|
if (!out) {
|
|
out = new Vec3();
|
|
}
|
|
|
|
mainCamera.worldToScreen(wpos, _temp_vec3_1);
|
|
_temp_vec3_1.x = _temp_vec3_1.x / cc.view.getScaleX();
|
|
_temp_vec3_1.y = _temp_vec3_1.y / cc.view.getScaleY();
|
|
const cmp = uiNode.getComponent(UITransformComponent);
|
|
|
|
if (!cmp){
|
|
return out;
|
|
}
|
|
|
|
cmp.convertToNodeSpaceAR(_temp_vec3_1, out);
|
|
const targetPos = uiNode.getPosition();
|
|
out.add(targetPos);
|
|
|
|
return out;
|
|
}
|
|
|
|
/**
|
|
* @en
|
|
* Conversion of non-UI nodes to UI Node (World) Space coordinate system.
|
|
* @zh
|
|
* 非 UI 节点转换到 UI 节点(世界) 空间坐标系。
|
|
* @param mainCamera 主相机。
|
|
* @param wpos 世界空间位置。
|
|
* @param out 返回世界坐标。
|
|
*/
|
|
export function WorldNode3DToWorldNodeUI (mainCamera: CameraComponent, wpos: Vec3, out?: Vec3){
|
|
if (!out) {
|
|
out = new Vec3();
|
|
}
|
|
|
|
mainCamera.worldToScreen(wpos, out);
|
|
out.x = out.x / cc.view.getScaleX();
|
|
out.y = out.y / cc.view.getScaleY();
|
|
return out;
|
|
}
|
|
|
|
cc.pipelineUtils = {
|
|
WorldNode3DToLocalNodeUI,
|
|
WorldNode3DToWorldNodeUI,
|
|
};
|