maprenderer

package module
v1.0.20 Latest Latest
Warning

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

Go to latest
Published: May 29, 2022 License: MIT Imports: 6 Imported by: 0

README

Minetest map renderer library for go

Coverage Status

State: WIP

Licenses

Code: MIT

Other assets

Documentation

Index

Examples

Constants

View Source
const (
	EXPECTED_BLOCKS_PER_FLAT_MAPBLOCK = 16 * 16
)

Variables

This section is empty.

Functions

func AddColorComponent

func AddColorComponent(c *color.RGBA, value int) *color.RGBA

add a color component (darker, lighter)

func AdjustAndFill added in v1.0.3

func AdjustAndFill(dc *gg.Context, r, g, b, adjust int)

func Clamp

func Clamp(num int) uint8

limit a number from 0 to 255

Types

type IsoDirection added in v1.0.3

type IsoDirection uint8
const (
	// default direction, x and z increase
	IsoDirectionNorthEast IsoDirection = 0
	IsoDirectionNorthWest IsoDirection = 1
	IsoDirectionSouthWest IsoDirection = 2
	IsoDirectionSouthEast IsoDirection = 3
)

look direction

type IsoRenderer added in v1.0.3

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

func NewIsoRenderer added in v1.0.3

func NewIsoRenderer(cm *colormapping.ColorMapping, mba MapblockAccessor, height int) (*IsoRenderer, error)

func (*IsoRenderer) GetImagePos added in v1.0.3

func (r *IsoRenderer) GetImagePos(x, y, z float64) (float64, float64)

func (*IsoRenderer) Render added in v1.0.3

func (r *IsoRenderer) Render(pos MapblockPosGetter, y_block_height int, direction IsoDirection) (*image.NRGBA, error)

type MapRenderer

type MapRenderer struct {
	// contains filtered or unexported fields
}
Example
// create color mapping
cm := colormapping.NewColorMapping()

// TODO: implemement mapblock fetching and parsing here
accessor := func(pos MapblockPosGetter) (Mapblock, error) {
	return nil, nil
}

// create renderer with 256 px sidelength
r, err := NewMapRenderer(cm, accessor, 256)
if err != nil {
	panic(err)
}

// render the mapblock at 0,0,0 with 10 mapblocks y-height into an image
img, err := r.Render(&MapblockPos{X: 0, Y: 0, Z: 0}, 10)
if err != nil {
	panic(err)
}

// create an output file
f, err := os.Create("output.png")
if err != nil {
	panic(err)
}

// write to the file
err = png.Encode(f, img)
if err != nil {
	panic(err)
}
Output:

func NewMapRenderer

func NewMapRenderer(cm *colormapping.ColorMapping, mba MapblockAccessor, size int) (*MapRenderer, error)

func (*MapRenderer) IsViewBocking

func (r *MapRenderer) IsViewBocking(nodename string) bool

func (*MapRenderer) Render

func (r *MapRenderer) Render(pos MapblockPosGetter, y_block_height int) (*image.NRGBA, error)

type Mapblock

type Mapblock interface {
	GetNodeName(x, y, z int) string
	GetParam2(x, y, z int) int
	IsEmpty() bool
}

type MapblockAccessor

type MapblockAccessor func(pos MapblockPosGetter) (Mapblock, error)

type MapblockPos

type MapblockPos struct {
	X, Y, Z int
}

func (*MapblockPos) GetX added in v1.0.2

func (pos *MapblockPos) GetX() int

func (*MapblockPos) GetY added in v1.0.2

func (pos *MapblockPos) GetY() int

func (*MapblockPos) GetZ added in v1.0.2

func (pos *MapblockPos) GetZ() int

type MapblockPosGetter added in v1.0.2

type MapblockPosGetter interface {
	GetX() int
	GetY() int
	GetZ() int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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