Gosu Forums
Topic Gosu / Gosu Showcase / Verlet Physics on Ruby/Gosu
By vadim2 Date 2011-03-12 19:30 Edited 2011-03-13 09:30
Hello. There was nothing and tried to implement a physics engine based on the Verlet Integration. So far, only the behavior of material points and constraints. I also want to ask - how to implement a collision in my algorithm? Source: Code here
By RunnerPack Date 2011-03-12 20:29
You have to put it in your Dropbox's "pub" folder to share a link. I really want to try this out (and look at the code, of course ;)!
By vadim2 Date 2011-03-13 06:56
Sorry? I use dropbox just firts time. Update first post.
By RavensKrag Date 2011-03-13 09:33
Collision detection itself isn't really that hard.  The problem is trying to get the culling right so the collision detection doesn't get too slow.

The most basic collision detection is circle-on-circle, which can be found by seeing of the center of the smaller circle is a shorter distance away than the radius of the larger circle.  There might be better way to do this, but this is the most basic way I could think of.

Rectangles are not too bad either, assuming they are oriented the same way as the axes of the coordinate system.  If not, you need to do oriented bounding box collision detection using the parallel axis theorem or something.  Just a bit a linear algebra there.

Not too sure about triangles though.

As for culling, most implementations of 2D collision detection tend to use quartic trees, I believe.  Chipmunk uses a hash instead, but I hear the algorithm is much more complicated.  The reward for the underlying hash is the speed of course.

However, Chipmunk uses Euler integration, so it should be interesting to see how the two stack up, if you ever get to implementing collision detection as well.  Still, even with good culling, most of this stuff gets pretty slow fairly quickly.  Thus, if you know C, it would be cool to see this re-implemented in C.

Hope that's enough to point you in the right direction.
By Basic Date 2011-03-13 13:54
This might not be what you are looking for but its a good article, most of the pictures are interactive so it helps drive the point across.

http://www.metanetsoftware.com/technique/tutorialA.html
By vadim2 Date 2011-03-13 14:23
snx. I find this - http://www.gamedev.net/page/resources/_//feature/fprogramming/a-verlet-based-approach-for-2d-game-physics-r2714 . I'll try to implement a ruby, in the old version did water (defined area, falling objects to behave as in water), but I'll rewrite.
By vadim2 Date 2011-03-13 16:15
Entangled in a trivial problem - the center of the square :) . Evaluates it like this:

@image.draw_rot((@points[0].x+@points[1].x)/2,(@points[0].y+@points[2].y)/2,1,@contacts[0].angle)

That is half the width and half the height, but here are obtained the following results:
http://xmages.net/show.php/2555678_before-png.html
http://xmages.net/show.php/2555677_after-png.html
By RavensKrag Date 2011-03-14 00:59
I assume the blue-white lines show where the image is supposed to go? I'm pretty sure that line you posted is correct, so it would be helpful to see the code as a whole to see what the problem is.  Any chance you could throw it in a gist? It'd be cool to get a few of us to hack at this together, but I can understand if you'd rather go it alone and just pop in for some hints every now and then.
By erisdiscord Date 2011-03-14 03:16
Without knowing anything about the context of this code snippet, one small part kind of jumps out at me as probably wrong:

`@image.draw_rot((@points[0].x+@points[1].x)/2,(@points[0].y+@points[2].y)/2,1,@contacts[0].angle)`

Is this copy-pasted from the actual source or did you retype it? Are you sure 2 is the correct index here, when 1 is used for the x? :)
By vadim2 Date 2011-03-14 13:00
Sorry that he wrote just a line of code, just the whole it is not very "handsome". In the problem figured out as soon as decorated as gem (who suddenly come in handy) and want to do a complete physical library. Can be obtained and it will be useful to someone.
By Basic Date 2011-03-14 15:48
Eh! I've had a long day granted but that made no sense to me.
By banister Date 2011-03-15 01:16
you need some leisure time, basic, make some time for leisure, there are a few leisure activities available to the interested person: sailing, running, gardening, swimming. You should choose one of them and undergo relaxation and pleasure etc.
By Basic Date 2011-03-15 20:06
If I had the time I would; except for the running, and gardening. Oh not going sailing ether. hmm don't like swimming in pools now that I think about it :( and I live in Scotland so swimming in the sea is reserved for New Years day only.

Suppose I could sit out side in the snow/rain/fog/cloud with iPad, relax and play some games.
By Basic Date 2011-03-14 16:01
You midpoint calculations are fine, (unless the cube has already been rotated, then you might get some unexpected results).

Without full code its hard to see the problem.
Topic Gosu / Gosu Showcase / Verlet Physics on Ruby/Gosu

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill