PV3D获得二维坐标

PV3D是把虚拟的x,y,z坐标映射到真实屏幕的x,y坐标系的,可我怎么读取真实的x,y呢?这在做一些二维+三维的项目的时候非常关键。

do3d.calculateScreenCoords(current_camera);
real2DX=do3d.screen.x+current_viewport.width/2;
real2DY=do3d.screen.y+current_viewport.height/2;

此时的x和y都是平均值,也就是是说中心点的坐标。这就导致无法得到边缘的坐标,比如左上角点。这种情况下可以通过do3d上的节点的坐标来计算边界坐标,以四个节点的Plane为例:
左下角
do3d.geometry.vertices[0].vertex3DInstance.x+current_viewport.width/2;
do3d.geometry.vertices[0].vertex3DInstance.y+current_viewport.height/2;
左上角
do3d.geometry.vertices[1].vertex3DInstance.x+current_viewport.width/2;
do3d.geometry.vertices[1].vertex3DInstance.y+current_viewport.height/2;
右上角
do3d.geometry.vertices[2].vertex3DInstance.x+current_viewport.width/2;
do3d.geometry.vertices[2].vertex3DInstance.y+current_viewport.height/2;
右下角
do3d.geometry.vertices[3].vertex3DInstance.x+current_viewport.width/2;
do3d.geometry.vertices[3].vertex3DInstance.y+current_viewport.height/2;
如果需要每一帧都使用这个值,为了方便起见,可以将do3d.autoCalcScreenCoords(Bool)属性设置为true,这样在渲染的时候会自动计算并更新screen属性,无需每次调用calculateScreenCoords
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值