understanding and implementing Boids
        Posted  
        
            by 
                alphablender
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by alphablender
        
        
        
        Published on 2012-10-21T21:59:01Z
        Indexed on 
            2012/10/21
            23:00 UTC
        
        
        Read the original article
        Hit count: 210
        
So I'm working on porting Boids to Brightscript, based on the pseudocode here:
http://www.kfish.org/boids/pseudocode.html
I'm trying to understand the data structures involved, for example is Velocity a single value, or is it a 3D value, ie velocity={x,y,z}
It seems as if the pseudocode seems to mix this up where sometimes it has an equation that incudes both vectors and single-value items:
        v1 = rule1(b)
        v2 = rule2(b)
        v3 = rule3(b)
        b.velocity = b.velocity + v1 + v2 + v3
If Velocity is a tripartite value then this would make sense, but I'm not sure.
So my first question here is, is this the correct datastructure for a single boid based on the Pseudocode on that page:
boid={position:{px:0,py:0,pz:0},velocity:{x:0,y:0,z:0},vector:{x:0,y:0,z:0},pc:{x:0,y:0,z:0},pv:{x:0,y:0,z:0})
where pc=perceived center, pv= perceived velocity
I"ve implemented a vector_add, vector_sub, vector_div, and vector boolean functions.
The reason I'm starting from this pseudocode is I've not been able to find anything else that is as readable, but it still leaves me with lots of questions as the data structures are not explicitly defined for each variable.
(edit) here's a good example of what i'm talking about:
IF |b.position - bJ.position| < 100 THEN
if b.position - b[j].position are both 3D coordinates, how can they be considered "less than 100" unless they are < {100,100,100} ?
Maybe that is what I need to do here, use a vector comparison function?
© Stack Overflow or respective owner