1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 // An implementation of Craig Reynold's Boid Simulation.
15 #ifndef BOID_H
16 #define BOID_H
17 
18 #include <graphics/Vector2D.h>
19 
20 class Boid {
21 public:
22     Boid(float x, float y);
23     void resetAcceleration();
24     void flock(const Boid* boids[], int numBoids, int index, float limitX, float limitY);
25     // The following floats are the parameters for the flocking algorithm, changing these
26     // modifies the boid's behaviour.
27     static const constexpr float MAX_SPEED = 2.0f;// Upper limit of boid velocity.
28     static const constexpr float MAX_FORCE = 0.05f;// Upper limit of the force used to push a boid.
29     static const constexpr float NEIGHBOUR_RADIUS = 70.0f;// Radius used to find neighbours, was 50.
30     static const constexpr float DESIRED_BOID_DIST = 35.0f;// Distance boids want to be from others, was 25.
31     // The weightings of the components.
32     static const constexpr float SEPARATION_WEIGHT = 2.0f;
33     static const constexpr float ALIGNMENT_WEIGHT = 1.0f;
34     static const constexpr float COHESION_WEIGHT = 1.0f;
35     Vector2D mPosition;
36     Vector2D mVelocity;
37     Vector2D mAcceleration;
38 };
39 #endif
40