-
For this assignment you can use Java or Javascript. Javascript is
probably easier (mainly because you don't have to use all those annoying
access functions to get at fields of a node, or do any of the event decoding
stuff).
-
You can make a transparent fish bowl (cylinder whatever) by using the transparency field for the material node.
-
You can "pass a node" to your javascript like so:
DEF fish1 Transform{ // This transform node positions the
fish
.
.
.
children[
// The fish is defined in here
]
}
DEF the_script Script{
url "javascript:
function some_function (frac, eventTime) {
.
.
.
fish_1_translation = ifish1.translation;
.
.
.
}
"
field SFNode ifish1 USE fish1 //This makes an
SFNode variable
//initialized to the Transform
//for fish
eventIn SFFloat some_function
}
# Route the time signal to the some_function
ROUTE MainClock.fraction_changed TO the_script.some_function
-
How to make the fish move:
-
All the fish move based more or less on the idea that they attempt to be
in some location.
-
The lead fish should always be swimming around in circles, but should occasionally
decide to change its depth and radius. The professor suggests that
you use a random variable to decide when to make a change in desired depth
or radius, and then simulate some force acting on the fish to get it to
that depth and radius as it continues to circle the tank. To do this
you need to come up with some formula which determines a force based on
how far the fish is from where it wants to be. Note that it is important
that the fish not approach its desired location too fast, so as the fish
approaches you should probably have some force retarding its motion so
that it does not overshoot the desired location (at least not by too much).
Also note that you do not actually have to compute the force all at once,
but could compute a force (actually an acceleration) for the radius seperately
from an acceleration up and down, and again for angular acceleration (the
angle of the fish around the tank should not always change at the same
rate). You could see this as computing the force on the fish in a
different (cylindrical) coordinate system. Finally you can avoid
doing the second order dynamics (basically skip a step) by simply making
the fish change its radius rapidly towards the desired radius at first,
and then more slowly as it approaches. This simulates the effect
of makeing some force which at first pushed the fish towards the desired
radius, and then slows it down.
-
The following fish work along similar lines, but attempt to stay in a fixed
position relative to the lead fish. By giving each following fish
a significantly different desired position relative to the lead fish you
can make collisions unlikely. In addition you should prevent the
following
fish from staying exactly in their desired locations relative to the lead
fish. (Optional: You could also do collision detection between all
of the fish, or use some technique to apply repulsive forces to the fish
if they get too close)