expose additional parameters to ini files

stable0711
Jon Cundill 2011-07-11 00:08:26 +01:00
parent f0bc7e018b
commit 75f4750694
4 changed files with 64 additions and 26 deletions

View File

@ -40,13 +40,8 @@ namespace Flocking
private Vector3 m_vel;
private Vector3 m_acc;
private Random m_rndnums = new Random (Environment.TickCount);
private float m_tolerance; // how close can we get to things witout being edgy
private float m_maxForce; // Maximum steering force
private float m_maxSpeed; // Maximum speed
private float m_neighborDist = 25.0f;
private float m_desiredSeparation = 20.0f;
private FlockingModel m_model;
private FlowMap m_flowMap;
@ -62,14 +57,12 @@ namespace Flocking
/// <param name='mf'>
/// Mf. max force / acceleration this boid can extert
/// </param>
public Boid (string id, float ms, float mf, FlowMap flowMap)
public Boid (string id, FlockingModel model, FlowMap flowMap)
{
m_id = id;
m_acc = Vector3.Zero;
m_vel = new Vector3 (m_rndnums.Next (-1, 1), m_rndnums.Next (-1, 1), m_rndnums.Next (-1, 1));
m_tolerance = 5.0f;
m_maxSpeed = ms;
m_maxForce = mf;
m_model = model;
m_flowMap = flowMap;
}
@ -159,7 +152,7 @@ namespace Flocking
m_vel += m_acc;
// Limit speed
//m_vel.limit(maxspeed);
m_vel = Util.Limit (m_vel, m_maxSpeed);
m_vel = Util.Limit (m_vel, m_model.MaxSpeed);
m_loc += m_vel;
// Reset accelertion to 0 each cycle
m_acc *= 0.0f;
@ -201,15 +194,15 @@ namespace Flocking
desired.Normalize ();
// Two options for desired vector magnitude (1 -- based on distance, 2 -- maxspeed)
if ((slowdown) && (d < 100.0f)) {
desired *= (m_maxSpeed * (d / 100.0f)); // This damping is somewhat arbitrary
desired *= (m_model.MaxSpeed * (d / 100.0f)); // This damping is somewhat arbitrary
} else {
desired *= m_maxSpeed;
desired *= m_model.MaxSpeed;
}
// Steering = Desired minus Velocity
//steer = target.sub(desired,m_vel);
steer = Vector3.Subtract (desired, m_vel);
//steer.limit(maxforce); // Limit to maximum steering force
steer = Util.Limit (steer, m_maxForce);
steer = Util.Limit (steer, m_model.MaxForce);
} else {
steer = Vector3.Zero;
}
@ -226,7 +219,7 @@ namespace Flocking
{
//look tolerance metres ahead
Vector3 normVel = Vector3.Normalize(m_vel);
Vector3 inFront = m_loc + Vector3.Multiply(normVel, m_tolerance);
Vector3 inFront = m_loc + Vector3.Multiply(normVel, m_model.Tolerance);
if( m_flowMap.WouldHitObstacle( m_loc, inFront ) ) {
AdjustVelocityToAvoidObstacles ();
@ -243,7 +236,7 @@ namespace Flocking
normVel.X += xDelta;
normVel.Y += yDelta;
normVel.Z += zDelta;
Vector3 inFront = m_loc + Vector3.Multiply(normVel, m_tolerance);
Vector3 inFront = m_loc + Vector3.Multiply(normVel, m_model.Tolerance);
if( !m_flowMap.WouldHitObstacle( m_loc, inFront ) ) {
m_vel.X += xDelta;
m_vel.Y += yDelta;
@ -280,7 +273,7 @@ namespace Flocking
foreach (Boid other in boids) {
float d = Vector3.Distance (m_loc, other.Location);
// If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself)
if ((d > 0) && (d < m_desiredSeparation)) {
if ((d > 0) && (d < m_model.DesiredSeparation)) {
// Calculate vector pointing away from neighbor
Vector3 diff = Vector3.Subtract (m_loc, other.Location);
diff.Normalize ();
@ -298,10 +291,10 @@ namespace Flocking
if (steer.Length () > 0) {
// Implement Reynolds: Steering = Desired - Velocity
steer.Normalize ();
steer *= m_maxSpeed;
steer *= m_model.MaxSpeed;
steer -= m_vel;
//steer.limit(maxforce);
steer = Util.Limit (steer, m_maxForce);
steer = Util.Limit (steer, m_model.MaxForce);
}
return steer;
}
@ -320,7 +313,7 @@ namespace Flocking
int count = 0;
foreach (Boid other in boids) {
float d = Vector3.Distance (m_loc, other.Location);
if ((d > 0) && (d < m_neighborDist)) {
if ((d > 0) && (d < m_model.NeighbourDistance)) {
steer += other.Velocity;
count++;
}
@ -333,10 +326,10 @@ namespace Flocking
if (steer.Length () > 0) {
// Implement Reynolds: Steering = Desired - Velocity
steer.Normalize ();
steer *= m_maxSpeed;
steer *= m_model.MaxSpeed;
steer -= m_vel;
//steer.limit(maxforce);
steer = Util.Limit (steer, m_maxForce);
steer = Util.Limit (steer, m_model.MaxForce);
}
return steer;
@ -357,7 +350,7 @@ namespace Flocking
foreach (Boid other in boids) {
float d = Vector3.Distance (m_loc, other.Location);
if ((d > 0) && (d < m_neighborDist)) {
if ((d > 0) && (d < m_model.NeighbourDistance)) {
sum += other.Location; // Add location
count++;
}

View File

@ -20,6 +20,7 @@
<include name="FlockingModel.cs" />
<include name="FlockingModule.cs" />
<include name="FlockingView.cs" />
<include name="FlowMap.cs" />
<include name="Util.cs" />
</sources>
<references basedir="${project::get-base-directory()}">

View File

@ -34,6 +34,11 @@ namespace Flocking
{
private List<Boid> m_flock = new List<Boid>();
private FlowMap m_flowMap;
private float m_maxSpeed;
private float m_maxForce;
private float m_neighbourDistance;
private float m_desiredSeparation;
private float m_tolerance;
private Random m_rnd = new Random(Environment.TickCount);
@ -47,10 +52,18 @@ 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;
}
void AddBoid (string name)
{
Boid boid = new Boid (name, 3.0f, 0.05f, m_flowMap);
Boid boid = new Boid (name, this, m_flowMap);
// find an initial random location for this Boid
// somewhere not within an obstacle
@ -68,8 +81,27 @@ namespace Flocking
m_flock.Add (boid);
}
public float MaxSpeed {
get {return m_maxSpeed;}
}
public float MaxForce {
get {return m_maxForce;}
}
public float NeighbourDistance {
get {return m_neighbourDistance;}
}
public float DesiredSeparation {
get {return m_desiredSeparation;}
}
public float Tolerance {
get {return m_tolerance;}
}
public void Initialise (int num, FlowMap flowMap)
{
m_flowMap = flowMap;

View File

@ -55,6 +55,12 @@ namespace Flocking
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 UUID m_owner;
#region IRegionModule Members
@ -70,6 +76,12 @@ namespace Flocking
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);
// we're in the config - so turn on this module
m_enabled = true;
@ -89,7 +101,7 @@ namespace Flocking
m_scene.EventManager.OnChatFromClient += SimChatSent; //listen for commands sent from the client
// init module
m_model = new FlockingModel ();
m_model = new FlockingModel (m_maxSpeed, m_maxForce, m_neighbourDistance, m_desiredSeparation, m_tolerance);
m_view = new FlockingView (m_scene);
m_view.BoidPrim = m_boidPrim;
}