MASON-INTEREST-L Archives

November 2004

MASON-INTEREST-L@LISTSERV.GMU.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Sean Luke <[log in to unmask]>
Reply To:
MASON Multiagent Simulation Toolkit <[log in to unmask]>
Date:
Mon, 15 Nov 2004 17:12:31 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (30 lines)
MASON at present doesn't have built-in support for adding new objects
via the mouse, but that's just because we hadn't needed it ourselves
yet.  While you *can* compute all the coordinates yourself, it's
complex.  Each field portrayal can have its own coordinate system.

Here's how I'd do it.  In Display2D there's a method called
objectsHitBy(rect), which takes a rect (in InnerDisplay2D coordinates)
and returns LocationWrappers for all the objects in fields which
happened to fall into this region.  It does most of the math for you if
you want to cut-and-paste and modify.  The heavy lifting is done clear
to the line

             p.portrayal.hitObjects( new DrawInfo2D(region,rect),
hitObjs[x] );

...at which point you'd replace this line with some appropriate code
(and probably reduce your copy of the the objectsHitBy(...) code so it
doesn't go through all the field portrayals but just the one you need).

region defines a rectangle whose <x,y> is the origin of the field, and
whose <width,height> is the scaled width and height of the field.  So
you could interpret the DrawInfo2D as saying:  "imagine if you will
that your field has been translated and stretched so that its origin
lies on <x,y> in the cartesian plane, and has been bent to a width and
height of <width,height>.  Then the area I'm interested in is the rect
'rect' in that imaginary situation."  For a mouse click, rect will
probably have a width and height of 1,1.

Sean

ATOM RSS1 RSS2