Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2 3 ... 5
1  Java Game APIs & Engines / JOGL Development / Re: Debugging my render code on: 2009-05-19 15:39:29
I've had a similar problem before. In my case I think I messed up setting the clipping planes(put zNear where zFar should have been).
A good idea if your IDE doesn't have a good debugger is to rig your spacebar or enterkey to use a series of System.out.println statements such as:

Camera| X: # Y:# Z:#
Object| X: # Y:# Z:#
Object Scale| X:# Y:# Z:#

I'm sure I recapped things you've already checked for but I figured no one else responded so I might as well.
but as for GL commands that return that kind of information, to be honest I'm not sure.
2  Java Game APIs & Engines / JOGL Development / Re: Evolution on: 2009-05-06 03:57:34
This is prolly not a constructive post. Here's how I'm looking at it(I'm a noober so don't get too mad at me):

1. I don't see what it matter's whether or not JOGL is discontinued or not. It's easy to implement, cross-platform, and excellent for what it does. Course it could be better, but so can everything else. So if JoGL should die before I wake, I thank it's creators for the applications it let's us make.

2. O3D does look cool, and could be promising.

3. I feel as if it's not a lack of an amazing java3D or JoGL game project, I've seen some really impressive ones from posters on this board! Java's gaming libraries may not be as powerful as the hard-ware on a machine. But like everyone around here says, graphics are not a game, graphics are good for movies and realism. but how many people play on-line chess or checkers(hundreds of thousands dare I say millions)? It's more of a matter of marketing, and getting the word out there.

4.I guess I don't see a reason for Java to become industry standard for game-dev, though it would be nice because I am very comfortable with it. Never-the-less if I'm not gonna write the libraries then there's no reason for flipping out about what get's abandoned or expanded.

Part of being a developer in my opinion is adaptability. Whether it's creative solution to a problem or whether it's learning O3D verses JoGL verses Java3D verses LWJGL.

If O3D is the next big step in the Java Game Dev community, I'll follow it.
Though it just seems so frivolous to be counting sheep that haven't been born yet.

wow I'm bored.
3  Java Game APIs & Engines / JOGL Development / Re: Applet Troubles..."Error: Class not found: " on: 2009-05-04 01:15:53
Am I stupid or is something just going wrong. Your jar isn't working either...

http://www.caseykneale.000space.com/java/galleryPlay.php

Edit:
Nevermind. But I can only get it to run from your webspace... weirdddd. Lemme host it third party then maybe it'll work

It must be my host after-all... Wow... That is endlessly frusterating.

Thanks SO MUCH HSAKA!
4  Java Game APIs & Engines / JOGL Development / Re: Applet Troubles..."Error: Class not found: " on: 2009-05-03 18:51:08
I'm using eclipse but if that's an issue I could build it in NetBeans.

heres the zip:

www.caseykneale.000space.com/ArtLabGallery.zip

Thanks so much for trying.
5  Java Game APIs & Engines / JOGL Development / Re: Applet Troubles..."Error: Class not found: " on: 2009-05-02 20:23:28
Is anyone on here nice enough to build me the freaking .jar if I send them all the code + media and everything? Seriously this is reallly frustrating, and after this I'm switching over to C.
6  Java Game APIs & Engines / JOGL Development / Re: Applet Troubles..."Error: Class not found: " on: 2009-04-28 00:22:27
Okay I recently found out... I can't upload any files anywhere? persecutioncomplex
Literally I cannot complete Instant Messenger Transfers, FTP Uploads. I'm googling around right now trying to figure out why(turning off my fire-wall did nothing). I'm not sure if this is the root of my problem, but it sounds like it certainly isn't helping...

Edit: Fixed the virus and the problem. Still can't make .Jar's...
7  Java Game APIs & Engines / JOGL Development / Re: Applet Troubles..."Error: Class not found: " on: 2009-04-26 01:32:17
Interesting... Thanks for helping me through this!

GluGen...

it was built using java 1.6 (if that makes a difference?).

The application runs perfectly fine in IDE(not even a warning).

I copied the Applet code you made (using your host) into my host and it's still just giving me the class not found error. This is screwing with my head. If I posted code do you think it'd help you understand what may be going on?

Applet Launch Class
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
//Imports up here
public class ArtLabAppletLaunch extends Applet implements ActionListener {
   private static final long serialVersionUID = 1L;
   
   protected GLCanvas canvas;
   protected Animator animator;
   //Listener's/Handlers for input
  private KeyboardHandler keyboardHandler = new KeyboardHandler();
   //GUI for Applet
  private TextArea descriptionTxt = new TextArea();
   private Button backToGalleryBtn = new Button();
   //Load Canvas stuff?
  private ArtLab artLabProcess = new ArtLab(this);
   //GUI
  private Panel movePnl = new Panel();
   private Label[] controlLbl = new Label[5];
   private Button scaleHeightPlusBtn = new Button();
   private Button scaleHeightLessBtn = new Button();
   private Button scaleWidthPlusBtn = new Button();
   private Button scaleWidthLessBtn = new Button();
   private Button zoomInBtn = new Button();
   private Button zoomOutBtn = new Button();
   private Button resetBtn = new Button();
   
   public void addKeyListener(KeyboardListenerInterface listener){
        keyboardHandler.addListener(listener);
   }
   
   public void changeText(String text){
      descriptionTxt.setText(text);
   }
   
   public void setGalleryGUIVisibility(boolean visible){
      backToGalleryBtn.setVisible(visible);
      movePnl.setVisible(visible);
   }
   
   public void init() {
      //setSize(512, 256 + 128 + 32 + 128); this is commented out
     setLayout(new BorderLayout());
      GLCapabilities glCapabilities = new GLCapabilities();
     
      glCapabilities.setDoubleBuffered(true);
      glCapabilities.setHardwareAccelerated(true);

      canvas = new GLCanvas(glCapabilities);
     
      setLayout(null);
     
      animator = new Animator(canvas);
     
      canvas.addGLEventListener(keyboardHandler);
        canvas.addKeyListener(keyboardHandler);
       
      canvas.addGLEventListener(artLabProcess);
     
      canvas.setBounds(0, 0, 512, 256);
     
      backToGalleryBtn.setBounds(0, 384, 512, 32);
      backToGalleryBtn.setLabel("~ Go Back To The Art Gallery ~");
      backToGalleryBtn.setVisible(false);
     
      descriptionTxt.setBounds(0, 256, 512, 128);
      //GUI PANEL for looking Directions
     movePnl.setVisible(false);
      movePnl.setBounds(0, 417, 512, 128);
      movePnl.setLayout(null);
         controlLbl[0] = new Label();
         controlLbl[0].setBounds(0, 0, 64, 32);
         controlLbl[0].setText("Height: ");
         movePnl.add(controlLbl[0]);
            scaleHeightPlusBtn.setBounds(64, 0, 32, 32);
            scaleHeightPlusBtn.setLabel("+");
            movePnl.add(scaleHeightPlusBtn);
           
            scaleHeightLessBtn.setBounds(128, 0, 32, 32);
            scaleHeightLessBtn.setLabel("-");
            movePnl.add(scaleHeightLessBtn);
         //More boring GUI adding code
           
      //Add All GUI to Applet
     add(canvas);
      add(descriptionTxt);
      //more GUI added here
     
      //Add Event Listeners for all GUI
     backToGalleryBtn.addActionListener(this);
      //More of those
  }
   
   public void start() {
      animator.setRunAsFastAsPossible(false);
      animator.start();
   }

   public void stop() {
      animator.stop();
   }
   
   public void actionPerformed(ActionEvent unknownEvent){
      //Handles GUI actions
  }
}


Actual Applet Code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
public class ArtLab implements GLEventListener{
   private float LOOK_AT_DIST = 100.0f;
   private final static float FOV = 45.0f;
   private final static float DEFAULT_ART_SIZE = 10.0f;
   private final static float CAMERA_MOVEMENT_INCREMENT = 0.2f;
   private GL gl;
   private GLU glu = new GLU();
   
   //Camera Points
  private Point3D CameraLook = new Point3D(0.0f, 1.0f, 0.0f);
   private Point3D Camera = new Point3D(5.0f, 5.0f, 10.0f,  0,270,0);

   private Point3D standAloneCamera = standAloneCameraReset;
   
   //Gallery Objects
  private LinkedList <Plane> walls = new LinkedList <Plane> ();
   private Plane floor = null;
   private Plane ceiling = null;
   private LinkedList <Art> artThumbNails = new LinkedList <Art> ();
   
   //Stand-alone art Object
  private Art standAlone = null;
   
   //Huds
  private HeadsUpDisplay cursor = new HeadsUpDisplay(0.50f, 0.50f, 0.064f, 0.128f);
   
   //Display Lists
  private int room;
   private int art;
   
   //TOP
  private ArtLabAppletLaunch artLabTOP;

   //Application Variables
  private int lastSelectedImage = -1, galleryImage = -1;
   private boolean inGallery = true;
   private boolean hasResetCamera = false;
   
   public ArtLab(ArtLabAppletLaunch cg) {
       cg.addKeyListener(new KeyboardListenerInterface() {
          public void buttonPressed(int i){handleKeyboardInput(i);}
       });
       
       artLabTOP = cg;
   }
   
   public void init(GLAutoDrawable drawable) {
       gl = drawable.getGL(); //Set Up GL
      gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);//Black GL clear color
      gl.glEnable(GL.GL_DEPTH_TEST);
       gl.glClearDepth(1.0f);
       gl.glDepthFunc(GL.GL_LEQUAL);
       gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
       
       //Initialize Camera
      updateCamera();
       
       //Create Room Environment
      walls.add(new Plane(15f, 5.0f, 0f,
            30.0f, 10.0f, 0.0f));
       walls.add(new Plane(15f, 5.0f, 30f,
            30.0f, 10.0f, 0.0f));
       walls.add(new Plane(0f, 5.0f, 15f,
            0.0f, 10.0f, 30.0f));
       walls.add(new Plane(30f, 5.0f, 15f,
            0.0f, 10.0f, 30.0f));
       floor = new Plane(15f, 0.0f, 15f,
            30.0f, 0.0f, 30.0f);
       ceiling = new Plane(15f, 10.0f, 15f,
            30.0f, 0.0f, 30.0f);
       
       //Create Paintings
      artThumbNails.add(new Art(15f, 5.0f, 0.2f,
            5.0f, 4.5f, 0.0f));
       //etc
     
       //Create Stand-Alone Art
      standAlone = new Art(0.0f, 5.0f, 0f,
            5.0f, 5.0f, 0.0f);
       
       //Load Images

       //Load Textures From Images
     
       //Create Display List's
      room = gl.glGenLists(1);
       art = gl.glGenLists(2);
       
       //Populate Room Display List
      gl.glNewList(room, GL.GL_COMPILE);
          //Draw Walls
         for(int index = 0; index < walls.size(); index++){
             gl.glPushMatrix();
                gl.glTranslatef(walls.get(index).X, walls.get(index).Y, walls.get(index).Z);
                walls.get(index).draw(gl);
             gl.glPopMatrix();
          }
         //Draw Floor
        gl.glPushMatrix();
            gl.glTranslatef(floor.X, floor.Y, floor.Z);
            floor.draw(gl);
         gl.glPopMatrix();
         //Draw Ceiling
        gl.glPushMatrix();
            gl.glTranslatef(ceiling.X, ceiling.Y, ceiling.Z);
            ceiling.draw(gl);
         gl.glPopMatrix();
       gl.glEndList();
       
     //Populate Art Display List
      gl.glNewList(art, GL.GL_COMPILE);
       //Draw Art in Canvas's
         for(int index = 0; index < artThumbNails.size(); index++){
             gl.glPushMatrix();
                gl.glTranslatef(artThumbNails.get(index).X, artThumbNails.get(index).Y,artThumbNails.get(index).Z);
                artThumbNails.get(index).draw(gl);
             gl.glPopMatrix();
          }
       gl.glEndList();
    }
   
   public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
      GL gl = drawable.getGL();
      if (height == 0){height = 1;} //Avoid Division by Zero Error
     
      gl.glViewport(x, y, width, height);
      gl.glMatrixMode(GL.GL_PROJECTION);
      gl.glLoadIdentity();
      glu.gluPerspective(FOV, (float)width/(float)height, 1, LOOK_AT_DIST);

      gl.glMatrixMode(GL.GL_MODELVIEW);
      gl.glLoadIdentity();
   }
   
   public void display(GLAutoDrawable drawable) {
      GL gl = drawable.getGL();
      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
      gl.glLoadIdentity();

      if(inGallery){
         //Use In Gallery Camera
        glu.gluLookAt(Camera.X, Camera.Y, Camera.Z,
               CameraLook.X, CameraLook.Y, CameraLook.Z, 0,1,0);
         //Environment
        gl.glCallList(room);
         gl.glCallList(art);
         //Heads Up Displays
        begin2D();
            gl.glPushMatrix();
               cursor.draw(gl);
            gl.glPopMatrix();
         end2D();
      } else {
         //Use Solo Art Viewing Camera
        glu.gluLookAt(standAloneCamera.X, standAloneCamera.Y, standAloneCamera.Z,
               CameraLook.X, CameraLook.Y, CameraLook.Z, 0,1,0);
         //Environment for Viewing Single Art-work
        gl.glPushMatrix();
            gl.glTranslatef(standAlone.X, standAlone.Y, standAlone.Z);
            standAlone.drawBigArt(gl);
         gl.glPopMatrix();
      }
     
       gl.glFlush();
   }
   
    private void begin2D() {
        gl.glMatrixMode(GL.GL_PROJECTION);        
        gl.glPushMatrix();        
           gl.glLoadIdentity();        
           gl.glOrtho(0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f);        
           gl.glMatrixMode(GL.GL_MODELVIEW);        
              gl.glPushMatrix();        
                 gl.glLoadIdentity();        
                 gl.glDisable(GL.GL_DEPTH_TEST);        
                 gl.glDisable(GL.GL_LIGHTING);
    }
   
    private void end2D() {
                gl.glEnable(GL.GL_LIGHTING);
                gl.glEnable(GL.GL_DEPTH_TEST);
                gl.glMatrixMode(GL.GL_PROJECTION);
             gl.glPopMatrix();
          gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glPopMatrix();
    }
   
}


Do Display Lists work in Applets?
8  Java Game APIs & Engines / JOGL Development / Re: Applet Troubles..."Error: Class not found: " on: 2009-04-26 00:36:11
http://www.filedropper.com/artlabplz

that's the link for download.
9  Java Game APIs & Engines / JOGL Development / Re: Applet Troubles..."Error: Class not found: " on: 2009-04-25 16:28:41
Why could it corrupted?
How can I get it to not be corrupted?
10  Java Game APIs & Engines / JOGL Development / Re: Applet Troubles..."Error: Class not found: " on: 2009-04-25 01:44:59
The link is broken for some reason but if you copy and paste the URL in it will work. I don't know why it's doing that...
11  Java Game APIs & Engines / JOGL Development / Re: Applet Troubles..."Error: Class not found: " on: 2009-04-24 22:14:34
Sorry about the link being broken. I've tried creating new projects with different names which changed my export .jar name (over and over).

here's the updated link and applet code:
http://www.caseykneale.000space.com/ArtLaboratory.jar

Here's my Applet Code(HTML)
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
<applet code="org.jdesktop.applet.util.JNLPAppletLauncher" width=480 height=320
      archive="http://download.java.net/media/applet-launcher/applet-launcher.jar,
               http://download.java.net/media/jogl/builds/archive/jsr-231-webstart-current/jogl.jar,
               http://download.java.net/media/gluegen/webstart/gluegen-rt.jar,
               http://caseykneale.000space.com/ArtLaboratory.jar"
>
   <param name="codebase_lookup" value="false">
   <param name="subapplet.classname" value="ArtLabAppletLaunch">
   <param name="subapplet.displayname" value="ArtLab - Casey Kneale">
   <param name="noddraw.check" value="true">
   <param name="progressbar" value="true">
   <param name="jnlpNumExtensions" value="1">
   <param name="jnlpExtension1" value="http://download.java.net/media/jogl/builds/archive/jsr-231-webstart-current/jogl.jnlp">
</applet>


Steveyo I'll look into that... I don't see why Eclipse and Net-Beans would both build un-working manifest files though?

Someone said that the Jar file was corrupted?

I'm not sure exactly what you mean gouessej. The Applet runs perfectly fine in the IDE(which is good). 

I just rebuilt an old project into a new .Jar and it works perfectly fine. The code is very similar... I'm wondering if I have like class-path errors with perhaps how I imported my "Media" folder to my project. Blah.

Is there a different way to deploy Multi-Class applet's without using a .jar? At this point I don't care if things are practical I just really want to be able to show my professor some side-projects of mine so I can convince him to be a computer science tutor.

Thanks for replying.
12  Java Game APIs & Engines / JOGL Development / Re: Applet Troubles..."Error: Class not found: " on: 2009-04-22 23:14:00
I just downloaded net-beans and had the same exact results. What is going on? Until I figure this out there is no point in even programming with Java.
13  Java Game APIs & Engines / JOGL Development / Re: More Applet Troubles... on: 2009-04-22 00:34:22
I am starting to lose my cool...
here's my applet code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
<applet code="org.jdesktop.applet.util.JNLPAppletLauncher" width=480 height=320
      archive="http://download.java.net/media/applet-launcher/applet-launcher.jar,
               http://download.java.net/media/jogl/builds/archive/jsr-231-webstart-current/jogl.jar,
               http://download.java.net/media/gluegen/webstart/gluegen-rt.jar,
               http://caseykneale.000space.com/gallery2.jar"
>
   <param name="codebase_lookup" value="false">
   <param name="subapplet.classname" value="ArtLabAppletLaunch">
   <param name="subapplet.displayname" value="ArtLab - Casey Kneale">
   <param name="noddraw.check" value="true">
   <param name="progressbar" value="true">
   <param name="jnlpNumExtensions" value="1">
   <param name="jnlpExtension1" value="http://download.java.net/media/jogl/builds/archive/jsr-231-webstart-current/jogl.jnlp">
</applet>


Here's the .jar
http://www.caseykneale.000space.com/gallery2.jar

I checked a working .jar file of mine's manifest that is NOT the issue. I'm clueless. I did the same thing twice and got two very different results..
14  Java Game APIs & Engines / JOGL Development / [solved]Applet Troubles..."Error: Class not found: " on: 2009-04-21 20:07:09
I guess JVM cannot find my main class?

Even though when making my .Jar file, in Eclipse, I select my main class?

Any idea's whats going on?

Edit: It says "Can not fin artLabApplet.class"
When I opened the .jar and the manifest file says it's there, and it is in the .jar...Huh

Edit #2: I've tried every single option I've tried adding a Main function to the file I want to be the "main", I've tried everything I could think of. Any ideas would be reallly beneficial. Hour 6 so far on getting a working applet onto the web...
15  Java Game APIs & Engines / JOGL Development / Re: Camera Can't Look Directly Down? on: 2009-04-19 18:03:45
figured it out haha

1  
2  
3  
glu.gluLookAt(Camera.X, Camera.Y, Camera.Z,
            CameraLook.X, CameraLook.Y, CameraLook.Z,
            1,0,0);

^^^^^ The above works.

vvvvvvvv the below was the issue
1  
2  
3  
glu.gluLookAt(Camera.X, Camera.Y, Camera.Z,
            CameraLook.X, CameraLook.Y, CameraLook.Z,
            0,1,0);

16  Java Game APIs & Engines / JOGL Development / [SOLVED]Camera Can't Look Directly Down? on: 2009-04-19 17:51:55
 Undecided I just realized that the openGL camera can't look directly downward (the XZ axis).
I understand why, it's because how could OpenGl derive an angle/perspective with say the given commands
1  
2  
       private Point3D Camera = new Point3D(0.0f, 16.0f, 0.0f);
private Point3D CameraLook = new Point3D(0.0f, 00.0f, 0.0f);

Well it couldn't.

How can I work around this?

I don't really need the perspective to change. I guess this is what I get for making 2-D esque games in 3-D.

Things I've tried so far:
1. Offsetting the camera by miniscule ammounts (ex 0.1f, 0, 0), but that creates a shuddering effect and makes my quads all choppy.
2. glOrtho, either I'm not setting the viewport up right or it's not working for some reason?
17  Java Game APIs & Engines / JOGL Development / Re: [SOLVED] How to invoke display() - react on changed value on: 2009-04-19 15:28:10
Nicely structured code, also thanks for sharing your solution rather then just saying you figured it out Cheesy
18  Java Game APIs & Engines / JOGL Development / Re: Bouncing objects off "walls" on: 2009-04-18 01:07:24
wow... FINALLLY SOLVED.
I only tested it on one wall so I'm not 100%, but I think this is it Smiley
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
//Start point of Wall line
Vector2D collisionV1 = new Vector2D(wall.X - (wall.Width/2), wall.Z - (wall.Depth/2));
//End point of Wall line
Vector2D collisionV2 = new Vector2D(wall.X + (wall.Width/2), wall.Z - (wall.Depth/2));
           
//Create Line Vector
Vector2D surfaceVector = collisionV2.sub(collisionV1);
           
//Start point of intersecting line
Vector2D velocityVector1 = ballBehavior.toVector2D();
//End Point of the intersecting line
Vector2D velocityVector2 = ballBehavior.movePointForward(10f).toVector2D();
//Create Line Vector
Vector2D velocityVector = velocityVector2.sub(velocityVector1);
           
//Normalize the two surface vector
surfaceVector = surfaceVector.normalize();
           
//Get the Normal by flipping the X and Y
Vector2D normal = new Vector2D( surfaceVector.Y, surfaceVector.X);
           
float vectorX = surfaceVector.dotProduct(surfaceVector, velocityVector);
float vectorY = surfaceVector.dotProduct(normal, velocityVector);
//Make the VectorY negative as to "flip" the collision
vectorY = -vectorY;
                     
Vector2D mathVector = normal.mul(vectorY);//To simplify the final operation
Vector2D bouncedVector = surfaceVector.mul(vectorX).add(mathVector);
                     
//Place on Object on the Point of the reflection
reflect = new Point2D(bouncedVector.X, bouncedVector.Y);
   
19  Java Game APIs & Engines / JOGL Development / Re: How to invoke display() - react on changed value on: 2009-04-17 22:47:05
So all your trying to do is after a function/method call change a variable which moves your "scene" around?

I always thought Display was automaticly called every "frame"...

If your post some of your code I can help you figure out what your problem is, but you shouldn't have to invoke display() as it's already being invoked. Much like "paint()" of the graphics class(I think).
20  Java Game APIs & Engines / JOGL Development / Re: Bouncing objects off "walls" on: 2009-04-17 20:05:07
here's my vector class
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
public class Vector2D {
    public float X = 0.0f, Y = 0.0f;

    public Vector2D() {}
    public Vector2D( float x, float y ) { X = x; Y = y; }
    public Vector2D( Vector2D a ) { X = a.X; Y = a.Y; }
   
    public float length() {
        return (float) Math.sqrt( (X * X) + (Y * Y) );
    }

    public Vector2D normalize(){
        float len = length();
        if (len > 0f || len < 0f) {
            X /= len;
            Y /= len;
        }
        return new Vector2D(X, Y);
    }
   
    public float dotProduct( Vector2D A, Vector2D B) {                      
        return (A.X * B.X) + (A.Y * B.Y);
    }

    public Vector2D add( Vector2D a ) {
        X += a.X;
        Y += a.Y;
        return new Vector2D(X, Y);
    }
   
    public Vector2D sub( Vector2D a ) {
        X -= a.X;
        Y -= a.Y;
        return new Vector2D(X, Y);
    }

    public Vector2D mul( Vector2D a ) {
        X *= a.X;
        Y *= a.Y;
        return new Vector2D(X, Y);
    }

    public Vector2D mul( float scalar ) {
        X *= scalar;
        Y *= scalar;
        return new Vector2D(X, Y);
    }
   
}


But how do you turn a line into a vector if you only know it's two end points?

edit:
I found this:
Quote
In order to write down the vector equation of this line, we need to know two things.

    * We have to know the position vector of some point which lies on the line, like a on my diagram.
    * We have to know a vector which gives the direction of the line, like b in my diagram. This is called a direction vector.

Then the position vector r of any general point P on the line is given by the equation
r = a + tb
but to be honest... I don't really understand how to program the "direction vector" thing?

Edit #2: Now I'm REALLLY confused. For a direction vector you need degrees?
http://www.analyzemath.com/vector_calculators/magnitude_direction.html
so do I need a direction vector, or just a vector, or the vector equation of a line(consisting of both)?

edit # 3: Wait so a vectors direction is derived from the line it makes from the origin 0,0?
21  Java Game APIs & Engines / JOGL Development / Re: Bouncing objects off "walls" on: 2009-04-17 19:04:15
I see what you mean now h3ckboy. If only I could tweak things by their angles verses vectors...But everyone so far has said this is vector math.

hmm... time to try this from a different "angle" har har har...<cheesey>

I think the problem is this.

The "vectors" I made aren't real vectors. And I still cannot find a way to programmaticly(made-up word) turn a LINE (two end-points{X1,Y1}{X2,Y2}) into a "direction vector". Anyone just wanna help me with the understanding of this, or do I actually already have it? Link's, concepts, anything and everything would be appreciated, right now it's looking like 14 hours of wasted time.
22  Java Game APIs & Engines / JOGL Development / Re: Bouncing objects off "walls" on: 2009-04-16 19:03:59
I found out that if my degree of "rotation" is less then 90 then it at least bounces back towards the blue box, but if it's greater than 90, then it bounces through the green wall(with the original code I posted)

Just saw orangytangs edit, I'm gonna try to figure it out.

Still no dice...
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
if(intersectionPoint.X != 0f && intersectionPoint.Y != 0f){//If Lines Intersect
     //Start point of Wall line
     Vector2D collisionV1 = new Vector2D(wall.X - (wall.Width/2), wall.Z - (wall.Depth/2));
      //End point of Wall line
     Vector2D collisionV2 = new Vector2D(wall.X + (wall.Width/2), wall.Z - (wall.Depth/2));
      //Subtract the two wall vectors
     Vector2D surfaceVector = collisionV2.sub(collisionV1);
      //Normalize the two wall vectors
     surfaceVector = surfaceVector.normalize();
           
      //Get the Normal
     Vector2D normal = new Vector2D( surfaceVector.Y, -surfaceVector.X);
           
      //Start point of intersecting line
     Vector2D velocityVector1 = ballBehavior.toVector2D();
      //End Point of the intersecting line
     Vector2D velocityVector2 = ballBehavior.movePointForward(10f).toVector2D();
           
      float vectorX = surfaceVector.dotProduct(surfaceVector, velocityVector1);
      float vectorY = surfaceVector.dotProduct(normal, velocityVector2);
      //Make the VectorY negative as to "flip" the collision
     vectorY =  -vectorY;
           
      Vector2D bouncedVector = surfaceVector.mul(vectorX).add(normal.mul(vectorY));
           
      //Place on Object on the Point of the reflection
     reflect = new Point2D(bouncedVector.X, bouncedVector.Y);
   }


is it because my vectors for my "lines" are just the two end points on my line segments?

edit:
found a good web-site but can't make programming sense of it...
http://www-cs-students.stanford.edu/~adityagp/final/node3.html

edit #2: should this be moved to game physics?
23  Java Game APIs & Engines / JOGL Development / Re: Bouncing objects off "walls" on: 2009-04-16 18:52:30
NeHe says
Quote
R is the new direction vector
I is the old direction vector before the collision
N is the Normal at the collision point

The new vector R is calculated as follows:

R= 2*(-I dot N)*N + I

The restriction is that the I and N vectors have to be unit vectors. The velocity vector as used in our examples represents speed and direction. Therefore it can not be plugged into the equation in the place of I, without any transformation. The speed has to be extracted. The speed for such a velocity vector is extracted finding the magnitude of the vector. Once the magnitude is found, the vector can be transformed to a unit vector and plugged into the equation giving the reflection vector R. R shows us now the direction, of the reflected ray, but in order to be used as a velocity vector it must also incorporate the speed. Therefore it gets, multiplied with the magnitude of the original ray, thus resulting in the correct velocity vector.
I am currently taking the normal of just the colliding wall... lemme try to play with this.. If this is even right.

Edit:
...
Now I'm seriously just so confused... Could anyone lend a hand here? I've been given 3 ways to do this, and have found another two, I bet they all work, but honestly I can't get any of them to work. I promise to post the source-code once it's all good and done just so no one ever has to do this again.
24  Java Game APIs & Engines / JOGL Development / Re: Bouncing objects off "walls" on: 2009-04-16 18:25:40
I discovered that

Vector2D normal = new Vector2D( surfaceVector.Y, surfaceVector.X * -1);

produces the opposite effect as

Vector2D normal = new Vector2D( surfaceVector.Y * -1, surfaceVector.X );

So I'm going to assume that is the faulty line. However, I'm not sure how to fix it, or if that is actually the case...

H3ckboy if you look at the picture top right hand side, it's off by over 180 degreees(I think). This is real weird.
edit -
JSon sorry I didn't see that link you posted before. I'm looking into it now!
Edit#2 - Tried to sift through that NeHe Code and honestly... Either it's poorly written for understanding or I'm a poor reader.
25  Java Game APIs & Engines / JOGL Development / Re: Bouncing objects off "walls" on: 2009-04-16 16:55:05
Will do! Hey by negating the variable for the normal you meant multiplying it by -1 right? And not omitting it?

But thanks for helping me through this guys haha. Hopefully one I figure this out I'll have a much better understanding of vectors.


Here's a picture of what's going on(I already apologize for the size):
<img src="http://i310.photobucket.com/albums/kk420/SmaerdsDreams/angles.gif">
Stupid image won't show up...Here's a link to it...
http://i310.photobucket.com/albums/kk420/SmaerdsDreams/angles.gif
The white box is where you are "aiming".
The green box is the colliding "wall".
The blue box is where the line is "cast" from.
The white line is the path of "lazer".
26  Java Game APIs & Engines / JOGL Development / Re: Bouncing objects off "walls" on: 2009-04-16 16:31:43
Everything makes alot more sense then it did last night... Like alot more sense. But there's a problem with my code, anyone wanna help debug? It is calculating new points but I know their wrong because sometimes they are behind the collision line Sad.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
if(intersectionPoint.X != 0f && intersectionPoint.Y != 0f){//If Lines Intersect
  System.out.println("Collision Has Occured!");
   //Start point of Wall line
  Vector2D collisionV1 = new Vector2D(wall.X - (wall.Width/2), wall.Z - (wall.Depth/2));
   //End point of Wall line
  Vector2D collisionV2 = new Vector2D(wall.X + (wall.Width/2), wall.Z - (wall.Depth/2));
   //Subtract the two wall vectors
  Vector2D surfaceVector = collisionV2.sub(collisionV1);
   //Normalize the two wall vectors
  surfaceVector = surfaceVector.normalize();
           
   //Get the Normal
  Vector2D normal = new Vector2D( ( surfaceVector.Y * -1), surfaceVector.X);
           
   //Start point of intersecting line
  Vector2D velocityVector1 = ballBehavior.toVector2D();
   //End Point of the intersecting line
  Vector2D velocityVector2 = ballBehavior.movePointForward(10f).toVector2D();
   float vectorX = surfaceVector.dotProduct(surfaceVector, velocityVector1);
   float vectorY = surfaceVector.dotProduct(surfaceVector, velocityVector2);
   //Make the VectorY negative as to "flip" the collision
  vectorY = -vectorY;
           
   Vector2D mathVector = normal.mul(vectorY);//To simplify the final operation
  Vector2D bouncedVector = surfaceVector.mul(vectorX).add(mathVector);
           
   //Place on Object on the Point of the reflection
  endPoint.X = bouncedVector.X;
   endPoint.Z = bouncedVector.Y;
}


and maybe I messed up my Vector2D class...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
public class Vector2D {
    public float X = 0.0f, Y = 0.0f;
    public float velocity = 1.0f;
   
    public Vector2D() {}
    public Vector2D( float x, float y ) { X = x; Y = y; }
    public Vector2D( Vector2D a ) { X = a.X; Y = a.Y; }
   
    public float length() {
        return (float) Math.sqrt( (X * X) + (Y * Y) );
    }

    public Vector2D normalize(){
        float len = length();
        if (len > 0f || len < 0f) {
            X /= len;
            Y /= len;
        }
        return new Vector2D(X, Y);
    }
   
    public float dotProduct(Vector2D A, Vector2D B) {                      
        return (A.X * B.X) + (A.Y * B.Y);
    }

    public Vector2D add( Vector2D a ) {
        X += a.X;
        Y += a.Y;
        return new Vector2D(X, Y);
    }
   
    public Vector2D sub( Vector2D a ) {
        X -= a.X;
        Y -= a.Y;
        return new Vector2D(X, Y);
    }

    public Vector2D mul( Vector2D vec ) {
        X *= vec.X;
        Y *= vec.Y;
        return new Vector2D(X, Y);
    }

    public Vector2D mul( float scalar ) {
        X *= scalar;
        Y *= scalar;
        return new Vector2D(X, Y);
    }
   
}
27  Java Game APIs & Engines / JOGL Development / Re: Bouncing objects off "walls" on: 2009-04-15 21:57:18
Okay so for a vector I need,
X and Y coordinates for the Point. (I already have this in my Point2D Class)
And a stored angle Value?

Then the dot product aka scalar product is just
Let A & B be 2-D Vector's
dotProduct(Vector A, Vector B) {                       
            return A.X * B.X + A.Y * B.Y;
}

Huh Maybe

I'm just confused how a line get's represented by a vector( a point + magnitude)

does my 2D vector class look okay??

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
public class Point2D {
   public float X = 0f, Y = 0f;//Point Locations
  public float angle = 0f;//Point Rotations
     
   public Point2D(float x, float y){X = x; Y = y;}
     
   public Point2D(float x, float y, float angleIn)
      {X = x; Y = y; angle = angleIn;}
     
   public Point2D(){};
     
   public Point2D movePointForward(float distance){
      Point2D newPoint = new Point2D();
      double tmpAngle = Math.toRadians(angle);
      newPoint.X = (float)(Math.cos(tmpAngle) * distance) + X;
      newPoint.Y = (float)(Math.sin(tmpAngle) * distance) + Y;
      newPoint.angle = angle;
      return newPoint;
   }
   
   public static float dotProduct(Point2D A, Point2D B) {                      
        return A.X * B.X + A.Y * B.Y;
    }

    public float magnitude() {
        return (float) Math.sqrt(X * X + Y * Y);
    }

    public void normalize() {
        float M = magnitude();
        if (M > 0f || M < 0f) {
            X /= M;
            Y /= M;
        }
    }
   
   
   public void wrapAngle(){angle = wrapValue(angle, 360.0f);}
   
   public float wrapValue(float in, float max){return in % max;}
}
28  Java Game APIs & Engines / JOGL Development / Re: Bouncing objects off "walls" on: 2009-04-15 21:28:31
Oh yeah and inertia/momentum/velocity is pretty irrelvant(I think) because I am dealing with "light" verses an actual object bouncing.

Damn.. I really do need to learn vectors...
29  Java Game APIs & Engines / JOGL Development / Re: Bouncing objects off "walls" on: 2009-04-15 20:19:22
I guess I'm not longer dealing with shapes I'm doing it strictly with segments.

Here's what I have so far:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
   public void handleKeyboardInput(int ki){
      if(ki == KeyEvent.VK_SPACE){
         Point2D intersectionPoint = lineIntersectionTest();
         if(intersectionPoint != null){
            System.out.println(intersectionPoint.X + "\n" + intersectionPoint.Y);
            endPoint.X = intersectionPoint.X;
            endPoint.Z = intersectionPoint.Y;
            //Now I have the points of collision on the line
        }
         
      }
   }

   public Point2D lineIntersectionTest(){
      double intersectionX, intersectionY;
      Point2D Line1P1 = ballBehavior;
      Point2D Line1P2 = ballBehavior.movePointForward(10f);
     
      Point2D Line2P1 = new Point2D(wall.X - (wall.Width/2), wall.Z - (wall.Depth/2));
      Point2D Line2P2 = new Point2D(wall.X + (wall.Width/2), wall.Z - (wall.Depth/2));
     
      double denominator, numeratorA, numeratorB, r, s;

      denominator =  ( ( Line2P2.Y - Line2P1.Y ) * ( Line1P2.X - Line1P1.X ) ) -
                  ( ( Line2P2.X - Line2P1.X ) * ( Line1P2.Y - Line1P1.Y ) );
   
      //if(denominator != 0){ //check for parrellel lines
     numeratorA = ( ( Line2P2.X - Line2P1.X) * (Line1P1.Y - Line2P1.Y ) ) -
                ( ( Line2P2.Y - Line2P1.Y) * (Line1P1.X - Line2P1.X ) );

      numeratorB = ( (Line1P2.X - Line1P1.X ) * ( Line1P1.Y - Line2P1.Y) ) -
                ( (Line1P2.Y - Line1P1.Y ) * ( Line1P1.X - Line2P1.X) );

      r = ( numeratorA / denominator ) ;
       s = ( numeratorB / denominator ) ;

       if(r >= 0.0f && r <= 1.0f  &&
          s >= 0.0f && s <= 1.0f){
          intersectionX = r * (Line1P2.X - Line1P1.X) + Line1P1.X;
           intersectionY = r * (Line1P2.Y  - Line1P1.Y) + Line1P1.Y;
           return new Point2D((float) intersectionX, (float) intersectionY);
       }
       
       return new Point2D();
   }


So far I have found the collision point of the  segments Cheesy.

I only posted the code so you guys know I'm actually trying to sort through this...
I've been googling for a while and cannot for the life of my find out how to normalise a segment. Anyone got a link or a brief explanation of what I might have to do? Or is that even possible? Is it just the midpoint?

Or should I be trying to calculate the angle the two lines make?
30  Java Game APIs & Engines / JOGL Development / Re: Bouncing objects off "walls" on: 2009-04-15 18:07:54
Hmmm I understand Riven's link thanks. I'm gonna play with this a little bit and once I get it to work I'll post the code. Cheesy

also thanks orangytang I'm gonna try out both and see which one is easiest to work with. Vector maths + me = new aquantences.
Pages: [1] 2 3 ... 5
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (23 views)
2014-09-12 09:08:26

Norakomi (56 views)
2014-09-10 13:57:51

TehJavaDev (69 views)
2014-09-10 06:39:09

Tekkerue (34 views)
2014-09-09 02:24:56

mitcheeb (56 views)
2014-09-08 06:06:29

BurntPizza (40 views)
2014-09-07 01:13:42

Longarmx (26 views)
2014-09-07 01:12:14

Longarmx (32 views)
2014-09-07 01:11:22

Longarmx (31 views)
2014-09-07 01:10:19

mitcheeb (39 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!