Cyrus
JGO n00b  Posts: 17
Lean Mean Programming Machine
|
 |
«
on:
2008-02-10 17:28:45 » |
|
Sorry, it's very late, sometimes i make simple mistakes.
You can ofc always access variables/methods from other files by calling filename.variable
somehow it totally slipped my mind.
------------------------------------------ I have two seperate classes for handeling GLEvents and KeyEvents.
I want to bind the classes so, that if i press "W" that,the boolean statement becomes true. now, nothing happens.
What should i do? Any tips are welcome!
(yeah ok, i'm new)
Greetings, Cyrus
///GfxFactory.java (GLEventListener) import javax.media.opengl.*; import javax.media.opengl.glu.*; import java.awt.event.*;
public class GfxFactory extends KeyBehaviour implements GLEventListener { private final GLU glu = new GLU(); ObjectLibrary ol = new ObjectLibrary(); KeyBehaviour kb = new KeyBehaviour(); float rot; public void display(GLAutoDrawable gld) { final GL gl = gld.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); ol.camera(gl, kb.posx, kb.posy, kb.posz, kb.rotx, kb.roty, kb.rotz); gl.glTranslatef(0.0f, 0.0f, -5.0f); gl.glRotatef(rot, 1.0f, 0.0f, 0.0f); ol.cube(gl); rot += 4.0f; System.out.println(kb.FORWARD); } public void init(GLAutoDrawable gld) { final GL gl = gld.getGL(); gl.glShadeModel(GL.GL_SMOOTH); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glClearDepth(1.0f); gl.glEnable(GL.GL_DEPTH_TEST); gl.glDepthFunc(GL.GL_LEQUAL); gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); } public void reshape(GLAutoDrawable gld, int x, int y, int width, int height) { final GL gl = gld.getGL(); if(height < 1) height = 1; float ratio = (float)width / (float)height; gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(50.0f, ratio, 1.0f, 1000.0f); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); } public void displayChanged(GLAutoDrawable gld, boolean modeChanged, boolean deviceChanged) { } }
///KeyBehaviour.java import java.awt.event.*; import java.awt.*; import javax.media.opengl.*;
public class KeyBehaviour implements KeyListener, MouseListener, MouseMotionListener { /***************************** GAME VARIABLES *****************************/ final float SPEED = 2.0f; final float ANGLESPEED = 1.0f; float posx, posy, posz; float rotx, roty, rotz; float angle; boolean FORWARD = false; boolean BACKWARD = false; boolean STRAFELEFT = false; boolean STRAFERIGHT = false; /***************************** INTERFACE METHODS *****************************/ GLCanvas glc; public void getGLCanvas(GLCanvas glc) { this.glc = glc; } /***************************** KEY PROCESSING *****************************/ /***************************** KEYBOARD EVENTS *****************************/ public void keyPressed(KeyEvent e) { switch(e.getKeyCode()) { case KeyEvent.VK_W: FORWARD = true; break; case KeyEvent.VK_S: BACKWARD = true; break; case KeyEvent.VK_A: STRAFELEFT = true; break; case KeyEvent.VK_D: STRAFERIGHT = true; break; case KeyEvent.VK_ESCAPE: case KeyEvent.VK_F10: System.exit(0); break; } glc.repaint(); } public void keyReleased(KeyEvent e) { switch(e.getKeyCode()) { case KeyEvent.VK_W: FORWARD = false; break; case KeyEvent.VK_S: BACKWARD = false; break; case KeyEvent.VK_A: STRAFELEFT = false; break; case KeyEvent.VK_D: STRAFERIGHT = false; break; } glc.repaint(); } public void keyTyped(KeyEvent e) { } /***************************** MOUSE EVENTS *****************************/ public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } /***************************** MOUSE MOTION EVENTS *****************************/ public void mouseMoved(MouseEvent e) { } public void mouseDragged(MouseEvent e) { } }
|