github.com/df-mc/dragonfly@v0.9.13/server/block/cube/axis.go (about)

     1  package cube
     2  
     3  import "github.com/go-gl/mathgl/mgl64"
     4  
     5  // Axis represents the axis that a block may be directed in. Most blocks do not have an axis, but blocks such
     6  // as logs or pillars do.
     7  type Axis int
     8  
     9  const (
    10  	// Y represents the vertical Y axis.
    11  	Y Axis = iota
    12  	// Z represents the horizontal Z axis.
    13  	Z
    14  	// X represents the horizontal X axis.
    15  	X
    16  )
    17  
    18  // String converts an Axis into either x, y or z, depending on which axis it is.
    19  func (a Axis) String() string {
    20  	if a == X {
    21  		return "x"
    22  	} else if a == Y {
    23  		return "y"
    24  	}
    25  	return "z"
    26  }
    27  
    28  // RotateLeft rotates an Axis from X to Z or from Z to X.
    29  func (a Axis) RotateLeft() Axis {
    30  	if a == X {
    31  		return Z
    32  	} else if a == Z {
    33  		return X
    34  	}
    35  	return 0
    36  }
    37  
    38  // RotateRight rotates an Axis from X to Z or from Z to X.
    39  func (a Axis) RotateRight() Axis {
    40  	// No difference in rotating left or right for an Axis.
    41  	return a.RotateLeft()
    42  }
    43  
    44  // Vec3 returns a unit Vec3 of either (1, 0, 0), (0, 1, 0) or (0, 0, 1),
    45  // depending on the Axis.
    46  func (a Axis) Vec3() mgl64.Vec3 {
    47  	if a == X {
    48  		return mgl64.Vec3{1, 0, 0}
    49  	} else if a == Y {
    50  		return mgl64.Vec3{0, 1, 0}
    51  	}
    52  	return mgl64.Vec3{0, 0, 1}
    53  }
    54  
    55  // Axes return all possible axes. (x, y, z)
    56  func Axes() []Axis {
    57  	return []Axis{X, Y, Z}
    58  }