Hello I´m very new to jogel
i´ve tried to move an geometric objekt with Pressed Keys, but it does not work. That´s what i´ve done:
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import net.java.games.jogl.*;
//import net.java.games.jogl.util.GLUT;
public class MoveTest_view implements GLEventListener, KeyListener
{
public static float x=0;
public void init(GLDrawable drawable)
{
GL gl = drawable.getGL();
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glFrustum(-5, 5, -5, 5, 2, 12.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
drawable.addKeyListener(this);
gl.glLoadIdentity();
}
public void display(GLDrawable drawable)
{
GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glTranslatef (x, 0, 0);
gl.glPushMatrix();
gl.glTranslatef (0.0f, 0.0f, -3.0f);
gl.glBegin(GL.GL_POLYGON);
gl.glVertex3f(-0.5f, 0.35f, 0.0f); // links unten (x,y,z) koordinate
gl.glVertex3f(0.5f, 0.35f, 0.0f);
gl.glVertex3f(0.0f, 1.4f, 0.0f);
gl.glEnd();
gl.glPopMatrix();
}
public void reshape(GLDrawable drawable, int x, int y, int width, int height)
{}
public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged)
{}
public void keyTyped(KeyEvent arg0) {}
public void keyPressed(KeyEvent arg0)
{
switch(arg0.getKeyCode())
{
case KeyEvent.VK_LEFT: x=x-0.1f ; break;
case KeyEvent.VK_RIGHT: x=x+0.1f ; break;
}
}
public void keyReleased(KeyEvent arg0) {}
}
Can someone tell me where my problem is?
Does Someone here knows a GOOD jogl Tutorial (somthing like NEHE´s but for Java).
Thank You