Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 2 3 [4]
  Print  
  2D Physics System  (Read 16813 times)
0 Members and 2 Guests are viewing this topic.
Offline ryanm
« League of Dukes »

JGO Strike Force
*****

Posts: 788
Medals: 4


Used to be bleb


« Reply #90 on: 2006-09-04 05:02:45 »

It probably won't solve all your problems, but I would recommend changing your collision detection routines from looking for points inside polygons ( O(n*n) unless you're doing something really clever ) to looking for intersections between line segments ( can be done in O(n log n ) ).
As well as being more scalable, it will catch collisions that looking for point inclusion won't, particularly with fast-moving or thin bodies.

Once you've identified an intersection, you need to determine which is the incident face, and which is the penetrating vertex. This can be a bit tricky, but you can generally get away with just choosing the solution that results in the smallest corrective impulse.
Offline CommanderKeith

JGO Wizard
****

Posts: 1455
Medals: 9



« Reply #91 on: 2006-09-04 06:07:47 »

Good idea.  Originally I did use intersections but the trouble was that there were 2 contact points to apply forces to for every overlap rather than just one inner point.  Getting the force angles & sizes right for 2 force-points was too tricky.  Also the code I made for that method was about 3 times longer than what I have here - this (& the fact it didn't work properly anyway) made me wonder whether it would actually be more efficient. 

I actually hadn't thought about thin bodies at all  Tongue - the inner point method with a slow frame rate or fast object will completely miss collisions.  But this could be solved by updating the physics multiple times between redraws.  Since the actual physics calculations are pretty fast (its only drawing that can take ages) that problem should be fixable for anybody who runs into it.

Thanks for the pointers,
Keith

EDIT: come to think of it, fast-moving bodies/slow frame rate/ thin bodies problem will still be present in the intersection method because of the smallest-impulse way of computing the angle of the force, will it not?  Both probably need to be solved by doing small time updates. 

Offline ryanm
« League of Dukes »

JGO Strike Force
*****

Posts: 788
Medals: 4


Used to be bleb


« Reply #92 on: 2006-09-04 06:57:04 »

EDIT: come to think of it, fast-moving bodies/slow frame rate/ thin bodies problem will still be present in the intersection method because of the smallest-impulse way of computing the angle of the force, will it not?  Both probably need to be solved by doing small time updates. 

Not necessarily, it all depends on how you determine which is the incident face and which is the offending vertex.
Choosing the smallest impulse solution should probably be the last resort after you've exhausted looking at the two body's relative velocities and so on.
Games published by our own members! Go get 'em!
Offline Daniel_F

JGO n00b
*

Posts: 36


Java games rock!


« Reply #93 on: 2006-09-04 09:14:46 »

Very cool physics engine, I like especially the stacking demo part.

Did somebody consider doing a bridgebuilder type demo-game with it? Seems the main part (physics) is already ready  Smiley
Offline CommanderKeith

JGO Wizard
****

Posts: 1455
Medals: 9



« Reply #94 on: 2006-09-11 05:41:55 »

Did somebody consider doing a bridgebuilder type demo-game with it? Seems the main part (physics) is already ready  Smiley

Kev's code is certainly ready to do stuff like that, give it a try! 

I can't wait to use this in a game either, trouble is that i need polygons and i've got to iron out the bugs...

Offline CommanderKeith

JGO Wizard
****

Posts: 1455
Medals: 9



« Reply #95 on: 2006-09-13 03:51:41 »



This is my progress on polygons, its working much better now that there's no overlapping.  To solve that I just had to use a negative 'separation' value... grrrrrrr  Angry

This has mitigated some of the troubles, but as you'll find in demo 9 with the stacking triangles, there are still massive problems.

WebStart: www.freewebs.com/commanderkeith/PolygonPhysics.jnlp

Source: www.freewebs.com/commanderkeith/PolygonPhysicsSource.zip (note that this is a work in progress, I haven't worked in Kev's original Boxes etc yet)

Keith

PS: Here are some performance stats to compare the original code with the polygon code.  To get these stats I just looped world.step(0.02f) 3000 times using the stacking box demo for both:
Polygon boxes:
seconds elapsed: 12.169297
nanos per world.step(0.02f): 4056432.2

Box boxes:
seconds elapsed: 9.543804
nanos per world.step(0.02f): 3181268.0

So the polygon collision code takes about 28% longer.  This can be improved once I profile it.

Offline Daniel_F

JGO n00b
*

Posts: 36


Java games rock!


« Reply #96 on: 2006-09-18 07:24:02 »

I looked a bit more into it and I wonder why is everything float and not double? Roll Eyes

Speed-wise they should be the same.
Offline Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5862
Medals: 255


Hand over your head.


« Reply #97 on: 2006-09-18 10:33:55 »

With these kind of dimensions you don't need more than 7 significant digits.

And you save half the RAM. (but that's peanuts)

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline CommanderKeith

JGO Wizard
****

Posts: 1455
Medals: 9



« Reply #98 on: 2006-09-18 23:19:39 »

I used floats because I thought they were faster than doubles, but apparently they aren't:

http://www.velocityreviews.com/forums/t134954-float-vs-double-speed-on-p4-machine.html, see Roedy Green's reply.

It could be changed to doubles, but it would be a bit of work removing all of the float casts.  Not much point anyway, as Riven said there's not much of an advantage to have that little bit of extra precision.

Thanks for taking a look at the code.  By the way, I've changed the polygon collsion code so its working much better.  I'll post it and a new demo in a couple of hours.  I figured out what was making the triangles demo go haywire - I was scaling the triangle's y-coordinates by -1 to flip them over, but that meant that the points weren't listed in anti-clockwise order which is what the collision code assumes.  Anyway, now the triangles bounce off properly and you don't see the big ones sucking the smaller ones in.

Offline kevglass
« League of Dukes »

JGO Kernel
*****

Posts: 5214
Medals: 49


Mentally unstable, best avoided.


« Reply #99 on: 2006-09-18 23:46:07 »

Ok, you're getting pretty close now Smiley So, how do you want to go about integrating these changes. If you've changed alot of stuff unrelated to the collision code then we've got two choices:

1) I integrate stuff, probably modifing your mods on the way to fit in with the existing code

2) You integrate stuff (I add you to the authors on google code) and you can modify it however is easiest for you.

With 1) it may take me a while (given upcoming commitments). With 2) you'll end up taking the brunt of the flak as people find problems and need them resolved. Either way it might well make sense to add your the project on google code if you're so inclined Smiley

Your dollar,

Kev

Games published by our own members! Go get 'em!
Offline CommanderKeith

JGO Wizard
****

Posts: 1455
Medals: 9



« Reply #100 on: 2006-09-19 01:28:36 »

There's still problems with my code such as with fast-moving thin bodies & also with intersecting vertices where neither vertice is inside the other shape, which you'll see in the next demo.  I think I can only solve it by using intersections (as bleb prescribed), but I'll apply the forces at each bodies' vertices, not at the intersections themselves (this shouldn't require too much extra work). 

Until I solve this I think its best to keep your working code away from my buggy version.  If you want to add my project on to google code and have the two going in parallel that's fine.

Thanks for offering to integrate them.  Hopefully I will be able to do most of it - at least the parts that only I understand.  I'll post the new demo & code soon.

Keith

PS: I haven't changed too much except for what I said before: making the bounds a max radius from a centroid point.
The only other important change was using Point2D.Float class rather than Vector2f  - but that's not too much work to change. 

I don't really like Point2D.Float anyway since you can't serialize it or extend it.  Though I'd like to add some more methods to Vector2f  if you don't mind - like setX, setY, getPoint2DFloat() and let it implement Serializable.

Offline CommanderKeith

JGO Wizard
****

Posts: 1455
Medals: 9



« Reply #101 on: 2006-09-19 05:52:19 »



Web Start: http://www.freewebs.com/commanderkeith/PolygonPhysics.jnlp

Demos 11, 6 & 9 show the problems I mentioned - I think both can be mitigated by using line intersection.

I think this could be used by someone to make a cool Worms type of game  Smiley.  I'll give it a go eventually too
.
Keith

Offline Evil-Devil

Full Member
**

Posts: 244
Medals: 2


Fir Tree Master


« Reply #102 on: 2006-09-20 06:07:50 »

@Float vs Double: Don't forget that opengl uses internally only floats. So the speed gain might be lost due the downcast from double to float.
Offline CommanderKeith

JGO Wizard
****

Posts: 1455
Medals: 9



« Reply #103 on: 2006-10-08 05:25:42 »

Hi,

I just want to let people know that I won't have time to work on this project until November. 

I haven't lost interest at all - I've just got a deadline on the 30th of October that I'm running late for.  I will get the polygons working seemlessly in November Smiley.

Keith

Offline Death33284

Jr. Member
**

Posts: 70



« Reply #104 on: 2006-10-10 17:06:53 »

Hi,

I just want to let people know that I won't have time to work on this project until November. 

I haven't lost interest at all - I've just got a deadline on the 30th of October that I'm running late for.  I will get the polygons working seemlessly in November Smiley.

Keith

Good to know this hasn't been abandoned.  Smiley

Looking forward to the newer versions
Pages: 1 2 3 [4]
  Print  
 
 
Jump to:  


Add your game by posting it in the showcase section.

The first screenshot will be displayed as a thumbnail.

Danny02 2012-05-21 17:10:34

Danny02 2012-05-21 17:07:10

Danny02 2012-05-21 16:56:12

davedes 2012-05-21 13:59:23

obsidian_golem 2012-05-20 20:28:41

darkjava55 2012-05-12 16:14:40

Ultroman 2012-05-12 09:36:05

Ultroman 2012-05-11 22:49:53

Ultroman 2012-05-11 22:20:01

Ultroman 2012-05-11 22:17:34
Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.091 seconds with 19 queries.