Click here to Skip to main content
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 17: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 OriginalGriff 480
1 Maciej Los 330
2 Richard MacCutchan 225
3 BillWoodruff 185
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,759
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,269
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411028.1 | Last Updated 27 Apr 2012
Copyright © CodeProject, 1999-2014
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