I'll have to work out the math, but it might be a good idea to add a
transform to the existing portrayals to allow them to be displayed
"upside down" so to speak. MASON draws portrayals at (0,0) top-left
because that's the orientation for 2D computer graphics in Java (and
in most systems in general). I'll have to mull it over.
But there's another way to do this that's probably easier for you to
hack: add another Continuous2D that's updated as necessary and
contains all the agents flipped. For example, let's assume the
"bottom-right" corner origin is at (0,mycontinuous2d.height) in
Continuous2D's display space. You might keep around another
Continuous2D called "other" which is registered with the portrayals.
Then you could create a Steppable which, when stepped, does something
along these lines:
Bag agents = mycontinuous2d.allObjects;
double width = mycontinuous2d.width;
Object agent = agents.objs[x];
Double2D loc = (Double2D)(mycontinuous2d.getObjectLocation(loc));
Where to put the Steppable? Probably the smart place to put it is in
the GUIState's minischeduler, stuck in before the Displays register
themselves (they do so when their reset() method is called).
So just before display.reset(), do this:
1. if (stoppable!=null) stoppable.stop();
2. stoppable = myguistate.scheduleImmediateRepeat(true,thesteppable);
This presumes you have an instance variable called stoppable in which
you can hold the Stoppable you're given when you schedule the above
steppable in your guiststate.
I hope this guidance is of some help! And no, I've not tested it in
On Jun 12, 2006, at 12:04 PM, Diane Kramer wrote:
> I'm working with Mason and I have a Continuous2D field where
> I store the data for my agents. I'm using a SimplePortrayal2D
> that contains a RectanglePortrayal2D to draw my agents, and a
> LabelledPortrayal2D for drawing the agents' names. Everything
> is working fine, except that my simulation drawing is upside-
> The data used for my original agent locations, and the code
> that moves agents around during the simulation assume that
> the origin [0,0] is at the bottom-left corner of the screen.
> But it appears that Mason believes the origin is at the top-left
> corner of the screen. So I need to flip my agents' locations
> about the Y axis when the portrayal is drawn.
> I wrote the following code which I call from my draw method.
> private DrawInfo2D transform(DrawInfo2D orig, Continuous2D field)
> // calculate the new Y location
> // multiply by draw's height because it represents scale
> double height = field.getHeight() * orig.draw.getHeight();
> double origY = orig.draw.getY();
> double flipY = height - origY;
> // create new draw & clip from original draw info, with new Y
> Rectangle2D.Double flipDraw = new Rectangle2D.Double
> origY = orig.clip.getY();
> flipY = height - origY;
> Rectangle2D.Double flipClip = new Rectangle2D.Double
> DrawInfo2D flip = new DrawInfo2D(flipDraw, flipClip);
> return flip;
> This code works only initially. It does not draw correctly if
> I change the size of the display window (e.g., maximize) or
> change the scale.
> I would appreciate some advice from anyone who can give it. Do
> you know what I'm doing wrong? Is there another approach to
> solving this problem? (Changing the input data is unfortunately
> not an option.)
> Thanks very much. -Diane Kramer