Problem: Android uses a vastly different coordinate system than openGL. In the X coordinate, Android’s screen goes from 0 to the width of the screen (400 pixels). OpenGL goes from -1 to 1. Also, android and OpenGL’s y coordinates are reversed. Because of this, early attempt to move a triangle to a touch screen event location failed, passing the location of the touch screen event directly to openGL made the triangle instantly disappear.
Impact: Technically, the program was still running just fine. It was just running a vast distance off the screen and impossible to see, and also upside down.
Solution: The location of the mouse event’s x/y location had to have half the screen’s width/height subtracted from it, and then be divided by half the screen’s width/height, to make it between -1 and 1. This number could then be given to openGL to draw the triangle in the correct place.
No comments:
Post a Comment