Documentation ¶
Index ¶
- Constants
- Variables
- type AABB
- type Cell
- type Chunk
- func (c *Chunk) Dimensions() (w, h, d int)
- func (c *Chunk) Fill(f Cell)
- func (c *Chunk) Get(x, y, z int) Cell
- func (c *Chunk) GetCell(p IVec3) Cell
- func (c *Chunk) GetRelative(p IVec3) Cell
- func (c *Chunk) IsEmpty(v Cell) bool
- func (c *Chunk) SetCell(p IVec3, v Cell) bool
- func (c *Chunk) SetRelative(p IVec3, v Cell) bool
- type ChunkRef
- type Cube
- type CubeRef
- type FaceIndex
- type Facing
- type IVec3
- type Orientation
- func (o Orientation) Accumulate(r Orientation) Orientation
- func (o Orientation) Pitch(r float32) Orientation
- func (o Orientation) Roll(r float32) Orientation
- func (o Orientation) RotationMatrix() mgl32.Mat4
- func (o Orientation) TransformMatrix() mgl32.Mat4
- func (o Orientation) Translate(t mgl32.Vec3) Orientation
- func (o Orientation) TranslationMatrix() mgl32.Mat4
- func (o *Orientation) UnmarshalJSON(d []byte) error
- func (o Orientation) VoxelScaleTransformMatrix() mgl32.Mat4
- func (o Orientation) Yaw(r float32) Orientation
- type Ray
- type VoxRef
- type World
- type WorldIntersection
Constants ¶
const AtlasDims = AtlasTextureDims / FaceDims
atlasDims are the X and Y dimensions of the face atlas in faces.
const AtlasTextureDims = 2048
AtlasTextureDims are the X and Y dimensions of the face atlas texture in pixels.
const CellDimsVS int = VSGlyphWidth
CellDimsVS is the dimensions of a cell in screen units.
const FACellHeight int = 64
FACellHeight is the height of one cell in the atlas in pixels.
const FACellWidth int = 32
FACellWidth is the width of one cell in the atlas in pixels.
const FACellXOfs int = (FACellWidth - FAGlyphSize) / 2
FACellXOfs is the X offset to use when rendering a glyph in pixels.
const FACellYOfs int = (FACellHeight - FAGlyphSize) / 2
FACellYOfs is the Y offset to use when rendering a glyph in pixels.
const FACellsWide int = FADims / FACellWidth
FACellsWide is the width of the font atlas in glyphs.
const FADims int = 2048
FADims is the font atlas dimensions.
const FAGlyphSize int = 32
FAGlyphSize is the dimensions of a glyph in pixels.
const FaceDims = 16
FaceDims are the X and Y dimensions of a face in pixels.
const LineSpacingVS int = (VSGlyphWidth / 2) * 3 // 1.5
LineSpacingVS is the line spacing used in print commands in virtual screen units.
const PageStep float32 = float32(1) / float32(AtlasDims)
Stepping value for face U and V offsets.
const VSBaseline int = VSCellHeight / 4
vsBaseline is the Y offset for baseline in virtual screen units.
const VSCellHeight int = (VSGlyphWidth * FACellHeight) / FACellWidth
vsCellHeight is the height of one font atlas cell in virtual screen units.
const VSGlyphWidth int = VirtualScreenWidth / VirtualScreenGlyphsWide
VSGlyphWidth is the width of one glyph in virtual screen units, minus boarder width.
const VirtualScreenGlyphSize int = 4
VirtualScreenGlyphSize is the dimensions of a glyph.
const VirtualScreenGlyphsHigh int = VirtualScreenHeight / VirtualScreenGlyphSize
VirtualScreenGlyphsHigh is the width of the screen in glyphs.
const VirtualScreenGlyphsWide int = VirtualScreenWidth / VirtualScreenGlyphSize
VirtualScreenGlyphsWide is the width of the screen in glyphs.
const VirtualScreenHeight int = 180
VirtualScreenHeight is the width of the virtual 2D screen in pixels.
const VirtualScreenWidth int = 320
VirtualScreenWidth is the width of the virtual 2D screen in pixels.
const VoxelScale float32 = 1.0 / 16.0
VoxelScale is the scale of a single voxel.
Variables ¶
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.
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.
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.
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.
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.
var XAxis mgl32.Vec3 = mgl32.Vec3{1, 0, 0}
XAxis is a unit vector pointing along the positive X axis.
var YAxis mgl32.Vec3 = mgl32.Vec3{0, 1, 0}
YAxis is a unit vector pointing along the positive Y axis.
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 ¶
AABB represents an axis-aligned bounding box.
func (*AABB) UnmarshalJSON ¶
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 ¶
CellForCube returns the cell value with the given values encoded.
func CellForVox ¶
CellForVox returns the cell value with the given values encoded.
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 ¶
Dimensions implements the c3d.VoxelSource interface.
func (*Chunk) GetCell ¶
GetCell returns the value at the given location, or the invalid value if out of bounds.
func (*Chunk) GetRelative ¶
GetRelative is like Get(), but the location is 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 ¶
NewChunkRef creates a new chunk reference with the given chunk coordinates.
func NewChunkRefForWorldPosition ¶
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 ¶
FaceIndexFromXYZ returns the FaceIndex value for the given coordinates, where X and Y range 0-7 and Z ranges 0-255.
func (FaceIndex) ToUV ¶
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) UnmarshalJSON ¶
type Facing ¶
type Facing uint8
Facing encodes one of the facing values, North, South, East, West, Up, Down.
type IVec3 ¶
type IVec3 [3]int
IVec3 represents a cube position within the world.
type Orientation ¶
Orientation combines a position and a rotation quaternion and offers functions to transform the values.
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 (*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 ¶
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 (*World) GetChunkByRef ¶
GetChunkByRef returns the chunk for the given chunk reference, or nil if no chunk exists.
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.