Documentation
¶
Overview ¶
Package math3d provides 3D math primitives for the Trophy engine.
Index ¶
- type Mat4
- func Identity() Mat4
- func LookAt(eye, center, up Vec3) Mat4
- func Mat4FromSlice(s []float64) Mat4
- func Orthographic(left, right, bottom, top, near, far float64) Mat4
- func Perspective(fovy, aspect, near, far float64) Mat4
- func QuatToMat4(x, y, z, w float64) Mat4
- func Rotate(axis Vec3, angle float64) Mat4
- func RotateX(angle float64) Mat4
- func RotateY(angle float64) Mat4
- func RotateZ(angle float64) Mat4
- func Scale(v Vec3) Mat4
- func ScaleUniform(s float64) Mat4
- func Translate(v Vec3) Mat4
- func (m Mat4) Determinant() float64
- func (m Mat4) Get(row, col int) float64
- func (m Mat4) Inverse() Mat4
- func (m Mat4) Mul(b Mat4) Mat4
- func (m Mat4) MulVec3(v Vec3) Vec3
- func (m Mat4) MulVec3Dir(v Vec3) Vec3
- func (m Mat4) MulVec4(v Vec4) Vec4
- func (m *Mat4) Set(row, col int, val float64)
- func (m *Mat4) SetTranslation(v Vec3)
- func (m Mat4) Translation() Vec3
- func (m Mat4) Transpose() Mat4
- type Vec2
- func (a Vec2) Add(b Vec2) Vec2
- func (a Vec2) Angle() float64
- func (a Vec2) AngleTo(b Vec2) float64
- func (a Vec2) Distance(b Vec2) float64
- func (a Vec2) Dot(b Vec2) float64
- func (a Vec2) Len() float64
- func (a Vec2) LenSq() float64
- func (a Vec2) Lerp(b Vec2, t float64) Vec2
- func (a Vec2) Mul(b Vec2) Vec2
- func (a Vec2) Negate() Vec2
- func (a Vec2) Normalize() Vec2
- func (a Vec2) Perpendicular() Vec2
- func (a Vec2) Rotate(angle float64) Vec2
- func (a Vec2) Scale(s float64) Vec2
- func (a Vec2) Sub(b Vec2) Vec2
- type Vec3
- func (a Vec3) Abs() Vec3
- func (a Vec3) Add(b Vec3) Vec3
- func (a Vec3) Ceil() Vec3
- func (a Vec3) Cross(b Vec3) Vec3
- func (a Vec3) Distance(b Vec3) float64
- func (a Vec3) Div(s float64) Vec3
- func (a Vec3) Dot(b Vec3) float64
- func (a Vec3) Floor() Vec3
- func (a Vec3) Len() float64
- func (a Vec3) LenSq() float64
- func (a Vec3) Lerp(b Vec3, t float64) Vec3
- func (a Vec3) Max(b Vec3) Vec3
- func (a Vec3) Min(b Vec3) Vec3
- func (a Vec3) Mul(b Vec3) Vec3
- func (a Vec3) Negate() Vec3
- func (a Vec3) Normalize() Vec3
- func (a Vec3) Reflect(n Vec3) Vec3
- func (a Vec3) Scale(s float64) Vec3
- func (a Vec3) Sub(b Vec3) Vec3
- type Vec4
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Mat4 ¶
type Mat4 [16]float64
Mat4 is a 4x4 matrix stored in column-major order. This matches OpenGL conventions for easier reasoning about transforms.
Memory layout (indices): | 0 4 8 12 | | 1 5 9 13 | | 2 6 10 14 | | 3 7 11 15 |
For a transform matrix: | Xx Yx Zx Tx | X,Y,Z = basis vectors (rotation/scale) | Xy Yy Zy Ty | T = translation | Xz Yz Zz Tz | | 0 0 0 1 |.
func Mat4FromSlice ¶
Mat4FromSlice creates a Mat4 from a slice of 16 floats (column-major order).
func Orthographic ¶
Orthographic creates an orthographic projection matrix.
func Perspective ¶
Perspective creates a perspective projection matrix. fovy is vertical field of view in radians. aspect is width/height. near and far are clipping planes.
func QuatToMat4 ¶
QuatToMat4 converts a quaternion (x, y, z, w) to a rotation matrix. The quaternion is expected in GLTF format: (x, y, z, w) where w is the scalar.
func ScaleUniform ¶
ScaleUniform creates a uniform scaling matrix.
func (Mat4) Determinant ¶
Determinant returns the determinant of the matrix.
func (Mat4) Inverse ¶
Inverse returns the inverse of the matrix. Returns identity if the matrix is singular (det=0).
func (Mat4) MulVec3Dir ¶
MulVec3Dir transforms a Vec3 as a direction (w=0, no translation).
func (*Mat4) SetTranslation ¶
SetTranslation sets the translation component.
func (Mat4) Translation ¶
Translation extracts the translation component.
type Vec2 ¶
type Vec2 struct {
X, Y float64
}
Vec2 represents a 2D vector.
func (Vec2) Perpendicular ¶
Perpendicular returns a perpendicular vector (90° counter-clockwise).
type Vec3 ¶
type Vec3 struct {
X, Y, Z float64
}
Vec3 represents a 3D vector.