Possible bug regarding lines in Breve 2.1
Christoffer Karlsson <[email protected]> Tue, 18 Jan 2005 21:59:40 +0100
| Newsgroups | gmane.comp.breve |
|---|---|
| Message-ID | <[email protected]> |
Hi!
I think I've might have found a small bug in Breve 2.1b. I have
modified the RandomWalkers example to draw a line from any RandomWalker
to its closest neighbour (in an inefficent way, just a quick hack). It
seems to work just fine in Breve 2.0.1 but in 2.1b every random walker
gets a line to every other walker. But, inspection of the walkers seem
to indicate that they actually only have one line attached. Also, if I
remove all attached lines (with self remove-all-lines) they are still
left behind (altough inspection indicates that the walkers in fact have
no lines attached).
This is the simulation I've used (the important change is in
RandomWalker>>iterate):
#
# RandomWalker is a simulation in which small spheres do
# a random walk. This is a very simple simulation which
# can be used as a skeleton for more complex simulations.
#
# include some required breve class files
@use Control.
@use Mobile.
# First tell the breve engine the name of our controller class
Controller myControl.
# Subclass "Control" and define our "myControl" object.
Control : myControl {
# Here we define the class variables.
+ variables:
walkerShape (object).
# Next we define a method called init. The init method is called
# automatically when our class is created. Since this is the
controller
# class, an instance gets created when we launch the simulation,
# so this is the entry point for our simulation.
+ to init:
print "Setting up the simulation.".
self point-camera at (0, 0, 0) from (0, 60, 0).
# set up a shape that all of the RandomWalker objects will use.
walkerShape = (new Sphere init-with radius 1).
# Create a bunch of RandomWalkers. You can create as few or
# as many as you want...
10 new RandomWalkers.
# The get-walker-shape is a method that allows other objects
# to look at the walkerShape variable. we do this so that
# each RandomWalker object can reuse the same Shape object.
# This is not strictly required--each RandomWalker could create
# it's own copy of the same Shape, but fewer objects means
# less memory used and more efficient simulations, so it's
# a good programming practice.
+ to get-walker-shape:
return walkerShape.
+ to iterate:
#print "======".
super iterate.
}
# The "RandomWalker" object is the physical object in the simulation
# that does the random walk. It is a subclass of "Mobile".
Mobile : RandomWalker (aka RandomWalkers) {
+ to init:
# During init, the object asks the controller for the shape
# it should use. It then sets itself to a random color.
self set-shape to (controller get-walker-shape).
self set-color to random[(1.0, 1.0, 1.0)].
+ to iterate:
# Set a new random velocity at every timestep.
self set-velocity to random[(60, 60, 60)] - (30, 30, 30).
# Draw a line to the closest neighbour.
# First remove all old lines.
self remove-all-lines.
# print "Closest neighbour to ", self, "is ", (self
closest-neighbour).
self add-line to (self closest-neighbour) with-color (1.0, 0.0,
0.0).
# self remove-all-lines.
# print "Removed??".
+ to closest-neighbour:
item (object).
items (list).
closestItem (object).
distance (float).
closestDistance (float).
closestDistance = 1000000.
items = all RandomWalkers.
foreach item in items: {
if item != self : {
distance = self get-distance from item.
if distance < closestDistance: {
closestDistance = distance.
closestItem = item.
}
}
}
return closestItem.
}
--
Christoffer Karlsson
Väntar på Godot
_______________________________________________
breve mailing list
[email protected]
http://lists.spiderland.org/mailman/listinfo/breve