coords

package
v0.0.0-...-dfb2563 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChunkWidth     = 32
	ChunkHeight    = 32
	ChunkDepth     = 32
	BlocksPerChunk = ChunkWidth * ChunkHeight * ChunkDepth
)

Variables

This section is empty.

Functions

func EachOffset

func EachOffset(cb func(oc Offset))

Calls the given function with every valid offset coordinate. Useful for going through all the blocks in a chunk.

Types

type Block

type Block struct {
	X int
	Y int
	Z int
}

Block represents the coordinates of any block in the world. It represents the same units as World, but without any precision (because blocks can only exist at integer boundries).

func (Block) Center

func (bc Block) Center() World

func (Block) Chunk

func (bc Block) Chunk() Chunk

func (Block) Float64

func (bc Block) Float64() (float64, float64, float64)

func (Block) Offset

func (bc Block) Offset() Offset

type Chunk

type Chunk struct {
	X int
	Y int
	Z int
}

func (Chunk) EachBlock

func (cc Chunk) EachBlock(cb func(oc Offset, bc Block))

Calls the given function with every valid offset and block coordinate in this chunk. TODO: Should this give both Offset and Block coordinates or just Block?

func (Chunk) Origin

func (cc Chunk) Origin() Block

returns the bottom left block in this chunk

type Direction

type Direction vmath.Vec3

func (Direction) Vec3

func (d Direction) Vec3() vmath.Vec3

type Offset

type Offset struct {
	X int
	Y int
	Z int
}

func IndexOffset

func IndexOffset(index int) Offset

Given an integer 0 <= index < BlocksPerChunk, returns the offset coordinate for that index in "standard" packed format. This logic is duplicated on the client.

func (Offset) Block

func (oc Offset) Block(cc Chunk) Block

func (Offset) Index

func (oc Offset) Index() int

Index is the inverse of IndexOffset. Given a chunk offset coordinate, it returns the offset into the standard packed chunk representation. This logic is duplicated on the client.

type Size

type Size struct {
	X int
	Y int
	Z int
}
var ChunkSize Size = Size{
	X: ChunkWidth,
	Y: ChunkHeight,
	Z: ChunkDepth,
}

type World

type World vmath.Vec3

World represents a position in the 3d world.

var Origin World = World{
	X: 0,
	Y: 0,
	Z: 0,
}

func (World) Block

func (wc World) Block() Block

func (World) Chunk

func (wc World) Chunk() Chunk

func (World) Offset

func (wc World) Offset() Offset

func (World) Vec3

func (wc World) Vec3() vmath.Vec3

Jump to

Keyboard shortcuts

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