encapsulated parameters that control flock behaviour
parent
c1109c1810
commit
bf2061a391
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
|
||||
namespace Flocking
|
||||
{
|
||||
public struct FlockParameters
|
||||
{
|
||||
public int flockSize;
|
||||
public float maxSpeed;
|
||||
public float maxForce;
|
||||
public float neighbourDistance;
|
||||
public float desiredSeparation;
|
||||
public float tolerance;
|
||||
public float separationWeighting;
|
||||
public float alignmentWeighting;
|
||||
public float cohesionWeighting;
|
||||
public float lookaheadDistance;
|
||||
}
|
||||
}
|
||||
|
|
@ -35,17 +35,7 @@ namespace Flocking
|
|||
{
|
||||
private List<Boid> m_flock = new List<Boid>();
|
||||
private FlowField m_flowField;
|
||||
private float m_maxSpeed;
|
||||
private float m_maxForce;
|
||||
private float m_neighbourDistance;
|
||||
private float m_desiredSeparation;
|
||||
private float m_tolerance;
|
||||
private float m_separationWeighting = 1.5f;
|
||||
private float m_alignmentWeighting = 1f;
|
||||
private float m_cohesionWeighting = 1f;
|
||||
private float m_lookaheadDistance = 100f;
|
||||
|
||||
|
||||
private FlockParameters m_parameters;
|
||||
private Random m_rnd = new Random(Environment.TickCount);
|
||||
|
||||
public int Size {
|
||||
|
@ -59,12 +49,8 @@ namespace Flocking
|
|||
}
|
||||
}
|
||||
|
||||
public FlockingModel( float maxSpeed, float maxForce, float neighbourDistance, float desiredSeparation, float tolerance ) {
|
||||
m_maxSpeed = maxSpeed;
|
||||
m_maxForce = maxForce;
|
||||
m_neighbourDistance = neighbourDistance;
|
||||
m_desiredSeparation = desiredSeparation;
|
||||
m_tolerance = tolerance;
|
||||
public FlockingModel( FlockParameters parameters ) {
|
||||
m_parameters = parameters;
|
||||
}
|
||||
|
||||
void AddBoid (string name)
|
||||
|
@ -82,57 +68,58 @@ namespace Flocking
|
|||
}
|
||||
|
||||
public float MaxSpeed {
|
||||
get {return m_maxSpeed;}
|
||||
get {return m_parameters.maxSpeed;}
|
||||
}
|
||||
|
||||
public float MaxForce {
|
||||
get {return m_maxForce;}
|
||||
get {return m_parameters.maxForce;}
|
||||
}
|
||||
|
||||
public float NeighbourDistance {
|
||||
get {return m_neighbourDistance;}
|
||||
get {return m_parameters.neighbourDistance;}
|
||||
}
|
||||
|
||||
public float DesiredSeparation {
|
||||
get {return m_desiredSeparation;}
|
||||
get {return m_parameters.desiredSeparation;}
|
||||
}
|
||||
|
||||
public float Tolerance {
|
||||
get {return m_tolerance;}
|
||||
get {return m_parameters.tolerance;}
|
||||
}
|
||||
|
||||
public float SeparationWeighting {
|
||||
get{ return m_separationWeighting; }
|
||||
set{ m_separationWeighting = value;}
|
||||
get{ return m_parameters.separationWeighting; }
|
||||
set{ m_parameters.separationWeighting = value;}
|
||||
}
|
||||
|
||||
public float AlignmentWeighting {
|
||||
get{ return m_alignmentWeighting; }
|
||||
set{ m_alignmentWeighting = value;}
|
||||
get{ return m_parameters.alignmentWeighting; }
|
||||
set{ m_parameters.alignmentWeighting = value;}
|
||||
}
|
||||
|
||||
public float CohesionWeighting {
|
||||
get{ return m_cohesionWeighting; }
|
||||
set{ m_cohesionWeighting = value;}
|
||||
get{ return m_parameters.cohesionWeighting; }
|
||||
set{ m_parameters.cohesionWeighting = value;}
|
||||
}
|
||||
|
||||
public float LookaheadDistance {
|
||||
get { return m_lookaheadDistance; }
|
||||
set { m_lookaheadDistance = value;}
|
||||
get { return m_parameters.lookaheadDistance; }
|
||||
set { m_parameters.lookaheadDistance = value;}
|
||||
}
|
||||
|
||||
|
||||
public void Initialise (int num, FlowField flowField)
|
||||
public void Initialise (FlowField flowField)
|
||||
{
|
||||
m_flowField = flowField;
|
||||
for (int i = 0; i < num; i++) {
|
||||
for (int i = 0; i < m_parameters.flockSize; i++) {
|
||||
AddBoid ("boid"+i );
|
||||
}
|
||||
}
|
||||
|
||||
public List<Boid> GetNeighbours(Boid boid) {
|
||||
return m_flock.FindAll(delegate(Boid other) {
|
||||
return (boid != other) && (Utils.GetDistanceTo (boid.Location, other.Location) < m_neighbourDistance);
|
||||
return m_flock.FindAll(delegate(Boid other)
|
||||
{
|
||||
return (boid != other) && (Utils.GetDistanceTo (boid.Location, other.Location) < m_parameters.neighbourDistance);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -54,17 +54,8 @@ namespace Flocking
|
|||
private int m_frameUpdateRate = 1;
|
||||
private int m_chatChannel = 118;
|
||||
private string m_boidPrim;
|
||||
private int m_flockSize = 100;
|
||||
private float m_maxSpeed;
|
||||
private float m_maxForce;
|
||||
private float m_neighbourDistance;
|
||||
private float m_desiredSeparation;
|
||||
private float m_tolerance;
|
||||
private float m_separationWeighting = 1.5f;
|
||||
private float m_alignmentWeighting = 1f;
|
||||
private float m_cohesionWeighting = 1f;
|
||||
private float m_lookaheadDistance = 100f;
|
||||
private ChatCommandParser m_chatCommandParser;
|
||||
private FlockParameters m_parameters;
|
||||
|
||||
private UUID m_owner;
|
||||
|
||||
|
@ -80,18 +71,19 @@ namespace Flocking
|
|||
if (config != null) {
|
||||
m_chatChannel = config.GetInt ("chat-channel", 118);
|
||||
m_boidPrim = config.GetString ("boid-prim", "boidPrim");
|
||||
m_flockSize = config.GetInt ("flock-size", 100);
|
||||
m_maxSpeed = config.GetFloat("max-speed", 3f);
|
||||
m_maxForce = config.GetFloat("max-force", 0.25f);
|
||||
m_neighbourDistance = config.GetFloat("neighbour-dist", 25f);
|
||||
m_desiredSeparation = config.GetFloat("desired-separation", 20f);
|
||||
m_tolerance = config.GetFloat("tolerance", 5f);
|
||||
m_separationWeighting = config.GetFloat("separation-weighting", 1.5f);
|
||||
m_alignmentWeighting = config.GetFloat("alignment-weighting", 1f);
|
||||
m_cohesionWeighting = config.GetFloat("cohesion-weighting", 1f);
|
||||
m_lookaheadDistance = config.GetFloat("lookahead-dist",100f);
|
||||
|
||||
|
||||
m_parameters = new FlockParameters();
|
||||
m_parameters.flockSize = config.GetInt ("flock-size", 100);
|
||||
m_parameters.maxSpeed = config.GetFloat("max-speed", 3f);
|
||||
m_parameters.maxForce = config.GetFloat("max-force", 0.25f);
|
||||
m_parameters.neighbourDistance = config.GetFloat("neighbour-dist", 25f);
|
||||
m_parameters.desiredSeparation = config.GetFloat("desired-separation", 20f);
|
||||
m_parameters.tolerance = config.GetFloat("tolerance", 5f);
|
||||
m_parameters.separationWeighting = config.GetFloat("separation-weighting", 1.5f);
|
||||
m_parameters.alignmentWeighting = config.GetFloat("alignment-weighting", 1f);
|
||||
m_parameters.cohesionWeighting = config.GetFloat("cohesion-weighting", 1f);
|
||||
m_parameters.lookaheadDistance = config.GetFloat("lookahead-dist", 100f);
|
||||
|
||||
// we're in the config - so turn on this module
|
||||
m_enabled = true;
|
||||
}
|
||||
|
@ -111,11 +103,8 @@ namespace Flocking
|
|||
m_scene.EventManager.OnChatFromClient += m_chatCommandParser.SimChatSent; //listen for commands sent from the client
|
||||
|
||||
// init module
|
||||
m_model = new FlockingModel (m_maxSpeed, m_maxForce, m_neighbourDistance, m_desiredSeparation, m_tolerance);
|
||||
m_model.SeparationWeighting = m_separationWeighting;
|
||||
m_model.AlignmentWeighting = m_alignmentWeighting;
|
||||
m_model.CohesionWeighting = m_cohesionWeighting;
|
||||
m_model.LookaheadDistance = m_lookaheadDistance;
|
||||
m_model = new FlockingModel (m_parameters);
|
||||
|
||||
m_view = new FlockingView (m_scene);
|
||||
m_view.BoidPrim = m_boidPrim;
|
||||
}
|
||||
|
@ -134,7 +123,7 @@ namespace Flocking
|
|||
FlowField field = new FlowField(scene, new Vector3(128f, 128f, 128f), 200, 200, 200);
|
||||
|
||||
// Generate initial flock values
|
||||
m_model.Initialise (m_flockSize, field);
|
||||
m_model.Initialise (field);
|
||||
|
||||
// who is the owner for the flock in this region
|
||||
m_owner = m_scene.RegionInfo.EstateSettings.EstateOwner;
|
||||
|
|
Loading…
Reference in New Issue