Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid OpenGL - difficulties with simple 2D transformations
    primarykey
    data
    text
    <p>I'm trying to migrate graphics in my game to OpenGL for performance reasons. </p> <ol> <li>I need to draw an object using exact screen coordinates. Say a box 100x100 pixels in the center of 240x320 screen.</li> <li>I need to rotate it around Z axis, preserving its size.</li> <li>I need to rotate it around X axis, with perspective effect, preserving (or close to) its size.</li> <li>I need to rotate it around Y axis, with perspective effect, preserving (or close to) its size.</li> </ol> <p><a href="http://img265.imageshack.us/img265/5448/1234ua.jpg" rel="nofollow">Here's a picture.</a></p> <p>So far I managed to achieve first 2 tasks:</p> <pre><code>public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); gl.glTranslatef(120, 160, 0); // move rotation point gl.glRotatef(angle, 0.0f, 0.0f, 1.0f); // rotate gl.glTranslatef(-120, -160, 0); // restore rotation point mesh.draw(gl); // draws 100x100 px rectangle with the following coordinates: (70, 110, 170, 210) } public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrthof(0f, (float)width, (float)height, 0f, -1f, 1f); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); } </code></pre> <p>But when I'm trying to rotate my box around x or y, nasty thing are happening with my box and there is no perspective effect. I tried to use some other function instead of glRotate (glFrustum, glPerspective, gluLookAt, applying "skewing" matrix), but I couldn't make them work properly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload