DEV Community

Using Linear Interpolation to map android touch screen values to OpenGL's coordinate system

The author has created an app on the Google Play Store that allows users to play a ping pong game in OpenGL while watching streams. To make this work, the author needs to convert Android's pixel-based grid system to OpenGL's coordinate system. This can be achieved through linear interpolation, which is a method of calculating intermediate data between known values. Linear interpolation involves finding the slope between two points and using the point-slope form to derive an equation. The point-slope form is y-y1=m(x-x1), where (x1,y1) is a known point, m is the slope, and x and y are arbitrary points on the line. By applying this formula to the overlapping points [0,width] and [-1,1] for the x value, and [0,height] and [1,-1] for the y value, the author can simplify the equation to convert screen coordinates to OpenGL coordinates. The resulting equations are used in the app's code to convert Android screen coordinates to OpenGL coordinates. The author provides a GitHub link to the app's code and a YouTube video explaining linear interpolation. The author invites readers to comment or reach out on Twitter with any questions or concerns.
favicon
dev.to
dev.to
Image for the article: Using Linear Interpolation to map android touch screen values to OpenGL's coordinate system