Documentation
¶
Overview ¶
Package cube provides types and functions to handle positions and rotations of voxel-based objects in a 3D world.
Index ¶
- func AnyIntersections(boxes []BBox, search BBox) bool
- func AnyIntersections32(boxes []BBox32, search BBox32) bool
- func Range3D(p1, p2 Pos) iter.Seq[Pos]
- type Axis
- type BBox
- type BBox32
- type Direction
- type Face
- type Orientation
- type Pos
- func (p Pos) Add(pos Pos) Pos
- func (p Pos) Face(other Pos) Face
- func (p Pos) NeighbourFace(other Pos) (Face, bool)
- func (p Pos) Neighbours(f func(neighbour Pos), r Range)
- func (p Pos) OutOfBounds(r Range) bool
- func (p Pos) Side(face Face) Pos
- func (p Pos) String() string
- func (p Pos) Sub(pos Pos) Pos
- func (p Pos) Vec3() mgl64.Vec3
- func (p Pos) Vec3Centre() mgl64.Vec3
- func (p Pos) Vec3Middle() mgl64.Vec3
- func (p Pos) Within(min, max Pos) bool
- func (p Pos) X() int
- func (p Pos) Y() int
- func (p Pos) Z() int
- type Range
- type Rotation
- func (r Rotation) Add(r2 Rotation) Rotation
- func (r Rotation) Direction() Direction
- func (r Rotation) Elem() (yaw, pitch float64)
- func (r Rotation) Neg() Rotation
- func (r Rotation) Opposite() Rotation
- func (r Rotation) Orientation() Orientation
- func (r Rotation) Pitch() float64
- func (r Rotation) Vec3() mgl64.Vec3
- func (r Rotation) Yaw() float64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnyIntersections ¶ added in v0.7.0
AnyIntersections checks if any of boxes intersect with search.
func AnyIntersections32 ¶ added in v0.11.1
AnyIntersections32 checks if any of the float32 boxes intersect with search.
Types ¶
type Axis ¶
type Axis int
Axis represents the axis that a block, such as a log, may be directed in.
func (Axis) Faces ¶ added in v0.11.0
Faces returns the negative and positive Face along the Axis. For X it returns FaceWest, FaceEast; for Y, FaceDown, FaceUp; for Z, FaceNorth, FaceSouth.
func (Axis) RotateLeft ¶ added in v0.2.0
RotateLeft rotates an Axis from X to Z or from Z to X.
func (Axis) RotateRight ¶ added in v0.2.0
RotateRight rotates an Axis from X to Z or from Z to X.
type BBox ¶ added in v0.7.0
BBox represents an Axis Aligned Bounding Box in a 3D space. It is defined as two Vec3s, of which one is the minimum and one is the maximum.
type BBox32 ¶ added in v0.11.1
BBox32 represents a float32 Axis Aligned Bounding Box in a 3D space. It is defined as two Vec3s, of which one is the minimum and one is the maximum.
type Direction ¶
type Direction int
Direction represents a direction towards one of the horizontal axes
const ( // North represents the north direction, towards the negative Z. North Direction = iota // South represents the south direction, towards the positive Z. South // West represents the west direction, towards the negative X. West // East represents the east direction, towards the positive X. East )
func Directions ¶
func Directions() []Direction
Directions returns a list of all directions, going from North to West.
func (Direction) RotateLeft ¶ added in v0.2.0
RotateLeft rotates the direction 90 degrees to the left horizontally (counter-clockwise) and returns the new direction.
func (Direction) RotateRight ¶ added in v0.2.0
RotateRight rotates the direction 90 degrees to the right horizontally (clockwise) and returns the new direction.
type Face ¶
type Face int
Face represents the face of a block or entity.
const ( // FaceDown represents the bottom face of a block. FaceDown Face = iota // FaceUp represents the top face of a block. FaceUp // FaceNorth represents the north face of a block. FaceNorth // FaceSouth represents the south face of a block. FaceSouth // FaceWest represents the west face of the block. FaceWest // FaceEast represents the east face of the block. FaceEast )
func Faces ¶ added in v0.2.0
func Faces() []Face
Faces returns a list of all faces, starting with down, then up, then north to west.
func HorizontalFaces ¶
func HorizontalFaces() []Face
HorizontalFaces returns a list of all horizontal faces, from north to west.
func (Face) Axis ¶
Axis returns the Axis the face is facing. FaceEast and FaceWest correspond to the X Axis, FaceNorth and FaceSouth to the Z Axis and FaceUp and FaceDown to the Y Axis.
func (Face) Direction ¶
Direction converts the Face to a Direction and returns it, assuming the Face is horizontal and not FaceUp or FaceDown.
func (Face) Opposite ¶
Opposite returns the opposite Face. FaceDown will return FaceUp, FaceNorth will return FaceSouth, FaceWest will return FaceEast, and vice versa.
func (Face) RotateLeft ¶ added in v0.2.0
RotateLeft rotates the face 90 degrees to the left horizontally (counter-clockwise) and returns the new Face.
func (Face) RotateRight ¶ added in v0.2.0
RotateRight rotates the face 90 degrees to the right horizontally (clockwise) and returns the new Face.
type Orientation ¶ added in v0.2.0
type Orientation int
Orientation represents the rotation of a block divided into 16 options.
func OrientationFromYaw ¶ added in v0.2.0
func OrientationFromYaw(yaw float64) Orientation
OrientationFromYaw returns an Orientation value that (roughly) matches the yaw passed.
func (Orientation) Opposite ¶ added in v0.2.0
func (o Orientation) Opposite() Orientation
Opposite returns the opposite orientation value of the Orientation.
func (Orientation) RotateLeft ¶ added in v0.2.0
func (o Orientation) RotateLeft() Orientation
RotateLeft rotates the orientation left by 90 degrees and returns it.
func (Orientation) RotateRight ¶ added in v0.2.0
func (o Orientation) RotateRight() Orientation
RotateRight rotates the orientation right by 90 degrees and returns it.
func (Orientation) Yaw ¶ added in v0.2.0
func (o Orientation) Yaw() float64
Yaw returns the yaw value that matches the orientation.
type Pos ¶
type Pos [3]int
Pos holds the position of a block. The position is represented as an array with an x, y and z value, where the y value is positive.
func Max ¶ added in v0.10.11
Max returns a new position where each coordinate is the maximum of input positions p1 and p2.
func Min ¶ added in v0.10.11
Min returns a new position where each coordinate is the minimum of input positions p1 and p2.
func PosFromVec3 ¶
PosFromVec3 returns a block position by a Vec3, rounding the values down adequately.
func (Pos) Face ¶
Face returns the face that the other Pos was on compared to the current Pos. The other Pos is assumed to be a direct neighbour of the current Pos.
func (Pos) NeighbourFace ¶ added in v0.11.0
NeighbourFace returns the face that the other Pos was on compared to the current Pos, if the other Pos is a direct neighbour of the current Pos. Example: Pos{0, 0, 0}.NeighbourFace(Pos{0, 1, 0}) returns FaceUp, true.
func (Pos) Neighbours ¶
Neighbours calls the function passed for each of the block position's neighbours. If the Y value is out of bounds, the function will not be called for that position.
func (Pos) OutOfBounds ¶
OutOfBounds checks if the Y value is either bigger than r[1] or smaller than r[0].
func (Pos) String ¶ added in v0.4.1
String converts the Pos to a string in the format (1,2,3) and returns it.
func (Pos) Sub ¶ added in v0.7.0
Sub subtracts pos from p and returns a new one with the subtracted values.
func (Pos) Vec3Centre ¶
Vec3Centre returns a Vec3 holding the coordinates of the block position with 0.5 added on all axes.
func (Pos) Vec3Middle ¶
Vec3Middle returns a Vec3 holding the coordinates of the block position with 0.5 added on both horizontal axes.
type Range ¶ added in v0.5.0
type Range [2]int
Range represents the height range of a Dimension in blocks. The first value of the Range holds the minimum Y value, the second value holds the maximum Y value.
func (Range) Height ¶ added in v0.5.0
Height returns the total height of the Range, the difference between Max and Min.
type Rotation ¶ added in v0.8.7
type Rotation [2]float64
Rotation describes the rotation of an object in the world in degrees. It holds a yaw (r[0]) and pitch value (r[1]). Yaw is in the range (-180, 180) while pitch is in the range (-90, 90). A positive pitch implies an entity is looking downwards, while a negative pitch implies it is looking upwards.
func (Rotation) Add ¶ added in v0.8.7
Add adds the values of two Rotations element-wise and returns a new Rotation. If the yaw or pitch would otherwise exceed their respective range as described, they are 'overflown' to the other end of the allowed range.
func (Rotation) Direction ¶ added in v0.8.7
Direction returns the horizontal Direction that r points towards based on the yaw of r.
func (Rotation) Elem ¶ added in v0.8.7
Elem extracts the elements of the Rotation for direct value assignment.
func (Rotation) Neg ¶ added in v0.10.0
Neg returns the negation of the Rotation. It is equivalent to creating a new Rotation{-r[0], -r[1]}.
func (Rotation) Opposite ¶ added in v0.8.7
Opposite returns the Rotation opposite r, so that r.Vec3().Add(r.Opposite().Vec3()).Len() is equal to 0.
func (Rotation) Orientation ¶ added in v0.8.7
func (r Rotation) Orientation() Orientation
Orientation returns an Orientation value that most closely matches the yaw of r.