Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gs-boids
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
graphstream
gs-boids
Commits
132fbda6
Commit
132fbda6
authored
Mar 28, 2012
by
gsavin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move isVisible() into BoidForces.
parent
8cb3920b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
70 deletions
+83
-70
src/org/graphstream/boids/BoidForces.java
src/org/graphstream/boids/BoidForces.java
+61
-2
src/org/graphstream/boids/forces/greedy/GreedyForces.java
src/org/graphstream/boids/forces/greedy/GreedyForces.java
+18
-10
src/org/graphstream/boids/forces/ntree/NTreeForces.java
src/org/graphstream/boids/forces/ntree/NTreeForces.java
+4
-58
No files found.
src/org/graphstream/boids/BoidForces.java
View file @
132fbda6
...
...
@@ -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.
*
* <p>
* 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.
* </p>
*
* @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
src/org/graphstream/boids/forces/greedy/GreedyForces.java
View file @
132fbda6
...
...
@@ -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
;
}
}
src/org/graphstream/boids/forces/ntree/NTreeForces.java
View file @
132fbda6
...
...
@@ -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.
*
* <p>
* 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.
* </p>
*
* @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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment