Make TrMat funcs chainable+more 32 scalar funcs

This commit is contained in:
bloeys
2022-01-13 17:51:04 +04:00
parent 80d1c12e2d
commit f4f06c54b3
3 changed files with 22 additions and 9 deletions

View File

@ -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

View File

@ -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)

View File

@ -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 {