Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (500)
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 24198 times)
0 Members and 1 Guest are viewing this topic.
Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #30 - Posted 2006-07-30 21:47:30 »

I slapped a BSD license on it - so you can use it as long as you credit the people mentioned in the license header (currently thats most importantly Erin Catto, and then Me).

However, I'm still toying with making this a community project if anyone else would be likely to contribute. What I don't want to do is make it into a project that promptly dies.

I'm still actively developing it so I guess we can where it goes?

Kev

Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #31 - Posted 2006-07-31 04:43:21 »

Would be a good project for the community.   And an opportunity to try out Google Code Smiley (Subversion is cool)

Offline Markus_Persson

JGO Wizard


Medals: 12
Projects: 19


Mojang Specifications


« Reply #32 - Posted 2006-07-31 15:01:36 »

Wow, this is awesome. Cheesy

Although,
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
java.lang.NullPointerException
   at net.phys2d.raw.World.step(World.java:199)
   at net.phys2d.raw.test.AbstractDemo.start(AbstractDemo.java:204)
   at net.phys2d.raw.test.DemoBox.main(DemoBox.java:120)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at com.sun.javaws.Launcher.executeApplication(Unknown Source)
   at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
   at com.sun.javaws.Launcher.continueLaunch(Unknown Source)
   at com.sun.javaws.Launcher.handleApplicationDesc(Unknown Source)
   at com.sun.javaws.Launcher.handleLaunchFile(Unknown Source)
   at com.sun.javaws.Launcher.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)

Play Minecraft!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Death33284

Junior Member





« Reply #33 - Posted 2006-07-31 21:17:41 »

error in BodyList.java:
1  
2  
3  
4  
5  
6  
7  
8  
/**
    * Remove a body from the list
    *
    * @param body The body to remove from the list
    */

   void remove(Body body) {
      elements.add(body);
   }


Also it might get that nullpointer error when there are too many objects on the screen?
Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #34 - Posted 2006-07-31 21:49:34 »

Already fixed. Problem with having the source not in an open repository.

I'm going to start a google project later this week. Havinng a bunch of issues with bounce not being configurable. Maybe a topic for somewhere else.

Kev

Offline CommanderKeith
« Reply #35 - Posted 2006-08-03 09:09:36 »

In AbstractDemo's start() method, why is World.step(time) called four times with every iteration of the game loop?  How come not just once? 

And is there a thread that discusses the interesting 'adaptive timing loop' you're using which you attribute to Master Onyx?

Thanks,
Keith

Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #36 - Posted 2006-08-03 09:32:53 »

Short answer on step(time) - it looked better. Longer answer - I don't know and it's one of the things I have on the list to work out. It seems like to me that the time step in a simulation effects the acceleration, and the only reference point we have for acceleration is gravity. Since my units are pixels (not scaled in anyway) then gravity is 10 down on the y-axis in pixels - which looks a bit slow. Running at 4 times the speed makes gravity look normal - I suppose upping the gravity would have the same effect.

The abstract demo is more just a test bed to check things don't break.

The adaptive timing loop was developed for the 4k contest - you'd have to ask Master Onyx for the linky.

Kev

Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #37 - Posted 2006-08-03 10:56:04 »

http://www.java-gaming.org/forums/index.php?topic=11640.msg93602#msg93602

It takes the averaged time of the last 10 frames (rolling average) and uses that for changing the number of yields proportionally... and there is some damping on top for keeping it smooth.

It over/understeers a little if the changes from one frame to the next are very extreme, but other than that it behaves very well. Even if the timer resolution is as bad as 250msec (win9x has the worst one with 50-55msec).

If you want to see how well it behaves print the yield value and the fps (but dont use frameAverage for that it isnt all that accurate (but its good enough as an input value Wink)).

edit: With "print" I dont mean System.out.print... of course. Doing that each frame will lag the loop a lot.

弾幕 ☆ @mahonnaiseblog
Offline CommanderKeith
« Reply #38 - Posted 2006-08-03 11:22:06 »

Many thanks for explaining those 2 things.  I'm just trying to figure out why a non-fixed step causes problems.  I will try using a regular game loop time with System.nanoTime() & only one World.step(float timeElapsedSinceLastStep) per frame & report back if its fixed. 

Maybe the combination of a slightly inaccurate time compounded by 4 updates per frame gives the weird behaviour.   

PS: why do you count on yield taking a fixed amount of time?  There is no guarantee that it will effectively 'sleep' the same amount with each call, is there?  Especially on windows where there's a stack of other processes/threads waiting to execute - Thread.yield() may let them have a go, which could take any amount of time, will it not?

I'm referring to this, from AbstractDemo:
         // adaptive timing loop from Master Onyx
         long timeNow = System.currentTimeMillis();
         frameAverage = (frameAverage * 10 + (timeNow - lastFrame)) / 11;
         lastFrame = timeNow;
         
         yield+=yield*((target/frameAverage)-1)*damping+0.05f;

         for(int i=0;i<yield;i++) {
            Thread.yield();
         }

Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #39 - Posted 2006-08-03 16:28:37 »

For reference I haven't had an issues using a variable time step - except that the simulation isn't predictable since the collision in this engine isn't swept and different amount of penetration occurs if you use different time steps.

Kev

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

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #40 - Posted 2006-08-05 07:20:05 »

I've created a google code project for this physics stuff now I've sorted a few more bits and pieces out. The project is at:

http://code.google.com/p/phys2d/

SVN browse is here:

http://phys2d.googlecode.com/svn/trunk/phys2d/

The dated fixed builds are still available from:

http://www.cokeandcode.com/phys2d/source/

The webstart has just been updated with some new features:

* Hardness factors for elastic collisions [EDIT: This doesn't seem to be working well, extra energy creeping into the pool simulation]
* Refactored code - now supports pluggable joints, broad collision strategies
* QuadSpace collision strategy for more optimal body2body collisions detection
* New collision shape: Line - not 100% on this one yet but seems reasonably. Useful only for static elements.

Finally a new demo screenshot:


Webstart is still at: http://www.cokeandcode.com/phys2d/phys2d.jnlp

Just hope the project doesn't keel now,

Kev

Offline CommanderKeith
« Reply #41 - Posted 2006-08-05 09:39:27 »

Nice work, that's really helpful. 

Now that lines are supported, could these be the building blocks of 2D polygons?

PS: Cool billiards triangle!

Offline bgilb

Senior Newbie




Java games rock!


« Reply #42 - Posted 2006-08-05 14:26:28 »

will it ever be able to handle fluids?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 605
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #43 - Posted 2006-08-05 15:01:29 »

Fluids are just lots of tiny spheres.

So it already supports fluids, but probably not fast on current hardware enough to be useful.

Somebody should write a GPU accelerated implementation Wink

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Amos Wenger

Senior Member




Everything's possible, but not everything's fun...


« Reply #44 - Posted 2006-08-05 16:29:04 »

Awesome  Shocked ! I just hope with you kevglass that it will continue..

EDIT : Just 2 small questions : is the collision library separated from the core ? And : can I use your lib in a strategy game with 2D-movement ? actually I use my own detection thingy but it's naive On2 cost so I saw you implemented quadTree so it's interesting  Smiley

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline CommanderKeith
« Reply #45 - Posted 2006-08-05 17:03:06 »

This is a really exciting project, I'll gladly jump on the bandwagon! 

To get smoothness & to cope with sub-60 FPS performance I've changed the AbstractDemo's game loop - it may help to analyse performance, it seems that the stack performs the worst.

Added the following in AbstractDemo:

   long nanoTimeLastUpdated = 0;
   long cumulativeNanosBetweenUpdates = 0;
   float avMillisBetweenUpdates;
   int counter = 0;
   long tripNanos = 125000000; // 1/8 second, this is how often avMillisBetweenUpdates is updated.

   public void start() {
      initGUI();
      initDemo();
      nanoTimeLastUpdated = System.nanoTime();
      while (running) {
         long currentTime = System.nanoTime();
         long timeSinceLastUpdate = (currentTime - nanoTimeLastUpdated);
         nanoTimeLastUpdated = currentTime;
         cumulativeNanosBetweenUpdates += timeSinceLastUpdate;
         float timeMultiplier = 4;
         world.step((float)timeSinceLastUpdate*timeMultiplier/1000000000f);//frameAverage / 1000.0f);
         // render
         Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
         g.setColor(Color.white);
         g.fillRect(0,0,500,500);
         draw(g);
         renderGUI(g);
         g.setColor(Color.black);
         g.drawString("ms/frame: "+(avMillisBetweenUpdates),10,50);
         g.drawString("FPS: "+(1000f/avMillisBetweenUpdates),10,70);
         //g.drawString("Yield: "+yield,10,90);
         g.dispose();
         strategy.show();
         if (needsReset) {
            world.clear();
            initDemo();
            needsReset = false;
         }
         counter++;
         if (cumulativeNanosBetweenUpdates >= tripNanos){
            avMillisBetweenUpdates = (float)((cumulativeNanosBetweenUpdates)/(counter*1000000f));
            cumulativeNanosBetweenUpdates = 0;
            counter = 0;
         }
         Thread.yield();
         //update();
      }
   }

Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #46 - Posted 2006-08-05 18:14:19 »

Thanks for the feedbacks.

@CommandKeith - thanks for the code - I'll use it locally but for personal reasons (GCJ) I need the project to stick to 1.4 right now (this might change if it just gets too plain annoying Smiley)

@Magic - currently you could use the collision system with getting response or doing the physics computations by subclassing World. However, if this is a possible usecase I'll refactor the world so it can do this without effort.

I'm not intending to add a Fluid layer but if it just sphere then yes it's fine. However, not something I've ever thought of so if it's useful

To Do in no particular order:

- Fix hardness/elastic collisions
- Refactor collision so it can easily be used seperately
- Test line collisions further and expand to line/line
- Add polys (either by using multiple lines - or some other neat system)
- Fixed Joints - joints which don't allow rotation so we can bind bodies together in one lump
- Body collision control - define bodies that don't collide against each other (useful for a bunch of situations)
- Body collision feedback and control - registering a listener against the world to be notified of collisions and determine whether response should be computed.
- Performance/Memory
- Static Body detection
(These issues are recorded here: http://code.google.com/p/phys2d/issues/list)

If anyone has things to add to the list or wants to get involved with the source (I'm not sure how this works with the google code system yet) then let me know here.

Kev

Offline CommanderKeith
« Reply #47 - Posted 2006-08-05 19:08:44 »

I'd be glad to help with the source, but I'm still getting my head around it.  If you could explain how the box-box collison works or put a couple more comments in I can try to use the ideas for polygons.

Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #48 - Posted 2006-08-05 19:26:33 »

Thats a really good question - I don't really understand box/box collisions - I ported it straight from C. While porting I picked up some of it - but code line for code line I don't get.

Essentially it projects one box onto the other box's  face axis. It determines if these projected points are on the same side of the face as the centre of the other box. It then clips the points to the segments that actually build up the face. Then some mojo (read: this is the bit I don't get) cuts if the projected points arn't on the faces to detect whether its a corner hit. If the points are on the same side as the centre they're determined as collision points.

At least that's how it seems to me.

Kev

Offline Death33284

Junior Member





« Reply #49 - Posted 2006-08-06 17:19:47 »

Thanks for adding lines to the collision bodies, this could potentially be great for a little project I wanted to do but thought I couldn't.
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #50 - Posted 2006-08-07 17:44:40 »

Ant build of the source with no ant targets specified asks for a keystore password.

Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #51 - Posted 2006-08-07 17:49:24 »

Run the compile task - I'm afraid I've been unable to update google code since yesterday  - subversion commits not responding Sad

Kev

Offline bahuman

Junior Member





« Reply #52 - Posted 2006-08-09 17:14:38 »

This reminds me of http://www.sodaplay.com/constructor/
It seems like this physics engine should be capable of that, and more! Cool
Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #53 - Posted 2006-08-09 17:34:58 »

There's a hell of lot more going on in SodaPlay than it looks like. This physics engine might be able to be used as a base for something similar - but right now the basics need to get solidified.

In case anyone's interested - I'm currently working on restitution support and integrating the new version of Box2D which seperates out bias and physical velocities.

Kev

Offline Markus_Persson

JGO Wizard


Medals: 12
Projects: 19


Mojang Specifications


« Reply #54 - Posted 2006-08-10 11:26:11 »

There's a hell of lot more going on in SodaPlay than it looks like.

There is? Looks like just springs with gravity, friction and stiffness settigns, and a sinus curve "motor" that you can bind to different springs.

I mean, it's cool and all, but there's really not that much going on, is there?

Play Minecraft!
Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #55 - Posted 2006-08-10 16:12:29 »

I could be wrong - but it looks like theres some IK going on in there too - thats where I am with this physics engine. Probably should have said

"There's a hell of a lot more going on in SodaPlay than is available in this physics engine"

Kev

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 605
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #56 - Posted 2006-08-10 17:46:44 »

No, there isn't IK, otherwise it would be way too easy to make those 'robots' run around: just give a few keyframes and it jumps away.

SodaPlay is really simple, it's Verlet-Integration AFAIK, you can't really get it much simpler.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #57 - Posted 2006-08-10 19:15:07 »

Shows how much I know Wink Now if I could only prevent engery being adding to the system in my *simple* 2D system I'd be happy Smiley

Kev

Offline bahuman

Junior Member





« Reply #58 - Posted 2006-08-10 23:18:13 »

Shows how much I know Wink Now if I could only prevent engery being adding to the system in my *simple* 2D system I'd be happy Smiley

Kev

prevent what? Is my English failing me  Embarrassed (or is yours ?  Grin)
Offline kevglass

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #59 - Posted 2006-08-10 23:41:41 »

engery = energy.

Sorry.

Kev 'Not My Day' Glass

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.

xsi3rr4x (51 views)
2014-04-15 18:08:23

BurntPizza (48 views)
2014-04-15 03:46:01

UprightPath (63 views)
2014-04-14 17:39:50

UprightPath (45 views)
2014-04-14 17:35:47

Porlus (62 views)
2014-04-14 15:48:38

tom_mai78101 (86 views)
2014-04-10 04:04:31

BurntPizza (146 views)
2014-04-08 23:06:04

tom_mai78101 (243 views)
2014-04-05 13:34:39

trollwarrior1 (202 views)
2014-04-04 12:06:45

CJLetsGame (209 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!