Android click screen coordinates correspond to OpenGL ES coordinates

Simple application scenarios are as follows:

The user clicks on the screen, and a triangle is generated at the clicked position. The triangle of OpenGL ES is generated with three vertices, but the coordinate range of the vertices of OpenGL ES is [-1.0, 1.0]. There is a problem here. The location is mapped to the coordinates of OpenGL ES. In fact, the reason is very simple. It is to map the x-axis coordinates of the screen such as [0, 1080] to the range of [-1.0, 1.0]. There is a small problem here. If the screen is The size of 1080 * 1920, if you want to click on each position on the screen, you must map to OpenGL ES coordinates, because the x-axis and y-axis coordinates of OpenGL ES are both [- 1.0, 1.0], so if glViewport (0, 0, 1080, 1920), the range of orthogonal projection or perspective projection should be left = -ratio, right = ratio, bottom = -1, top = 1, where ratio = (float) width / height. The code is relatively simple, directly on the renderings and source code download link.


Download link:Click to open the link

Intelligent Recommendation

Baidu map SDK for Android [Demo click on the screen to get geographic coordinates]

Getting the geographic coordinates of the clicked point by tapping the screen with your finger is a common feature in real-world applications. Below, I will show you how to implement this feature. Bas...

This non-Android app to get the coordinates of the screen click on the (practice papers)

Foreword This week encountered a troublesome thing, the company docked a foreigner customer requires a custom password interface style, but the password key data processing, and obtain the password ne...

OpenGL screen coordinates into two-dimensional coordinates into three-dimensional model

We model the three-dimensional coordinates in OpenGL to convert two-dimensional coordinates is calledprojection, The two-dimensional coordinates on the screen into three-dimensional coordinate transfo...

Regarding the conversion of OpenGL model coordinates to final screen coordinates

Reference: https://zhidao.baidu.com/question/560324903.html The personal test code is given below For the sake of simplicity, the model view and projection are all unit arrays, and the viewport is tra...

More Recommendation

OpenGL: Screen coordinates to the world coordinate (GLFW implementation)

OpenGL: Screen coordinates to the world coordinate (GLFW implementation) The first blog post (I am the porter of the network) Screen Coordinates to World Coordinates Existence problem Original link: h...

OpenGL with qtwidgets: Screen coordinate Turn world coordinates

(This article is Learnopengl learning note, tutorial Chinese translation addresshttps://learnopengl-cn.github.io/(Alternate addresshttps://learnopengl-cn.readthedocs.io/zh/latest/), Written on 2022-04...

[OpenGL] Click the mouse to get the world coordinates

[OpenGL] Click the mouse to get the world coordinates Labels (space separated): OpenGL cause Because I am doing graphics-related design recently, it takes time for the mouse to interactively acquire t...

Revit coordinates and screen coordinates

Map of the big plug-in company has a basic functionality that the floating range is the principle of achieving (of course they may have a more high implementation method, but I said this method is fea...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top