rotate in opengl es

All your problems with Audio, Video and Images.

rotate in opengl es

Postby superj » Mon Oct 06, 2008 5:17 pm

Hello!

I wanna rotate my Cube in OpenGL ES with the DPAD, but I don't know how.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. class GLThread extends Thread {
  2.  
  3. private float xRot, yRot;
  4.  
  5.  
  6.  
  7. //............................
  8.  
  9. private void drawFrame(GL10 gl) {
  10.  
  11.       // Clear the screen to black
  12.  
  13.       gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
  14.  
  15.  
  16.  
  17.       // Other drawing commands go here...
  18.  
  19.      
  20.  
  21.       gl.glMatrixMode(GL10.GL_MODELVIEW);
  22.  
  23.       gl.glLoadIdentity();
  24.  
  25.       gl.glPushMatrix();
  26.  
  27.         gl.glTranslatef(0, 0, -2.0f);
  28.  
  29.        
  30.  
  31.         //************ ROTATE BY THE DPAD ************
  32.  
  33.         gl.glRotatef(yRot, 0, 1, 0);
  34.  
  35.         gl.glRotatef(xRot, 1, 0, 0);
  36.  
  37.        
  38.  
  39.         // ... Draw the model
  40.  
  41.         cube.draw(gl);
  42.  
  43.       gl.glPopMatrix();
  44.  
  45.      
  46.  
  47.       gl.glPushMatrix();
  48.  
  49.         gl.glTranslatef(-1.0f, 1.0f, -2.0f);
  50.  
  51.         gl.glScalef(0.5f, 0.5f, 0.5f);
  52.  
  53.         cube.draw(gl);
  54.  
  55.       gl.glPopMatrix();
  56.  
  57.      
  58.  
  59.       gl.glPushMatrix();
  60.  
  61.         gl.glTranslatef(1.0f, -1.0f, -2.0f);
  62.  
  63.         gl.glScalef(0.3f, 0.3f, 0.3f);
  64.  
  65.         cube.draw(gl);
  66.  
  67.     gl.glPopMatrix();
  68.  
  69.    }
  70.  
  71.  
  72.  
  73.    public boolean onKeyDown(int keyCode, KeyEvent ev) {
  74.  
  75.            switch (keyCode) {
  76.  
  77.            case KeyEvent.KEYCODE_DPAD_UP:
  78.  
  79.                    xRot += 30.0f;
  80.  
  81.                    yRot += 30.0f;
  82.  
  83.                    return true;
  84.  
  85.            default:
  86.  
  87.                    return false;
  88.  
  89.            }
  90.  
  91.    }
  92.  
  93. //.............................
  94.  
  95. }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


az the ********** line:
for example, I push the DPAD_UP, the Cube(s) rotate around the X axis by 30.

Please help me!
superj
Freshman
Freshman
 
Posts: 7
Joined: Thu Sep 11, 2008 3:22 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Exabot [Bot] and 16 guests