Class l2df.class.component.physix.grid

Last updated 2021-05-28 15:24:22

Grid helper.

Info:

Functions

Grid:toWorld(cellsize, cx, cy, cz) Get left-top corner cell coordinates.
Grid:toCell(cellsize, x, y, z) Convert left-top corner cell coordinates to cell indexes.
Grid:toCellCube(cellsize, x, y, z, w, h, d) Convert cube from world to cell coordinates.
Grid:traverse(cellsize, x1, y1, z1, x2, y2, z2, f) Function is based on "A Fast Voxel Traversal Algorithm for Ray Tracing", by John Amanides and Andrew Woo - http://www.cse.yorku.ca/~amana/research/grid.pdf It has been modified to include both cells when the ray "touches a grid corner", and with a different exit condition.


Functions

Methods
Grid:toWorld(cellsize, cx, cy, cz)
Get left-top corner cell coordinates.

Parameters:

  • cellsize number Size of the cell in pixels.
  • cx number Cell X index.
  • cy number Cell Y index.
  • cz number Cell Z index.

Returns:

  1. number X coordinate.
  2. number Y coordinate.
  3. number Z coordinate.
Grid:toCell(cellsize, x, y, z)
Convert left-top corner cell coordinates to cell indexes.

Parameters:

  • cellsize number Size of the cell in pixels.
  • x number X coordinate.
  • y number Y coordinate.
  • z number Z coordinate.

Returns:

  1. number Cell X index.
  2. number Cell Y index.
  3. number Cell Z index.
Grid:toCellCube(cellsize, x, y, z, w, h, d)
Convert cube from world to cell coordinates.

Parameters:

  • cellsize number Size of the cell in pixels.
  • x number Cube X coordinate.
  • y number Cube Y coordinate.
  • z number Cube Z coordinate.
  • w number Cube width.
  • h number Cube height.
  • d number Cube depth.

Returns:

  1. number Cell X index.
  2. number Cell Y index.
  3. number Cell Z index.
  4. number Cell width.
  5. number Cell height.
  6. number Cell depth.
Grid:traverse(cellsize, x1, y1, z1, x2, y2, z2, f)
Function is based on "A Fast Voxel Traversal Algorithm for Ray Tracing", by John Amanides and Andrew Woo - http://www.cse.yorku.ca/~amana/research/grid.pdf It has been modified to include both cells when the ray "touches a grid corner", and with a different exit condition.

Parameters:

  • cellsize number Size of the cell in pixels.
  • x1 number Start X coordinate.
  • y1 number Start Y coordinate.
  • z1 number Start Z coordinate.
  • x2 number End X coordinate.
  • y2 number End Y coordinate.
  • z2 number End Z coordinate.
  • f function Traverse function called for each cell in path.