|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
Hi, im doing a project and need some advice regarding what the best way of programming it is.I am basically gonna create what looks like a tank with organisms floating in it. Now, their positions are going to be dynamic. They will either float up or down to represent stocks that are up and down.(This bit im fine with). But i would like to do the following things and am not sure what approaches i should take,(such as flocking etc) 1. An organism will be made up of a number of smaller particles which should be attracted together so they stay in a clump. 2. These clumps/organisms need to repel eachother/collide but then bounce off. 3. As i said they will move up or down, but i would like to add some random movement in between, so they dont just go straight up and down. ??? I have looked in to flocking and obstacle avoidance but seem to be drowning in all this info. Could someone possibe guide me on the best way to create these behaviours/relationships? (p.s, i am doing this in actionscript 2.0, if anyone needs to know (and i am an intermediate newbie)) |
|
#2
|
||||
|
||||
|
I'm really tired and I think I'm a little brain dead but this sounds fun so I'll try to say anything anyway.
1. Hmm.. How about giving each particle something like a "body id". All particles with the same body id attract each other with a constant attraction +/- a little random fraction so it wobbles a little. 2. You have a few ways to approach this. The first one would to give each "organism" an exterior invisible shell or box that detects collision and bounces the organism away when it collides with another box. Another more realistic ( also more computationally consuming) method is to do collision detection on each and every particle. So when a particle of organism A hits a particle of organism B, they bounce away from each other. This will create a chain of reaction as each particle in organism A hits organism B's particles goes the opposite direction, attracting other particles of its same organism ( due to part #1 ). 3. You'll have to implement a mini-physics engine anyway so the hell with it. Give each organism a certain (or random) velocity. Any organism could have states that represent how it moves. If it is idle, it will be going on a random small acceleration oscillating between negative and positive values ( so it kinda goes up and down ). If you want a certain organism to suddenly go up or down, just edit that specific organism's velocity or acceleration to reflect the direction you want it to go. Then just set its state back to idle when you're done with it. Please correct me if my ideas are stupid. Have fun ![]() |
|
#3
|
|||
|
|||
|
As has been said, you are probably going to have to implement a mini physics engine. This is based on Newtons laws, and basically says:
Forces acting on particles with a certain mass gives them acceleration in time. Acceleration in time will lead to velocity. And velocity in time will lead to displacement. I learned how to program those concepts from the articles presented here: http://www.chrishecker.com/Rigid_Body_Dynamics Now when you have that implemented (it shouldnt be that hard, but will take some time). Then for each of your particles (of the same object), go through all other particles and calculate the distance (try not to do double work). And then assign a force, inverse proportional to the distance, for each distance (force is a vector). Then do the vector sum of all the force vectors of a particle to get the resulting force. This force vector you calculate for each particle, and put it in your physics engine, and it will give you the new accelerations which lead to velocities, which lead to the next position of each particle. Then do it all over again for the next timestep. For part 2, When approached in a simple way: I would calculate the centre of gravity of the particles of each clump (should be easy to find how to with google). And use that point and assign it the mass of the sum of the particles of that clump. Then calculate a bounding sphere/box around the particles, and let that sphere/box do the collision with the other clumps. 3. Add a random force vector in the equation. Which changes over a few timesteps (you could crossfade between sequential random vectors, probably best to do that in polar coordinates) Last edited by ejac : April 11th, 2008 at 03:07 PM. |
|
#4
|
|||
|
|||
|
Flocking's a pretty simple concenpt to understand if you understand the distance/speed/acc equations first and then separation, cohesion, alignment.
The general idea is velocity + current position is the next position, acc + current velocity is the new velocity. Then for one boid, use the distance between it and all other boids to determine the acc. You could use the Strategy pattern for implementing the behaviour of each boid/particle. Basically it's just the concept of being able to replace a set of code with another to achieve dynamic behaviour. so it could be something like if close to wall, boid.behaviour=evade wall else boid.behaviour=flock; But you know if you do any random movement, and the particles are supposed to represent movements of stock up and down, wouldn't you be restricted to making the particles move only left /right in 2D or a plane in 3D? |
|
#5
|
|||
|
|||
|
This is very interesting.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Software Design > What algorithm? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|