3D线框图库 – pinhole

pinhole

3D线框图库

Why does this exist?

I needed a CPU based 3D rendering library with a very simple API for visualizing data structures. No bells or whistles, just clean lines and solid colors.

Getting Started

Installing

To start usingpinhole, install Go and rungo get:

$ go get -u github.com/tidwall/pinhole

This will retrieve the library.

Using

The coordinate space has a locked origin of0,0,0with the min/max boundaries of-1,-1,-1to+1,+1,+1. TheZcoordinate extends from-1(nearest) to+1(farthest).

There are four types of shapes;line,cube,circle, anddot. These can be transformed with theScale,Rotate, andTranslatefunctions. Multiple shapes can be transformed by nesting in aBegin/Endblock.

A simple cube:

p := pinhole.New()
p.DrawCube(-0.3, -0.3, -0.3, 0.3, 0.3, 0.3)
p.SavePNG("cube.png", 500, 500, nil)

Rotate the cube:

p := pinhole.New()
p.DrawCube(-0.3, -0.3, -0.3, 0.3, 0.3, 0.3)
p.Rotate(math.Pi/3, math.Pi/6, 0)
p.SavePNG("cube.png", 500, 500, nil)

Add, rotate, and transform a circle:

p := pinhole.New()
p.DrawCube(-0.3, -0.3, -0.3, 0.3, 0.3, 0.3)
p.Rotate(math.Pi/3, math.Pi/6, 0)

p.Begin()
p.DrawCircle(0, 0, 0, 0.2)
p.Rotate(0, math.Pi/2, 0)
p.Translate(-0.6, -0.4, 0)
p.Colorize(color.RGBA{255, 0, 0, 255})
p.End()

p.SavePNG("cube.png", 500, 500, nil)

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:3D线框图库 – pinhole