vox

package module
v0.0.0-...-264f608 Latest Latest
Warning

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

Go to latest
Published: May 14, 2017 License: Apache-2.0 Imports: 17 Imported by: 0

README

Vox

Vox is a WIP voxel engine written in Go & OpenGL.

Building and running the demo

go get github.com/mbrlabs/vox
cd $GOPATH/github.com/mbrlabs/vox
go run sandbox/*.go

Dependencies

go get github.com/go-gl/gl/v3.3-core/gl
go get github.com/go-gl/glfw/v3.2/glfw

Documentation

Index

Constants

View Source
const (
	ChunkWidth  = 16
	ChunkDepth  = 16
	ChunkHeight = 16
	ChunkXZ     = ChunkWidth * ChunkDepth
	ChunkXYZ    = ChunkXZ * ChunkHeight
)
View Source
const (
	AttribIndexPositions = 0
	AttribIndexNormals   = 1
	AttribIndexUvs       = 2
)
View Source
const (
	BlockNil = 0x00
)
View Source
const CubeSize = 1.0
View Source
const Radius = 12

Variables

View Source
var (
	ColorWhite = NewColor(1, 1, 1, 1)
	ColorBlack = NewColor(0, 0, 0, 1)
	ColorRed   = NewColor(1, 0, 0, 1)
	ColorGreen = NewColor(0, 1, 0, 1)
	ColorBlue  = NewColor(0, 0, 1, 1)
	ColorTeal  = NewColor(0.5, 1, 1, 1)
)
View Source
var (
	Vox *vox
)

Functions

func Sign

func Sign(x int) int

Types

type Block

type Block uint8

func (Block) Activate

func (b Block) Activate(active bool) Block

func (Block) Active

func (b Block) Active() bool

func (Block) ChangeType

func (b Block) ChangeType(t *BlockType) Block

func (Block) TypeID

func (b Block) TypeID() uint8

type BlockBank

type BlockBank struct {
	Types []*BlockType
	// contains filtered or unexported fields
}

func NewBlockBank

func NewBlockBank() *BlockBank

func (*BlockBank) AddType

func (b *BlockBank) AddType(blockType *BlockType)

func (*BlockBank) TypeOf

func (b *BlockBank) TypeOf(block Block) *BlockType

type BlockType

type BlockType struct {
	ID     uint8
	Top    *TextureRegion
	Bottom *TextureRegion
	Side   *TextureRegion
}

type Camera

type Camera struct {
	Combined *glm.Mat4
	// contains filtered or unexported fields
}

func NewCamera

func NewCamera(fov, ratio, near, far float32) *Camera

func (*Camera) Move

func (cam *Camera) Move(x, y, z float32)

func (*Camera) Update

func (cam *Camera) Update()

type Chunk

type Chunk struct {
	Position ChunkPosition
	Blocks   [ChunkXYZ]Block
	Mesh     *Mesh
	// contains filtered or unexported fields
}

func NewChunk

func NewChunk(x, y, z int) *Chunk

func (*Chunk) Get

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

func (*Chunk) IndexAt

func (c *Chunk) IndexAt(x, y, z int) int

func (*Chunk) Set

func (c *Chunk) Set(x, y, z int, block Block)

type ChunkPosition

type ChunkPosition struct {
	X, Y, Z int
}

func (*ChunkPosition) Distance

func (v *ChunkPosition) Distance(other *ChunkPosition) float32

func (*ChunkPosition) Equals

func (p *ChunkPosition) Equals(other *ChunkPosition) bool

func (*ChunkPosition) Set

func (p *ChunkPosition) Set(x, y, z int) *ChunkPosition

func (*ChunkPosition) String

func (p *ChunkPosition) String() string

type ChunkProvider

type ChunkProvider interface {
	GetChunk(x, y, z int) *Chunk
}

type Color

type Color struct {
	R, G, B, A float32
}

func NewColor

func NewColor(r, g, b, a float32) *Color

func (*Color) Copy

func (c *Color) Copy() *Color

func (*Color) String

func (c *Color) String() string

type CulledMesher

type CulledMesher struct {
}

func (*CulledMesher) Generate

func (cm *CulledMesher) Generate(chunk *Chunk, bank *BlockBank) *MeshData

type Disposable

type Disposable interface {
	Dispose()
}

type Environment

type Environment struct {
	Sun *SunLight
	Fog *Fog
}

func NewEnvironment

func NewEnvironment() *Environment

type FlatGenerator

type FlatGenerator struct {
}

func (*FlatGenerator) GenerateChunkAt

func (g *FlatGenerator) GenerateChunkAt(x, y, z int, bank *BlockBank) *Chunk

type Fog

type Fog struct {
	Color   *Color
	Density float32
}

type FpsCameraController

type FpsCameraController struct {
	MouseSensivity float32 // degress per pixel
	Velocity       float32
	// contains filtered or unexported fields
}

func NewFpsController

func NewFpsController(cam *Camera) *FpsCameraController

func (*FpsCameraController) KeyDown

func (c *FpsCameraController) KeyDown(key Key) bool

func (*FpsCameraController) KeyPressed

func (c *FpsCameraController) KeyPressed(key Key) bool

func (*FpsCameraController) KeyUp

func (c *FpsCameraController) KeyUp(key Key) bool

func (*FpsCameraController) MouseMoved

func (c *FpsCameraController) MouseMoved(x, y float64) bool

func (*FpsCameraController) Update

func (c *FpsCameraController) Update(delta float32)

type FpsLogger

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

func (*FpsLogger) Log

func (l *FpsLogger) Log(delta float32)

type Game

type Game interface {
	Disposable
	Create()
	Resize(width, height int)
	Render(delta float32)
	Update(delta float32)
}

Game todo

type Generator

type Generator interface {
	GenerateChunkAt(x, y, z int, bank *BlockBank) *Chunk
}

func NewSimplexGenerator

func NewSimplexGenerator(seed int64) Generator

type InfiniteWorldController

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

func NewInifinteWorldController

func NewInifinteWorldController(cam *Camera, world *World) *InfiniteWorldController

func (*InfiniteWorldController) Update

func (c *InfiniteWorldController) Update()

type Key

type Key uint16
const (
	KeyUnknown      Key = 0
	KeySpace        Key = 1
	KeyApostrophe   Key = 2
	KeyComma        Key = 3
	KeyMinus        Key = 4
	KeyPeriod       Key = 5
	KeySlash        Key = 6
	Key0            Key = 7
	Key1            Key = 8
	Key2            Key = 9
	Key3            Key = 10
	Key4            Key = 11
	Key5            Key = 12
	Key6            Key = 13
	Key7            Key = 14
	Key8            Key = 15
	Key9            Key = 16
	KeySemicolon    Key = 17
	KeyEqual        Key = 18
	KeyA            Key = 19
	KeyB            Key = 20
	KeyC            Key = 21
	KeyD            Key = 22
	KeyE            Key = 23
	KeyF            Key = 24
	KeyG            Key = 25
	KeyH            Key = 26
	KeyI            Key = 27
	KeyJ            Key = 28
	KeyK            Key = 29
	KeyL            Key = 30
	KeyM            Key = 31
	KeyN            Key = 32
	KeyO            Key = 33
	KeyP            Key = 34
	KeyQ            Key = 35
	KeyR            Key = 36
	KeyS            Key = 37
	KeyT            Key = 38
	KeyU            Key = 39
	KeyV            Key = 40
	KeyW            Key = 41
	KeyX            Key = 42
	KeyY            Key = 43
	KeyZ            Key = 44
	KeyLeftBracket  Key = 45
	KeyBackslash    Key = 46
	KeyRightBracket Key = 47
	KeyGraveAccent  Key = 48
	KeyWorld1       Key = 49
	KeyWorld2       Key = 50
	KeyEscape       Key = 51
	KeyEnter        Key = 52
	KeyTab          Key = 53
	KeyBackspace    Key = 54
	KeyInsert       Key = 55
	KeyDelete       Key = 56
	KeyRight        Key = 57
	KeyLeft         Key = 58
	KeyDown         Key = 59
	KeyUp           Key = 60
	KeyPageUp       Key = 61
	KeyPageDown     Key = 62
	KeyHome         Key = 63
	KeyEnd          Key = 64
	KeyCapsLock     Key = 65
	KeyScrollLock   Key = 66
	KeyNumLock      Key = 67
	KeyPrintScreen  Key = 68
	KeyPause        Key = 69
	KeyF1           Key = 70
	KeyF2           Key = 71
	KeyF3           Key = 72
	KeyF4           Key = 73
	KeyF5           Key = 74
	KeyF6           Key = 75
	KeyF7           Key = 76
	KeyF8           Key = 77
	KeyF9           Key = 78
	KeyF10          Key = 79
	KeyF11          Key = 80
	KeyF12          Key = 81
	KeyF13          Key = 82
	KeyF14          Key = 83
	KeyF15          Key = 84
	KeyF16          Key = 85
	KeyF17          Key = 86
	KeyF18          Key = 87
	KeyF19          Key = 88
	KeyF20          Key = 89
	KeyF21          Key = 90
	KeyF22          Key = 91
	KeyF23          Key = 92
	KeyF24          Key = 93
	KeyF25          Key = 94
	KeyKP0          Key = 95
	KeyKP1          Key = 96
	KeyKP2          Key = 97
	KeyKP3          Key = 98
	KeyKP4          Key = 99
	KeyKP5          Key = 100
	KeyKP6          Key = 101
	KeyKP7          Key = 102
	KeyKP8          Key = 103
	KeyKP9          Key = 104
	KeyKPDecimal    Key = 105
	KeyKPDivide     Key = 106
	KeyKPMultiply   Key = 107
	KeyKPSubtract   Key = 108
	KeyKPAdd        Key = 109
	KeyKPEnter      Key = 110
	KeyKPEqual      Key = 111
	KeyLeftShift    Key = 112
	KeyLeftControl  Key = 113
	KeyLeftAlt      Key = 114
	KeyLeftSuper    Key = 115
	KeyRightShift   Key = 116
	KeyRightControl Key = 117
	KeyRightAlt     Key = 118
	KeyRightSuper   Key = 119
	KeyMenu         Key = 120
)

type KeyListener

type KeyListener interface {
	KeyDown(key Key) bool
	KeyUp(key Key) bool
	KeyPressed(key Key) bool
}

KeyListener todo

type Mesh

type Mesh struct {
	IndexCount int32
	// contains filtered or unexported fields
}

func NewMesh

func NewMesh() *Mesh

func (*Mesh) Bind

func (m *Mesh) Bind()

func (*Mesh) Dispose

func (m *Mesh) Dispose()

func (*Mesh) Load

func (m *Mesh) Load(data *MeshData)

func (*Mesh) Unbind

func (m *Mesh) Unbind()

type MeshData

type MeshData struct {
	Positions  []float32
	Normals    []float32
	Uvs        []float32
	IndexCount int
}

type Mesher

type Mesher interface {
	Generate(chunk *Chunk, bank *BlockBank) *MeshData
}

type MouseListener

type MouseListener interface {
	//MouseDown(x, y float64) bool
	//MouseUp(x, y float64) bool
	MouseMoved(x, y float64) bool
}

MouseListener todo

type Pixmap

type Pixmap struct {
	Data   []uint8
	Width  int32
	Height int32
}

func NewPixmap

func NewPixmap(path string) *Pixmap

type Shader

type Shader struct {
	ID uint32
}

func NewShader

func NewShader(vertexSource, fragmentSource string, attribs []VertexAttribute) (*Shader, error)

func (*Shader) Disable

func (s *Shader) Disable()

func (*Shader) Dispose

func (s *Shader) Dispose()

func (*Shader) Enable

func (s *Shader) Enable()

type SimplexGenerator

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

func (*SimplexGenerator) GenerateChunkAt

func (g *SimplexGenerator) GenerateChunkAt(xx, yy, zz int, bank *BlockBank) *Chunk

type SimplexNoise

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

func NewSimplex

func NewSimplex(seed int64) *SimplexNoise

func (*SimplexNoise) Simplex2

func (s *SimplexNoise) Simplex2(x, y float64, octaves int, persistence, lacunarity float64) float64

type SunLight

type SunLight struct {
	Color     *Color
	Direction *glm.Vector3
	Intensity float32
}

type Texture

type Texture struct {
	Disposable
	// contains filtered or unexported fields
}

func NewTexture

func NewTexture(path string, genMipmaps bool) *Texture

func (*Texture) Bind

func (t *Texture) Bind()

func (*Texture) Dispose

func (t *Texture) Dispose()

func (*Texture) Height

func (t *Texture) Height() int32

func (*Texture) Unbind

func (t *Texture) Unbind()

func (*Texture) Width

func (t *Texture) Width() int32

type TextureAtlas

type TextureAtlas struct {
	Regions map[string]*TextureRegion
	// contains filtered or unexported fields
}

func NewTextureAtlas

func NewTextureAtlas(jsonPath, imagePath string) *TextureAtlas

func (*TextureAtlas) Bind

func (a *TextureAtlas) Bind()

func (*TextureAtlas) Dispose

func (a *TextureAtlas) Dispose()

func (*TextureAtlas) Unbind

func (a *TextureAtlas) Unbind()

type TextureRegion

type TextureRegion struct {
	Atlas *TextureAtlas
	Uvs   [4]glm.Vector2

	Name   string  `json:"name"`
	Width  float32 `json:"width"`
	Height float32 `json:"height"`
	X      float32 `json:"x"`
	Y      float32 `json:"y"`
}

type VertexAttribute

type VertexAttribute struct {
	Position uint32
	Name     string
}

type Window

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

Window todo

func NewWindow

func NewWindow(config *WindowConfig) *Window

NewWindow todo

func (*Window) Dispose

func (w *Window) Dispose()

Dispose todo

func (*Window) Start

func (w *Window) Start(game Game)

Start todo

type WindowConfig

type WindowConfig struct {
	Height       int
	Width        int
	Title        string
	Resizable    bool
	Fullscreen   bool
	Vsync        bool
	HiddenCursor bool
}

WindowConfig todo

type World

type World struct {

	// Chunks are all chunks that are ready to be rendered
	Chunks map[ChunkPosition]*Chunk

	MaxUploadsPerFrame int
	// contains filtered or unexported fields
}

func NewWorld

func NewWorld(bank *BlockBank, mesher Mesher, generator Generator) *World

NewWorld creates a new world

func (*World) GenerateNewChunk

func (w *World) GenerateNewChunk(x, y, z int)

GenerateNewChunk generates a new chunk at the given chunk-coordinates. This does not perform, any OpenGL calls.

func (*World) RemoveChunk

func (w *World) RemoveChunk(x, y, z int)

RemoveChunk schedules the cunk for removal.

func (*World) Update

func (w *World) Update()

Update updates the chunk meshes

type WorldRenderer

type WorldRenderer struct {
	Disposable
	// contains filtered or unexported fields
}

func NewWorldRenderer

func NewWorldRenderer() *WorldRenderer

func (*WorldRenderer) Dispose

func (r *WorldRenderer) Dispose()

func (*WorldRenderer) Render

func (r *WorldRenderer) Render(cam *Camera, world *World, env *Environment)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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