goengine

package module
v0.0.0-...-c2e5bb3 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DegToRadFactor is the number of radians per degree.
	DegToRadFactor = math32.Pi / 180

	// RadToDegFactor is the number of degrees per radian.
	RadToDegFactor = 180 / math32.Pi
)
View Source
const VERTSIZE = 9

Variables

View Source
var Infinity = float32(math32.Inf(1))

Infinity is positive infinity.

Functions

func ActiveTexture

func ActiveTexture(texID uint32, uniformId string, program uint32, texActive uint32) int32

func Clamp

func Clamp(x, a, b float32) float32

Clamp clamps x to the provided closed interval [a, b]

func ColToFloats

func ColToFloats(col uint32) []float32

func CreateLathe

func CreateLathe(lpath []Vec2, inverted, startAngle, endAngle, rise float32, edges, uvtype uint32, pos Vec3) []float32

func CreateShaderProgram

func CreateShaderProgram(vertexShader, fragShader *Shader, attributes []string) (uint32, string)

func CreateVCone

func CreateVCone(radius, radius2, height float32, sides int) []float32

func DegToRad

func DegToRad(degrees float32) float32

DegToRad converts a number from degrees to radians

func DrawQuads

func DrawQuads(verts []float32)

func DrawSharedQuads

func DrawSharedQuads(verts []float32, edges int)

func Find

func Find(str, find string, index int) int

func GLVersion

func GLVersion() string

func GetAttributes

func GetAttributes(vertShaderSource string) ([]string, string)

func GetSetFloat

func GetSetFloat(program uint32, name *uint8, v float32) int32

func GetSetInt

func GetSetInt(program uint32, name *uint8, v int32) int32

func GetSetVec3

func GetSetVec3(program uint32, name *uint8, vec []float32) int32

func OpenTextFile

func OpenTextFile(path string) string

func RadToDeg

func RadToDeg(radians float32) float32

RadToDeg converts a number from radians to degrees

func SetFog

func SetFog(refs []int32, minDist, maxDist float32, colour []float32)

func SetRenderBuffer

func SetRenderBuffer(bufID uint32, stride int32)

func SetTexture

func SetTexture(uniformId string, program uint32, texLoc int32) int32

func Vec3toCol

func Vec3toCol(v *Vec3) uint32

func Vec3toFloats

func Vec3toFloats(v *Vec3) []float32

Types

type Mat4s

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

Mat4 is 4x4 matrix organized internally as column matrix.

func Identity4

func Identity4() *Mat4s

Identity4 returns a new identity [Mat4] matrix

func NewLookAt

func NewLookAt(eye, target, up Vec3) *Mat4s

NewLookAt returns Mat4 matrix as view transform matrix with origin at eye, looking at target and using the up vector.

func (*Mat4s) CopyFrom

func (m *Mat4s) CopyFrom(src *Mat4s)

CopyFrom copies from source matrix into this matrix (a regular = assign does not copy data, just the pointer!)

func (*Mat4s) CopyPos

func (m *Mat4s) CopyPos(src *Mat4s)

CopyPos copies the position elements of the src matrix into this one.

func (*Mat4s) Determinant

func (m *Mat4s) Determinant() float32

Determinant calculates and returns the determinat of this matrix.

func (*Mat4s) ExtractRotation

func (m *Mat4s) ExtractRotation(src *Mat4s)

ExtractRotation sets this matrix as rotation matrix from the src transformation matrix.

func (*Mat4s) FromArray

func (m *Mat4s) FromArray(array []float32, offset int)

FromArray set this matrix elements from the array starting at offset.

func (*Mat4s) GetMaxScaleOnAxis

func (m *Mat4s) GetMaxScaleOnAxis() float32

GetMaxScaleOnAxis returns the maximum scale value of the 3 axes.

func (*Mat4s) Inverse

func (m *Mat4s) Inverse() (*Mat4s, error)

Inverse returns the inverse of this matrix. If the matrix cannot be inverted returns error and sets this matrix to the identity matrix.

func (*Mat4s) LookAt

func (m *Mat4s) LookAt(eye, target, up Vec3)

LookAt sets this matrix as view transform matrix with origin at eye, looking at target and using the up vector.

func (*Mat4s) Mul

func (m *Mat4s) Mul(other *Mat4s) *Mat4s

Mul returns this matrix times other matrix (this matrix is unchanged)

func (*Mat4s) MulMatrices

func (m *Mat4s) MulMatrices(a, b *Mat4s)

MulMatrices sets this matrix as matrix multiplication a by b (i.e. b*a).

func (*Mat4s) MulScalar

func (m *Mat4s) MulScalar(s float32)

SetMulScalar multiplies each element of this matrix by the specified scalar.

func (*Mat4s) Pos

func (m *Mat4s) Pos() Vec3

Pos returns the position component of the matrix

func (*Mat4s) ScaleCols

func (m *Mat4s) ScaleCols(v Vec3) *Mat4s

ScaleCols returns matrix with first column of this matrix multiplied by the vector X component, the second column by the vector Y component and the third column by the vector Z component. The matrix fourth column is unchanged.

func (*Mat4s) Set

func (m *Mat4s) Set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 float32)

Set sets all the elements of this matrix row by row starting at row1, column1, row1, column2, row1, column3 and so forth.

func (*Mat4s) SetFrustum

func (m *Mat4s) SetFrustum(left, right, bottom, top, near, far float32)

SetFrustum sets this matrix to a projection frustum matrix bounded by the specified planes.

func (*Mat4s) SetIdentity

func (m *Mat4s) SetIdentity()

SetIdentity sets this matrix as the identity matrix.

func (*Mat4s) SetInverse

func (m *Mat4s) SetInverse(src *Mat4s) error

SetInverse sets this matrix to the inverse of the src matrix. If the src matrix cannot be inverted returns error and sets this matrix to the identity matrix.

func (*Mat4s) SetMul

func (m *Mat4s) SetMul(other *Mat4s)

SetMul sets this matrix to this matrix times other

func (*Mat4s) SetOrthographic

func (m *Mat4s) SetOrthographic(width, height, near, far float32)

SetOrthographic sets this matrix to an orthographic projection matrix.

func (*Mat4s) SetPerspective

func (m *Mat4s) SetPerspective(fov, aspect, near, far float32)

SetPerspective sets this matrix to a perspective projection matrix with the specified field of view in degrees, aspect ratio (width/height) and near and far planes.

func (*Mat4s) SetPos

func (m *Mat4s) SetPos(v Vec3)

SetPos sets this transformation matrix position fields from the specified vector v.

func (*Mat4s) SetRotationAxis

func (m *Mat4s) SetRotationAxis(axis *Vec3, angle float32)

SetRotationAxis sets this matrix to a rotation matrix of the specified angle around the specified axis.

func (*Mat4s) SetRotationFromEuler

func (m *Mat4s) SetRotationFromEuler(euler Vec3)

SetRotationFromEuler set this a matrix as a rotation matrix from the specified euler angles.

func (*Mat4s) SetRotationFromQuat

func (m *Mat4s) SetRotationFromQuat(q Quat)

SetRotationFromQuat sets this matrix as a rotation matrix from the specified quaternion.

func (*Mat4s) SetRotationX

func (m *Mat4s) SetRotationX(theta float32)

SetRotationX sets this matrix to a rotation matrix of angle theta around the X axis.

func (*Mat4s) SetRotationY

func (m *Mat4s) SetRotationY(theta float32)

SetRotationY sets this matrix to a rotation matrix of angle theta around the Y axis.

func (*Mat4s) SetRotationZ

func (m *Mat4s) SetRotationZ(theta float32)

SetRotationZ sets this matrix to a rotation matrix of angle theta around the Z axis.

func (*Mat4s) SetScale

func (m *Mat4s) SetScale(x, y, z float32)

SetScale sets this matrix to a scale transformation matrix using the specified x, y and z values.

func (*Mat4s) SetScaleCols

func (m *Mat4s) SetScaleCols(v Vec3)

SetScaleCols multiplies the first column of this matrix by the vector X component, the second column by the vector Y component and the third column by the vector Z component. The matrix fourth column is unchanged.

func (*Mat4s) SetTransform

func (m *Mat4s) SetTransform(pos Vec3, quat Quat, scale Vec3)

SetTransform sets this matrix to a transformation matrix for the specified position, rotation specified by the quaternion and scale.

func (*Mat4s) SetTranslation

func (m *Mat4s) SetTranslation(x, y, z float32)

SetTranslation sets this matrix to a translation matrix from the specified x, y and z values.

func (*Mat4s) SetTranspose

func (m *Mat4s) SetTranspose()

SetTranspose transposes this matrix.

func (*Mat4s) SetVkFrustum

func (m *Mat4s) SetVkFrustum(left, right, bottom, top, near, far float32)

SetVkFrustum sets this matrix to a projection frustum matrix bounded by the specified planes. This version is for use with Vulkan, and does the equivalent of GLM_DEPTH_ZERO_ONE in glm and also multiplies the Y axis by -1, preserving the original OpenGL Y-up system. OpenGL provides a "natural" coordinate system for the physical world so it is useful to retain that for the world system and just convert on the way out to the render using this projection matrix.

func (*Mat4s) SetVkPerspective

func (m *Mat4s) SetVkPerspective(fov, aspect, near, far float32)

SetVkPerspective sets this matrix to a vulkan appropriate perspective projection matrix, assuming the use of the OpenGL Y-up coordinate system for the geometry points. OpenGL provides a "natural" coordinate system for the physical world so it is useful to retain that for the world system and just convert on the way out to the render using this projection matrix. The specified field of view is in degrees, aspect ratio (width/height) and near and far planes.

func (*Mat4s) SetZero

func (m *Mat4s) SetZero()

SetZero sets this matrix as the zero matrix.

func (*Mat4s) ToArray

func (m *Mat4s) ToArray() []float32

Different from Goki ToArray - and with no offset

func (*Mat4s) Transpose

func (m *Mat4s) Transpose() *Mat4s

Transpose returns the transpose of this matrix.

type Mesh

type Mesh struct {
	Verts       []float32
	VC          uint32
	MaterialRef int
	Stride      int
	BufRef      int
	VertOffset  int
	VertSize    int
	Mode        int
}

func (*Mesh) AddPackedVert

func (m *Mesh) AddPackedVert(pos Vec3, normal Vec3, uv Vec2, col uint32)

func (*Mesh) Init

func (m *Mesh) Init()

func (*Mesh) Render

func (m *Mesh) Render()

func (*Mesh) RenderIndexed

func (m *Mesh) RenderIndexed(indexCo int32, indexes []*uint32)

func (*Mesh) RenderMesh

func (m *Mesh) RenderMesh()

func (*Mesh) TransformVerts

func (m *Mesh) TransformVerts(matrix *Mat4s)

type Mouse

type Mouse struct {
	X            int32
	Y            int32
	Z            int32
	LeftButton   bool
	RightButton  bool
	MiddleButton bool
}

func (Mouse) GetDelta

func (m Mouse) GetDelta(x, y int32) (int32, int32)

func (*Mouse) SetCoords

func (m *Mouse) SetCoords(x, y int32)

type Quat

type Quat struct {
	X float32
	Y float32
	Z float32
	W float32
}

Quat is quaternion with X,Y,Z and W components.

func NewQuat

func NewQuat(x, y, z, w float32) Quat

NewQuat returns a new quaternion from the specified components.

func NewQuatAxisAngle

func NewQuatAxisAngle(axis Vec3, angle float32) Quat

NewQuatAxisAngle returns a new quaternion from given axis and angle rotation (radians).

func NewQuatEuler

func NewQuatEuler(euler Vec3) Quat

NewQuatEuler returns a new quaternion from given Euler angles.

func (*Quat) Conjugate

func (q *Quat) Conjugate() Quat

Conjugate returns the conjugate of this quaternion.

func (*Quat) Dot

func (q *Quat) Dot(other Quat) float32

Dot returns the dot products of this quaternion with other.

func (*Quat) FromArray

func (q *Quat) FromArray(array []float32, offset int)

FromArray sets this quaternion's components from array starting at offset.

func (*Quat) GenGoNew

func (q *Quat) GenGoNew() string

GenGoNew returns code to create new

func (*Quat) GenGoSet

func (q *Quat) GenGoSet(path string) string

GenGoSet returns code to set values in object at given path (var.member etc)

func (*Quat) Inverse

func (q *Quat) Inverse() Quat

Inverse returns the inverse of this quaternion.

func (*Quat) IsEqual

func (q *Quat) IsEqual(other Quat) bool

IsEqual returns if this quaternion is equal to other.

func (*Quat) IsIdentity

func (q *Quat) IsIdentity() bool

IsIdentity returns if this is an identity quaternion.

func (*Quat) IsNil

func (q *Quat) IsNil() bool

IsNil returns true if all values are 0 (uninitialized).

func (Quat) Length

func (q Quat) Length() float32

Length returns the length of this quaternion

func (Quat) LengthSq

func (q Quat) LengthSq() float32

LengthSq returns this quanternion's length squared

func (*Quat) Mul

func (q *Quat) Mul(other Quat) Quat

Mul returns returns multiplication of this quaternion with other

func (*Quat) MulQuats

func (q *Quat) MulQuats(a, b Quat)

MulQuats set this quaternion to the multiplication of a by b.

func (*Quat) Normalize

func (q *Quat) Normalize()

Normalize normalizes this quaternion.

func (*Quat) NormalizeFast

func (q *Quat) NormalizeFast()

NormalizeFast approximates normalizing this quaternion. Works best when the quaternion is already almost-normalized.

func (*Quat) Set

func (q *Quat) Set(x, y, z, w float32)

Set sets this quaternion's components.

func (*Quat) SetConjugate

func (q *Quat) SetConjugate()

SetConjugate sets this quaternion to its conjugate.

func (*Quat) SetFromAxisAngle

func (q *Quat) SetFromAxisAngle(axis Vec3, angle float32)

SetFromAxisAngle sets this quaternion with the rotation specified by the given axis and angle.

func (*Quat) SetFromEuler

func (q *Quat) SetFromEuler(euler Vec3)

SetFromEuler sets this quaternion from the specified vector with Euler angles for each axis. It is assumed that the Euler angles are in XYZ order.

func (*Quat) SetFromRotationMatrix

func (q *Quat) SetFromRotationMatrix(m *Mat4s)

SetFromRotationMatrix sets this quaternion from the specified rotation matrix.

func (*Quat) SetFromUnitVectors

func (q *Quat) SetFromUnitVectors(vFrom, vTo Vec3)

SetFromUnitVectors sets this quaternion to the rotation from vector vFrom to vTo. The vectors must be normalized.

func (*Quat) SetIdentity

func (q *Quat) SetIdentity()

SetIdentity sets this quanternion to the identity quaternion.

func (*Quat) SetInverse

func (q *Quat) SetInverse()

SetInverse sets this quaternion to its inverse.

func (*Quat) SetMul

func (q *Quat) SetMul(other Quat)

SetMul sets this quaternion to the multiplication of itself by other.

func (*Quat) Slerp

func (q *Quat) Slerp(other Quat, t float32)

Slerp sets this quaternion to another quaternion which is the spherically linear interpolation from this quaternion to other using t.

func (Quat) String

func (q Quat) String() string

func (*Quat) ToArray

func (q *Quat) ToArray(array []float32, offset int)

ToArray copies this quaternions's components to array starting at offset.

func (*Quat) ToAxisAngle

func (q *Quat) ToAxisAngle() Vec4

ToAxisAngle returns the Vec4 holding axis and angle of this Quaternion

type RenderBuffer

type RenderBuffer struct {
	BufferID      []uint32
	Verts         [][]float32
	VertsPtr      []int
	MaxBufSize    uint32
	CurrentBuffer int
}

func (*RenderBuffer) AddMesh

func (b *RenderBuffer) AddMesh(mesh *Mesh) (int32, string)

func (*RenderBuffer) Init

func (b *RenderBuffer) Init()

func (*RenderBuffer) RemainingBuffer

func (b *RenderBuffer) RemainingBuffer(bufRef int) int

type Scene

type Scene struct {
	Width  int32
	Height int32

	Textures map[string]uint32
	Shapes   map[string]*Shape

	Window  *sdl.Window
	Context sdl.GLContext
}

func (*Scene) AddShape

func (s *Scene) AddShape(name string, shape ShapeType, width, depth, height float32, position, rotation Vec3, edges, col uint32, textureFile string)

func (*Scene) Draw

func (s *Scene) Draw()

func (*Scene) Quit

func (s *Scene) Quit()

func (*Scene) Setup

func (s *Scene) Setup(title string, w, h int32)

func (*Scene) Shape

func (s *Scene) Shape(name string) *Shape

type Shader

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

func LoadShaderStr

func LoadShaderStr(shaderType uint32, shaderSource string) (*Shader, string)

type ShaderSettings

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

func (*ShaderSettings) SetupShaderSettings

func (settings *ShaderSettings) SetupShaderSettings(program uint32) []int32

type Shape

type Shape struct {
	Name      string
	ShapeType ShapeType
	Position  Vec3
	Rotation  Vec3
	Scale     Vec3
	Center    Vec3
	Colour    uint32
	Texture   Texture
	W         float32
	H         float32
	D         float32
	Edges     uint32
	Path      []Vec2
	Verts     []float32
	Indexes   []int
	Group     []Shape
}

func NewShape

func NewShape(name string, shape ShapeType, width, height, depth float32, position, rotation Vec3, edges, col uint32, textureFile string) Shape

func ReadOBJ

func ReadOBJ(file string, scene Scene) []Shape

func (*Shape) CreateCone

func (c *Shape) CreateCone() []float32

func (*Shape) CreateCuboid

func (c *Shape) CreateCuboid() []float32

func (*Shape) CreateCylinder

func (c *Shape) CreateCylinder() []float32

func (*Shape) CreatePlane

func (c *Shape) CreatePlane() []float32

func (*Shape) CreateSphere

func (c *Shape) CreateSphere() []float32

func (*Shape) CreateSpring

func (c *Shape) CreateSpring() []float32

func (*Shape) CreateTCone

func (c *Shape) CreateTCone() []float32

func (*Shape) CreateTorus

func (c *Shape) CreateTorus() []float32

func (*Shape) CreateTube

func (c *Shape) CreateTube() []float32

func (*Shape) Draw

func (s *Shape) Draw()

func (*Shape) DrawTriangles

func (s *Shape) DrawTriangles()

type ShapeType

type ShapeType int
const (
	ShapeCuboid ShapeType = iota
	ShapePlane
	ShapeSphere
	ShapeCylinder
	ShapeCone
	ShapeTCone
	ShapeTube
	ShapeTorus
	ShapeLathe
	ShapeExtrude
	ShapeSpring
	ShapeTriangles
)

type Texture

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

func (*Texture) LoadTexture

func (t *Texture) LoadTexture(file string)

type UserInput

type UserInput struct {
	Mouse     Mouse
	Quit      bool
	PlayerPos Vec3
}

func (*UserInput) GetUserInput

func (ui *UserInput) GetUserInput()

type Vec2

type Vec2 struct {
	X float32
	Y float32
}

func V2

func V2(x, y float32) Vec2

V2 returns a new Vec2 with the given x and y components.

func (*Vec2) Distance

func (v1 *Vec2) Distance(v2 Vec2) float32

func (*Vec2) Dot

func (v1 *Vec2) Dot(v2 Vec2) Vec2

func (*Vec2) Length

func (v *Vec2) Length() float32

func (*Vec2) Minus

func (v1 *Vec2) Minus(v2 Vec2) Vec2

func (Vec2) MulScalar

func (v Vec2) MulScalar(s float32) Vec2

MulScalar multiplies each component of this vector by the scalar s and returns resulting vector.

func (Vec2) WindowToNDC

func (v Vec2) WindowToNDC(size, off Vec2, flipY bool) Vec3

WindowToNDC converts window (pixel) coordinates to normalized display coordinates (NDC), using given window size parameters. The Z depth coordinate (0-1) must be set manually or by reading from framebuffer flipY if true means flip the Y axis (top = 0 for windows vs. bottom = 0 for 3D coords)

type Vec3

type Vec3 struct {
	X float32
	Y float32
	Z float32
}

func NewEulerAnglesFromMatrix

func NewEulerAnglesFromMatrix(m *Mat4s) Vec3

NewEulerAnglesFromMatrix returns a Vec3 with components as the Euler angles from the specified pure rotation matrix.

func V3

func V3(x, y, z float32) Vec3

V3 returns a new Vec3 with the given x, y and z components.

func V3Scalar

func V3Scalar(s float32) Vec3

V3Scalar returns a new Vec3 with all components set to the given scalar value.

func (Vec3) Abs

func (v Vec3) Abs() Vec3

Abs returns vector with Abs of each component.

func (Vec3) Add

func (v Vec3) Add(other Vec3) Vec3

Add adds other vector to this one and returns result in a new vector.

func (Vec3) AddScalar

func (v Vec3) AddScalar(s float32) Vec3

AddScalar adds scalar s to each component of this vector and returns new vector.

func (*Vec3) AlmostEqual

func (v *Vec3) AlmostEqual(other Vec3, tol float32) bool

AlmostEqual returns whether the vector is almost equal to another vector within the specified tolerance.

func (Vec3) AngleTo

func (v Vec3) AngleTo(other Vec3) float32

AngleTo returns the angle between this vector and other. Returns angles in range of -PI to PI (not 0 to 2 PI).

func (Vec3) Ceil

func (v Vec3) Ceil() Vec3

Ceil returns vector with mat32.Ceil() applied to each of this vector's components.

func (*Vec3) Clamp

func (v *Vec3) Clamp(min, max Vec3)

Clamp sets this vector components to be no less than the corresponding components of min and not greater than the corresponding component of max. Assumes min < max, if this assumption isn't true it will not operate correctly.

func (*Vec3) ClampScalar

func (v *Vec3) ClampScalar(minVal, maxVal float32)

ClampScalar sets this vector components to be no less than minVal and not greater than maxVal.

func (Vec3) CosTo

func (v Vec3) CosTo(other Vec3) float32

CosTo returns the cosine (normalized dot product) between this vector and other.

func (Vec3) Cross

func (v Vec3) Cross(other Vec3) Vec3

Cross returns the cross product of this vector with other.

func (Vec3) DistTo

func (v Vec3) DistTo(other Vec3) float32

DistTo returns the distance of this point to other.

func (Vec3) DistToSquared

func (v Vec3) DistToSquared(other Vec3) float32

DistToSquared returns the distance squared of this point to other.

func (Vec3) Div

func (v Vec3) Div(other Vec3) Vec3

Div divides each component of this vector by the corresponding one from other vector and returns resulting vector.

func (Vec3) DivScalar

func (v Vec3) DivScalar(scalar float32) Vec3

DivScalar divides each component of this vector by the scalar s and returns resulting vector. If scalar is zero, returns zero.

func (Vec3) Dot

func (v Vec3) Dot(other Vec3) float32

Dot returns the dot product of this vector with other.

func (Vec3) Floor

func (v Vec3) Floor() Vec3

Floor returns vector with mat32.Floor() applied to each of this vector's components.

func (Vec3) IsEqual

func (v Vec3) IsEqual(other Vec3) bool

IsEqual returns if this vector is equal to other.

func (Vec3) Length

func (v Vec3) Length() float32

Length returns the length of this vector.

func (Vec3) LengthSq

func (v Vec3) LengthSq() float32

LengthSq returns the length squared of this vector. LengthSq can be used to compare vectors' lengths without the need to perform a square root.

func (Vec3) Lerp

func (v Vec3) Lerp(other Vec3, alpha float32) Vec3

Lerp returns vector with each components as the linear interpolated value of alpha between itself and the corresponding other component.

func (Vec3) Max

func (v Vec3) Max(other Vec3) Vec3

Max returns max of this vector components vs. other vector.

func (Vec3) Min

func (v Vec3) Min(other Vec3) Vec3

Min returns min of this vector components vs. other vector.

func (Vec3) Mul

func (v Vec3) Mul(other Vec3) Vec3

Mul multiplies each component of this vector by the corresponding one from other and returns resulting vector.

func (Vec3) MulMat4

func (v Vec3) MulMat4(m *Mat4s) Vec3

MulMat4 returns vector multiplied by specified 4x4 matrix.

func (Vec3) MulProjection

func (v Vec3) MulProjection(m *Mat4s) Vec3

MulProjection returns vector multiplied by the projection matrix m

func (Vec3) MulQuat

func (v Vec3) MulQuat(q Quat) Vec3

MulQuat returns vector multiplied by specified quaternion and then by the quaternion inverse. It basically applies the rotation encoded in the quaternion to this vector.

func (Vec3) MulScalar

func (v Vec3) MulScalar(s float32) Vec3

MulScalar multiplies each component of this vector by the scalar s and returns resulting vector.

func (Vec3) NDCToWindow

func (v Vec3) NDCToWindow(size, off Vec2, near, far float32, flipY bool) Vec3

NDCToWindow converts normalized display coordinates (NDC) to window (pixel) coordinates, using given window size parameters. near, far are 0, 1 by default (glDepthRange defaults). flipY if true means flip the Y axis (top = 0 for windows vs. bottom = 0 for 3D coords)

func (Vec3) Negate

func (v Vec3) Negate() Vec3

Negate returns vector with each component negated.

func (Vec3) Normal

func (v Vec3) Normal() Vec3

Normal returns this vector divided by its length

func (*Vec3) Normalize

func (v *Vec3) Normalize()

Normalize normalizes this vector so its length will be 1.

func (*Vec3) ProjectOnPlane

func (v *Vec3) ProjectOnPlane(planeNormal Vec3) Vec3

ProjectOnPlane returns vector projected on the plane specified by normal vector.

func (*Vec3) ProjectOnVector

func (v *Vec3) ProjectOnVector(other Vec3) Vec3

ProjectOnVector returns vector projected on other vector.

func (*Vec3) RandomTangents

func (v *Vec3) RandomTangents() (Vec3, Vec3)

RandomTangents computes and returns two arbitrary tangents to the vector.

func (*Vec3) Reflect

func (v *Vec3) Reflect(normal Vec3) Vec3

Reflect returns vector reflected relative to the normal vector (assumed to be already normalized).

func (Vec3) RotateAxisAngle

func (v Vec3) RotateAxisAngle(axis Vec3, angle float32) Vec3

RotateAxisAngle returns vector rotated around axis by angle.

func (Vec3) Round

func (v Vec3) Round() Vec3

Round returns vector with mat32.Round() applied to each of this vector's components.

func (*Vec3) Set

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

Set sets this vector X, Y and Z components.

func (*Vec3) SetAdd

func (v *Vec3) SetAdd(other Vec3)

SetAdd sets this to addition with other vector (i.e., += or plus-equals).

func (*Vec3) SetAddScalar

func (v *Vec3) SetAddScalar(s float32)

SetAddScalar sets this to addition with scalar.

func (*Vec3) SetCeil

func (v *Vec3) SetCeil()

SetCeil applies mat32.Ceil() to each of this vector's components.

func (*Vec3) SetDiv

func (v *Vec3) SetDiv(other Vec3)

SetDiv sets this to division by other vector (i.e., /= or divide-equals).

func (*Vec3) SetDivScalar

func (v *Vec3) SetDivScalar(s float32)

SetDivScalar sets this to division by scalar.

func (*Vec3) SetEulerAnglesFromMatrix

func (v *Vec3) SetEulerAnglesFromMatrix(m *Mat4s)

SetEulerAnglesFromMatrix sets this vector components to the Euler angles from the specified pure rotation matrix.

func (*Vec3) SetEulerAnglesFromQuat

func (v *Vec3) SetEulerAnglesFromQuat(q Quat)

SetEulerAnglesFromQuat sets this vector components to the Euler angles from the specified quaternion.

func (*Vec3) SetFloor

func (v *Vec3) SetFloor()

SetFloor applies mat32.Floor() to each of this vector's components.

func (*Vec3) SetFromMatrixPos

func (v *Vec3) SetFromMatrixPos(m *Mat4s)

SetFromMatrixPos set this vector from the translation coordinates in the specified transformation matrix.

func (*Vec3) SetLength

func (v *Vec3) SetLength(l float32)

SetLength sets this vector to have the specified length. If the current length is zero, does nothing.

func (*Vec3) SetLerp

func (v *Vec3) SetLerp(other Vec3, alpha float32)

SetLerp sets each of this vector's components to the linear interpolated value of alpha between itself and the corresponding other component.

func (*Vec3) SetMax

func (v *Vec3) SetMax(other Vec3)

SetMax sets this vector components to the maximum value of itself and other vector.

func (*Vec3) SetMin

func (v *Vec3) SetMin(other Vec3)

SetMin sets this vector components to the minimum values of itself and other vector.

func (*Vec3) SetMul

func (v *Vec3) SetMul(other Vec3)

SetMul sets this to multiplication with other vector (i.e., *= or times-equals).

func (*Vec3) SetMulMat4

func (v *Vec3) SetMulMat4(m *Mat4s)

SetMulMat4 sets vector multiplied by specified 4x4 matrix.

func (*Vec3) SetMulQuat

func (v *Vec3) SetMulQuat(q Quat)

SetMulQuat multiplies vector by specified quaternion and then by the quaternion inverse. It basically applies the rotation encoded in the quaternion to this vector.

func (*Vec3) SetMulScalar

func (v *Vec3) SetMulScalar(s float32)

SetMulScalar sets this to multiplication by scalar.

func (*Vec3) SetNegate

func (v *Vec3) SetNegate()

SetNegate negates each of this vector's components.

func (*Vec3) SetNormal

func (v *Vec3) SetNormal()

SetNormal normalizes this vector so its length will be 1.

func (*Vec3) SetRotateAxisAngle

func (v *Vec3) SetRotateAxisAngle(axis Vec3, angle float32)

SetRotateAxisAngle sets vector rotated around axis by angle.

func (*Vec3) SetRound

func (v *Vec3) SetRound()

SetRound rounds each of this vector's components.

func (*Vec3) SetScalar

func (v *Vec3) SetScalar(s float32)

SetScalar sets all vector X, Y and Z components to same scalar value.

func (*Vec3) SetSub

func (v *Vec3) SetSub(other Vec3)

SetSub sets this to subtraction with other vector (i.e., -= or minus-equals).

func (*Vec3) SetSubScalar

func (v *Vec3) SetSubScalar(s float32)

SetSubScalar sets this to subtraction of scalar.

func (*Vec3) SetZero

func (v *Vec3) SetZero()

SetZero sets this vector X, Y and Z components to be zero.

func (Vec3) Sub

func (v Vec3) Sub(other Vec3) Vec3

Sub subtracts other vector from this one and returns result in new vector.

func (Vec3) SubScalar

func (v Vec3) SubScalar(s float32) Vec3

SubScalar subtracts scalar s from each component of this vector and returns new vector.

type Vec4

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

Vec4 is a vector/point in homogeneous coordinates with X, Y, Z and W components.

func V4

func V4(x, y, z, w float32) Vec4

V4 returns a new Vec4 with the given x, y, z, and w components.

func V4FromV3

func V4FromV3(v Vec3, w float32) Vec4

V4FromV3 returns a new Vec4 from the given Vec3 and w component.

func V4Scalar

func V4Scalar(s float32) Vec4

V4Scalar returns a new Vec4 with all components set to the given scalar value.

func (Vec4) Add

func (v Vec4) Add(other Vec4) Vec4

Add adds other vector to this one and returns result in a new vector.

func (Vec4) AddScalar

func (v Vec4) AddScalar(s float32) Vec4

AddScalar adds scalar s to each component of this vector and returns new vector.

func (*Vec4) AlmostEqual

func (v *Vec4) AlmostEqual(other Vec4, tol float32) bool

AlmostEqual returns whether the vector is almost equal to another vector within the specified tolerance.

func (Vec4) Ceil

func (v Vec4) Ceil() Vec4

Ceil returns vector with mat32.Ceil() applied to each of this vector's components.

func (*Vec4) Clamp

func (v *Vec4) Clamp(min, max Vec4)

Clamp sets this vector components to be no less than the corresponding components of min and not greater than the corresponding component of max. Assumes min < max, if this assumption isn't true it will not operate correctly.

func (*Vec4) ClampScalar

func (v *Vec4) ClampScalar(minVal, maxVal float32)

ClampScalar sets this vector components to be no less than minVal and not greater than maxVal.

func (Vec4) Div

func (v Vec4) Div(other Vec4) Vec4

Div divides each component of this vector by the corresponding one from other vector and returns resulting vector.

func (Vec4) DivScalar

func (v Vec4) DivScalar(scalar float32) Vec4

DivScalar divides each component of this vector by the scalar s and returns resulting vector. If scalar is zero, returns zero.

func (Vec4) Dot

func (v Vec4) Dot(other Vec4) float32

Dot returns the dot product of this vector with other.

func (Vec4) Floor

func (v Vec4) Floor() Vec4

Floor returns vector with mat32.Floor() applied to each of this vector's components.

func (*Vec4) FromArray

func (v *Vec4) FromArray(array []float32, offset int)

FromArray sets this vector's components from the specified array and offset

func (*Vec4) IsEqual

func (v *Vec4) IsEqual(other Vec4) bool

IsEqual returns if this vector is equal to other.

func (Vec4) Length

func (v Vec4) Length() float32

Length returns the length of this vector.

func (Vec4) LengthSq

func (v Vec4) LengthSq() float32

LengthSq returns the length squared of this vector. LengthSq can be used to compare vectors' lengths without the need to perform a square root.

func (Vec4) Lerp

func (v Vec4) Lerp(other Vec4, alpha float32) Vec4

Lerp returns vector with each components as the linear interpolated value of alpha between itself and the corresponding other component.

func (Vec4) Max

func (v Vec4) Max(other Vec4) Vec4

Max returns max of this vector components vs. other vector.

func (Vec4) Min

func (v Vec4) Min(other Vec4) Vec4

Min returns min of this vector components vs. other vector.

func (Vec4) Mul

func (v Vec4) Mul(other Vec4) Vec4

Mul multiplies each component of this vector by the corresponding one from other and returns resulting vector.

func (Vec4) MulMat4

func (v Vec4) MulMat4(m *Mat4s) Vec4

MulMat4 returns vector multiplied by specified 4x4 matrix.

func (Vec4) MulScalar

func (v Vec4) MulScalar(s float32) Vec4

MulScalar multiplies each component of this vector by the scalar s and returns resulting vector.

func (Vec4) Negate

func (v Vec4) Negate() Vec4

Negate returns vector with each component negated.

func (Vec4) Normal

func (v Vec4) Normal() Vec4

Normal returns this vector divided by its length

func (*Vec4) Normalize

func (v *Vec4) Normalize()

Normalize normalizes this vector so its length will be 1.

func (Vec4) PerspDiv

func (v Vec4) PerspDiv() Vec3

PerspDiv returns the 3-vector of normalized display coordinates (NDC) from given 4-vector By dividing by the 4th W component

func (Vec4) Round

func (v Vec4) Round() Vec4

Round returns vector with mat32.Round() applied to each of this vector's components.

func (*Vec4) Set

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

Set sets this vector X, Y, Z and W components.

func (*Vec4) SetAdd

func (v *Vec4) SetAdd(other Vec4)

SetAdd sets this to addition with other vector (i.e., += or plus-equals).

func (*Vec4) SetAddScalar

func (v *Vec4) SetAddScalar(s float32)

SetAddScalar sets this to addition with scalar.

func (*Vec4) SetAxisAngleFromQuat

func (v *Vec4) SetAxisAngleFromQuat(q Quat)

SetAxisAngleFromQuat set this vector to be the axis (x, y, z) and angle (w) of a rotation specified the quaternion q. Assumes q is normalized.

func (*Vec4) SetAxisFromRotationMatrix

func (v *Vec4) SetAxisFromRotationMatrix(m *Mat4s)

SetAxisFromRotationMatrix sets this vector to be the axis (x, y, z) and angle (w) of a rotation specified the matrix m. Assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled).

func (*Vec4) SetByName

func (v *Vec4) SetByName(name string, value float32)

SetByName sets this vector component value by its case insensitive name: "x", "y", "z" or "w".

func (*Vec4) SetCeil

func (v *Vec4) SetCeil()

SetCeil applies mat32.Ceil() to each of this vector's components.

func (*Vec4) SetDiv

func (v *Vec4) SetDiv(other Vec4)

SetDiv sets this to division by other vector (i.e., /= or divide-equals).

func (*Vec4) SetDivScalar

func (v *Vec4) SetDivScalar(s float32)

SetDivScalar sets this to division by scalar.

func (*Vec4) SetFloor

func (v *Vec4) SetFloor()

SetFloor applies mat32.Floor() to each of this vector's components.

func (*Vec4) SetFromVec2

func (v *Vec4) SetFromVec2(other Vec2)

SetFromVec2 sets this vector from a Vec2 with 0,1 for Z,W

func (*Vec4) SetFromVec3

func (v *Vec4) SetFromVec3(other Vec3, w float32)

SetFromVec3 sets this vector from a Vec3 and W

func (*Vec4) SetLength

func (v *Vec4) SetLength(l float32)

SetLength sets this vector to have the specified length. If the current length is zero, does nothing.

func (*Vec4) SetLerp

func (v *Vec4) SetLerp(other *Vec4, alpha float32)

SetLerp sets each of this vector's components to the linear interpolated value of alpha between ifself and the corresponding other component.

func (*Vec4) SetMax

func (v *Vec4) SetMax(other Vec4)

SetMax sets this vector components to the maximum value of itself and other vector.

func (*Vec4) SetMin

func (v *Vec4) SetMin(other Vec4)

SetMin sets this vector components to the minimum values of itself and other vector.

func (*Vec4) SetMul

func (v *Vec4) SetMul(other Vec4)

SetMul sets this to multiplication with other vector (i.e., *= or times-equals).

func (*Vec4) SetMulScalar

func (v *Vec4) SetMulScalar(s float32)

SetMulScalar sets this to multiplication by scalar.

func (*Vec4) SetNegate

func (v *Vec4) SetNegate()

SetNegate negates each of this vector's components.

func (*Vec4) SetNormal

func (v *Vec4) SetNormal()

SetNormal normalizes this vector so its length will be 1.

func (*Vec4) SetRound

func (v *Vec4) SetRound()

SetRound rounds each of this vector's components.

func (*Vec4) SetSub

func (v *Vec4) SetSub(other Vec4)

SetSub sets this to subtraction with other vector (i.e., -= or minus-equals).

func (*Vec4) SetSubScalar

func (v *Vec4) SetSubScalar(s float32)

SetSubScalar sets this to subtraction of scalar.

func (*Vec4) SetZero

func (v *Vec4) SetZero()

SetZero sets this vector X, Y and Z components to be zero and W to be one.

func (Vec4) String

func (v Vec4) String() string

func (Vec4) Sub

func (v Vec4) Sub(other Vec4) Vec4

Sub subtracts other vector from this one and returns result in new vector.

func (Vec4) SubScalar

func (v Vec4) SubScalar(s float32) Vec4

SubScalar subtracts scalar s from each component of this vector and returns new vector.

func (Vec4) ToArray

func (v Vec4) ToArray(array []float32, offset int)

ToArray copies this vector's components to array starting at offset.

Jump to

Keyboard shortcuts

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