コード例 #1
0
		/** Adds an obstacle described by the vertices.
		 * 
		 * \see RemoveObstacle
		 */
		public ObstacleVertex AddObstacle (Vector3[] vertices, float height, Matrix4x4 matrix, RVOLayer layer = RVOLayer.DefaultObstacle) {
			
			if (vertices == null) throw new System.ArgumentNullException ("Vertices must not be null");
			
			if (vertices.Length < 2) throw new System.ArgumentException ("Less than 2 vertices in an obstacle");
			
			ObstacleVertex first = null;
			ObstacleVertex prev = null;
			
			bool identity = matrix == Matrix4x4.identity;
			
			//Don't interfere with ongoing calculations
			if (Multithreading && doubleBuffering) for (int j=0;j<workers.Length;j++) workers[j].WaitOne();
			
			for (int i=0;i<vertices.Length;i++) {
				ObstacleVertex v = new ObstacleVertex();
				if (first == null) first = v;
				else prev.next = v;
				
				v.prev = prev;
				v.layer = layer;

				//Premature optimization ftw!
				v.position = identity ? vertices[i] : matrix.MultiplyPoint3x4(vertices[i]);
				
				//v.thin = thin;
				v.height = height;
				
				prev = v;
			}
			
			prev.next = first;
			first.prev = prev;
			
			ObstacleVertex c = first;
			do {
				Vector3 dir = c.next.position - c.position;
				c.dir = new Vector2 (dir.x,dir.z).normalized;


				c = c.next;
			} while (c != first);
			
			obstacles.Add (first);
			
			UpdateObstacles ();
			return first;
		}
コード例 #2
0
ファイル: Simulator.cs プロジェクト: GameDiffs/TheForest
 public ObstacleVertex AddObstacle(Vector3[] vertices, float height, Matrix4x4 matrix, RVOLayer layer = RVOLayer.DefaultObstacle)
 {
     if (vertices == null)
     {
         throw new ArgumentNullException("Vertices must not be null");
     }
     if (vertices.Length < 2)
     {
         throw new ArgumentException("Less than 2 vertices in an obstacle");
     }
     ObstacleVertex obstacleVertex = null;
     ObstacleVertex obstacleVertex2 = null;
     bool flag = matrix == Matrix4x4.identity;
     if (this.Multithreading && this.doubleBuffering)
     {
         for (int i = 0; i < this.workers.Length; i++)
         {
             this.workers[i].WaitOne();
         }
     }
     for (int j = 0; j < vertices.Length; j++)
     {
         ObstacleVertex obstacleVertex3 = new ObstacleVertex();
         if (obstacleVertex == null)
         {
             obstacleVertex = obstacleVertex3;
         }
         else
         {
             obstacleVertex2.next = obstacleVertex3;
         }
         obstacleVertex3.prev = obstacleVertex2;
         obstacleVertex3.layer = layer;
         obstacleVertex3.position = ((!flag) ? matrix.MultiplyPoint3x4(vertices[j]) : vertices[j]);
         obstacleVertex3.height = height;
         obstacleVertex2 = obstacleVertex3;
     }
     obstacleVertex2.next = obstacleVertex;
     obstacleVertex.prev = obstacleVertex2;
     ObstacleVertex obstacleVertex4 = obstacleVertex;
     do
     {
         Vector3 vector = obstacleVertex4.next.position - obstacleVertex4.position;
         ObstacleVertex arg_13E_0 = obstacleVertex4;
         Vector2 vector2 = new Vector2(vector.x, vector.z);
         arg_13E_0.dir = vector2.normalized;
         obstacleVertex4 = obstacleVertex4.next;
     }
     while (obstacleVertex4 != obstacleVertex);
     this.obstacles.Add(obstacleVertex);
     this.UpdateObstacles();
     return obstacleVertex;
 }
コード例 #3
0
ファイル: Agent.cs プロジェクト: GameDiffs/TheForest
 public void BufferSwitch()
 {
     this.radius = this.Radius;
     this.height = this.Height;
     this.maxSpeed = this.MaxSpeed;
     this.neighbourDist = this.NeighbourDist;
     this.agentTimeHorizon = this.AgentTimeHorizon;
     this.obstacleTimeHorizon = this.ObstacleTimeHorizon;
     this.maxNeighbours = this.MaxNeighbours;
     this.desiredVelocity = this.DesiredVelocity;
     this.locked = this.Locked;
     this.collidesWith = this.CollidesWith;
     this.layer = this.Layer;
     this.Velocity = this.velocity;
     List<ObstacleVertex> list = this.obstaclesBuffered;
     this.obstaclesBuffered = this.obstacles;
     this.obstacles = list;
 }
コード例 #4
0
ファイル: RVOAgent.cs プロジェクト: westernknight/RVO
        public void BufferSwitch()
        {
            // <==
            radius = Radius;
            height = Height;
            maxSpeed = MaxSpeed;
            neighbourDist = NeighbourDist;
            agentTimeHorizon = AgentTimeHorizon;
            obstacleTimeHorizon = ObstacleTimeHorizon;
            maxNeighbours = MaxNeighbours;
            desiredVelocity = DesiredVelocity;
            locked = Locked;
            collidesWith = CollidesWith;
            layer = Layer;

            //position = Position;

            // ==>
            Velocity = velocity;
            List<ObstacleVertex> tmp = obstaclesBuffered;
            obstaclesBuffered = obstacles;
            obstacles = tmp;
        }