primitives

package
v0.0.0-...-296174e Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToHex

func ToHex(color color.Color, l float64) uint32

Types

type Image

type Image struct {
	Data image.Image
}

func LoadImage

func LoadImage(path string) *Image

func (*Image) GetPixel

func (img *Image) GetPixel(u, v, l float64) uint32

type Matrix4x4

type Matrix4x4 struct {
	M [4][4]float64
}

func IdentityMatrix

func IdentityMatrix() *Matrix4x4

func PointAtMatrix

func PointAtMatrix(pos, target, up *Vector3d) *Matrix4x4

func ProjectionMatrix

func ProjectionMatrix(aspectRatio, fNear, fFar float64, fov float64) *Matrix4x4

func TranslationMatrix

func TranslationMatrix(v *Vector3d) *Matrix4x4

func XRotationMatrix

func XRotationMatrix(angle float64) *Matrix4x4

func YRotationMatrix

func YRotationMatrix(angle float64) *Matrix4x4

func ZRotationMatrix

func ZRotationMatrix(angle float64) *Matrix4x4

func (Matrix4x4) Inverse

func (m Matrix4x4) Inverse() *Matrix4x4

func (*Matrix4x4) MulM

func (m1 *Matrix4x4) MulM(m2 *Matrix4x4) *Matrix4x4

func (*Matrix4x4) MulV

func (m *Matrix4x4) MulV(v *Vector3d) *Vector3d

func (*Matrix4x4) Print

func (m *Matrix4x4) Print()

type Mesh

type Mesh struct {
	Tris    []*Triangle
	Texture *Image
}

type Plane

type Plane struct {
	P *Vector3d
	N *Vector3d
}

func NewPlane

func NewPlane(p, n *Vector3d) *Plane

func (*Plane) Clip

func (plane *Plane) Clip(tri *Triangle) []*Triangle

func (*Plane) Dist

func (plane *Plane) Dist(p *Vector3d) float64

func (*Plane) Intersection

func (p *Plane) Intersection(lineStart, lineEnd *Vector3d) (*Vector3d, float64)

type Triangle

type Triangle struct {
	P         [3]*Vector3d
	T         [3]*Vector2d
	Color     color.Color
	Texture   *Image
	Luminance float64
}

func EmptyTriangle

func EmptyTriangle() *Triangle

func NewTriangle

func NewTriangle(x1, y1, z1, x2, y2, z2, x3, y3, z3, tx1, ty1, tx2, ty2, tx3, ty3 float64) *Triangle

func (*Triangle) Normal

func (t *Triangle) Normal() *Vector3d

func (*Triangle) Print

func (t *Triangle) Print()

type Vector

type Vector interface {
	Negative() Vector
	Add(v2 Vector) Vector
	Sub(v2 Vector) Vector
	DotProduct(v2 Vector) float64
	CrossProduct(v2 Vector) Vector
	Mul(k float64) Vector
	Div(k float64) Vector
	Length() float64
	Normalize() Vector
}

type Vector2d

type Vector2d struct {
	U, V, W float64
}

func NewVector2d

func NewVector2d(u, v float64) *Vector2d

func (*Vector2d) Add

func (v1 *Vector2d) Add(v2 *Vector2d) *Vector2d

func (*Vector2d) Copy

func (v1 *Vector2d) Copy() *Vector2d

func (*Vector2d) Div

func (v1 *Vector2d) Div(k float64) *Vector2d

func (*Vector2d) Mul

func (v1 *Vector2d) Mul(k float64) *Vector2d

func (*Vector2d) Sub

func (v1 *Vector2d) Sub(v2 *Vector2d) *Vector2d

type Vector3d

type Vector3d struct {
	X, Y, Z, W float64
}

func NewVector3d

func NewVector3d(x, y, z float64) *Vector3d

func (*Vector3d) Add

func (v1 *Vector3d) Add(v2 *Vector3d) *Vector3d

func (*Vector3d) CrossProduct

func (v1 *Vector3d) CrossProduct(v2 *Vector3d) *Vector3d

func (*Vector3d) Div

func (v *Vector3d) Div(k float64) *Vector3d

func (*Vector3d) DotProduct

func (v1 *Vector3d) DotProduct(v2 *Vector3d) float64

func (*Vector3d) Length

func (v *Vector3d) Length() float64

func (*Vector3d) Mul

func (v *Vector3d) Mul(k float64) *Vector3d

func (*Vector3d) Negative

func (v1 *Vector3d) Negative() *Vector3d

func (*Vector3d) Normalize

func (v *Vector3d) Normalize() *Vector3d

func (*Vector3d) Print

func (v1 *Vector3d) Print()

func (*Vector3d) Sub

func (v1 *Vector3d) Sub(v2 *Vector3d) *Vector3d

Jump to

Keyboard shortcuts

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