Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > Occupied Space and cellRadius
 

Occupied Space and cellRadius

I'm confused by the following code provided in the developer documentation:

Why would an organism with a cellRadius of 1 occupy a rectangle that is 3 cells wide minus 1 pixel?  Is it assumed that an organism occupies 1 cell plus a number of cells in radius around that center cell?  Would it be correct to say that an organism's position would have to move between 1 and 8 pixels before it would occupy a different set of cells?  Finally, is blocking caused by trying to occupy the same set of cells as described by this formula... or can there be overlap and blocking be determined by a rectangle precisely bounding the actual position of the organism?

??? width = (((cellRadius*2+1)*8)-1) ???

Function GetBoundsOfState(orgState As OrganismState) As Rectangle
    Dim origin As Point = orgState.Position
    Dim cellRadius as Integer = orgState.CellRadius

    Dim p1 As New Point( _
        (CInt(origin.X/8))*8, _
        (CInt(origin.Y/8))*8 _
    )

    Dim bounds As New Rectangle( _
        p1.X - (cellRadius*8), _
        p1.Y - (cellRadius*8), _
        (((cellRadius*2+1)*8)-1), _
        (((cellRadius*2+1)*8)-1) _
    )

    Return bounds
End Function
 
MigrationUser 1  Sunday, June 22, 2003 5:45 AM
Don't know about the -1 pixel.  Doesn't make sense to me either.  Blocking is caused by trying to occupy the same cells.
MigrationUser 1  Sunday, June 22, 2003 11:31 PM
This "-1" is coused by the fact that a segment containing N pixels has length = (N - 1).

Terrarium is divided to cells - {(0,0)-(7,7)}, {(8,0)-(8,7)} and so on. To determine space occupied by an organism you must take the cell containing its center (State.Position) and add "CellRadius" number of cells in each direction.

The cell containing an organism's center:
x1 = ( State.Position.X / 8 ) * 8
y1 = ( State.Position.Y / 8 ) * 8
x2 = x1 + 7
y2 = y1 + 7

The occupied space:
X1 = x1 - CellRadius * 8
Y1 = y1 - CellRadius * 8
X2 = x2 + CellRadius * 8
Y2 = y2 + CellRadius * 8

MigrationUser 1  Wednesday, June 25, 2003 3:54 AM
Thanks, my pathing is working much better since I corrected my misunderstanding of the space occupied by organisms.
MigrationUser 1  Saturday, June 28, 2003 4:21 AM

You can use google to search for other answers

Custom Search

More Threads

• "The terrarium server is experiencing temporary difficulties. This is probably why you are not receiving any animals. Please bear with us while we get the issue resolved."
• How to serialize your target
• Anything WoW you lately
• Error when attempting to start terrarium for first time
• Insttal problems
• TaskVision Source lite now available
• function help.
• Terrarium 1.2 Server -> Peercount fix
• WS-Security
• Terrarium server is experienceing temporty difficulities