001 package test; 002 003 import java.awt.Container; 004 005 import javax.media.opengl.GLCanvas; 006 import javax.media.opengl.GLCapabilities; 007 import javax.media.opengl.GLEventListener; 008 import javax.swing.JFrame; 009 010 import physics3d.Angle; 011 import physics3d.GamePhysics; 012 import physics3d.Vect3; 013 014 import rendering.Renderer; 015 016 import components.Ball; 017 import components.GameSettings; 018 import components.GameSpace; 019 import components.SquareBumper; 020 import components.TriangleBumper; 021 022 public class BouncingOffWalls extends JFrame implements Runnable { 023 static final long serialVersionUID = 1495; 024 025 //GameSpace 026 private GameSpace gs; 027 private Ball b; //shall bounce!... maybe 028 029 //rendering stuff 030 private final GLCanvas canvasPanel; 031 private final Renderer myRenderer; 032 033 public BouncingOffWalls() { 034 super("Bouncing Off Walls"); 035 036 this.setDefaultCloseOperation(EXIT_ON_CLOSE); 037 this.setResizable(false); 038 this.setSize(600, 600); 039 040 //GameSpace 041 gs = new GameSpace(new GameSettings()); 042 b = new Ball(Vect3.ZERO, Vect3.ZERO, "bouncing ball", gs); 043 gs.add(b); 044 b.setCenter(new Vect3(10, 10, 5)); // start ball at 2.5 in y direction 045 b.setVelocity(new Vect3(40, 50, 10)); 046 gs.getSettings().setGravity(new Vect3(0, 100, 0)); //with an iron fist 047 gs.getSettings().setMu2(0.5); //some drag 048 049 //renderer 050 canvasPanel = new GLCanvas(new GLCapabilities()); 051 myRenderer = new Renderer(gs); 052 canvasPanel.addGLEventListener(myRenderer); 053 canvasPanel.setSize(600, 600); 054 055 Container mainPane; 056 mainPane = getContentPane(); 057 mainPane.add(canvasPanel); 058 } 059 060 public void run() { 061 for (int f = 0; f < 120; f++) { 062 canvasPanel.display(); 063 try { 064 Thread.sleep(33); 065 } catch (InterruptedException e) { 066 e.printStackTrace(); 067 } 068 gs.stepFrame(); 069 //\\System.outprintln("frame +"+f+": p="+b.getPosition()+", v="+b.getVelocity()); 070 } //120 frames 071 } 072 073 /** 074 * @param args 075 */ 076 public static void main(String[] args) { 077 BouncingOffWalls myGUI = new BouncingOffWalls(); 078 myGUI.setVisible(true); 079 myGUI.run(); 080 } 081 082 }