GLSurfaceView 纹理矩形作为按钮点击

发布于 2024-09-29 19:09:39 字数 463 浏览 0 评论 0原文

我只想问一个与 GLSurfaceView 和其上绘制的对象相关的简单问题。我正在绘制一个矩形并将纹理绑定到它。效果很好。然后,我正在绘制的纹理矩形位于 GLSurfaceView 上。我正在绘制一个类似“按钮”的对象,我应该知道用户是否单击了该按钮。

我想像这样:如果用户点击屏幕并且点击的 .y 位于绘制对象的矩形中(在我的例子中是按钮),我需要执行另一个操作(即更改另一个视图等)。 ..)。我的想法正确吗?

现在的问题是:如何处理用户交互?如何获取映射在 GLSurfaceView 上的绘制对象(按钮)的 Rect(即 Rect(120, 80)),以便我可以检查用户是否单击了按钮?或者还有其他方法。

我还对以下内容感兴趣: 我想让我的应用程序完全基于 opengl es。我不会使用 Android 中的按钮视图。我正在处理大纹理,我认为 OpenGL ES 是更好的方法,因为通过平移、旋转和缩放的动画更容易处理。我说得对吗?

谢谢

I just want to ask a simple question related the GLSurfaceView and drawn objects on it. I am drawing a rect and bind a texture to it. It works great. Then, the textured rect I am drawing is on a GLSurfaceView. I am drawing a "button"-like object for which I should know whether the user clicked on the button or not.

I imagined that like this: if the user taps the screen and the .y of the tap are in the rect of the drawn object (in my case the button), I need another operation to be performed (i.e. change another view or so...). Is my idea correct?

Now the question: How do I handle user interactions? And how can I get the Rect of the drawn object (button) maped on the GLSurfaceView (i.e. Rect(120, 80)) so that I can then check whether the user clicked the button or not? Or there is some other approach.

Also I am interested in the following:
I have in mind to make my application full opengl es based. I won't use Button views from Android. I am working with big textures and I think OpenGL ES is the better way to do it since animations via translations and rotations and scaling are much easier to handle. Am I right?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

汐鸠 2024-10-06 19:09:39

您可以使用 onTouchEvent 获取用户触摸的 x 和 y 点。

   @Override
   public boolean onTouchEvent(MotionEvent event) {

     float x = event.getX();
     float y = event.getY();

    } 

You can use onTouchEvent to get the x and y points where user touches.

   @Override
   public boolean onTouchEvent(MotionEvent event) {

     float x = event.getX();
     float y = event.getY();

    } 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文