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