Click here to Skip to main content
11,707,254 members (45,235 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ OpenGL
Hi there,

It's about OpenGLES 2 again. Now I got something nasty in my mind -_-.
How to rotate my draw (triangle and rectangle) with keyboard input? Such as, (w,a,s,d) for (up,down,right,left) and so on.

Thanks in advance

Ps : I found something interesting in OpenGLES 2, that every command which seems not exist from OpenGL like glTranslate and so on was being overwritten as esTranslate, esPerspective and so on. Is it obvious?
Posted 24-Apr-12 16:42pm
Comments
Amar Tivari at 25-Apr-12 2:17am
   
Which application you are trying to write is it android application,Iphone app etc.
satrio_budidharmawan at 27-Apr-12 2:35am
   
Oh it's android.
But i've solved it

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Implements this
...
...
@Override
    public boolean onKeyDown(int keyCode, KeyEvent msg) {
        if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
            renderer.mY -= 1;
            requestRender();
            return (true);
		}
           
        if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
            renderer.mY += 1;
            requestRender();
            return (true);
        }
 
        if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
            renderer.mX -= 1;
            requestRender();
            return (true);
        }
 
        if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
			renderer.mX += 1;
            requestRender();
            return (true);
        }
 
        return true;
    }
 
...
...

and this
...
...
@Override
public void onDrawFrame(GL10 gl) 
{
    gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
 
    enable2d(gl);
	gl.glMatrixMode(GL10.GL_MODELVIEW);
	gl.glLoadIdentity();
	//gl.glTranslatef(0, 0, -3.0f);
	gl.glTranslatef(mX, 0, -3.0f);
	gl.glTranslatef(0, mY, -3.0f);
	gl.glRotatef(mAngleX, 0, 1, 0);
	gl.glRotatef(mAngleY, 1, 0, 0);
	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
	gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
 
    drawTriangle(gl, 160.0f, 100.0f, 110.0f, 200.0f, 210.0f, 200.0f, 1.0f, 1.0f, 1.0f);
    drawTriangle(gl, 110.0f, 200.0f, 60.0f, 300.0f, 160.0f, 300.0f, 1.0f, 1.0f, 1.0f);
    drawTriangle(gl, 210.0f, 200.0f, 160.0f, 300.0f, 260.0f, 300.0f, 1.0f, 1.0f, 1.0f);
    disable2d(gl);
}
...
...

It works. And should be works!
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 145
1 OriginalGriff 141
2 chainerlt 110
3 Mika Wendelius 80
4 Maciej Los 80
0 OriginalGriff 9,178
1 Sergey Alexandrovich Kryukov 8,562
2 CPallini 5,189
3 Maciej Los 4,806
4 Mika Wendelius 3,706


Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 27 Apr 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100