mathgl

package module
v0.0.0-haunted Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2025 License: BSD-2-Clause Imports: 2 Imported by: 0

README

Forked from github.com/MobRulesGames/mathgl@79bd4ce3042d23c2cb1ea06df739b527d6fca96f

MathGL is a simple 3D math library written in Go which should help writing
OpenGL code.

It is heavily influenced by the kazmath C library which you can find under:
http://www.kazade.co.uk/kazmath/

The library is tested to work under linux/amd64. Please feel free to submit
bugreports/issues/code at the following github page:
http://github.com/arbaal/mathgl

For documentation try: godoc -http=:6060

This library is released under the modified BSD license, which you can find in
the LICENSE file.

Documentation

Overview

MathGL is a simple 3D math library written in Go which should help writing OpenGL code.

MathGL is a simple 3D math library written in Go which should help writing OpenGL code.

Index

Constants

View Source
const (
	PI         float32 = 3.14159265358979323846264338327950288419716939937510582097494459
	PIover180  float32 = 0.017453292519943295
	PIunder180 float32 = 57.29577951308232
)

Some constants which are often used

Variables

This section is empty.

Functions

func Fabs32

func Fabs32(f float32) float32

Returns the absolute value from a float

func FalmostEqual32

func FalmostEqual32(lhs float32, rhs float32) bool

Returns true if two float32 are almost the same (the threshold is epsilon = 1/64).

func Fcos32

func Fcos32(x float32) float32

Returns the cos of a given float32 radiant

func Fdeg2rad32

func Fdeg2rad32(degrees float32) float32

Returns the radius value from a given degree value given in float32.

func Fmax32

func Fmax32(lhs float32, rhs float32) float32

Returns biggest value of two given float32 values.

func Fmin32

func Fmin32(lhs float32, rhs float32) float32

Returns the smallest value of two given float32 values.

func Frad2deg32

func Frad2deg32(radians float32) float32

Returns the degrees value from a given radius value given in float32.

func Fsin32

func Fsin32(x float32) float32

Returns the sin of a given float32 radiant

func Fsqr32

func Fsqr32(s float32) float32

The Square of a given float32.

func Fsqrt32

func Fsqrt32(x float32) float32

Types

type Mat3

type Mat3 [9]float32

3x3 Matrix type. Column major.

func (*Mat3) Adjugate

func (m *Mat3) Adjugate()

Adjugates the matrix.

func (*Mat3) AreEqual

func (m *Mat3) AreEqual(candidate *Mat3) bool

Returns true if the 2 matrices are equal (approximately)

func (*Mat3) Assign

func (m *Mat3) Assign(input *Mat3)

Assigns the values of the input matrix

func (*Mat3) Determinant

func (m *Mat3) Determinant() float32

Returns the calculated determinant from the matrix as float32.

func (*Mat3) Fill

func (m *Mat3) Fill(content float32)

Fills the matrix with the given float32.

func (*Mat3) Identity

func (m *Mat3) Identity()

Sets the matrix to a 3x3 identity matrix.

func (*Mat3) Inverse

func (m *Mat3) Inverse() bool

Inverse the matrix. Returns true if the inverse could be build.

func (*Mat3) IsIdentity

func (m *Mat3) IsIdentity() bool

Returns true if the matrix is a identity matrix.

func (*Mat3) Multiply

func (m *Mat3) Multiply(in *Mat3)

Multiplies the matrix with a given Mat3 matrix

func (*Mat3) RotationAxisAngle

func (m *Mat3) RotationAxisAngle(axis Vec3, radians float32)

Sets the matrix to a matrix that rotates with the help of the given vector Vec3 and angle float32

func (*Mat3) RotationX

func (m *Mat3) RotationX(radians float32)

Set the matrix to a matrix that rotates around the x-axis

func (*Mat3) RotationY

func (m *Mat3) RotationY(radians float32)

Set the matrix to a matrix that rotates around the y-axis

func (*Mat3) RotationZ

func (m *Mat3) RotationZ(radians float32)

Set the matrix to a matrix that rotates around the z-axis

func (*Mat3) ScalarMultiply

func (m *Mat3) ScalarMultiply(factor float32)

Multiplies the matrix with a given scalar in float32.

func (*Mat3) Scaling

func (m *Mat3) Scaling(x, y float32)

Set the matrix to a scaling matrix, which scale with given x,y floats32

func (*Mat3) Translation

func (m *Mat3) Translation(x, y float32)

Set the matrix to a translation matrix, which translates with given x,y floats32

func (*Mat3) Transpose

func (m *Mat3) Transpose()

Transpose the matrix

type Mat4

type Mat4 [16]float32

4x4 Matrix type. Column major.

func (*Mat4) AreEqual

func (m *Mat4) AreEqual(candidate *Mat4) bool

Returns true if the 2 matrices are equal (approximately)

func (*Mat4) Assign

func (m *Mat4) Assign(input *Mat4)

Assigns the values of the input matrix

func (*Mat4) Determinant

func (m *Mat4) Determinant() float32

Returns the calculated determinant from the matrix as float32.

func (*Mat4) ExtractRotation

func (m *Mat4) ExtractRotation() *Mat3

Extract a 3x3 rotation matrix from the input 4x4 transformation.

func (*Mat4) Fill

func (m *Mat4) Fill(content float32)

Fills the matrix with the given float32.

func (*Mat4) GetForwardVec3

func (m *Mat4) GetForwardVec3() *Vec3

Get the forward vector from a 4x4 matrix.

func (*Mat4) GetRightVec3

func (m *Mat4) GetRightVec3() *Vec3

Get the right vector from a 4x4 matrix.

func (*Mat4) GetUpVec3

func (m *Mat4) GetUpVec3() *Vec3

Get the up vector from a 4x4 matrix.

func (*Mat4) Identity

func (m *Mat4) Identity()

Sets the matrix to a 3x3 identity matrix.

func (*Mat4) Inverse

func (m *Mat4) Inverse() bool

Inverse the matrix with the given determinant in float32. Returns true if the inverse could be build.

func (*Mat4) IsIdentity

func (m *Mat4) IsIdentity() bool

Returns true if the matrix is a identity matrix.

func (*Mat4) Multiply

func (m *Mat4) Multiply(in *Mat4)

Multiplies the matrix with a given Mat4 matrix

func (*Mat4) RotationAxisAngle

func (m *Mat4) RotationAxisAngle(axis Vec3, radians float32)

Sets the matrix to a matrix that rotates with the help of the given vector Vec3 and angle float32

func (*Mat4) RotationPitchYawRoll

func (m *Mat4) RotationPitchYawRoll(pitch, yaw, roll float32)

Sets the matrix to a rotation matrix from pitch, yaw and roll.

func (*Mat4) RotationTranslation

func (m *Mat4) RotationTranslation(rotation *Mat3, translation *Vec3)

Sets the matrix to a transformation matrix using a 3x3 rotation matrix and a 3d vector representing a translation.

func (*Mat4) RotationX

func (m *Mat4) RotationX(radians float32)

Set the matrix to a matrix that rotates around the x-axis

func (*Mat4) RotationY

func (m *Mat4) RotationY(radians float32)

Set the matrix to a matrix that rotates around the y-axis

func (*Mat4) RotationZ

func (m *Mat4) RotationZ(radians float32)

Set the matrix to a matrix that rotates around the z-axis

func (*Mat4) ScalarMultiply

func (m *Mat4) ScalarMultiply(factor float32)

Multiplies the matrix with a given scalar in float32.

func (*Mat4) Scaling

func (m *Mat4) Scaling(x, y, z float32)

Set the matrix to a scaling matrix, which scale with given x,y floats32

func (*Mat4) Translation

func (m *Mat4) Translation(x, y, z float32)

Set the matrix to a translation matrix, which translates with given x,y floats32

func (*Mat4) Transpose

func (m *Mat4) Transpose()

Transpose the matrix

type Plane

type Plane struct {
	A, B, C, D float32
}

type PlaneEnum

type PlaneEnum int
const (
	PLANE_LEFT PlaneEnum = iota
	PLANE_RIGHT
	PLANE_BOTTOM
	PLANE_TOP
	PLANE_NEAR
	PLANE_FAR
)

type PointClassificationEnum

type PointClassificationEnum int
const (
	POINT_INFRONT_OF_PLANE PointClassificationEnum = iota
	POINT_BEHIND_PLANE
	POINT_ON_PLANE
)

type Poly

type Poly []Vec2

Polys need to be defined in clock-wise order

func (*Poly) Clip

func (p *Poly) Clip(s *Seg2)

type Seg2

type Seg2 struct {
	A, B Vec2
}

func (Seg2) DistFromOrigin

func (a Seg2) DistFromOrigin() float32

func (Seg2) Isect

func (u Seg2) Isect(v *Seg2) Vec2

Returns a Vec2 indicating the intersection point of the lines passing through segments a and b

func (Seg2) Left

func (a Seg2) Left(u *Vec2) bool

Returns true iff u lies to the left of a

func (Seg2) Ray

func (a Seg2) Ray() Vec2

func (Seg2) Right

func (a Seg2) Right(u *Vec2) bool

Returns true iff u lies to the left of a

type Vec2

type Vec2 struct {
	X, Y float32
}

2 dimensional vector.

func (*Vec2) Add

func (v *Vec2) Add(x *Vec2)

Adds the given Vec2 with the vector

func (*Vec2) AreEqual

func (v *Vec2) AreEqual(x *Vec2) bool

Returns true if the vectors are approximately equal in value

func (*Vec2) Assign

func (v *Vec2) Assign(x *Vec2)

Assigns the given Vec2 to the Vec2

func (*Vec2) Cross

func (v *Vec2) Cross()

func (*Vec2) Dot

func (v *Vec2) Dot(x *Vec2) float32

Returns the cosine of the angle between the vectors as float32

func (*Vec2) Fill

func (v *Vec2) Fill(x, y float32)

Fills the vector with the given float32

func (*Vec2) Length

func (v *Vec2) Length() float32

Returns the length as float32

func (*Vec2) LengthSq

func (v *Vec2) LengthSq() float32

Returns the length as square as float32

func (*Vec2) Normalize

func (v *Vec2) Normalize()

Normalize the vector

func (*Vec2) Scale

func (v *Vec2) Scale(s float32)

Scales the vector with the given float32.

func (*Vec2) String

func (v *Vec2) String() string

func (*Vec2) Subtract

func (v *Vec2) Subtract(x *Vec2)

Subtracts the given Vec2 from the vector

func (*Vec2) Transform

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

Transforms the Vec2 by a given Mat3

func (*Vec2) Zero

func (v *Vec2) Zero()

Sets all the elements of Vec2 to zero.

type Vec3

type Vec3 struct {
	X, Y, Z float32
}

2 dimensional vector.

func (*Vec3) Add

func (v *Vec3) Add(x *Vec3)

Adds the given Vec3 with the vector

func (*Vec3) AreEqual

func (v *Vec3) AreEqual(x *Vec3) bool

Returns true if the vectors are approximately equal in value

func (*Vec3) Assign

func (v *Vec3) Assign(x *Vec3)

Assigns the given Vec3 to the Vec3

func (*Vec3) Cross

func (v *Vec3) Cross(x *Vec3)

Saves the Vec3 perpendicular to the given Vec3

func (*Vec3) Dot

func (v *Vec3) Dot(x *Vec3) float32

Returns the cosine of the angle between the vectors as float32

func (*Vec3) Fill

func (v *Vec3) Fill(x, y, z float32)

Fills the vector with the given float32

func (*Vec3) InverseTransform

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

Transforms the Vec3 by a given Mat4 inversely

func (*Vec3) InverseTransformNormal

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

Transforms a normal Vec3 with the given Mat4 matrix inversely. Omits the translation, only scaling + rotating

func (*Vec3) Length

func (v *Vec3) Length() float32

Returns the length as float32

func (*Vec3) LengthSq

func (v *Vec3) LengthSq() float32

Returns the length as square as float32

func (*Vec3) Normalize

func (v *Vec3) Normalize()

Normalize the vector

func (*Vec3) Scale

func (v *Vec3) Scale(s float32)

Scales a vector to the given length s in float32.

func (*Vec3) String

func (v *Vec3) String() string

func (*Vec3) Subtract

func (v *Vec3) Subtract(x *Vec3)

Subtracts the given Vec3 from the vector

func (*Vec3) Transform

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

Transforms the Vec3 by a given Mat4

func (*Vec3) TransformArray

func (v *Vec3) TransformArray(x []Vec4, m *Mat4)

/ Loops through an input slice transforming each Vec4 by the given Mat3

func (*Vec3) TransformCoord

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

Transform a texture Vec3 with the given Mat4 matrix

func (*Vec3) TransformNormal

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

Transform a normal Vec3 with the given Mat4 matrix. Omits the translation, only scaling + rotating

func (*Vec3) Zero

func (v *Vec3) Zero()

Sets all the elements of Vec3 to zero

type Vec4

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

4 dimensional vector.

func (*Vec4) Add

func (v *Vec4) Add(x *Vec4)

Adds the given Vec4 with the vector

func (*Vec4) AreEqual

func (v *Vec4) AreEqual(x *Vec4) bool

Returns true if the vectors are approximately equal in value

func (*Vec4) Assign

func (v *Vec4) Assign(x *Vec4)

Assigns the given Vec4 to the Vec4

func (*Vec4) Cross

func (v *Vec4) Cross(x *Vec4)

Saves the Vec4 perpendicular to the given Vec4 (Attention: This is a Vec3 Cross Product in a homogeneous 4D environment!)

func (*Vec4) Dot

func (v *Vec4) Dot(x *Vec4) float32

Returns the cosine of the angle between the vectors as float32

func (*Vec4) Fill

func (v *Vec4) Fill(x, y, z, w float32)

Fills the vector with the given float32

func (*Vec4) Length

func (v *Vec4) Length() float32

Returns the length as float32

func (*Vec4) LengthSq

func (v *Vec4) LengthSq() float32

Returns the length as square as float32

func (*Vec4) Normalize

func (v *Vec4) Normalize()

Normalize the vector

func (*Vec4) Scale

func (v *Vec4) Scale(s float32)

Scales a vector to the given length s in float32.

func (*Vec4) String

func (v *Vec4) String() string

func (*Vec4) Subtract

func (v *Vec4) Subtract(x *Vec4)

Subtracts the given Vec4 from the vector

func (*Vec4) Transform

func (v *Vec4) Transform(m *Mat4)

Transforms the Vec4 by a given Mat4

func (*Vec4) Zero

func (v *Vec4) Zero()

Sets all the elements of Vec4 to zero

Jump to

Keyboard shortcuts

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