Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 25th, 2008, 04:21 PM
samUK samUK is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 3 samUK User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 37 sec
Reputation Power: 0
Question What algorithm?

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))

Reply With Quote
  #2  
Old April 8th, 2008, 10:52 PM
Ramihg's Avatar
Ramihg Ramihg is offline
unlink /usr/bin/*
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Vancouver, Canada
Posts: 181 Ramihg User rank is Second Lieutenant (5000 - 10000 Reputation Level)Ramihg User rank is Second Lieutenant (5000 - 10000 Reputation Level)Ramihg User rank is Second Lieutenant (5000 - 10000 Reputation Level)Ramihg User rank is Second Lieutenant (5000 - 10000 Reputation Level)Ramihg User rank is Second Lieutenant (5000 - 10000 Reputation Level)Ramihg User rank is Second Lieutenant (5000 - 10000 Reputation Level)Ramihg User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 7 h 37 m 27 sec
Reputation Power: 64
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

Reply With Quote
  #3  
Old April 11th, 2008, 03:03 PM
ejac ejac is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Location: Belgium
Posts: 109 ejac User rank is Sergeant (500 - 2000 Reputation Level)ejac User rank is Sergeant (500 - 2000 Reputation Level)ejac User rank is Sergeant (500 - 2000 Reputation Level)ejac User rank is Sergeant (500 - 2000 Reputation Level)ejac User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 7 h 7 m 21 sec
Reputation Power: 9
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.

Reply With Quote
  #4  
Old April 22nd, 2008, 09:03 PM
disablek disablek is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 47 disablek User rank is Sergeant (500 - 2000 Reputation Level)disablek User rank is Sergeant (500 - 2000 Reputation Level)disablek User rank is Sergeant (500 - 2000 Reputation Level)disablek User rank is Sergeant (500 - 2000 Reputation Level)disablek User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 4 h 21 m 47 sec
Reputation Power: 9
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?

Reply With Quote
  #5  
Old May 5th, 2008, 05:38 AM
Peter_APIIT Peter_APIIT is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 22 Peter_APIIT Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 40 m 10 sec
Reputation Power: 0
This is very interesting.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > What algorithm?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT