So I'm working on porting Boids to Brightscript, based on the pseudocode here.
I'm trying to understand the data structures involved, for example is Velocity a single value, or is it a 3D value? (i.e. 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: based on the pseudocode above, is this the correct data structure for a single boid?
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, and 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}
?
What is ment here by the expression:
Is actually a scalar from the difference of the two vectors.
This scalar is a single value and can thus be < 100.