Skip to content

Commit

Permalink
Merge branch 'gen2brain:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Hultan authored Oct 24, 2024
2 parents d6c07f1 + f2ab1b0 commit 6807b5c
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 4 deletions.
9 changes: 8 additions & 1 deletion raylib/raylib.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,14 @@ type AutomationEvent struct {
type AutomationEventList struct {
Capacity uint32
Count uint32
Events *AutomationEvent
// Events array (c array)
//
// Use AutomationEventList.GetEvents instead (go slice)
Events *AutomationEvent
}

func (a *AutomationEventList) GetEvents() []AutomationEvent {
return unsafe.Slice(a.Events, a.Count)
}

// CameraMode type
Expand Down
53 changes: 53 additions & 0 deletions raylib/raymath.go
Original file line number Diff line number Diff line change
Expand Up @@ -1792,3 +1792,56 @@ func QuaternionEquals(p, q Quaternion) bool {
math.Abs(float64(p.Z+q.Z)) <= 0.000001*math.Max(1.0, math.Max(math.Abs(float64(p.Z)), math.Abs(float64(q.Z)))) &&
math.Abs(float64(p.W+q.W)) <= 0.000001*math.Max(1.0, math.Max(math.Abs(float64(p.W)), math.Abs(float64(q.W)))))
}

// MatrixDecompose - Decompose a transformation matrix into its rotational, translational and scaling components
func MatrixDecompose(mat Matrix, translation *Vector3, rotation *Quaternion, scale *Vector3) {
// Extract translation.
translation.X = mat.M12
translation.Y = mat.M13
translation.Z = mat.M14

// Extract upper-left for determinant computation
a := mat.M0
b := mat.M4
c := mat.M8
d := mat.M1
e := mat.M5
f := mat.M9
g := mat.M2
h := mat.M6
i := mat.M10
A := e*i - f*h
B := f*g - d*i
C := d*h - e*g

// Extract scale
det := a*A + b*B + c*C
abc := NewVector3(a, b, c)
def := NewVector3(d, e, f)
ghi := NewVector3(g, h, i)

scalex := Vector3Length(abc)
scaley := Vector3Length(def)
scalez := Vector3Length(ghi)
s := NewVector3(scalex, scaley, scalez)

if det < 0 {
s = Vector3Negate(s)
}

*scale = s

// Remove scale from the matrix if it is not close to zero
clone := mat
if !FloatEquals(det, 0) {
clone.M0 /= s.X
clone.M5 /= s.Y
clone.M10 /= s.Z

// Extract rotation
*rotation = QuaternionFromMatrix(clone)
} else {
// Set to identity if close to zero
*rotation = QuaternionIdentity()
}
}
55 changes: 55 additions & 0 deletions raylib/raymath.h
Original file line number Diff line number Diff line change
Expand Up @@ -2524,4 +2524,59 @@ RMAPI int QuaternionEquals(Quaternion p, Quaternion q)
return result;
}

// Decompose a transformation matrix into its rotational, translational and scaling components
RMAPI void MatrixDecompose(Matrix mat, Vector3 *translation, Quaternion *rotation, Vector3 *scale)
{
// Extract translation.
translation->x = mat.m12;
translation->y = mat.m13;
translation->z = mat.m14;

// Extract upper-left for determinant computation
const float a = mat.m0;
const float b = mat.m4;
const float c = mat.m8;
const float d = mat.m1;
const float e = mat.m5;
const float f = mat.m9;
const float g = mat.m2;
const float h = mat.m6;
const float i = mat.m10;
const float A = e*i - f*h;
const float B = f*g - d*i;
const float C = d*h - e*g;

// Extract scale
const float det = a*A + b*B + c*C;
Vector3 abc = { a, b, c };
Vector3 def = { d, e, f };
Vector3 ghi = { g, h, i };

float scalex = Vector3Length(abc);
float scaley = Vector3Length(def);
float scalez = Vector3Length(ghi);
Vector3 s = { scalex, scaley, scalez };

if (det < 0) s = Vector3Negate(s);

*scale = s;

// Remove scale from the matrix if it is not close to zero
Matrix clone = mat;
if (!FloatEquals(det, 0))
{
clone.m0 /= s.x;
clone.m5 /= s.y;
clone.m10 /= s.z;

// Extract rotation
*rotation = QuaternionFromMatrix(clone);
}
else
{
// Set to identity if close to zero
*rotation = QuaternionIdentity();
}
}

#endif // RAYMATH_H
2 changes: 1 addition & 1 deletion raylib/rlgl_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ func CheckErrors() {
}

// SetBlendMode - Set blending mode
func SetBlendMode(mode int32) {
func SetBlendMode(mode BlendMode) {
cmode := C.int(mode)
C.rlSetBlendMode(cmode)
}
Expand Down
4 changes: 2 additions & 2 deletions raylib/rlgl_purego.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ func CheckErrors() {
}

// SetBlendMode - Set blending mode
func SetBlendMode(mode int32) {
rlSetBlendMode(mode)
func SetBlendMode(mode BlendMode) {
rlSetBlendMode(int32(mode))
}

// SetBlendFactors - Set blending mode factor and equation (using OpenGL factors)
Expand Down
8 changes: 8 additions & 0 deletions raylib/rshapes.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ func DrawCircleLines(centerX, centerY int32, radius float32, col color.RGBA) {
C.DrawCircleLines(ccenterX, ccenterY, cradius, *ccolor)
}

// DrawCircleLinesV - Draw circle outline (Vector version)
func DrawCircleLinesV(center Vector2, radius float32, col color.RGBA) {
ccenter := center.cptr()
cradius := (C.float)(radius)
ccolor := colorCptr(col)
C.DrawCircleLinesV(*ccenter, cradius, *ccolor)
}

// DrawEllipse - Draw ellipse
func DrawEllipse(centerX, centerY int32, radiusH, radiusV float32, col color.RGBA) {
ccenterX := (C.int)(centerX)
Expand Down

0 comments on commit 6807b5c

Please sign in to comment.