cube

package
v0.9.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 3 Imported by: 128

Documentation

Overview

Package cube provides types and functions to handle positions and rotations of voxel-based objects in a 3D world.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyIntersections added in v0.7.0

func AnyIntersections(boxes []BBox, search BBox) bool

AnyIntersections checks if any of boxes1 have intersections with any of boxes2 and returns true if this happens to be the case.

Types

type Axis

type Axis int

Axis represents the axis that a block may be directed in. Most blocks do not have an axis, but blocks such as logs or pillars do.

const (
	// Y represents the vertical Y axis.
	Y Axis = iota
	// Z represents the horizontal Z axis.
	Z
	// X represents the horizontal X axis.
	X
)

func Axes

func Axes() []Axis

Axes return all possible axes. (x, y, z)

func (Axis) RotateLeft added in v0.2.0

func (a Axis) RotateLeft() Axis

RotateLeft rotates an Axis from X to Z or from Z to X.

func (Axis) RotateRight added in v0.2.0

func (a Axis) RotateRight() Axis

RotateRight rotates an Axis from X to Z or from Z to X.

func (Axis) String

func (a Axis) String() string

String converts an Axis into either x, y or z, depending on which axis it is.

func (Axis) Vec3 added in v0.9.0

func (a Axis) Vec3() mgl64.Vec3

Vec3 returns a unit Vec3 of either (1, 0, 0), (0, 1, 0) or (0, 0, 1), depending on the Axis.

type BBox added in v0.7.0

type BBox struct {
	// contains filtered or unexported fields
}

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.

func Box added in v0.7.0

func Box(x0, y0, z0, x1, y1, z1 float64) BBox

Box creates a new axis aligned bounding box with the minimum and maximum coordinates provided. The returned box has minimum and maximum coordinates swapped if necessary so that it is well-formed.

func (BBox) Corners added in v0.9.19

func (box BBox) Corners() []mgl64.Vec3

Corners returns slice of all hitbox corners.

func (BBox) Extend added in v0.7.0

func (box BBox) Extend(vec mgl64.Vec3) BBox

Extend expands the BBox on all axes as represented by the Vec3 passed. Negative coordinates result in an expansion towards the negative axis, and vice versa for positive coordinates.

func (BBox) ExtendTowards added in v0.7.0

func (box BBox) ExtendTowards(f Face, x float64) BBox

ExtendTowards extends the bounding box by x in a given direction.

func (BBox) Grow added in v0.7.0

func (box BBox) Grow(x float64) BBox

Grow grows the bounding box in all directions by x and returns the new bounding box.

func (BBox) GrowVec3 added in v0.7.0

func (box BBox) GrowVec3(vec mgl64.Vec3) BBox

GrowVec3 grows the BBox on all axes as represented by the Vec3 passed. The vec values are subtracted from the minimum values of the BBox and added to the maximum values of the BBox.

func (BBox) Height added in v0.7.0

func (box BBox) Height() float64

Height returns the height of the BBox.

func (BBox) IntersectsWith added in v0.7.0

func (box BBox) IntersectsWith(other BBox) bool

IntersectsWith checks if the BBox intersects with another BBox, returning true if this is the case.

func (BBox) Length added in v0.7.0

func (box BBox) Length() float64

Length returns the length of the BBox.

func (BBox) Max added in v0.7.0

func (box BBox) Max() mgl64.Vec3

Max returns the maximum coordinate of the bounding box.

func (BBox) Min added in v0.7.0

func (box BBox) Min() mgl64.Vec3

Min returns the minimum coordinate of the bounding box.

func (BBox) Mul added in v0.9.19

func (box BBox) Mul(val float64) BBox

Mul performs a scalar multiplication for min, max points of BBox.

func (BBox) Stretch added in v0.7.0

func (box BBox) Stretch(a Axis, x float64) BBox

Stretch stretches the bounding box by x in a given axis.

func (BBox) Translate added in v0.7.0

func (box BBox) Translate(vec mgl64.Vec3) BBox

Translate moves the entire BBox with the Vec3 given. The (minimum and maximum) x, y and z coordinates are moved by those in the Vec3 passed.

func (BBox) TranslateTowards added in v0.8.0

func (box BBox) TranslateTowards(f Face, x float64) BBox

TranslateTowards moves the entire AABB by x in the direction of a Face passed.

func (BBox) Vec3Within added in v0.7.0

func (box BBox) Vec3Within(vec mgl64.Vec3) bool

Vec3Within checks if the BBox has a Vec3 within it, returning true if it does.

func (BBox) Vec3WithinXY added in v0.7.0

func (box BBox) Vec3WithinXY(vec mgl64.Vec3) bool

Vec3WithinXY checks if the BBox has a Vec3 within its X and Y bounds, returning true if it does.

func (BBox) Vec3WithinXZ added in v0.7.0

func (box BBox) Vec3WithinXZ(vec mgl64.Vec3) bool

Vec3WithinXZ checks if the BBox has a Vec3 within its X and Z bounds, returning true if it does.

func (BBox) Vec3WithinYZ added in v0.7.0

func (box BBox) Vec3WithinYZ(vec mgl64.Vec3) bool

Vec3WithinYZ checks if the BBox has a Vec3 within its Y and Z bounds, returning true if it does.

func (BBox) Volume added in v0.9.19

func (box BBox) Volume() float64

Volume calculates the volume of the BBox.

func (BBox) Width added in v0.7.0

func (box BBox) Width() float64

Width returns the width of the BBox.

func (BBox) XOffset added in v0.7.0

func (box BBox) XOffset(nearby BBox, deltaX float64) float64

XOffset calculates the offset on the X axis between two bounding boxes, returning a delta always smaller than or equal to deltaX if deltaX is bigger than 0, or always bigger than or equal to deltaX if it is smaller than 0.

func (BBox) YOffset added in v0.7.0

func (box BBox) YOffset(nearby BBox, deltaY float64) float64

YOffset calculates the offset on the Y axis between two bounding boxes, returning a delta always smaller than or equal to deltaY if deltaY is bigger than 0, or always bigger than or equal to deltaY if it is smaller than 0.

func (BBox) ZOffset added in v0.7.0

func (box BBox) ZOffset(nearby BBox, deltaZ float64) float64

ZOffset calculates the offset on the Z axis between two bounding boxes, returning a delta always smaller than or equal to deltaZ if deltaZ is bigger than 0, or always bigger than or equal to deltaZ if it is smaller than 0.

type Direction

type Direction int

Direction represents a direction towards one of the horizontal axes of the world.

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) Face

func (d Direction) Face() Face

Face converts the direction to a Face and returns it.

func (Direction) Opposite

func (d Direction) Opposite() Direction

Opposite returns Direction opposite to the current one.

func (Direction) RotateLeft added in v0.2.0

func (d Direction) RotateLeft() Direction

RotateLeft rotates the direction 90 degrees to the left horizontally and returns the new direction.

func (Direction) RotateRight added in v0.2.0

func (d Direction) RotateRight() Direction

RotateRight rotates the direction 90 degrees to the right horizontally and returns the new direction.

func (Direction) String

func (d Direction) String() string

String returns the Direction as a string.

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

func (f Face) Axis() Axis

Axis returns the axis the face is facing. FaceEast and west correspond to the x-axis, north and south to the z axis and up and down to the y-axis.

func (Face) Direction

func (f Face) Direction() Direction

Direction converts the Face to a Direction and returns it, assuming the Face is horizontal and not FaceUp or FaceDown.

func (Face) Opposite

func (f Face) Opposite() Face

Opposite returns the opposite face. FaceDown will return up, north will return south and west will return east, and vice versa.

func (Face) RotateLeft added in v0.2.0

func (f Face) RotateLeft() Face

RotateLeft rotates the face 90 degrees to the left horizontally and returns the new face.

func (Face) RotateRight added in v0.2.0

func (f Face) RotateRight() Face

RotateRight rotates the face 90 degrees to the right horizontally and returns the new face.

func (Face) String

func (f Face) String() string

String returns the Face as a string.

type Orientation added in v0.2.0

type Orientation int

Orientation represents the orientation of a sign

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 of an array with an x, y and z value, where the y value is positive.

func PosFromVec3

func PosFromVec3(vec3 mgl64.Vec3) Pos

PosFromVec3 returns a block position by a Vec3, rounding the values down adequately.

func (Pos) Add

func (p Pos) Add(pos Pos) Pos

Add adds two block positions together and returns a new one with the combined values.

func (Pos) Face

func (p Pos) Face(other 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) Neighbours

func (p Pos) Neighbours(f func(neighbour Pos), r Range)

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

func (p Pos) OutOfBounds(r Range) bool

OutOfBounds checks if the Y value is either bigger than r[1] or smaller than r[0].

func (Pos) Side

func (p Pos) Side(face Face) Pos

Side returns the position on the side of this block position, at a specific face.

func (Pos) String added in v0.4.1

func (p Pos) String() string

String converts the Pos to a string in the format (1,2,3) and returns it.

func (Pos) Sub added in v0.7.0

func (p Pos) Sub(pos Pos) Pos

Sub subtracts pos from p and returns a new one with the subtracted values.

func (Pos) Vec3

func (p Pos) Vec3() mgl64.Vec3

Vec3 returns a vec3 holding the same coordinates as the block position.

func (Pos) Vec3Centre

func (p Pos) Vec3Centre() mgl64.Vec3

Vec3Centre returns a Vec3 holding the coordinates of the block position with 0.5 added on all axes.

func (Pos) Vec3Middle

func (p Pos) Vec3Middle() mgl64.Vec3

Vec3Middle returns a Vec3 holding the coordinates of the block position with 0.5 added on both horizontal axes.

func (Pos) X

func (p Pos) X() int

X returns the X coordinate of the block position.

func (Pos) Y

func (p Pos) Y() int

Y returns the Y coordinate of the block position.

func (Pos) Z

func (p Pos) Z() int

Z returns the Z coordinate of the block position.

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

func (r Range) Height() int

Height returns the total height of the Range, the difference between Max and Min.

func (Range) Max added in v0.5.0

func (r Range) Max() int

Max returns the maximum Y value of a Range. It is equivalent to Range[1].

func (Range) Min added in v0.5.0

func (r Range) Min() int

Min returns the minimum Y value of a Range. It is equivalent to Range[0].

type Rotation added in v0.8.7

type Rotation [2]float64

Rotation describes the rotation of an object in the world. 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

func (r Rotation) Add(r2 Rotation) Rotation

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

func (r Rotation) Direction() Direction

Direction returns the horizontal Direction that r points towards based on the yaw of r.

func (Rotation) Elem added in v0.8.7

func (r Rotation) Elem() (yaw, pitch float64)

Elem extracts the elements of the Rotation for direct value assignment.

func (Rotation) Opposite added in v0.8.7

func (r Rotation) Opposite() Rotation

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.

func (Rotation) Pitch added in v0.8.7

func (r Rotation) Pitch() float64

Pitch returns the pitch of r (r[1]).

func (Rotation) Vec3 added in v0.8.7

func (r Rotation) Vec3() mgl64.Vec3

Vec3 returns the direction vector of r. The length of the mgl64.Vec3 returned is always 1.

func (Rotation) Yaw added in v0.8.7

func (r Rotation) Yaw() float64

Yaw returns the yaw of r (r[0]).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL