mirror of
https://github.com/bloeys/gglm.git
synced 2025-12-29 13:38:20 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f4f06c54b3 | |||
| 80d1c12e2d |
@ -1,6 +1,6 @@
|
||||
# gglm
|
||||
|
||||
Fast Go OpenGL Mathematics library inspired by the c++ library [glm](https://github.com/g-truc/glm).
|
||||
Fast Go OpenGL/Graphics focused Mathematics library inspired by the c++ library [glm](https://github.com/g-truc/glm).
|
||||
|
||||
## Notes
|
||||
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
package gglm
|
||||
|
||||
const (
|
||||
Pi float32 = 3.14159265359
|
||||
Deg2Rad float32 = Pi / 180
|
||||
Rad2Deg float32 = 180 / Pi
|
||||
Pi float32 = 3.14159265359
|
||||
Deg2Rad float32 = Pi / 180
|
||||
Rad2Deg float32 = 180 / Pi
|
||||
F32Epsilon float32 = 1e-6
|
||||
|
||||
//CosHalf is Cos32(0.5)
|
||||
CosHalf float32 = 0.87758256189
|
||||
|
||||
@ -2,9 +2,6 @@ package gglm
|
||||
|
||||
import "math"
|
||||
|
||||
//F32Epsilon = 0.0000005
|
||||
const F32Epsilon float32 = 1e-6
|
||||
|
||||
//EqF32 true if abs(f1-f2) <= F32Epsilon
|
||||
func EqF32(f1, f2 float32) bool {
|
||||
return math.Abs(float64(f1-f2)) <= float64(F32Epsilon)
|
||||
@ -31,6 +28,18 @@ func Acos32(x float32) float32 {
|
||||
return float32(math.Acos(float64(x)))
|
||||
}
|
||||
|
||||
func Tan32(x float32) float32 {
|
||||
return float32(math.Tan(float64(x)))
|
||||
}
|
||||
|
||||
func Atan32(x float32) float32 {
|
||||
return float32(math.Atan(float64(x)))
|
||||
}
|
||||
|
||||
func Atan232(x, y float32) float32 {
|
||||
return float32(math.Atan2(float64(y), float64(x)))
|
||||
}
|
||||
|
||||
func Sincos32(x float32) (sinx, cosx float32) {
|
||||
a, b := math.Sincos(float64(x))
|
||||
return float32(a), float32(b)
|
||||
|
||||
@ -14,21 +14,23 @@ type TrMat struct {
|
||||
}
|
||||
|
||||
//Translate adds v to the translation components of the transformation matrix
|
||||
func (t *TrMat) Translate(v *Vec3) {
|
||||
func (t *TrMat) Translate(v *Vec3) *TrMat {
|
||||
t.Data[3][0] += v.Data[0]
|
||||
t.Data[3][1] += v.Data[1]
|
||||
t.Data[3][2] += v.Data[2]
|
||||
return t
|
||||
}
|
||||
|
||||
//Scale multiplies the scale components of the transformation matrix by v
|
||||
func (t *TrMat) Scale(v *Vec3) {
|
||||
func (t *TrMat) Scale(v *Vec3) *TrMat {
|
||||
t.Data[0][0] *= v.Data[0]
|
||||
t.Data[1][1] *= v.Data[1]
|
||||
t.Data[2][2] *= v.Data[2]
|
||||
return t
|
||||
}
|
||||
|
||||
//Rotate takes a *normalized* axis and angles in radians to rotate around the given axis
|
||||
func (t *TrMat) Rotate(rads float32, axis *Vec3) {
|
||||
func (t *TrMat) Rotate(rads float32, axis *Vec3) *TrMat {
|
||||
|
||||
s := Sin32(rads)
|
||||
c := Cos32(rads)
|
||||
@ -68,6 +70,7 @@ func (t *TrMat) Rotate(rads float32, axis *Vec3) {
|
||||
t.Data[0] = result.Data[0]
|
||||
t.Data[1] = result.Data[1]
|
||||
t.Data[2] = result.Data[2]
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *TrMat) Mul(m *TrMat) *TrMat {
|
||||
|
||||
Reference in New Issue
Block a user