util

package
v0.0.0-...-1050381 Latest Latest
Warning

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

Go to latest
Published: May 7, 2017 License: MIT Imports: 7 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTimeMillis

func GetTimeMillis() int64

TODO: Why is this not in the standard time library? Am I missing something?

func IsPowerOfTwo

func IsPowerOfTwo(n int) bool

func RandQuat

func RandQuat() mgl32.Quat

func RandUint8

func RandUint8() uint8

func RandVec3

func RandVec3() mgl32.Vec3

func RoundUpToPowerOfTwo

func RoundUpToPowerOfTwo(n int) int

RoundUpToPowerOfTwo returns the smallest number that is >= n and also a power of two. If n is close to the max int value, unexpected behavior results are likely.

func SaveScreenshot

func SaveScreenshot(width, height int, path string) error

SaveScreenshot reads pixel data from OpenGL buffers, so it must be run in the same main thread as the rest of OpenGL. TODO: write to file in a goroutine and return a (chan err), or just ignore slow errors. Handling errors that can be caught immediately is fine. Blocking while writing to file adds way too much delay.

func ScaleQuatRotation

func ScaleQuatRotation(q mgl32.Quat, percent float32) mgl32.Quat

ScaleQuatRotation scales the provided rotation by the provided percentage. For example, if you have a quaternion representing a 90 degree rotation: mgl32.AnglesToQuat(mgl32.DegToRad(90), 0, 0, mgl32.ZYX) you could get a quaternion that rotates half as much with: ScaleQuatRotation(q, 0.5) Note that percentages above 1.0 will increase the provided rotation as expected, and negative percentages will reverse the rotation.

Sample usage to limit rotation based on a maximum amount per second:

rotationSpeed := mgl32.AnglesToQuat(0, 0, 2 * math.Pi, mgl32.XYZ)	// Allow one full rotation per second.
deltaTime := 0.016 												// Time passed in the last frame is very small.
rotation := util.ScaleQuatRotation(rotationSpeed, deltaTime)		// rotationSpeed * time = rotation

Types

This section is empty.

Directories

Path Synopsis
Package fps can be used to keep track of framerate and delta time.
Package fps can be used to keep track of framerate and delta time.
glutil contains common functions to deal with OpenGl and WebGL, such as loading data into Buffers and Textures.
glutil contains common functions to deal with OpenGl and WebGL, such as loading data into Buffers and Textures.

Jump to

Keyboard shortcuts

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