本文介绍了的OpenGL-ES:如何在触摸的坐标设置对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找在您触摸屏幕在屏幕上的位置的方法有一个OpenGL对象(三角形等)。我现在在屏幕上的3D金字塔,在屏幕上移动至极,根据您的触摸开始之间的差异,并在您拖动它。结果
在正常surfaceViews我可以做类似 element.x = event.getX(),但这不会在OpenGL工作。因此,任何人有一个想法?结果
PS:我用java / Android版

I'm looking for a way to have an opengl object(triangles etc) at the location on the screen where you touch the screen. I now have an 3D pyramid on the screen, wich moves over the screen, based on the difference between the start of your touch, and where you dragged it to.
In normal surfaceViews I could just do something like element.x = event.getX(), but this will not work in openGL. So anyone has an idea?
ps: i'm using java/Android.

推荐答案

OpenGL是也不像表面看,其中每个元素是持久的。这是3D等同于画笔和画刷的。你需要保持所有数据的跟踪自己。

OpenGL is nor like a surface view, where each element is persistent. It's the 3D equivalent to pens and brushes. You need to keep track of all data yourself.

因此​​,在您触摸事件处理程序使用输入的坐标投射了一缕所以一些平面垂直于视图。您对自己实现这一预测,但它是很容易的:搜索光平面的交点。这给你的坐标上飞机,对应与当用户触摸屏幕上的点的投影。您可以使用此坐标变换对象,并重绘现场。

So in your touch event handler you use the input coordinate to project a ray so some plane perpendicular to the view. You've to implement this projection yourself, but it's easy enough: Search for "ray plane intersection". This gives you the coordinates on the plane, that corresponds with that points projection on the screen where the user touched. You use this coordinates to transform the object and redraw the scene.

这篇关于的OpenGL-ES:如何在触摸的坐标设置对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 14:17
查看更多