Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 2 [3] 4
  ignore  |  Print  
  2D Physics System  (Read 24838 times)
0 Members and 1 Guest are viewing this topic.
Offline kevglass

JGO Kernel


Medals: 159
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #60 - Posted 2006-08-11 05:59:57 »

Resolved the issues - demo updated. No new demos so don't get too excited - but energy in the system with restituion is now correctly conserved it seems.

Kev

Offline kevglass

JGO Kernel


Medals: 159
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #61 - Posted 2006-08-12 08:28:34 »

Updated again:

- Collision reactored so it can be used separately
- Collision callback listeners added
- Line collision detection touched up - seems more reasonable now
- Body exlcusion added - you can now define sets of bodies that don't collide with each other
- Fixed Joints added
- Elastic like joints added though not nearly right yet
- Few more demos added to the box to test out things above

Webstart is still: http://www.cokeandcode.com/phys2d/phys2d.jnlp
SVN: http://code.google.com/p/phys2d/
Builds: http://www.cokeandcode.com/phys2d/

Kev

Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #62 - Posted 2006-08-12 09:48:31 »

Neat Grin

弾幕 ☆ @mahonnaiseblog
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kevglass

JGO Kernel


Medals: 159
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #63 - Posted 2006-08-13 21:47:00 »

In an attempt to make the phys2d project look more cool and trendy (coolness factor is everything) I'm putting together a more polished looking demo:


It's currently called PhysiBall.
Controls are left/right cursors to apply force to the ball, space to jump and R to restart the demo. You need LWJGL compatible hardware (i.e. some up to date OpenGL). Source isn't currently available - will make it so if anyone wants but it's utitlises my main code base (which is also free source) so it might not be too useful.

Webstart is here: http://www.cokeandcode.com/physiball/physiball.jnlp

My aims are:

1) To have a nicer looking demo
2) To weed out problems with the API and missing bits of functionality need for games
3) To find problems with the physics engine through real scenarios

So far, updates/discoveries include:

* A Triangulator Utilty for polygon type shapes
* Adding damping as a world property - allows you to cause bodies to lose energy through heat/sound type things.
* The ability to determine all current contacts with a given body from the World (used to work out when you can jump)
* Two bugs with the physics code that currently prevent you pushing boxes off the edge Sad

If you try the demo and find issues let me know,

Kev

Offline CommanderKeith
« Reply #64 - Posted 2006-08-15 01:40:26 »

Nice job.  But it would be nice if you couldn't  fall off the edge forever & don't know how to restart.  Also, its nice the way the demo with the billiards triangle breaks symmetrically!

Thanks for doing the circle-circle collision by the way, I'm beginning to understand the way the code works now.  May I ask why the custom math & geometry classes are used rather than say java.awt.geom.Point2D.Float?

About polygons: intuitively all we need to do a collision is the

depth of penetration,
point of contact
the normal (this is just the angle of penetration entry, right?)

Using the java.awt.geom.Area class we can find polygons of intersection, and we could work out the above things so could polygon collision be done in this way?  I'd like your view on this method before I waste my time.
Thanks,
Keith

Offline kevglass

JGO Kernel


Medals: 159
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #65 - Posted 2006-08-15 03:02:17 »

Quote
R to restart the demo

Originally there was a dependency on vecmath.jar - however I used so little of it seemed a waste of bandwidth including given how simple the math required is. The custom geometry classes are so there isn't any depdency on AWT/SWT/Whatever. It's a data model not a renderer.

Using AWT classes doesn't seem like a good idea to me, bringing in Area brings in Shape which probably brings in a whole host of AWT stuff - this prevents us building a small binary later if so desired (GCJing out AWT is what I do for instance). I'm not keen on bringing in prescribing the rendering method like that. Also I've used Area in games beforce and do collisions between areas is pretty darn slow. However, I'm open to doing it if there was a really good reason - anyone?

To do the collision you just determine if the polygons intersect. To do the response you need the things you list but the normal is the normal of the surface from which the body is rebounding, not the inverse of penetration velocity (if thats what you meant?) since that'd mean things only ever rebounded straight back on themselfs.

I've not really thought about Polygon/Polygon intersection yet - I guess Area seems like the easiest route - I'm not sure how hard it is otherwise. If you can figure out Triangle/Triangle intersection in some quick form that might work since I recently added a quick&dirty triangulator to the source.

Kev

Offline CommanderKeith
« Reply #66 - Posted 2006-08-15 04:37:11 »

Also I've used Area in games beforce and doing collisions between areas is pretty darn slow.

Area & Shape classes do suck especially the way underlying points can't be got at except through PathIterator  & you can't extend them (final class) Angry.  I've got my own Area implementation that is badly designed & has bugs but it can test for intersections & can produce polygons of intersection.  It could also be useful because it can find the centre of mass of a shape.  I just wanted to know if my ideas about collision were on the right track.  I will clean up my polygon class & try to implement your code with polygons then.

My (faulty) Area-like polygon class extends java.awt.geom.Shape so it can be painted by Java2D but it can be re-worked without that (if I can conjure the talent to get polygons working, that is  Undecided).

Thanks for the help,
Keith

Offline kevglass

JGO Kernel


Medals: 159
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #67 - Posted 2006-08-16 16:04:10 »

Added a couple of new toys to physiball above. You can now play with

a) A stack of boxes woo
b) A seesaw/teeter
c) A rope bridge type contraption

Fixed the issues I've seen/been told about so far.

Kev

Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #68 - Posted 2006-08-16 17:32:30 »

Fixed the issues I've seen/been told about so far.

I'm sill here i'm afraid Wink

Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #69 - Posted 2006-08-16 17:38:43 »

Woa... awesome Smiley

It also seems to run way faster now, but i cant tell for sure since the older version was w/o frame counter.

弾幕 ☆ @mahonnaiseblog
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Death33284

Junior Member





« Reply #70 - Posted 2006-08-17 02:12:56 »

Idea from a newbie:

If you get dynamic line collisions working... couldn't you just make a polygon a group of lines that are linked together?
Offline noblemaster

JGO Ninja


Medals: 20
Projects: 10


Age of Conquest makes your day!


« Reply #71 - Posted 2006-08-17 03:16:02 »

very cool  Grin

Offline CommanderKeith
« Reply #72 - Posted 2006-08-17 05:57:03 »

If you get dynamic line collisions working... couldn't you just make a polygon a group of lines that are linked together?

I don't think that we could get dynamic lines working since with line-line there's no penetration, only intersection.  I'm working on polygons right now but my vector maths skills suck, I'm more into angles & trigonometry.

Kev, that see-saw is awesome, trying to balance it was fun enough, some really amazing games will come out of this project I'm sure!

Offline Micke

Senior Newbie




Yada-yada


« Reply #73 - Posted 2006-08-17 06:52:16 »

Looks (feels!) really cool!

Would it be hard to introduce a third but limited dimension?:
Rotations can only occur as now - around one axis (the "height" axis, if you consider the current view as top-down)
Geoms can only have "height" (apart from what they have now) so that circle would become a standing cylinder (ie aligned to the "height" axis)
Some more math for sure, but would it be "fairly easy" or "a total rethink of everything"?

This sort-of-3d would come in handy for a isometric style games (not necessarily isometric, but for that kind of view)

/M
Offline Evil-Devil

Senior Member


Medals: 2


Fir Tree Master


« Reply #74 - Posted 2006-08-17 10:51:13 »

Of what material is the ball? Or is the gravity that high? I like the demo, but for a ball it does not jump and bounce off enough.

Looks like a medicine ball...
Offline kevglass

JGO Kernel


Medals: 159
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #75 - Posted 2006-08-17 16:28:41 »

I'm sill here i'm afraid Wink

Think I've solved your issue (with the physics) now. Maybe?

Woa... awesome Smiley

It also seems to run way faster now, but i cant tell for sure since the older version was w/o frame counter.

Thanks. The speed up is most due to removing the black lines around elements.

If you get dynamic line collisions working... couldn't you just make a polygon a group of lines that are linked together?

I don't think that we could get dynamic lines working since with line-line there's no penetration, only intersection.  I'm working on polygons right now but my vector maths skills suck, I'm more into angles & trigonometry.

Kev, that see-saw is awesome, trying to balance it was fun enough, some really amazing games will come out of this project I'm sure!

Dynamic lines might actually work as polygons, but it might not be a very efficient scenario. I'd considered when implementing lines but it was just a quick way to get some of the effects I wanted.

Heh on the see-saw - daft isn't it? I'd like to see some games but I'm not sure it's really something anyone is going to use other than for toy projects.

Looks (feels!) really cool!

Would it be hard to introduce a third but limited dimension?:
Rotations can only occur as now - around one axis (the "height" axis, if you consider the current view as top-down)
Geoms can only have "height" (apart from what they have now) so that circle would become a standing cylinder (ie aligned to the "height" axis)
Some more math for sure, but would it be "fairly easy" or "a total rethink of everything"?

This sort-of-3d would come in handy for a isometric style games (not necessarily isometric, but for that kind of view)

/M

Interesting idea. Probably pretty easy - very little extra math, you'd just do a precheck on all collisions (could even be done outside the main collision code) to see if the "height" values overlapped. Yeah, I reakon this would be pretty simple to add.

Of what material is the ball? Or is the gravity that high? I like the demo, but for a ball it does not jump and bounce off enough.

Looks like a medicine ball...

The ball has a low resitution yes, as does the surfaces it's bouncing off. This is set as simply as Body.setRestitution() so not too tricky to change. Combined (surface and ball) restitution is very low so you don't see much bounce. However, with lots of bounce the ball is hard(er) to control which wouldn't make for a very enjoyable demo.

Kev

Offline BloodRain

Junior Member





« Reply #76 - Posted 2006-08-17 21:02:54 »

Insane ! Congratulations ! Wink

PS : At the begining it says to move the ball using the mouse... The ball is moved using the keyboard  Tongue
Offline me

Senior Member


Projects: 4


Java games rock!


« Reply #77 - Posted 2006-08-18 06:05:11 »

Hi Kev,

Very well done!
Definitely the polish is doing wonders to the engine!

I balanced the ball on different objects and it was fun for 5 minutes!!

When playing it fellt a bit like Professor FizzWizzle (http://grubbygames.com/)

Keep those briliant java games coming Kev!

Regards from

M.E.
--------
Offline CommanderKeith
« Reply #78 - Posted 2006-08-18 09:28:17 »

I've run into a snag with the polygon stuff.

Arbiters - the things that referee collisions between polygons (& other shapes) - can only seem to handle 2 Contacts between between a pair of shapes.  Since you need 2 contacts for when a corner of a shape hits a flat face, for convex polygons there may be many intersecting vertices so Arbiters need to handle multiple Contacts.

Kev I haven't even looked at the Arbiter & physics code yet, the polygons & vector math are hard enough.  I was wondering if you'd know anything about making the Arbiter referee 2+ Contacts?  Here's the stack trace of the exception I'm getting as soon as more than two contacts are given to the Arbiter.  I set Arbiter.MAX_POINTS = 10 and I still get this error when a thrid Contact was added in the KPolygonKPolygonCollider.collide(Contact[], Body, Body) method:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
        at net.phys2d.raw.Arbiter.update(Arbiter.java:169)
        at net.phys2d.raw.CollisionSpace.resolve(CollisionSpace.java:167)
        at net.phys2d.raw.strategies.BruteCollisionStrategy.collideBodies(BruteCollisionStrategy.java:55)
        at net.phys2d.raw.CollisionSpace.collide(CollisionSpace.java:61)
        at net.phys2d.raw.World.broadPhase(World.java:227)
        at net.phys2d.raw.World.step(World.java:163)
        at net.phys2d.raw.test.AbstractDemo.start(AbstractDemo.java:183)
        at net.phys2d.raw.test.Demo1.main(Demo1.java:184)

Let me know if you're busy because then I'll have a crack at it over the weekend.
Keith

Offline quixote_arg

Junior Member


Projects: 1


Jengibre


« Reply #79 - Posted 2006-08-18 12:04:59 »

Great! Thanks a lot for the contribution... one tiny request: some docs/tutorials besides the sources? Thanks again
Offline kevglass

JGO Kernel


Medals: 159
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #80 - Posted 2006-08-18 14:43:12 »

Quote
Insane ! Congratulations ! Wink

PS : At the begining it says to move the ball using the mouse... The ball is moved using the keyboard  Tongue

Heh, thanks. Actually it says "use the cursors" which means the cursor keys. However, since it confused you I've updated it to say "cursor keys".

Quote
When playing it fellt a bit like Professor FizzWizzle (http://grubbygames.com/)

Keep those briliant java games coming Kev!

I've never been quite so complimented by any comment on these forums. Prof FizzWizzle is one of my fave games of recent years (all time?). I absolutely love it. Thank you for the motivation.

Quote
Let me know if you're busy because then I'll have a crack at it over the weekend.

Thanks for putting the effort in on this Smiley I'll take a look at Arbiters later today (gotta get through the working day first). The max contact points has been annoying me for a while actually so it looks like it's time to fix it.

You could use the "CollisionTest" class (or an extension of ) to test out your polygon collision code without relying on Arbiters while I try and work out what to do Smiley

PS - KPolygon? special sort of Polygon?
PPS - with contributions to the source I want to try and be strict about coding standards/javadoc from the very start to avoid any issues that we see in other places (call it a less learnt). I'd don't mind doing the reformatting and/or javadocing if it's needed. Apologies if the Java coding standards and javadoc everywhere makes people less likely to contribute.

Quote
Great! Thanks a lot for the contribution... one tiny request: some docs/tutorials besides the sources? Thanks again

This stuff is still pretty new but I'm not sure what you'd be looking for in docs/tutorials. As physics go this is about as simple as it gets. Create World. Create Bodies. Add Bodies to the World. Step world.

Is there something specific I could produce to help you out?

@All

Thanks for the feedback everyone. Much appreciated.

I'll be adding springs as joints next probably and trying to work out how we can have bodies that are pseudo physcial - i.e. moving platforms that are driven from a script, constrained in some way but also work properly with the physics world.

Oh, and working on a totally unrelated space hulk game Wink

Kev

Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #81 - Posted 2006-08-18 16:43:11 »

Quote
've never been quite so complimented by any comment on these forums.

Kev, YOU the loosest slots in Vegas.  Cool
Offline kevglass

JGO Kernel


Medals: 159
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #82 - Posted 2006-08-21 18:33:35 »

I've updated the Arbiter code so MAX_CONTACTS is used every it needs to be. I've upped it to 10 and stuff still seems to work ok Smiley

Kev

Offline CommanderKeith
« Reply #83 - Posted 2006-08-22 01:55:39 »

Awesome  Smiley.  If you get time could you please post a full build of it on cokeandcode since I can't download everything from the SVN repository from this internet computer without clicking every single file from IE.

Thanks,
Keith

PS: let me know when you update the Arbiter file on SVN so I can get it & try it out!  Polygons are basically done (i think) except for when 2 vertices cross & there are 4 lines intersecting each other, but I should be able to fix it soon now that 2+ contact points are possible.

Offline kevglass

JGO Kernel


Medals: 159
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #84 - Posted 2006-08-22 02:29:31 »

How annoying that must be!

Here ya go: http://www.cokeandcode.com/phys2d/

Kev

Offline CommanderKeith
« Reply #85 - Posted 2006-08-22 05:04:07 »

Woo hoo! it works!  Thanks for fixing it!

Besides that vertice problem, polygons collision is working. 

I've deleted all other shape & collision classes like Box & Circle while testing polygons but now I suppose I only have to bring in Circle since a Box is a polygon.

I had to change a bit of your code though to work with polygons.  I chucked out AABox  in favour of the shape keeping its own Point centre & max radius 'circularBound' which are used to do bounds testing.  Also, the shape itself stores its coordinates, so for example when it is rotated, the actual coordinates are changed rather than the body's rotation field.

Also, the polygon currently stores coords in a java.awt.geom.Point2D.Float array. 

Once I get the vertice problem fixed I'll put up a demo, probably in a week at this rate.  What are your thoughts on having a circular bound & having the shape store its own coords?  I use a circular bound around a centroid so that when the polygon is rotated, there's no need to recalculate the bound.  Also when its scaled, the bound can just be scaled.  The polygon stores its array of corners, as well as a circularBound & a point centroid.

Offline kevglass

JGO Kernel


Medals: 159
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #86 - Posted 2006-08-22 16:07:08 »

The shapes keeping their own positions makes sense to me, but the original demo relied on them not working that way. Not sure how you've fixed it - do all the demos still work? OOI, why did you need to change it?

Don't remove the Box collision classes. The box specific code is bound to be more efficient than treating a box as a 4 sided polygon - and since boxes/circles is what most people will end up with it'd be best to keep the common path as performant as possible.

As to circle bounds, I had them originally, changed out when doing the quad space work since it made that much easier. I don't recompute bounds either, just make them big enough for any rotation - pretty similar to circles in that case. Don't really mind which as long as everything continues to work correctly.

Just need the code to integrate with whats there without breaking any of the existing functionality or performance really. As long as it does that I'm happy.

Can't wait to see the working demo!

EDIT:

Quote
Also, the polygon currently stores coords in a java.awt.geom.Point2D.Float array. 

Can we flip them out of this, I'd rather not have any binding to AWT in there if possible.

Kev

Offline Malohkan

Senior Member




while (true) System.out.println("WOO!!!!");


« Reply #87 - Posted 2006-08-22 22:02:17 »

I love the rope bridge thing.  I played with it a bit trying to get a trampoline effect.  It works pretty well but it's obvious the bridge doesn't stretch at all.  You think you could add a spot that can stretch some?  I'd love to be able to launch the ball up like a trampoline.

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
Offline kevglass

JGO Kernel


Medals: 159
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #88 - Posted 2006-08-22 22:25:14 »

Need spring joints for that I think - or at least semi elastic type things. It's a good idea Smiley

Kev

Offline CommanderKeith
« Reply #89 - Posted 2006-09-04 05:10:17 »

Here's how far I've got with polygons:  http://www.freewebs.com/commanderkeith/PolygonPhysics.jnlp

There are a couple of bugs that beat me, but maybe someone clever could look into it  Smiley:
   1) convex (>180 degree) vertices lead to overlap (see demo 6)
   2) points in a line cause 'bumps' as something slides down an otherwise straight line (see demo 2)
   3) the stacking boxes (demo 7) doesn't work properly without a high framerate - it's as if the penetration amount is being taken account of - the boxes overlap each other for frame rates of less than 20FPS.

In the demo you can see the size & angle of the forces being applied - they're all at vertices of polygons.  Also, you can zoom in using PG_DOWN or the mouse wheel to get a good look at what's happening.  Dragging the mouse moves the view.

The source is at http://www.freewebs.com/commanderkeith/PolygonPhysics.zip.

This is basically how it works:
// find point a on polyA that's contained in polyB.
// check if the line from a to a-1 intersects a line on polyB.
   // if it does, that polyB line is the 'incident face' - ie the one that the 'normal force' will be applied at 90 degrees.
   // if it doesn't, do same with a & a+1.  if still no instersection, just ignore point a.
// repeat for polyB on polyA.
// penetration (sep) is just the distance from the contained point a to the incident face (just perpendicular dist).

Kev & I would love some help with this project, and to be (geekily) honest its quite an interesting physics & geometry problem!  I don't want to bore everyone, but here's the (long but complete) code that works out the forces between 2 polygons, in PolygonPhysics/src - net.phys2d.raw.collide.KPolygonKPolygonCollider:
(note that I changed the array reference [ b ] to [b_] to stop bold text appearing).


   public int collide(Contact[] contacts, Body bodyA, Body bodyB) {
      
      float x1 = bodyA.getPosition().getX();
      float y1 = bodyA.getPosition().getY();
      float x2 = bodyB.getPosition().getX();
      float y2 = bodyB.getPosition().getY();
      
      boolean touches = bodyA.getShape().boundsIntersect(bodyB.getShape());
      if (!touches) {
         return 0;
      }
      
      KPolygon polyA = (KPolygon) bodyA.getShape();
      KPolygon polyB = (KPolygon) bodyB.getShape();
      polyA.name = "A";
      polyB.name = "B";
      
      int count = 0;
      boolean first = true;
      Point2D.Float[] pointsA = polyA.getPoints();
      Point2D.Float[] pointsB = polyB.getPoints();
      
      OuterLoopA:
      for (int a = 0; a < pointsA.length; a++){
         if (polyB.contains(pointsA[a])){
            //System.out.println("polyB contains a");
            int aPlus = (a+1 == pointsA.length ? 0 : a+1);
            Vector2f point = null;
            Vector2f normal = null;
            float separation = Float.MAX_VALUE;
            for (int b = 0; b < pointsB.length; b++){
               int bPlus = (b+1 == pointsB.length ? 0 : b+1);
               if (KPolygon.linesIntersect(pointsA[a].x,pointsA[a].y,pointsA[aPlus].x,pointsA[aPlus].y,
                                    pointsB[b_].x,pointsB[b_].y,pointsB[bPlus].x,pointsB[bPlus].y)){
                  float newSeparation = (float)Line2D.ptLineDist(pointsB[b_].x, pointsB[b_].y, pointsB[bPlus].x, pointsB[bPlus].y, pointsA[a].x, pointsA[a].y);
                  if (separation < newSeparation){
                     continue;
                  }
                  separation = newSeparation;
                  Vector2f face = new Vector2f(pointsB[b_].x-pointsB[bPlus].x, pointsB[b_].y-pointsB[bPlus].y);
                  normal = new Vector2f(face.getY(), -face.getX());
                  //System.out.println("polyB contains point a, a-aPlus intersects polyB");
                  normal.normalise();
                  point = new Vector2f(pointsA[a].x, pointsA[a].y);
               }
               int aMinus = (a-1 == -1 ? pointsA.length-1 : a-1);
               
               if (KPolygon.linesIntersect(pointsA[a].x,pointsA[a].y,pointsA[aMinus].x,pointsA[aMinus].y,
                                    pointsB[b_].x,pointsB[b_].y,pointsB[bPlus].x,pointsB[bPlus].y)){
                  float newSeparation = (float)Line2D.ptLineDist(pointsB[b_].x, pointsB[b_].y, pointsB[bPlus].x, pointsB[bPlus].y, pointsA[a].x, pointsA[a].y);
                  if (separation < newSeparation){
                     continue;
                  }
                  separation = newSeparation;
                  Vector2f face = new Vector2f(pointsB[b_].x-pointsB[bPlus].x, pointsB[b_].y-pointsB[bPlus].y);
                  normal = new Vector2f(face.getY(), -face.getX());
                  //System.out.println("polyB contains point a, a-aMinus intersects polyB");
                  normal.normalise();
                  point = new Vector2f(pointsA[a].x, pointsA[a].y);
               }
            }
            if (point != null){
               //System.out.println("added contact no. "+count);
               contacts[count].setSeparation(separation);
               contacts[count].setPosition(point);
               contacts[count].setNormal(normal);
               count++;
               if (count >= Arbiter.MAX_POINTS-1){
                  return count;
               }
               continue OuterLoopA;
            }
         }
      }
      OuterLoopB:
      for (int b = 0; b < pointsB.length; b++){
         if (polyA.contains(pointsB[b_])){
            //System.out.println("polyA contains b");
            int bPlus = (b+1 == pointsB.length ? 0 : b+1);
            Vector2f point = null;
            Vector2f normal = null;
            float separation = Float.MAX_VALUE;
            for (int a = 0; a < pointsA.length; a++){
               int aPlus = (a+1 == pointsA.length ? 0 : a+1);
               if (KPolygon.linesIntersect(pointsB[b_].x,pointsB[b_].y,pointsB[bPlus].x,pointsB[bPlus].y,
                                    pointsA[a].x,pointsA[a].y,pointsA[aPlus].x,pointsA[aPlus].y)){
                  float newSeparation = (float)Line2D.ptLineDist(pointsA[a].x, pointsA[a].y, pointsA[aPlus].x, pointsA[aPlus].y, pointsB[b_].x, pointsB[b_].y);
                  if (separation < newSeparation){
                     continue;
                  }
                  separation = newSeparation;
                  Vector2f face = new Vector2f(pointsA[a].x-pointsA[aPlus].x, pointsA[a].y-pointsA[aPlus].y);
                  normal = new Vector2f(-face.getY(), face.getX());
                  //System.out.println("polyA contains point b, b-bPlus intersects polyA");
                  normal.normalise();
                  point = new Vector2f(pointsB[b_].x, pointsB[b_].y);
               }
               int bMinus = (b-1 == -1 ? pointsB.length-1 : b-1);
               
               if (KPolygon.linesIntersect(pointsB[b_].x,pointsB[b_].y,pointsB[bMinus].x,pointsB[bMinus].y,
                                    pointsA[a].x,pointsA[a].y,pointsA[aPlus].x,pointsA[aPlus].y)){
                  float newSeparation = (float)Line2D.ptLineDist(pointsA[a].x, pointsA[a].y, pointsA[aPlus].x, pointsA[aPlus].y, pointsB[b_].x, pointsB[b_].y);
                  if (separation < newSeparation){
                     continue;
                  }
                  separation = newSeparation;
                  Vector2f face = new Vector2f(pointsA[a].x-pointsA[aPlus].x, pointsA[a].y-pointsA[aPlus].y);
                  normal = new Vector2f(-face.getY(), face.getX());
                  //System.out.println("polyA contains point b, b-bMinus intersects polyA");
                  normal.normalise();
                  point = new Vector2f(pointsB[b_].x, pointsB[b_].y);
               }
            }
            if (point != null){
               //System.out.println("added contact no. "+count);
               contacts[count].setSeparation(separation);
               contacts[count].setPosition(point);
               contacts[count].setNormal(normal);
               count++;
               if (count >= Arbiter.MAX_POINTS-1){
                  return count;
               }
               continue OuterLoopB;
            }
         }
      }
      return count;
   }


Cheers,
Keith

Pages: 1 2 [3] 4
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

TehJavaDev (16 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (34 views)
2014-08-16 06:45:27

Tekkerue (32 views)
2014-08-16 06:22:17

Tekkerue (20 views)
2014-08-16 06:20:21

Tekkerue (31 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (44 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
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!