### Move isVisible() into BoidForces.

parent 8cb3920b
 ... ... @@ -133,11 +133,70 @@ public abstract class BoidForces { } /** * Is the another point is space in the field of view? * True if the given position is visible by the boid. * *

* This method first check if the given point is under the max distance of * view. If so, it checks if the point is in the angle of view. The angle of * view is specified as the cosine of the angle between the boid direction * vector and the vector between the boid and the given point. This means * that -1 is equal to a 360 degree of vision (the angle of view test is * deactivated in this case), 0 means 180 degree angle, and 0.5 a 90 degree * angle for example. *

* * @param source * The source boid. * @param point * The point to consider. * * @return True if point is visible by source. */ public abstract boolean isVisible(Boid boid, Point3 other); public boolean isVisible(Boid boid, Point3 point) { // // Check both the distance and angle of view according to the // direction // of the source. // BoidSpecies species = boid.getSpecies(); Point3 pos = boid.getPosition(); double d = pos.distance(point); // At good distance. if (d <= species.getViewZone()) { // // If there is an angle of view. // if (species.getAngleOfView() > -1) { Vector3 dir = new Vector3(boid.getForces().getDirection()); Vector3 light = new Vector3(point.x - pos.x, point.y - pos.y, point.z - pos.z); dir.normalize(); light.normalize(); double angle = dir.dotProduct(light); // // In the field of view. // if (angle > species.getAngleOfView()) return true; } else { return true; } } // // Not in view. // return false; } public abstract void setPosition(double x, double y, double z); public abstract Point3 getPosition(); public abstract Vector3 getDirection(); } \ No newline at end of file
 ... ... @@ -28,30 +28,38 @@ */ package org.graphstream.boids.forces.greedy; import org.graphstream.boids.Boid; import org.graphstream.boids.BoidForces; import org.miv.pherd.geom.Point3; import org.miv.pherd.geom.Vector3; public class GreedyForces extends BoidForces { Point3 position; public void compute() { // TODO Auto-generated method stub } /* * (non-Javadoc) * * @see org.graphstream.boids.BoidForces#getPosition() */ public Point3 getPosition() { // TODO Auto-generated method stub return null; } public boolean isVisible(Boid boid, Point3 other) { // TODO Auto-generated method stub return false; return position; } /* * (non-Javadoc) * * @see org.graphstream.boids.BoidForces#setPosition(double, double, double) */ public void setPosition(double x, double y, double z) { // TODO Auto-generated method stub position.set(x, y, z); } public Vector3 getDirection() { return null; } }
 ... ... @@ -78,6 +78,10 @@ public class NTreeForces extends BoidForces { public void setPosition(double x, double y, double z) { p.setPosition(x, y, z); } public Vector3 getDirection() { return p.dir; } /* * (non-Javadoc) ... ... @@ -215,64 +219,6 @@ public class NTreeForces extends BoidForces { return true; } /** * True if the given position is visible by the boid. * *

* This method first check if the given point is under the max distance of * view. If so, it checks if the point is in the angle of view. The angle of * view is specified as the cosine of the angle between the boid direction * vector and the vector between the boid and the given point. This means * that -1 is equal to a 360 degree of vision (the angle of view test is * deactivated in this case), 0 means 180 degree angle, and 0.5 a 90 degree * angle for example. *

* * @param source * The source boid. * @param point * The point to consider. * * @return True if point is visible by source. */ @Override public boolean isVisible(Boid boid, Point3 point) { // Check both the distance and angle of view according to the // direction // of the source. BoidParticle source = ((NTreeForces) boid.getForces()).p; BoidSpecies species = source.getBoid().getSpecies(); Point3 pos = source.getPosition(); double d = pos.distance(point); // At good distance. if (d <= species.getViewZone()) { // If there is an angle of view. if (species.getAngleOfView() > -1) { Vector3 dir = new Vector3(source.dir); Vector3 light = new Vector3(point.x - pos.x, point.y - pos.y, point.z - pos.z);// (pos.x - point.x, pos.y // - point.y, pos.z - // point.z); dir.normalize(); light.normalize(); double angle = dir.dotProduct(light); // In the field of view. if (angle > species.getAngleOfView()) return true; } else { return true; } } // Not in view. return false; } /** * A boid particle p2 that is visible by p1 as been found, integrate it in * the forces that apply to the boid p1. ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!