Then we add our touch event handler to our custom GLSurfaceView: public boolean onTouchEvent(MotionEvent event)
Java lwjgl 2 rotate about axis how to#
Here’s how to get the pixel density: final DisplayMetrics displayMetrics = new DisplayMetrics() We also store the screen density so that drags across the screen can move the object a consistent amount across devices, regardless of the pixel density. We will store the previous pointer position each frame, so that we can calculate the relative movement left, right, up, or down.
In LessonSixGLSurfaceView.java, we declare a few member variables: private float mPreviousX
Java lwjgl 2 rotate about axis android#
The code is based on Android Lesson Six: An Introduction to Texture Filtering. The code examples here are written for Android, but can easily be adapted to any platform running OpenGL ES. What this means is that drags left, right, up, and down will always move the cube in the direction that we expect. This delta will be used to rotate our accumulated rotation matrix.
This.multiplicate(qPitch.toMatrix4f().toArray()) Quaternion qYaw = Quaternion.createFromAxis(cameraRotate.y, 0.0f, 1.0f, 0.0f)
This is a little piece of code that i'm using to make the rotation: Quaternion qPitch = Quaternion.createFromAxis(cameraRotate.x, 1.0f, 0.0f, 0.0f)
But even using Quaternions, this doesnt work and no matter how much I read about Euler Angles, everybody says to me dont touch on it! I need a camera to rotate arround world Axis and not about its own axis. The move (translation) is working fine but the rotation isnt working like I need. I have made my own math libary (Java) to use on my game (LWJGL). After 2 weeks of reading many math formulas and such I know what is a Quaternion, an Axis Angles and Matrices.