Print

Print


On Aug 3, 2005, at 12:45 PM, John Smith wrote:

>    Glad to hear from you. I appreciate your help and decide to give up
> using ValueGridPortrayal3D and ObjectGridPortrayal3D classes. I read
> your tutorial 7. And I modify your fly program. It looks very good.
> However, I still have a problem to ask you.
> SparseGrid3D and SparseGridPortrayal3D are easy to simulate the 3D
> visualization without rich memory requirement. But I want to know how
> you setup the x,y,z axis. If I make a 100*100*100 lattice with
> SparseGrid3D class, the origin point (0,0,0) is in the center of the
> screen. Then (-10,0,0) point should be in the left of the screen and
>  (0,-12,0) point should be in the bottom of the screen.

> But the stx, sty,stz function of SparseGrid3D will not return any
> negative value. If I set up the object position of (-10,7,-88), it
> will return (90,7,12). So I only could set the object in the northeast
> of the screen. If I want to control the object and set it in the
> screen like conway's game in your tutorial, how do I solve this
> problem.

stx, sty, and stz are toroidal wrapper functions, as are tx, ty, and
tz.  Their purpose is to simplify toroidal movement.  For example, if
you want to move an object one slot up, possibly wrapping around, then
you could do:

        Int3D loc = field.getObjectLocation(myobj);
        field.setObjectLocation(myobj, loc.x, field.sty(loc.y-1), loc.z);

Toroidal 3D spaces are bounded by (0,0,0) inclusive to
(width,height,length) exclusive.  If you're trying to set something in
a negative location, it sounds like you *don't* want a toroidal space.
In that case, if you want to move an object one slot up, never wrapping
around (but instead allowing it to go negative if necessary), you just
do:

        Int3D loc = field.getObjectLocation(myobj);
        field.setObjectLocation(myobj, loc.x, loc.y-1, loc.z);

Or perhaps you want to do toroidal space but you want your field
centered.  In that case you'll need to transform the field so that the
world origin is in the center of the field instead of aligned with the
field's origin.  In that case you might do something like (after
scaling to 2x2x2):

        display.translate(-1.0, -1.0, -1.0);

Sean