Show Posts
|
|
Pages: [1] 2 3 ... 5
|
|
1
|
Java Game APIs & Engines / JOGL Development / Re: Debugging my render code
|
on: 2009-05-19 17: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 05: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.
|
|
|
|
|
6
|
Java Game APIs & Engines / JOGL Development / Re: Applet Troubles..."Error: Class not found: "
|
on: 2009-04-28 02:22:27
|
Okay I recently found out... I can't upload any files anywhere?  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 03: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
| public class ArtLabAppletLaunch extends Applet implements ActionListener { private static final long serialVersionUID = 1L; protected GLCanvas canvas; protected Animator animator; private KeyboardHandler keyboardHandler = new KeyboardHandler(); private TextArea descriptionTxt = new TextArea(); private Button backToGalleryBtn = new Button(); private ArtLab artLabProcess = new ArtLab(this); 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() { 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); 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); add(canvas); add(descriptionTxt); backToGalleryBtn.addActionListener(this); } public void start() { animator.setRunAsFastAsPossible(false); animator.start(); }
public void stop() { animator.stop(); } public void actionPerformed(ActionEvent unknownEvent){ } } |
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(); 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; private LinkedList <Plane> walls = new LinkedList <Plane> (); private Plane floor = null; private Plane ceiling = null; private LinkedList <Art> artThumbNails = new LinkedList <Art> (); private Art standAlone = null; private HeadsUpDisplay cursor = new HeadsUpDisplay(0.50f, 0.50f, 0.064f, 0.128f); private int room; private int art; private ArtLabAppletLaunch artLabTOP;
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(); gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 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); updateCamera(); 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); artThumbNails.add(new Art(15f, 5.0f, 0.2f, 5.0f, 4.5f, 0.0f)); standAlone = new Art(0.0f, 5.0f, 0f, 5.0f, 5.0f, 0.0f); room = gl.glGenLists(1); art = gl.glGenLists(2); gl.glNewList(room, GL.GL_COMPILE); 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(); } gl.glPushMatrix(); gl.glTranslatef(floor.X, floor.Y, floor.Z); floor.draw(gl); gl.glPopMatrix(); gl.glPushMatrix(); gl.glTranslatef(ceiling.X, ceiling.Y, ceiling.Z); ceiling.draw(gl); gl.glPopMatrix(); gl.glEndList(); gl.glNewList(art, GL.GL_COMPILE); 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;} 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){ glu.gluLookAt(Camera.X, Camera.Y, Camera.Z, CameraLook.X, CameraLook.Y, CameraLook.Z, 0,1,0); gl.glCallList(room); gl.glCallList(art); begin2D(); gl.glPushMatrix(); cursor.draw(gl); gl.glPopMatrix(); end2D(); } else { glu.gluLookAt(standAloneCamera.X, standAloneCamera.Y, standAloneCamera.Z, CameraLook.X, CameraLook.Y, CameraLook.Z, 0,1,0); 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?
|
|
|
|
|
11
|
Java Game APIs & Engines / JOGL Development / Re: Applet Troubles..."Error: Class not found: "
|
on: 2009-04-25 00: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.jarHere'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.
|
|
|
|
|
13
|
Java Game APIs & Engines / JOGL Development / Re: More Applet Troubles...
|
on: 2009-04-22 02: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.jarI 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 22: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...  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 20: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 19:51:55
|
 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?
|
|
|
|
|
18
|
Java Game APIs & Engines / JOGL Development / Re: Bouncing objects off "walls"
|
on: 2009-04-18 03:07:24
|
wow... FINALLLY SOLVED. I only tested it on one wall so I'm not 100%, but I think this is it  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
| Vector2D collisionV1 = new Vector2D(wall.X - (wall.Width/2), wall.Z - (wall.Depth/2)); Vector2D collisionV2 = new Vector2D(wall.X + (wall.Width/2), wall.Z - (wall.Depth/2)); Vector2D surfaceVector = collisionV2.sub(collisionV1); Vector2D velocityVector1 = ballBehavior.toVector2D(); Vector2D velocityVector2 = ballBehavior.movePointForward(10f).toVector2D(); Vector2D velocityVector = velocityVector2.sub(velocityVector1); surfaceVector = surfaceVector.normalize(); Vector2D normal = new Vector2D( surfaceVector.Y, surfaceVector.X); float vectorX = surfaceVector.dotProduct(surfaceVector, velocityVector); float vectorY = surfaceVector.dotProduct(normal, velocityVector); vectorY = -vectorY; Vector2D mathVector = normal.mul(vectorY);Vector2D bouncedVector = surfaceVector.mul(vectorX).add(mathVector); 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-18 00: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 22: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: 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.htmlso 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 21: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 21: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){ Vector2D collisionV1 = new Vector2D(wall.X - (wall.Width/2), wall.Z - (wall.Depth/2)); Vector2D collisionV2 = new Vector2D(wall.X + (wall.Width/2), wall.Z - (wall.Depth/2)); Vector2D surfaceVector = collisionV2.sub(collisionV1); surfaceVector = surfaceVector.normalize(); Vector2D normal = new Vector2D( surfaceVector.Y, -surfaceVector.X); Vector2D velocityVector1 = ballBehavior.toVector2D(); Vector2D velocityVector2 = ballBehavior.movePointForward(10f).toVector2D(); float vectorX = surfaceVector.dotProduct(surfaceVector, velocityVector1); float vectorY = surfaceVector.dotProduct(normal, velocityVector2); vectorY = -vectorY; Vector2D bouncedVector = surfaceVector.mul(vectorX).add(normal.mul(vectorY)); 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.htmledit #2: should this be moved to game physics?
|
|
|
|
|
23
|
Java Game APIs & Engines / JOGL Development / Re: Bouncing objects off "walls"
|
on: 2009-04-16 20:52:30
|
NeHe says 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 20: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.
|
|
|
|
|
26
|
Java Game APIs & Engines / JOGL Development / Re: Bouncing objects off "walls"
|
on: 2009-04-16 18: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  . 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){ System.out.println("Collision Has Occured!"); Vector2D collisionV1 = new Vector2D(wall.X - (wall.Width/2), wall.Z - (wall.Depth/2)); Vector2D collisionV2 = new Vector2D(wall.X + (wall.Width/2), wall.Z - (wall.Depth/2)); Vector2D surfaceVector = collisionV2.sub(collisionV1); surfaceVector = surfaceVector.normalize(); Vector2D normal = new Vector2D( ( surfaceVector.Y * -1), surfaceVector.X); Vector2D velocityVector1 = ballBehavior.toVector2D(); Vector2D velocityVector2 = ballBehavior.movePointForward(10f).toVector2D(); float vectorX = surfaceVector.dotProduct(surfaceVector, velocityVector1); float vectorY = surfaceVector.dotProduct(surfaceVector, velocityVector2); vectorY = -vectorY; Vector2D mathVector = normal.mul(vectorY); Vector2D bouncedVector = surfaceVector.mul(vectorX).add(mathVector); 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 23: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; }  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; public float angle = 0f; 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;} } |
|
|
|
|
|
29
|
Java Game APIs & Engines / JOGL Development / Re: Bouncing objects off "walls"
|
on: 2009-04-15 22: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; } } }
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 ) ); 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  . 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?
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|