Kinetix - 2D physics engine

can be found here

http://www.homepages.inf.ed.ac.uk/s9902505/

I haven’t tested the link from outside uni though, so there may be some permissions fiddling needed.

Please have a play with it and tell me what you think.

It works best on linux, thanks to millisecond accuracy on the timing. It will still work on windows, just not as smoothly.

?? What to do? I have just a dialog with a disabled ‘Simulator’ menu.
If I enlarge the dialog and click into it, thats what I get:


java.lang.NullPointerException
        at ryanm.kinetix.editor.MouseAdjudicator.mouseReleased(MouseAdjudicator.java:74)
        at java.awt.Component.processMouseEvent(Component.java:5093)
        at java.awt.Component.processEvent(Component.java:4890)
        at java.awt.Container.processEvent(Container.java:1566)
        at java.awt.Component.dispatchEventImpl(Component.java:3598)
        at java.awt.Container.dispatchEventImpl(Container.java:1623)
        at java.awt.Component.dispatchEvent(Component.java:3439)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
        at java.awt.Container.dispatchEventImpl(Container.java:1609)
        at java.awt.Window.dispatchEventImpl(Window.java:1585)
        at java.awt.Component.dispatchEvent(Component.java:3439)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

Ah, better after using the ‘New…’ menuitem.

But still nothing I can do. Can select tools or modify body options, but what are they for??

there are some instructions on the download page, but anyhoo…

get a new simulation by selecting “file” -> “new”. Set the desired size and click “ok”. The editor window should resize to accomodate a white panel. This is the simulation.

To add a new body into the simulation, select the “Armour” tool and left click on the white panel where you want the vertices of your body to be. A green outline will show your progress so far. When you’ve added all the vertices you want, finish the body with a right-click. The green outline should become black. NB: you must have at least 3 vertices. and you should avoid self-intersecting shapes.

If you are not happy with the position of your body or it’s vertices, you can drag them around with the “grabber” tool.

You now have an unstructured body that will flop around uselessly. To make it more interesting, add some structure to it using the “stick”, “bumper”, “rope” and “spring” tools by dragging between two vertices of the same body. A black line should appear showing the constraint. The shortcut to a rigid body is simply to right-click on it and select “rigidify”. You can view any constraints of a particular type by selecting the appropriate tool. They will appear as black lines.

You should now have a rigid body. Make the simulation more interesting by increasing the gravity and perhaps raising the water level from the environment control panel, accessible from the “Simulator” menu

The body options panel on the main editor window allows you to set the attributes of any new bodies you create. You can alter the attributes of existing bodies by right-clicking on them and selcting “Options”.

When you are done editing your simulation, you can run it with “Simulator” -> “Run Simulation” and save it with “File” -> “save”.

[quote]there are some instructions on the download page, but anyhoo…
[/quote]
Yes, I know. I can read (actually I even have a academic degree).

No, this doesn’t happen. The panel is white and remains white.

Sorry about that, but I’ve also sent this to my brother, who apparently has a phd, and he needed spoonfeeding every step of the way. ::slight_smile:

[quote] No, this doesn’t happen. The panel is white and remains white.
[/quote]
Well shit. Once again I am forced to say “Write once, run anywhere, my hairy ass”. >:(
It sounds like the MouseAdapter is broken in some way.

Is anyone else having this problem? The jar works for me on my laptop and on the uni computers, both running linux with Java 1.4.0 and 1.4.1 respectively

What is your platform / JVM ?

There are some sample xml files available at the same URL as above, you could try to load those and see if there’s any joy.

Hm, the more often and the harder I try, the more successful I am! Meanwhile I managed to set green points (sometimes with a fast doubleclick, sometime with singleclick) that even appear near to the mouse position, estimated 30pixels to the upper left :slight_smile:

And I could create an exception with the right mouse button:


java.lang.ArrayIndexOutOfBoundsException: 13
        at ryanm.kinetix.Armour.getDirection(Armour.java:118)
        at ryanm.kinetix.Armour.<init>(Armour.java:85)
        at ryanm.kinetix.Body.<init>(Body.java:86)
        at ryanm.kinetix.editor.MouseAdjudicator.mouseClicked(MouseAdjudicator.j
ava:175)
        at java.awt.Component.processMouseEvent(Component.java:5096)
        at java.awt.Component.processEvent(Component.java:4890)
        at java.awt.Container.processEvent(Container.java:1566)
        at java.awt.Component.dispatchEventImpl(Component.java:3598)
        at java.awt.Container.dispatchEventImpl(Container.java:1623)
        at java.awt.Component.dispatchEvent(Component.java:3439)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3174)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
        at java.awt.Container.dispatchEventImpl(Container.java:1609)
        at java.awt.Window.dispatchEventImpl(Window.java:1585)
        at java.awt.Component.dispatchEvent(Component.java:3439)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:197)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:150)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

So it works - somehow.

I have w2k, jdk1.4.1_01.

Right, there’s a new version up now that shouldn’t have that ArrayOutOfBounds exception. It would only have appeared if you had all of your points in a line, but it shouldn’t have slipped through the testing net.

Thinking about it a bit more, it might be the VolatileImage code that is exhibiting platform dependent behaviour, since there’s all that “possible loss of image contents” kafuffle on Windows. I thought that copying the code from the VolatileImage API docs would cover me on both platforms, but apparently not. So in reality (possibly) you are creating points, you just can’t see them. Which is unhelpful. Thus, next on the bug-fix list is moving back to nice, dependable BufferedImages.

[quote]30pixels to the upper left
[/quote]
There’s a “Snap to grid” option in the File menu that’s on by default

thanks for your time Herkules, I promise that there’s somthing fairly cool at the other end of this compatability hell.

I’ll download JDK 1.4 for win98 when I get home. If anything can break my code, it’ll be good old 98. :wink:

I don’t know what to be more disappointed with, Windows or Java… :-/

Ok, there’s a new jar up at the above address that might be more successful on windows platforms. The drawing was about 60% slower :-/ when i tested it, but nevermind. It will also print out information on stdout about mouse events, so i you are clicking on the simulation panel and nothing comes up on stdout, let me know. If you do see the mouseClicked events appearing and still no green points, I’m not sure i want to know :(, but tell me anyway.

As far as i can see, that covers the only two bits that could be in any way platorm specific.

Here’s hoping…

Maybe I’ve catched the problem. It seems that NO point is set when mousePressed and mouseReleased occur not exactly on the same mouseposition? This is a hard restriction bc. pressing or releasing the button often moves the mouse as well (esp. with high-res optical mice we have today).

Taking this as an hypothesis, WinKinetix.jar and Kinetix.jar behave identical.

That could easily be it. I’ve been testing it with a touchpad and a fairly crap, sticky-as-hell mouse.

Unfortunately, this is just the way that MouseEvents work :frowning:

Ok, next up is a version where all the mouseClicked code is triggered on a mouseReleased event.

I’ll have to do it later on though, watch this space…

btw, was the volatileImage displaying correctly? can i go back to the speedy rendering code?

Cheers

No difference in display.

Why not use mouseClicked? Or ONLY mouseReleased or ONLY mousePressed? Never have seen problems like that…

[quote]Why not use mouseClicked?
[/quote]
I am, mouseClicked is used to add new points to an armour or to bring up the context menus.

mousePressed and mouseReleased are used for adding constraints or dragging objects and vertices around.

Unfortunately, it seems that a mouseClicked event is not generated if the corresponding mousePressed and mouseReleased events do not occur in the same place. Developing with a touchpad never exposed this limitation.

Good to know about the display though. VolatileImages, all is forgiven. BufferedImages, don’t show your slow-as-hell face around here ever again, or at least until i want direct pixel access. ::slight_smile:

There we are, the new version only uses mousePressed and mouseReleased, so those of us with nice hi-res mice and monitors can now have full functionality without entering a zen-like trance of absolute muscle control.

By the way, it seems that mouseClicked events are only generated when the mouse is pressed and released on the exact same pixel. Which seems a bit harsh to me. Ah well, it’s all a learning experience…

Could you please refrain from posting porn on this message board?

Your posts would also be less offensive in general if you simply stopped changing the the font and double spacing everything.

Is that too much to ask?

In answer to your questions:

  1. probably, but it’ll take time that currently i require to write my final year dissertation. Besides, all you need to do is download the jar and run it.

  2. Not at the moment, I really just made the physics engine for a 2-d game i am making.

  3. Nope, just unnecessary in a 2D game.

  4. very nice

[quote] I want my VRML H-Anim Avatars to obey the Laws of Physics !
[/quote]
The Kinetix system is based on a technique used for animating bodies, so you may find this paper useful.

[quote]I like playing ping-pong with beautiful nude blond girls and want to make java game of that too.
[/quote]
… indeed …

I would have to say that much of the appeal of the aforementioned activity would be lost in the transition to a computerised form, but hey, however you get your jollies…

For ping-pong, you would only need to simulate a large particle (the ball) bouncing off flat surfaces (the table, the bats). A full rigid-body simulator might be a bit of overkill.

[quote]I like your penguin.
[/quote]
Why thank you.

Thank you.

Your answsers beg for clarification & more wisdom … ( 2 questions ) …

Most applications can run as applets with trivial modifications.

Mostly I write mine to run as both.

If you're not writing anything to disk, I wounld't think any re-write would be required, 

and if something has to be written to disk … external Java Servlets can do that for you.

I’m trying to understand and help.

Part of the magic of Open Source is … having other people do your work for you … ;^)

Maybe someone here has the web services it would require !

Is there any resource you need that the security sand box locks out ?


Part of Java Gaming is getting people to play the games.

Part of making Java Gaming successful is removing the unnecessary 

obsticales to the game play: including unnecessary download & installs.

I have a 3d, multi-player, netwoked tank battle first - person - shoot game …

   it runs as either an applet or application.
 
                                                                                                 [   This space intensionally left blank   ]  
  1. Can your 2d Physics Engine handle the 2d Physics Problem of the ping-pong ball ?
You answered your engine was  " 2d only " ... I understand.

I can isolate a planar slice of my 3d world ...
I can protect my girl & the ping-ball from cross winds ...
I can reduce the 3d problem space of the ping-pong ball to a 2d problem space.
I can do all that ... 

so can your software handle the 2d Physics of the ping-pong ball traveling through the 2d planar suface of it’s trajectory ?

Hitting the table is still a 2-d problem ( or is by definition of the implementor )

It’s only when the ball is struck by a player’s paddle that the 3d has to re-emerge,
and I could compute the translation between the old 2d plane & the new one.

The ping-pong game was chosen for a good reasons,

It should be easy, and Sun already provides a simple demo.

The game can be contrained so the players can’t hit the ball until
it passes through a plane parallel to the end of table end ( one for each player )

So once a ball is hit, it is out of action, until a known interval of time has passed,
and you know where its terminal position will be, and when,
so you can go away and do other things until that time arrives.

Make games hard for the player, make life simple for yourself.


I haven’t tried your program yet, but it definately on my " to do " list.

What distro are you using ? (*)

Thank you,

       Sincerely,

– Paul, Java Developer & Web Animator

Imaging the Imagined: Modeling with Math & a Keyboard

(*) Inside Linux Speak for: You upgraded from Microsoft Ce-Me-NT to which Linux distribution ?

Yeah, it wouldn’t be hard to write an applet that will bring up the editor window, but this would preclude the possibility of loading and saving simulations.
The editor is not really an end in itself, but simply a framework to demonstrate the simulation technology. As such i can’t really be arsed messing around with servlets and such to let people use it seamlessly over the web. The jar file is all self contained, so installation involves nothing more than saving the jar and running “java -jar Kinetix.jar”.

Back to ping-pong…

I don’t really feel that this engine is the best fit for your problem. Ping-pong is just interactions between spheres and planes, which is quite simple to model

Off the top of my head:

whenever the center of the ball gets to within the ball’s radius of a plane, invert the component of the ball’s motion that is perpendicular to the plane.

This will model interactions between the ball and table, you’ll need too add something more to simulate moving planes (bats).

You can model this quite easily in 3D, with no messy slicing into 2D necessary.

I use Mandrake, for no other reason than my flatmate had the installation disks, although i am jealous of debian’s “apt-get” loveliness.

[quote] |
| Could you please refrain from posting porn … ?
|
[/quote]
[tr][td]

http://www.JavaGaming.org/JGOForumImages/avatars/linux.gif

[/td][td]

Are you complaining about …

the legs spread full frontal shot of JavaGaming’s Penguin ?

If you had a body & got some action,

               ... you woundn't be so uptight.


                                                           ... or ...    [/td][/tr] [tr][td] 

http://www3.sympatico.ca/scott.palmer/marvin_head.jpg

[/td][td] [b]

Her forehand is foreplay for you ?   

There's more, it gets better ...

Just wait for puberty !

Think contact sports !

Touchdown !

Ooooh !

Ah !              [/b]   [/td][/tr]

ahhh… I can’t hold it inside of me anymore… But I will try to be civil…

Vrml_Java_Animator
First of all, no nude womens on these forums. Even if women’s are the most beutiful things on this universe (and I am not taking about a j3d univerise with vrml loaders). These forums are about Java Gaming (no nude women forum yet, but if such is added feel free to post your porn collection there).

Also you must start to learn to respect people other than yourself. Most people learn this in an early age, but it seams like you missed that part.

Have you noticed that I am NOT using any large fonts, no extra spaces and still you can read this? amazing isn’t it! So please, cut down your post by not repeating what you already said and try to use the same font in your posts (that is use the standard font).

This is my third complete rewrite of this post, the first started with to many hard words so I couldn’t bare myself to post it. The second was abit better but still had references to mental institutions. The third, the one you are reading now, is how post should look like. A polite try to get you to understand that personal attacks, ugly post and other inmaturity isn’t appreciated here. So please stop with this and try to act as a normal mature man. Please!

Edit
Typos