glm

package
v0.0.0-...-878157d Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: MIT Imports: 4 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	White = RGBA{1, 1, 1, 1}
	Black = RGBA{0, 0, 0, 1}
)

Functions

func Angle

func Angle(a, b Vec2) float64

Finds the angle between two vectors

func Clamp

func Clamp[T cmp.Ordered](low, high, val T) T

Types

type Box

type Box struct {
	Min, Max Vec3
}

func (Box) Apply

func (b Box) Apply(mat Mat4) Box

TODO: This is the wrong input matrix type

func (Box) Rect

func (b Box) Rect() Rect

func (Box) Union

func (a Box) Union(b Box) Box

type IVec2

type IVec2 struct {
	X, Y int
}

func (IVec2) Add

func (v IVec2) Add(v2 IVec2) IVec2

func (IVec2) Sub

func (v IVec2) Sub(v2 IVec2) IVec2

type Line2

type Line2 struct {
	A, B Vec2
}

func (Line2) Intersects

func (l1 Line2) Intersects(l2 Line2) bool

Returns true if the two lines intersect

type Mat2

type Mat2 [4]float64

type Mat3

type Mat3 [9]float64
var Mat3Ident Mat3 = Mat3{
	1.0, 0.0, 0.0,
	0.0, 1.0, 0.0,
	0.0, 0.0, 1.0,
}

This is in column major order

func (*Mat3) Apply

func (m *Mat3) Apply(v Vec2) Vec2

func (*Mat3) Translate

func (m *Mat3) Translate(x, y float64) *Mat3

type Mat4

type Mat4 [16]float64
var Mat4Ident Mat4 = Mat4{
	1.0, 0.0, 0.0, 0.0,
	0.0, 1.0, 0.0, 0.0,
	0.0, 0.0, 1.0, 0.0,
	0.0, 0.0, 0.0, 1.0,
}

This is in column major order

func IM4

func IM4() *Mat4

func (*Mat4) Apply

func (m *Mat4) Apply(v Vec3) Vec3

func (*Mat4) GetTranslation

func (m *Mat4) GetTranslation() Vec3

func (*Mat4) Inv

func (m *Mat4) Inv() *Mat4

Note: Returns a new Mat4

func (*Mat4) Mul

func (m *Mat4) Mul(n *Mat4) *Mat4

Note: This modifies in place

func (*Mat4) Rotate

func (m *Mat4) Rotate(angle float64, axis Vec3) *Mat4

func (*Mat4) RotateQuat

func (m *Mat4) RotateQuat(quat Quat) *Mat4

func (*Mat4) RotateZ

func (m *Mat4) RotateZ(angle float64) *Mat4

Rotate around the Z axis

func (*Mat4) Scale

func (m *Mat4) Scale(x, y, z float64) *Mat4

Note: Scales around 0,0

func (*Mat4) Translate

func (m *Mat4) Translate(x, y, z float64) *Mat4

func (*Mat4) Transpose

func (m *Mat4) Transpose() *Mat4

type Quat

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

func IQuat

func IQuat() Quat

func QuatRotate

func QuatRotate(angle float64, axis Vec3) Quat

func QuatZ

func QuatZ(angle float64) Quat

func (*Quat) Equals

func (q *Quat) Equals(q2 Quat) bool

func (*Quat) Mat4

func (q *Quat) Mat4() Mat4

func (*Quat) Rotate

func (q *Quat) Rotate(angle float64, axis Vec3) *Quat

func (*Quat) RotateQuat

func (q *Quat) RotateQuat(rQuat Quat) *Quat

func (*Quat) RotateX

func (q *Quat) RotateX(angle float64) *Quat

func (*Quat) RotateY

func (q *Quat) RotateY(angle float64) *Quat

func (*Quat) RotateZ

func (q *Quat) RotateZ(angle float64) *Quat

type RGBA

type RGBA struct {
	R, G, B, A float64
}

Premultipled RGBA value scaled from [0, 1.0]

func Alpha

func Alpha(a float64) RGBA

func FromColor

func FromColor(c color.Color) RGBA

func FromNRGBA

func FromNRGBA(c color.NRGBA) RGBA

func FromRGBA

func FromRGBA(c color.RGBA) RGBA

func FromStraightRGBA

func FromStraightRGBA(r, g, b float64, a float64) RGBA

func FromUint8

func FromUint8(r, g, b, a uint8) RGBA

TODO - conversion from golang colors

func Greyscale

func Greyscale(g float64) RGBA

func HexColor

func HexColor(col uint64, alpha uint8) RGBA

func (RGBA) Add

func (c1 RGBA) Add(c2 RGBA) RGBA

func (RGBA) Desaturate

func (c RGBA) Desaturate(val float64) RGBA

func (RGBA) Mult

func (c1 RGBA) Mult(c2 RGBA) RGBA

type Rect

type Rect struct {
	Min, Max Vec2
}

func CR

func CR(radius float64) Rect

Creates a centered rect

func R

func R(minX, minY, maxX, maxY float64) Rect

func (Rect) Anchor

func (r Rect) Anchor(r2 Rect, anchor Vec2) Rect

Takes r2 and places it in r based on the alignment TODO - rename to InnerAnchor?

func (Rect) BR

func (r Rect) BR() Vec2

Returns the bottom right point

func (Rect) BottomHalf

func (r Rect) BottomHalf() Rect

Returns the bottom half of the rectangle. Doesn't modify the original rectangle

func (Rect) Box

func (r Rect) Box() Box

Returns a box that holds this rect. The Z axis is 0

func (Rect) Center

func (r Rect) Center() Vec2

func (Rect) CenterScaled

func (r Rect) CenterScaled(scale float64) Rect

func (Rect) CenterScaledXY

func (r Rect) CenterScaledXY(scaleX, scaleY float64) Rect

func (Rect) Contains

func (r Rect) Contains(pos Vec2) bool

Returns true if the point is inside (not on the edge of) the rect

func (*Rect) CutBottom

func (r *Rect) CutBottom(amount float64) Rect

func (*Rect) CutLeft

func (r *Rect) CutLeft(amount float64) Rect

func (*Rect) CutRight

func (r *Rect) CutRight(amount float64) Rect

func (*Rect) CutTop

func (r *Rect) CutTop(amount float64) Rect

func (Rect) Fit

func (r Rect) Fit(r2 Rect) Rect

Fits rect 'r' into another rect 'r2' with same center

func (Rect) FitInt

func (r Rect) FitInt(r2 Rect) Rect

Fits rect 'r' into another rect 'r2' with same center but only integer scaled

func (Rect) FitScale

func (r Rect) FitScale(r2 Rect) float64

Calculates the scale required to fit rect r inside r2

func (Rect) FullAnchor

func (r Rect) FullAnchor(r2 Rect, anchor, pivot Vec2) Rect

Anchors r2 to r1 based on two anchors, one for r and one for r2 TODO - rename to Anchor?

func (Rect) H

func (r Rect) H() float64

func (Rect) Intersects

func (r Rect) Intersects(r2 Rect) bool

func (Rect) LayoutHorizontal

func (r Rect) LayoutHorizontal(n int, padding float64) Rect

Layous out 'n' rectangles horizontally with specified padding between them and returns that rect The returned rectangle has a min point of 0,0

func (Rect) LeftHalf

func (r Rect) LeftHalf() Rect

Returns the left half of the rectangle. Doesn't modify the original rectangle

func (Rect) MoveMin

func (r Rect) MoveMin(pos Vec2) Rect

Move the min point of the rect to a certain position

func (Rect) Moved

func (r Rect) Moved(v Vec2) Rect

func (Rect) Norm

func (r Rect) Norm() Rect

func (Rect) OverlapsPoint

func (r Rect) OverlapsPoint(pos Vec3) bool

Returns true if the point is inside or on the edge of the rect

func (Rect) Pad

func (r Rect) Pad(pad Rect) Rect

Adds padding to a rectangle (pads inward if padding is negative)

func (Rect) PadAll

func (r Rect) PadAll(padding float64) Rect

Adds padding to a rectangle consistently on every edge

func (Rect) PadBottom

func (r Rect) PadBottom(padding float64) Rect

Adds padding to the bottom side of a rectangle

func (Rect) PadLeft

func (r Rect) PadLeft(padding float64) Rect

Adds padding to the left side of a rectangle

func (Rect) PadRight

func (r Rect) PadRight(padding float64) Rect

Adds padding to the right side of a rectangle

func (Rect) PadTop

func (r Rect) PadTop(padding float64) Rect

Adds padding to the top side of a rectangle

func (Rect) PadX

func (r Rect) PadX(padding float64) Rect

Adds padding to a rectangle on the X axis

func (Rect) PadY

func (r Rect) PadY(padding float64) Rect

Adds padding to a rectangle on the Y Axis

func (Rect) Point

func (r Rect) Point(x, y float64) Vec2

func (Rect) RectDraw

func (r Rect) RectDraw(r2 Rect) Mat4

func (Rect) RightHalf

func (r Rect) RightHalf() Rect

Returns the right half of the rectangle. Doesn't modify the original rectangle

func (Rect) Scaled

func (r Rect) Scaled(scale float64) Rect

TODO: I need to deprecate this. This currently just indepentently scales the min and max point which is only useful if the center, min, or max is on (0, 0)

func (Rect) ScaledToFit

func (r Rect) ScaledToFit(r2 Rect) Rect

Scales rect r uniformly to fit inside rect r2 TODO This only scales around {0, 0}

func (Rect) ScaledXY

func (r Rect) ScaledXY(scale Vec2) Rect

func (Rect) Size

func (r Rect) Size() Vec2

func (Rect) SliceHorizontal

func (r Rect) SliceHorizontal(amount float64) Rect

Returns a centered horizontal sliver with height set by amount

func (Rect) SliceSquare

func (r Rect) SliceSquare(amount float64) Rect

Returns a centered square with height and width set by amount

func (Rect) SliceVertical

func (r Rect) SliceVertical(amount float64) Rect

Returns a centered vertical sliver with width set by amount

func (Rect) Snap

func (r Rect) Snap() Rect

func (Rect) SubSquare

func (r Rect) SubSquare() Rect

Returns the largest square that fits inside the rectangle

func (Rect) TL

func (r Rect) TL() Vec2

Returns the top left point

func (Rect) ToBox

func (r Rect) ToBox() Box

func (Rect) TopHalf

func (r Rect) TopHalf() Rect

Returns the top half of the rectangle. Doesn't modify the original rectangle

func (Rect) Union

func (r Rect) Union(s Rect) Rect

TODO: Should I make a pointer version of this that handles the nil case too? Returns the smallest rect which contains both input rects

func (Rect) Unpad

func (r Rect) Unpad(pad Rect) Rect

Removes padding from a rectangle (pads outward if padding is negative). Essentially calls pad but with negative values

func (Rect) W

func (r Rect) W() float64

func (Rect) WithCenter

func (r Rect) WithCenter(v Vec2) Rect
func (r Rect) CenterAt(v Vec2) Rect {
	return r.Moved(r.Center().Scaled(-1)).Moved(v)
}

type Vec2

type Vec2 struct {
	X, Y float64
}

func V2

func V2(x, y float64) Vec2

func (Vec2) Add

func (v Vec2) Add(v2 Vec2) Vec2

func (Vec2) Angle

func (v Vec2) Angle() float64

func (Vec2) Dist

func (v Vec2) Dist(u Vec2) float64

func (Vec2) DistSq

func (v Vec2) DistSq(u Vec2) float64

func (Vec2) Dot

func (v Vec2) Dot(u Vec2) float64

func (Vec2) Len

func (v Vec2) Len() float64

Returns the length of the vector

func (Vec2) LenSq

func (v Vec2) LenSq() float64

Returns the length of the vector squared. Note this is slightly faster b/c it doesn't take the square root

func (Vec2) Mult

func (v Vec2) Mult(s Vec2) Vec2

func (Vec2) Norm

func (v Vec2) Norm() Vec2

func (Vec2) Rotated

func (v Vec2) Rotated(radians float64) Vec2

func (Vec2) Scaled

func (v Vec2) Scaled(s float64) Vec2

func (Vec2) ScaledXY

func (v Vec2) ScaledXY(s Vec2) Vec2

TODO: Same thing as mult

func (Vec2) Snap

func (v Vec2) Snap() Vec2

func (Vec2) Sub

func (v Vec2) Sub(v2 Vec2) Vec2

func (Vec2) Vec3

func (v Vec2) Vec3() Vec3

type Vec3

type Vec3 struct {
	X, Y, Z float64
}

func (Vec3) Add

func (v Vec3) Add(u Vec3) Vec3

func (Vec3) Angle

func (v Vec3) Angle(u Vec3) float64

Finds the angle between two vectors TODO: Is this correct?

func (Vec3) Dot

func (v Vec3) Dot(u Vec3) float64

Finds the dot product of two vectors

func (Vec3) Len

func (v Vec3) Len() float64

func (Vec3) Mult

func (v Vec3) Mult(s Vec3) Vec3

func (Vec3) Rotate2D

func (v Vec3) Rotate2D(theta float64) Vec3

Rotates the vector by theta on the XY 2d plane

func (Vec3) Scaled

func (v Vec3) Scaled(x, y, z float64) Vec3

func (Vec3) Sub

func (v Vec3) Sub(u Vec3) Vec3

func (Vec3) Theta

func (v Vec3) Theta() float64

func (Vec3) Unit

func (v Vec3) Unit() Vec3

func (Vec3) Vec2

func (v Vec3) Vec2() Vec2

type Vec4

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

Jump to

Keyboard shortcuts

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