Android ARCore屏幕坐标到世界坐标openGL
我试图放置一个锚并在用户点击屏幕的位置显示它,屏幕返回X和Y坐标Android ARCore屏幕坐标到世界坐标openGL,android,opengl-es-2.0,arcore,Android,Opengl Es 2.0,Arcore,我试图放置一个锚并在用户点击屏幕的位置显示它,屏幕返回X和Y坐标 tapX = tap.getX(); tapY = tap.getY(); 我想使用这些信息为我的模型创建一个矩阵。(即,将我的3D模型放在用户点击的位置) 现在我试着: float sceneX = (tap.getX()/mSurfaceView.getMeasuredWidth())*2.0f - 1.0f; float sceneY = (tap.getY()/mSurfaceView.getMeasuredHeigh
tapX = tap.getX();
tapY = tap.getY();
我想使用这些信息为我的模型创建一个矩阵。(即,将我的3D模型放在用户点击的位置)
现在我试着:
float sceneX = (tap.getX()/mSurfaceView.getMeasuredWidth())*2.0f - 1.0f;
float sceneY = (tap.getY()/mSurfaceView.getMeasuredHeight())*-2.0f + 1.0f; //if bottom is at -1. Otherwise same as X
Pose temp = frame.getPose().compose(Pose.makeTranslation(sceneX, sceneY, -1.0f)).extractTranslation();
我现在只是把3D物体放在前面1米处。我找不到合适的位置
有没有办法将局部坐标转换为世界坐标?屏幕上的点击没有到真实世界的一对一映射。它为您提供了无限多个可能的
(x,y,z)
位置,这些位置沿着从相机延伸的光线。例如,如果我点击屏幕中央,这可能对应于一个物体漂浮在离我一米远、两米远的地板上,穿过地板,等等
所以,您需要一些额外的约束来告诉ARCore沿着这条光线放置锚点的位置。在示例应用程序中,这是通过将此光线与ARCore检测到的平面相交来完成的。与平面相交的光线描述了一个点,因此设置为。这是他们在示例应用程序中的操作方式:
MotionEvent tap = mQueuedSingleTaps.poll();
if (tap != null && frame.getTrackingState() == TrackingState.TRACKING) {
for (HitResult hit : frame.hitTest(tap)) {
// Check if any plane was hit, and if it was hit inside the plane polygon.
if (hit instanceof PlaneHitResult && ((PlaneHitResult) hit).isHitInPolygon()) {
// Cap the number of objects created. This avoids overloading both the
// rendering system and ARCore.
if (mTouches.size() >= 16) {
mSession.removeAnchors(Arrays.asList(mTouches.get(0).getAnchor()));
mTouches.remove(0);
}
// Adding an Anchor tells ARCore that it should track this position in
// space. This anchor will be used in PlaneAttachment to place the 3d model
// in the correct position relative both to the world and to the plane.
mTouches.add(new PlaneAttachment(
((PlaneHitResult) hit).getPlane(),
mSession.addAnchor(hit.getHitPose())));
// Hits are sorted by depth. Consider only closest hit on a plane.
break;
}
}
}
特别是对于你的情况,我想看看AR绘图应用程序。它们的函数
GetWorldCoords()
从屏幕坐标到世界坐标,假设与屏幕的距离已知。它们的代码没有太大帮助,因为它们对世界空间的所有定位都是在顶点着色器中完成的。但在我的项目中很难实现这一点。