Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2

Author Topic: Dynamic Collisions (yet another programming thread)  (Read 3211 times)

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Dynamic Collisions (yet another programming thread)
« on: January 14, 2010, 12:16:38 pm »

Latest screenshot:
Spoiler (click to show/hide)


First off, the purpose of this thread is to bounce ideas off a wall, and hopefully figure some things out. I currently have decent knowledge of C++ and am teaching myself Direct3D.

This program is meant to simulate collisions between two objects, deforming both based on the physics involved in the collision. This is done through several independant code modules, each of which have the ability to be reused in similar programs, possibly extending the simulation ability to include non-moving objects through the application of outside forces. Lol, that's not gonna happen.

So, here are the primary modules:
1. The Collision Detection Module
Spoiler (click to show/hide)

2. The Collision Path Generation Module
Spoiler (click to show/hide)

3. The Node Generation Module
Spoiler (click to show/hide)

4. The Bond Generation Module
Spoiler (click to show/hide)

5. The Physics Based Collision Module
Spoiler (click to show/hide)

6. The Cleanup Module
Spoiler (click to show/hide)

7. Slice Method Module
Spoiler (click to show/hide)

The most interesting thing about this is how it could be used to simulate such a large number of materials. By altering parameters for the bonds, one could create a material which acts like rock (easy to break, but won't really bend), material which acts like metal (easy to bend, hard to break), or even wood by altering the x and y bond strength and adding in a bit of random factor while leaving z strong resulting in splintering.

Edit: this post has been VERY heavily edited to reflect changes made during design and implementation process. I am currently changing based on my typed up design docs which serve as both general docs reminding me of what to do as well as notes.

« Last Edit: April 09, 2010, 01:09:56 pm by alway »
Logged

Lord Dullard

  • Bay Watcher
  • Indubitably.
    • View Profile
    • Cult: Awakening of the Old Ones
Re: Dynamic Collisions (yet another programming thread)
« Reply #1 on: January 14, 2010, 12:27:29 pm »

Well, my first gut-response is this: it'd work for any object wherein the interior texture would exactly match the exterior texture, or for any model with a single uniform type of interior, but for any other model you're going to start running into a lot of difficulties.

To elaborate: if you blow up a watermelon, that sounds like something that could reasonably work here. A watermelon has a relatively uniform interior that could all just be textured in the same way.

Blow up an alarm clock, though, and you run into some serious problems. There are wires in there, and often circuitry pieces or mechanical gears, and probably quite a lot of formed plastic bits. Unless you literally model and texture the interior of all these kinds of objects in vast detail, and determine the strength of the bonds between each of the pieces - which is going to be a huge load on graphics processing and regular processing (probably) - you won't get realistic results.
« Last Edit: January 14, 2010, 12:30:38 pm by Lord Dullard »
Logged

Bricks

  • Bay Watcher
  • Because you never need one brick.
    • View Profile
Re: Dynamic Collisions (yet another programming thread)
« Reply #2 on: January 14, 2010, 12:51:25 pm »

Your idea bears more than a passing resemblance to the way "Sodaplay" works.  I haven't played with that webtoy in ages, but an ongoing (and perhaps now satisfied) community desire was to have collisions between moving objects, not just the boundaries of the screen or, as in a beta version, static player-placed walls.

The notion of increasing the simulation complexity near collision-prone points is interesting.  I think that would be the biggest hurdle and probably the most original part of your implementation.  Distortion and severing of objects would be pretty cool, but as far as human perception goes, distortion is either too fast or too slight to notice.  Severing would be useful in a few specific circumstances, though making that look nice would be tough.

I've found that the collision system you decide to use for a game often dictates the graphics style.  Visually-complex games rarely implement such advanced collision systems, since trying to illustrate how a particular wooden plank bends, cracks, and breaks could take months.  Games like N have a very smooth system for detecting collisions (and the creator wrote a great article describing how it worked), but graphically there isn't a whole lot going on.

The physics engine for "Star Wars: The Force Unleashed" had some cool distortion/severing effects, although it wasn't the best style of gameplay to show it off.
Logged
EMPATHY - being able to feel other peoples' stuff.

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: Dynamic Collisions (yet another programming thread)
« Reply #3 on: January 14, 2010, 01:15:31 pm »

Lord: I see your point, and it is one of the limitations to this sort of system. I hadn't really thought to deeply about the actual texturing... However, if the nodes were given another member in the form of an int/string telling what texture they used, it might not be overly difficult to at least make something which looks reasonable.

Bricks: Heh, sodaplay was fun. As for the system of generating the nodes, I have considered 2 possibilities:
1. Create nodes starting from the area of predicted impact (difficult, but probably more efficient)
2. Create a very large number of nodes, then use an algorithm based on distance from predicted impact to cull the unwanted ones (quite a bit easier, but involves generating literally millions of nodes which will merely be thrown away)
Logged

Bricks

  • Bay Watcher
  • Because you never need one brick.
    • View Profile
Re: Dynamic Collisions (yet another programming thread)
« Reply #4 on: January 14, 2010, 05:18:44 pm »

I think method 1 would be very possible as long as the objects in question aren't moving/spinning too quickly relative to your time interval.  For those that are, you could do some rough collision calculations to give you an idea of where nodes needs to be spawned.  I imagine you'd also need a way to analyze how many objects are possibly involved in a collision so you don't end up with weird clipping or certain objects taking priority over others.

Another issue to be mindful of:  Very springy objects would also have to check for collisions with themselves.  That could be very processor-heavy, so objects that have a chance of self-intersection should either have special code, or should be made of separate, strongly-linked objects.  For example, a simple wire spring could actually be made of a series of half-turns pieced together.  Bodies could be split into their articulatory parts.
Logged
EMPATHY - being able to feel other peoples' stuff.

Sean Mirrsen

  • Bay Watcher
  • Bearer of the Psionic Flame
    • View Profile
Re: Dynamic Collisions (yet another programming thread)
« Reply #5 on: January 14, 2010, 05:31:38 pm »

1: Download "Sumotori Dreams"
2: Disassemble
3: ???
4: Profit!

It doesn't do dynamic deformation, but neatly handles fracturing. And it's a demo-scene app.
Logged
Multiworld Madness Archive:
Game One, Discontinued at World 3.
Game Two, Discontinued at World 1.

"Europe has to grow out of the mindset that Europe's problems are the world's problems, but the world's problems are not Europe's problems."
- Subrahmanyam Jaishankar, Minister of External Affairs, India

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: Dynamic Collisions (yet another programming thread)
« Reply #6 on: January 14, 2010, 07:11:00 pm »

As for the issues you brought up in the first paragraph, something which will happen probably in between steps 1 and 2 (collision detection and node generation) would be the creation of an estimated trajectory. Many of the collisions will take place in between rendered frames, and as such it should be relatively easy to get a decent enough path as there will be no changing forces affecting it (basicly they will be affected by the same forces between end of frame and end of collision aside from the collision itself). As for more than 2 object collisions, how those would work I probably won't bother figuring out until/unless the system works with 2 object collisions.

Self collision will definately need to be dealt with within a collision (in fact, I think I will edit the way the repulsive forces work in the physics part to include all non-bonded nodes). However, other self-intersections would not be dealt with. Partly because nearly all would be sent to normal non-dynamic collision detection due to not meeting the minimum velocity requirement set to prevent static and non-deforming collisions from exploding the CPU. A separate system to accomidate such things would probably work. However, as this is more or less a standalone program which I'm making for fun, I probably won't create said system.
Logged

eerr

  • Bay Watcher
    • View Profile
Re: Dynamic Collisions (yet another programming thread)
« Reply #8 on: January 14, 2010, 08:18:28 pm »

Someday you will blow up the world.
« Last Edit: February 08, 2010, 09:39:14 pm by eerr »
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: Dynamic Collisions (yet another programming thread)
« Reply #9 on: January 26, 2010, 06:42:22 pm »

I'm slowly making progress on this project as well as managing to confuse both my physics and calculus proffessors who can't quite grasp what I am trying to do. I am currently putting any attempts at making it equation based physics in the back corner and I am beginning work on prototyping a simple version of the stepwise physics calculations. If I'm lucky, I will be able to get that working by the end of the month before starting on building modules for the actual program itself.
Logged

Bricks

  • Bay Watcher
  • Because you never need one brick.
    • View Profile
Re: Dynamic Collisions (yet another programming thread)
« Reply #10 on: January 26, 2010, 07:50:29 pm »

What do you mean by "equation based?"  Do you mean you want a closed-form solution that will tell you exactly how physical bodies will collide without simulating each action procedurally?  I can already tell that you will encounter a lot of situation that will require a numerical integration or an Euler's method approximation, so doing it stepwise makes the most sense in the first place.

If that's not what you mean, you could describe it and I might start working it out as much as I can.
Logged
EMPATHY - being able to feel other peoples' stuff.

eerr

  • Bay Watcher
    • View Profile
Re: Dynamic Collisions (yet another programming thread)
« Reply #11 on: January 26, 2010, 10:58:02 pm »

In Super Smash Brothers Brawl impacts stop both characters in their tracks.
I wonder if that would be acceptable in a physics engine?

I just bring it up because it looks dam cool. But if you use 3d there isn't much point because people will usually have to turn to see, rather than just glancing at that sweet explosion/smash attack.
« Last Edit: January 26, 2010, 11:03:25 pm by eerr »
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: Dynamic Collisions (yet another programming thread)
« Reply #12 on: January 28, 2010, 07:48:34 am »

What do you mean by "equation based?"  Do you mean you want a closed-form solution that will tell you exactly how physical bodies will collide without simulating each action procedurally?  I can already tell that you will encounter a lot of situation that will require a numerical integration or an Euler's method approximation, so doing it stepwise makes the most sense in the first place.

If that's not what you mean, you could describe it and I might start working it out as much as I can.
Ya, I've pretty much given up on that method. The reason I wanted to use it is because it probably would require a small fraction of the computing power of a stepwise method. The way I figure though, it will be better to have a working, albiet slow, version than a hypothetically faster version which I probably wouldn't get to work anytime soon. I'm hoping to get the first versions done by April so when I visit RIT I have something to brown-nose the programming proffessors with even before my first year there.  ;)

@eerr: I may end up doing something like that, but it all depends on how fast it is able to go through the collision code. If it takes under 1 second to go through it, probably not, but if it takes something more like 5 seconds I almost certainly will render some of the collision frames just so the veiwer isn't left wondering why the game froze for 5 seconds every time 2 objects collide. On a side note, that would probably make it the first bullet-time event which actually has a raison d'etre. :P
« Last Edit: January 28, 2010, 07:53:49 am by alway »
Logged

alfie275

  • Bay Watcher
    • View Profile
Re: Dynamic Collisions (yet another programming thread)
« Reply #13 on: January 28, 2010, 04:11:26 pm »

Make it like toribash, but you can walk around, it will have normal collision here, but at any time you can press space and enter the turn base melee mode/bullet time.
Logged
I do LP of videogames!
See here:
http://www.youtube.com/user/MrAlfie275

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: Dynamic Collisions (yet another programming thread)
« Reply #14 on: January 31, 2010, 05:12:43 pm »

While searching for a way to determine whether a point is within a volume for step 2, I stumbled across Delaunay triangluation, which then lead me to this: http://en.wikipedia.org/wiki/Finite_element_method
Seems my ideas aren't new... Which is actually a good thing. After all, it means I will now have some more material to work off of (although I find it is usually easier to come up with on my own than searching for on internet, not to mention more fun).
And it also means it is at least possible to do...

Further wiki-walking shows me it is nearly impossible, if not impossible to do fully equations based collisions, since it involves no less than 15 partial differential equations. http://en.wikipedia.org/wiki/Structural_analysis#Elasticity_methods  :o

On another note, I scrapped my first attempt at a prototype due to fundamental flaws in its writing (had seperate objects for nodes and bonds, but due to poor coding, ended up with issues involving multiple copies of the same node and/or bond floating around in vectors with differing values, causing all sorts of trouble. From this I have decided to store only pointers to the bonds (themselves stored nicely away in the main bond container) in the nodes. Aside from that, I still have to figure out what equations I will use for calculating forces. For the repelling force between nodes, I will likely use "modifier/(dist^2)" as this allows for the force to increase very quickly as objects approach one another, and decreasing to negligible amounts quickly, thus allowing for lower radius in which to check for repelling nodes. However, whether I use simple elastic (k*displacement) or some other equation for bonds is still very much up the air. I probably won't nail down these two equations until the program is both working and I am able to test it thoroughly. Another thing I will likely do is store the bonds and nodes in trees, allowing for much more rapid binary searching, as opposed to the standard vector iterations which require much longer to search through the (very large) lists of nodes and bonds.

I have also come up with a solution to finding a method for determining whether a point is in or out of any closed 3d volume given the points and triangle indicies which, although somewhat computationally taxing, should be made much more efficient by the fact that my nodes will initially be lined up in grids (which will keep the worst of the calculations to a minimum). Rather than going into a long description of this system, I think it would suffice to say it involves taking a 2 dimensional slice of the 3d object and using the number of intersecting lines on an axis to determine if it is in or out. There is only one flaw I can see in this method, but it is out of the ordinary enough that it should be relatively easy to compensate for it in the slicing stage.
« Last Edit: January 31, 2010, 08:22:28 pm by alway »
Logged
Pages: [1] 2