Class l2df.class.component.physix.cube
BBox cube intersections helper functions.
Info:
- Copyright: 2014 Enrique García Cota, 2020 Atom-TM
- Author: Abelidze, oniietzschan, Enrique García Cota
Functions
Tables
Collision | Collision description table. |
Functions
Methods- Cube:assert(x, y, z, w, h, d)
-
Asserts that passed dimensions form a corrent cube.
Parameters:
- x number BBox X position.
- y number BBox Y position.
- z number BBox Z position.
- w number BBox width.
- h number BBox height.
- d number BBox depth.
- Cube:nearestCorner(x, y, z, w, h, d, px, py, pz)
-
Returns nearest corner position to the point.
Parameters:
- x number BBox X position.
- y number BBox Y position.
- z number BBox Z position.
- w number BBox width.
- h number BBox height.
- d number BBox depth.
- px number Point's X position.
- py number Point's Y position.
- pz number Point's Z position.
Returns:
- number Nearest X position.
- number Nearest Y position.
- number Nearest Z position.
- Cube:segmentIntersectionIndices(x, y, z, w, h, d, x1, y1, z1, x2, y2, z2[, ti1=0[, ti2=1]])
-
This is a generalized implementation of the liang-barsky algorithm, which also returns
the normals of the sides where the segment intersects.
Returns nil if the segment never touches the cube.
Notice that normals are only guaranteed to be accurate when initially ti1, ti2 == -math.huge, math.huge.
Parameters:
- x number BBox X position.
- y number BBox Y position.
- z number BBox Z position.
- w number BBox width.
- h number BBox height.
- d number BBox depth.
- x1 number Segment's start X position.
- y1 number Segment's start Y position.
- z1 number Segment's start Z position.
- x2 number Segment's end X position.
- y2 number Segment's end Y position.
- z2 number Segment's end Z position.
- ti1 number Minimum starting value of the variable parameter. (default 0)
- ti2 number Maximum starting value of the variable parameter. (default 1)
- Cube:getDiff(x1, y1, z1, w1, h1, d1, x2, y2, z2, w2, h2, d2)
-
Calculates the minkowsky difference between 2 cubes, which is another cube.
Parameters:
- x1 number The first BBox X position.
- y1 number The first BBox Y position.
- z1 number The first BBox Z position.
- w1 number The first BBox width.
- h1 number The first BBox height.
- d1 number The first BBox depth.
- x2 number The second BBox X position.
- y2 number The second BBox Y position.
- z2 number The second BBox Z position.
- w2 number The second BBox width.
- h2 number The second BBox height.
- d2 number The second BBox depth.
Returns:
- number Difference BBox X position.
- number Difference BBox Y position.
- number Difference BBox Z position.
- number Difference BBox width.
- number Difference BBox height.
- number Difference BBox depth.
- Cube:containsPoint(x, y, z, w, h, d, px, py, pz)
-
Check if the point is inside cube.
Parameters:
- x number BBox X position.
- y number BBox Y position.
- z number BBox Z position.
- w number BBox width.
- h number BBox height.
- d number BBox depth.
- px number Point's X position.
- py number Point's Y position.
- pz number Point's Z position.
Returns:
-
boolean
- Cube:isIntersecting(x1, y1, z1, w1, h1, d1, x2, y2, z2, w2, h2, d2)
-
Check if two cubes are intersecting.
Parameters:
- x1 number The first BBox X position.
- y1 number The first BBox Y position.
- z1 number The first BBox Z position.
- w1 number The first BBox width.
- h1 number The first BBox height.
- d1 number The first BBox depth.
- x2 number The second BBox X position.
- y2 number The second BBox Y position.
- z2 number The second BBox Z position.
- w2 number The second BBox width.
- h2 number The second BBox height.
- d2 number The second BBox depth.
Returns:
-
boolean
- Cube:getCubeDistance(x1, y1, z1, w1, h1, d1, x2, y2, z2, w2, h2, d2)
-
Get the distance between two cubes.
Parameters:
- x1 number The first BBox X position.
- y1 number The first BBox Y position.
- z1 number The first BBox Z position.
- w1 number The first BBox width.
- h1 number The first BBox height.
- d1 number The first BBox depth.
- x2 number The second BBox X position.
- y2 number The second BBox Y position.
- z2 number The second BBox Z position.
- w2 number The second BBox width.
- h2 number The second BBox height.
- d2 number The second BBox depth.
Returns:
-
number
- Cube:detectCollision(x1, y1, z1, w1, h1, d1, x2, y2, z2, w2, h2, d2[, goalX[, goalY[, goalZ]]])
-
Detect collision of the two cubes one of which could be moving.
If goal position is not setted we expect colliding two static cubes (with no movement).
Returns table describing all collision details.
Parameters:
- x1 number The first BBox X position.
- y1 number The first BBox Y position.
- z1 number The first BBox Z position.
- w1 number The first BBox width.
- h1 number The first BBox height.
- d1 number The first BBox depth.
- x2 number The second BBox X position.
- y2 number The second BBox Y position.
- z2 number The second BBox Z position.
- w2 number The second BBox width.
- h2 number The second BBox height.
- d2 number The second BBox depth.
- goalX number Goal X movement position of the first BBox. (optional)
- goalY number Goal Y movement position of the first BBox. (optional)
- goalZ number Goal Z movement position of the first BBox. (optional)
Returns:
Tables
- Collision
-
Collision description table.
Fields:
- overlaps boolean True if one of the cubes was overlapping another before movement.
- ti number The negative volume of intersection.
- move {x=number,y=number,z=number} Movement vector table.
- normal {x=number,y=number,z=number} Normal of collision vector table.
- touch {x=number,y=number,z=number} Resulting position of the first cube after moving and possible collision.
- distance number Distance between cubes after movement. See Cube:getCubeDistance() for details.