
FreeBASIC's Official Forums
|
| View previous topic :: View next topic |
| Author |
Message |
|
|
Posted: Mar 03, 2006 8:27 Post subject: Atom Smash simulation |
|
|
EDIT: All of the source mentioned in this post is available for download here: http://frontpage.execulink.com/coder/freebasic/atoms.asp
I was looking around for a module in my old qb code and I found this instead:
Blocks (made of simulated bonded atoms) are dropped from some height and smash against the ground and each other.
I made it about 6 years ago in QB. It's one of several that I did trying to simulate things like jello and dominos. Anyway, I only had to change a few lines to get it to compile and run in freebasic. (it could not have been easier).
There are some constants at the top of the program that can be tweaked to give different effects. Since the simulation is not based on any real physics, numbers don't have any real world meaning: so you will just have to play with the values. And I'm sorry if it's too fast for newer computers, there's no timing code. Maybe you can add a sleep or something in the main loop.
Download Source :atom_smash.bas 10k
I now go back to my search for what I was really looking for.
Last edited by coderJeff on Mar 27, 2006 22:17; edited 1 time in total |
| |
|
| Back to top |
|
 |
|
|
Posted: Mar 03, 2006 8:30 Post subject: |
|
|
| Can you add a feature so I can hit space or click and bounce them against each other? I really like this program. |
| |
|
| Back to top |
|
 |
|
|
Posted: Mar 03, 2006 8:45 Post subject: |
|
|
| Hmmm, looking at the code, looks like I put something like that in there. (Must have been thinking the same thing as you) Press uppercase "A" and it will give one of the atoms a jerk upward. Look in the code around line 129 where it has CASE "A" Maybe you could add some of your own CASE statements in there and play around with it. |
| |
|
| Back to top |
|
 |
|
|
Posted: Mar 03, 2006 8:50 Post subject: |
|
|
| Thanks ^_~ |
| |
|
| Back to top |
|
 |
|
|
Posted: Mar 03, 2006 10:05 Post subject: |
|
|
That's cool , and look so realistic .... great physic stuff
I added SCREENSYNC before "FLIP" and the motion looks even better (less nervous move)
I really like it ! |
| |
|
| Back to top |
|
 |
|
|
Posted: Mar 03, 2006 13:10 Post subject: |
|
|
| screensync ... great idea, I wish I thought of that. I noticed that I was also missing a constant for the maximum speed an atom could go. (It is set to 5). So I also added that and updated the posted source. Thanks! |
| |
|
| Back to top |
|
 |
|
|
|
| Back to top |
|
 |
|
|
Posted: Mar 03, 2006 14:35 Post subject: |
|
|
| The fact that nodes snap off is incredible, imagine using this as a ragdoll system in some side scrolling game, your guy leaps off an edge, impacts the ground, and he is dismembered... |
| |
|
| Back to top |
|
 |
|
|
Posted: Mar 03, 2006 14:46 Post subject: |
|
|
| arenth wrote: | | The fact that nodes snap off is incredible, imagine using this as a ragdoll system in some side scrolling game, your guy leaps off an edge, impacts the ground, and he is dismembered... | Thanks. I'll add that to my project list.
EDIT: *Added Mr. Ragdoll to project list* |
| |
|
| Back to top |
|
 |
|
|
Posted: Mar 03, 2006 17:14 Post subject: |
|
|
2D stickmen ... Cool idea! Maybe a good way to get out aggressiveness by tossing them and squashing them with heavy virtual bricks. (Oh, nooo! who will help Mr. Bill? SPLAT!)
Some of the global constants could be coded in to the "Bonds" type so that things like body joints could have different properties from things like legs and arms. So that when dismemberment occurs, it's more likely to occur at a joint.
Here's an idea. Create a program that takes a color bitmap and converts it to an atom lattice structure, different colors could indicate different properties.
I added some of mambazo's code bits to add color to the atoms. Also, press "ESC" to exit, "R" to restart, SPACE to add random velocities.
I added a function to create a triangular shaped block, and I also re-read though my code and made a comment about how the program is supposed to work.
Link is as before: atom_smash.bas 12 k
| Code:
|
|
'' This particle system is not based on any real world model but '' it does have some theory. The math is simplified by having '' all "atoms" of the same size and mass. (There is no mass in '' any of the calculations) Also, certain physical effects are '' simulated using factors and conditions to change the state of '' the system. '' '' The solid bodies are made up of "atoms". '' '' * Atoms have a spacing and a size (ATOMSPACE, ATOMSIZE) '' * Atoms are affected by gravity (XGRAVITY, YGRAVITY) '' * Atoms can bounce off the sides and bottom of the screen '' and when they do, lose some momentum due to the '' collision (BOUNDDECAY) '' * Atoms have a max speed (MAXSPEED) to limit values and '' make the simulation work better. '' '' "Bonds" represent the relationship between two atoms. '' When a bond is first created a distance between two atoms '' is set to indicate how far the two atoms should be from '' each other. Too far or too close and the system will move '' the atoms closer or further apart. Let's call this the '' balanced distance. '' '' * The rate at which two atoms return to the balanced '' distance is affected by stiffness (STIFFNESS). '' * If two atoms are moving away from each other and the '' instantaneous velocity is high enough the bond is '' broken. (BREAKTHRESHOLD) '' * If the magnitude of the relative velocity between two '' atoms is high enough (DEFORMTHRESHOLD) the bond can be '' deformed. The amount of deformation is controlled '' by a factor. (FDEFORM)
|
|
| |
|
| Back to top |
|
 |
|
|
Posted: Mar 03, 2006 17:40 Post subject: |
|
|
| Did anyone see that "game", where you had a 3D Stickman, and a scene (like a flight of stairs, or a truck) and you had to cause as much damage as possible to the stick man by 'pushing' his limbs? |
| |
|
| Back to top |
|
 |
|
|
Posted: Mar 03, 2006 17:52 Post subject: |
|
|
Oh, I know what you're talking about now: http://jet.ro/dismount/
Not sure how it would work in 2D though ... |
| |
|
| Back to top |
|
 |
|
|
Posted: Mar 03, 2006 18:08 Post subject: |
|
|
| Thats the one! :P |
| |
|
| Back to top |
|
 |
|
|
Posted: Mar 03, 2006 19:53 Post subject: |
|
|
OK, here's another version that can load a from a bitmap.
ragdoll_smash.bas 14 k
ragdoll.bmp 4 k
WARNING: Some may find this program offensive and may not be suitable for younger audiences. |
| |
|
| Back to top |
|
 |
|
|
Posted: Mar 03, 2006 20:15 Post subject: |
|
|
| EDIT: Brilliant! :P |
| |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|