t

package
v0.0.0-...-86c6665 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const AtlasDims = AtlasTextureDims / FaceDims

atlasDims are the X and Y dimensions of the face atlas in faces.

View Source
const AtlasTextureDims = 2048

AtlasTextureDims are the X and Y dimensions of the face atlas texture in pixels.

View Source
const CellDimsVS int = VSGlyphWidth

CellDimsVS is the dimensions of a cell in screen units.

View Source
const FACellHeight int = 64

FACellHeight is the height of one cell in the atlas in pixels.

View Source
const FACellWidth int = 32

FACellWidth is the width of one cell in the atlas in pixels.

View Source
const FACellXOfs int = (FACellWidth - FAGlyphSize) / 2

FACellXOfs is the X offset to use when rendering a glyph in pixels.

View Source
const FACellYOfs int = (FACellHeight - FAGlyphSize) / 2

FACellYOfs is the Y offset to use when rendering a glyph in pixels.

View Source
const FACellsWide int = FADims / FACellWidth

FACellsWide is the width of the font atlas in glyphs.

View Source
const FADims int = 2048

FADims is the font atlas dimensions.

View Source
const FAGlyphSize int = 32

FAGlyphSize is the dimensions of a glyph in pixels.

View Source
const FaceDims = 16

FaceDims are the X and Y dimensions of a face in pixels.

View Source
const LineSpacingVS int = (VSGlyphWidth / 2) * 3 // 1.5

LineSpacingVS is the line spacing used in print commands in virtual screen units.

View Source
const PageStep float32 = float32(1) / float32(AtlasDims)

Stepping value for face U and V offsets.

View Source
const VSBaseline int = VSCellHeight / 4

vsBaseline is the Y offset for baseline in virtual screen units.

View Source
const VSCellHeight int = (VSGlyphWidth * FACellHeight) / FACellWidth

vsCellHeight is the height of one font atlas cell in virtual screen units.

VSGlyphWidth is the width of one glyph in virtual screen units, minus boarder width.

View Source
const VirtualScreenGlyphSize int = 4

VirtualScreenGlyphSize is the dimensions of a glyph.

View Source
const VirtualScreenGlyphsHigh int = VirtualScreenHeight / VirtualScreenGlyphSize

VirtualScreenGlyphsHigh is the width of the screen in glyphs.

View Source
const VirtualScreenGlyphsWide int = VirtualScreenWidth / VirtualScreenGlyphSize

VirtualScreenGlyphsWide is the width of the screen in glyphs.

View Source
const VirtualScreenHeight int = 180

VirtualScreenHeight is the width of the virtual 2D screen in pixels.

View Source
const VirtualScreenWidth int = 320

VirtualScreenWidth is the width of the virtual 2D screen in pixels.

View Source
const VoxelScale float32 = 1.0 / 16.0

VoxelScale is the scale of a single voxel.

Variables

View Source
var CubeInvalid = &Cube{
	Ref:  0xFFFF,
	ID:   "",
	Name: "invalid",
	Faces: [6]FaceIndex{
		0xFFFF,
		0xFFFF,
		0xFFFF,
		0xFFFF,
		0xFFFF,
		0xFFFF,
	},
	Transparent: true,
}

CubeInvalid is the invalid cube definition.

View Source
var FacingMap = [6][6]Facing{
	{
		North,
		South,
		East,
		West,
		Top,
		Bottom,
	},
	{
		South,
		North,
		West,
		East,
		Top,
		Bottom,
	},
	{
		West,
		East,
		North,
		South,
		Top,
		Bottom,
	},
	{
		East,
		West,
		South,
		North,
		Top,
		Bottom,
	},
	{
		Bottom,
		Top,
		East,
		West,
		North,
		South,
	},
	{
		Top,
		Bottom,
		East,
		West,
		South,
		North,
	},
}

FacingMap maps orientation facing to face index.

View Source
var FacingOffsets = [6][3]int{
	{0, 0, -1},
	{0, 0, 1},
	{1, 0, 0},
	{-1, 0, 0},
	{0, 1, 0},
	{0, -1, 0},
}

FacingOffsets are the offsets from the center voxel to the voxel in the direction of the indexed facing.

View Source
var FacingToOrientation = [6]Orientation{
	O(),
	O().Yaw(math.Pi),
	O().Yaw(-math.Pi * 0.5),
	O().Yaw(math.Pi * 0.5),
	O().Pitch(math.Pi * 0.5),
	O().Pitch(-math.Pi * 0.5),
}

FacingToOrientation is the facing to orientation table.

View Source
var PositionOffsets = [6]IVec3{
	{0, 0, -1},
	{0, 0, 1},
	{1, 0, 0},
	{-1, 0, 0},
	{0, 1, 0},
	{0, -1, 0},
}

Position offsets per c3d.Facing value index.

View Source
var XAxis mgl32.Vec3 = mgl32.Vec3{1, 0, 0}

XAxis is a unit vector pointing along the positive X axis.

View Source
var YAxis mgl32.Vec3 = mgl32.Vec3{0, 1, 0}

YAxis is a unit vector pointing along the positive Y axis.

View Source
var ZAxis mgl32.Vec3 = mgl32.Vec3{0, 0, 1}

ZAxis is a unit vector pointing along the positive Z axis.

Functions

This section is empty.

Types

type AABB

type AABB [2]mgl32.Vec3

AABB represents an axis-aligned bounding box.

func (*AABB) UnmarshalJSON

func (b *AABB) UnmarshalJSON(d []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type Cell

type Cell uint32

Cell encodes the cube or vox contained in a single Cell along with the orientation.

const CellInvalid Cell = 0xFFFFFFFF

CellInvalid is the invalid valid for cells.

func CellForCube

func CellForCube(r CubeRef, f Facing) Cell

CellForCube returns the cell value with the given values encoded.

func CellForVox

func CellForVox(r VoxRef, f Facing) Cell

CellForVox returns the cell value with the given values encoded.

func (Cell) Decompose

func (l Cell) Decompose() (c CubeRef, v VoxRef, f Facing)

Decompose returns the portions of the cell value broken out.

func (Cell) IsCube

func (l Cell) IsCube() bool

IsCube returns true if this is a cube reference.

func (Cell) IsVox

func (l Cell) IsVox() bool

IsVox returns true if this is a voxel model reference.

type Chunk

type Chunk struct {
	Position    IVec3  // World coordinates of the bottom-north-west corner of the chunk
	Revision    uint32 // Chunk revision number, increments with every change to cell contents
	VoxRevision uint32 // Chunk vox model revision number, increments with every insertion or removal of a vox model
	// contains filtered or unexported fields
}

Chunk manages a 16x16x16 dense matrix of 32-bit values.

func (*Chunk) Dimensions

func (c *Chunk) Dimensions() (w, h, d int)

Dimensions implements the c3d.VoxelSource interface.

func (*Chunk) Fill

func (c *Chunk) Fill(f Cell)

Fill fills the chunk with the given fill value.

func (*Chunk) Get

func (c *Chunk) Get(x, y, z int) Cell

Get implements the c3d.VoxelSource interface.

func (*Chunk) GetCell

func (c *Chunk) GetCell(p IVec3) Cell

GetCell returns the value at the given location, or the invalid value if out of bounds.

func (*Chunk) GetRelative

func (c *Chunk) GetRelative(p IVec3) Cell

GetRelative is like Get(), but the location is relative to the bottom-north- west corner of the chunk.

func (*Chunk) IsEmpty

func (c *Chunk) IsEmpty(v Cell) bool

IsEmpty implements the c3d.VoxelSource interface.

func (*Chunk) SetCell

func (c *Chunk) SetCell(p IVec3, v Cell) bool

SetCell sets the value at the given location. If the location is out of bounds this is a no-op. True is returned if the contents of the chunk were altered.

func (*Chunk) SetRelative

func (c *Chunk) SetRelative(p IVec3, v Cell) bool

SetRelative is like Get(), but the location ip.Zs relative to the bottom-north- west corner of the chunk.

type ChunkRef

type ChunkRef uint32

ChunkRef references a single chunk within the world.

const InvalidChunkRef ChunkRef = 0xFFFFFFFF

InvalidChunkRef is the invalid value for ChunkRef.

func NewChunkRef

func NewChunkRef(p IVec3) ChunkRef

NewChunkRef creates a new chunk reference with the given chunk coordinates.

func NewChunkRefForWorldPosition

func NewChunkRefForWorldPosition(p IVec3) ChunkRef

NewChunkRefForWorldPosition creates a new chunk reference with the chunk that contains the given world coordinates.

type Cube

type Cube struct {
	Ref         CubeRef      `json:"-"`           // CubeRef value assigned to the cube definition
	ID          string       `json:"-"`           // Unique ID
	Name        string       `json:"name"`        // Descriptive name
	Faces       [6]FaceIndex `json:"faces"`       // Face graphic to use for each face of the cube.
	Transparent bool         `json:"transparent"` // If true this cube can be seen through
}

Cube represents one cubic meter of the world.

type CubeRef

type CubeRef uint16

CubeRef is a reference to a single Cube object that holds all of the static data for the cube.

const CubeRefInvalid CubeRef = 0xFFFF

CubeRefInvalid is the invalid value for CubeRef types.

type FaceIndex

type FaceIndex uint16

FaceIndex indexes a tile in the face atlas. The 4 least significant bits encode the X face position with the source page image, and the next 4 bits encode the Y. The 8 most significant bits of the index encode the source face page.

const FaceIndexInvalid FaceIndex = 0xFFFF

FaceIndexInvalid is the invalid face index value.

func FaceIndexFromXYZ

func FaceIndexFromXYZ(x, y, z int) FaceIndex

FaceIndexFromXYZ returns the FaceIndex value for the given coordinates, where X and Y range 0-7 and Z ranges 0-255.

func (FaceIndex) ToAtlasXY

func (t FaceIndex) ToAtlasXY() (x int, y int)

ToXY returns the X and Y coordinates of the tile in atlas texture.

func (FaceIndex) ToUV

func (t FaceIndex) ToUV() (mgl32.Vec2, mgl32.Vec2)

ToUV returns the UV (texture coordinates) that should be assigned to the top-left and bottom-right vertexes of a face for the given FaceIndex value.

func (FaceIndex) ToXYZ

func (t FaceIndex) ToXYZ() (x int, y int, z int)

ToXY returns the X, Y, and Z coordinates of the tile in tile source sets.

func (*FaceIndex) UnmarshalJSON

func (t *FaceIndex) UnmarshalJSON(b []byte) error

type Facing

type Facing uint8

Facing encodes one of the facing values, North, South, East, West, Up, Down.

const (
	North Facing = iota
	South
	East
	West
	Top
	Bottom
)

type IVec3

type IVec3 [3]int

IVec3 represents a cube position within the world.

func (IVec3) Add

func (p IVec3) Add(r IVec3) IVec3

Add adds r to this position and returns the result.

func (IVec3) Div

func (p IVec3) Div(r IVec3) IVec3

Div divides this position by r and returns the result.

func (IVec3) Mod

func (p IVec3) Mod(r IVec3) IVec3

Mod returns the result of this position modulo r.

func (IVec3) Mul

func (p IVec3) Mul(r IVec3) IVec3

Mul multiplies r and this position and returns the result.

func (IVec3) Sub

func (p IVec3) Sub(r IVec3) IVec3

Sub subtracts r from this position and returns the result.

type Orientation

type Orientation struct {
	P mgl32.Vec3 // Position
	Q mgl32.Quat // Rotation quaternion
}

Orientation combines a position and a rotation quaternion and offers functions to transform the values.

func O

func O() Orientation

O returns a new orientation.

func (Orientation) Accumulate

func (o Orientation) Accumulate(r Orientation) Orientation

Accumulate accumulates the orientation and position in model space and returns the new orientation.

func (Orientation) Pitch

func (o Orientation) Pitch(r float32) Orientation

Pitch rotations the orientation about the X axis by r radians.

func (Orientation) Roll

func (o Orientation) Roll(r float32) Orientation

Roll rotations the orientation about the Z axis by r radians.

func (Orientation) RotationMatrix

func (o Orientation) RotationMatrix() mgl32.Mat4

RotationMatrix returns the rotation matrix for this orientation.

func (Orientation) TransformMatrix

func (o Orientation) TransformMatrix() mgl32.Mat4

TransformMatrix returns the full transform matrix for this orientation.

func (Orientation) Translate

func (o Orientation) Translate(t mgl32.Vec3) Orientation

Translate adds offsets to the orientation's current position.

func (Orientation) TranslationMatrix

func (o Orientation) TranslationMatrix() mgl32.Mat4

TranslationMatrix returns the translation matrix for this orientation.

func (*Orientation) UnmarshalJSON

func (o *Orientation) UnmarshalJSON(d []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (Orientation) VoxelScaleTransformMatrix

func (o Orientation) VoxelScaleTransformMatrix() mgl32.Mat4

VoxelScaleTransformMatrix returns the transform matrix of the orientation with the position component multiplied by t.VoxelScale.

func (Orientation) Yaw

func (o Orientation) Yaw(r float32) Orientation

Yaw rotations the orientation about the Y axis by r radians.

type Ray

type Ray struct {
	O mgl32.Vec3 // Origin
	N mgl32.Vec3 // Normal
	L float32    // Length
	// contains filtered or unexported fields
}

Ray represents a line in 3D space by defining an origin and normalized facing direction.

func NewRay

func NewRay(origin, dir mgl32.Vec3, length float32) *Ray

NewRay constructs a new Ray ready for use.

func (*Ray) IntersectWorld

func (r *Ray) IntersectWorld(w *World) *WorldIntersection

IntersectWorld returns a description of the point at which the ray intersects w, or nil if there is no intersection. Adopted from https://stackoverflow.com/questions/12367071/how-do-i-initialize-the-t-variables-in-a-fast-voxel-traversal-algorithm-for-ray

func (*Ray) IntersectsAABB

func (r *Ray) IntersectsAABB(b AABB) bool

IntersectsAABB returns true if the ray intersects the given AABB.

type VoxRef

type VoxRef uint16

VoxRef encodes a reference to a vox model.

const VoxRefInvalid VoxRef = 0xFFFF

VoxRefInvalid is the invalid valid value for VoxRef variables.

type World

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

World manages the state of the entire world.

func NewWorld

func NewWorld() *World

NewWorld returns a new World object read for use.

func (*World) GetCell

func (w *World) GetCell(p IVec3) Cell

GetCell returns the cell value at the given position in the world.

func (*World) GetChunkByRef

func (w *World) GetChunkByRef(r ChunkRef) *Chunk

GetChunkByRef returns the chunk for the given chunk reference, or nil if no chunk exists.

func (*World) SetCell

func (w *World) SetCell(p IVec3, v Cell) bool

SetCell sets the cube and facing at the given position in the world. Returns true if the voxel was changed.

type WorldIntersection

type WorldIntersection struct {
	Position IVec3   // World coordinate of the cell hit
	Face     Facing  // Face struck
	Cube     CubeRef // The cube intersected, if any
	Vox      VoxRef  // The voxel model intersected, if any
	Facing   Facing  // Facing of the cube or voxel model intersected
}

WorldIntersection represents a ray intersection with the world.

Jump to

Keyboard shortcuts

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