go3d

package module
v0.0.0-...-55ced4b Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 22 Imported by: 0

README

Package go3d is a performance oriented vector and matrix math package for 2D and 3D graphics.

Every type has its own sub-package and is named T. So vec3.T is the 3D vector type. For every vector and matrix type there is a String() method and a Parse() function. Besides methods of T there are also functions in the packages, like vec3.Dot(a, b).

Packages under the float64 directory are using float64 values instead of float32.

Matrices are organized as arrays of columns which is also the way OpenGL expects matrices. DirectX expects "arrays of rows" matrices, use the Transpose() to convert.

Methods that don't return a specific value, return a pointer to the struct to allow method call chaining.

Example:

a := vec3.Zero
b := vec3.UnitX
a.Add(&b).Scale(5)

Method names in the past tense return a copy of the struct instead of a pointer to it.

Example:

a := vec3.UnitX
b := a.Scaled(5) // a still equals vec3.UnitX

Note that the package is designed for performance over usability where necessary. This is the reason why many arguments are passed by pointer reference instead of by value. Sticking either to passing and returning everything by value or by pointer would lead to a nicer API, but it would be slower as demonstrated in mat4/mat4_test.go

cd mat4
go test -bench=BenchmarkMulAddVec4_PassBy*

Documentation: https://pkg.go.dev/github.com/ungerik/go3d

Documentation

Overview

Package go3d is a performance oriented vector and matrix math package for 2D and 3D graphics.

Every type has its own sub-package and is named T. So vec3.T is the 3D vector type. For every vector and matrix type there is a String() method and a Parse() function. Besides methods of T there are also functions in the packages, like vec3.Dot(a, b).

Packages under the float64 directory are using float64 values instead of float32.

Matrices are organized as arrays of columns which is also the way OpenGL expects matrices. DirectX expects "arrays of rows" matrices, use the Transpose() to convert.

Methods that don't return a specific value, return a pointer to the struct to allow method call chaining.

Example:

a := vec3.Zero
b := vec3.UnitX
a.Add(&b).Scale(5)

Method names in the past tense return a copy of the struct instead of a pointer to it.

Example:

a := vec3.UnitX
b := a.Scaled(5) // a still equals vec3.UnitX

Documentation: http://godoc.org/github.com/ungerik/go3d

Directories

Path Synopsis
float64
bezier2
Package bezier2 contains functions for 2D cubic Bezier splines.
Package bezier2 contains functions for 2D cubic Bezier splines.
generic
Package generic contains an interface T that that all float64 vector and matrix types implement.
Package generic contains an interface T that that all float64 vector and matrix types implement.
hermit2
Package hermit2 contains functions for 2D cubic hermit splines.
Package hermit2 contains functions for 2D cubic hermit splines.
hermit3
Package hermit3 contains functions for 3D cubic hermit splines.
Package hermit3 contains functions for 3D cubic hermit splines.
mat2
Package mat2 contains a 2x2 float64 matrix type T and functions.
Package mat2 contains a 2x2 float64 matrix type T and functions.
mat3
Package mat3 contains a 3x3 float64 matrix type T and functions.
Package mat3 contains a 3x3 float64 matrix type T and functions.
mat4
Package mat4 contains a 4x4 float64 matrix type T and functions.
Package mat4 contains a 4x4 float64 matrix type T and functions.
qbezier2
Package qbezier2 contains functions for 2D quadratic Bezier splines.
Package qbezier2 contains functions for 2D quadratic Bezier splines.
quaternion
Package quaternion contains a float64 unit-quaternion type T and functions.
Package quaternion contains a float64 unit-quaternion type T and functions.
vec2
Package vec2 contains a 2D float64 vector type T and functions.
Package vec2 contains a 2D float64 vector type T and functions.
vec3
Package vec3 contains a 3D float64 vector type T and functions.
Package vec3 contains a 3D float64 vector type T and functions.
vec4
Package vec4 contains a 4 float64 components vector type T and functions.
Package vec4 contains a 4 float64 components vector type T and functions.
float32 math package.
float32 math package.
Package generic contains an interface T that that all float32 vector and matrix types implement.
Package generic contains an interface T that that all float32 vector and matrix types implement.
Package hermit2 contains a float32 type T and functions for 2D cubic hermit splines.
Package hermit2 contains a float32 type T and functions for 2D cubic hermit splines.
Package hermit3 contains a float32 type T and functions for 3D cubic hermit splines.
Package hermit3 contains a float32 type T and functions for 3D cubic hermit splines.
Package mat2 contains a 2x2 float32 matrix type T and functions.
Package mat2 contains a 2x2 float32 matrix type T and functions.
Package mat3 contains a 3x3 float32 matrix type T and functions.
Package mat3 contains a 3x3 float32 matrix type T and functions.
Package mat4 contains a 4x4 float32 matrix type T and functions.
Package mat4 contains a 4x4 float32 matrix type T and functions.
Package quaternion contains a float32 unit-quaternion type T and functions.
Package quaternion contains a float32 unit-quaternion type T and functions.
Package vec2 contains a 2D float32 vector type T and functions.
Package vec2 contains a 2D float32 vector type T and functions.
Package vec3 contains a 3D float32 vector type T and functions.
Package vec3 contains a 3D float32 vector type T and functions.
Package vec4 contains a 4 float32 components vector type T and functions.
Package vec4 contains a 4 float32 components vector type T and functions.

Jump to

Keyboard shortcuts

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