Add Spline functions
This commit is contained in:
parent
61e85d2e51
commit
5830da3d87
1 changed files with 159 additions and 5 deletions
|
@ -60,9 +60,9 @@ func DrawLineEx(startPos, endPos Vector2, thick float32, col color.RGBA) {
|
|||
}
|
||||
|
||||
// DrawLineStrip - Draw lines sequence
|
||||
func DrawLineStrip(points []Vector2, pointCount int32, col color.RGBA) {
|
||||
func DrawLineStrip(points []Vector2, col color.RGBA) {
|
||||
cpoints := (*C.Vector2)(unsafe.Pointer(&points[0]))
|
||||
cpointCount := (C.int)(pointCount)
|
||||
cpointCount := (C.int)(len(points))
|
||||
ccolor := colorCptr(col)
|
||||
C.DrawLineStrip(cpoints, cpointCount, *ccolor)
|
||||
}
|
||||
|
@ -302,7 +302,7 @@ func DrawTriangleLines(v1, v2, v3 Vector2, col color.RGBA) {
|
|||
// DrawTriangleFan - Draw a triangle fan defined by points
|
||||
func DrawTriangleFan(points []Vector2, col color.RGBA) {
|
||||
cpoints := (*C.Vector2)(unsafe.Pointer(&points[0]))
|
||||
cpointsCount := (C.int)(int32(len(points)))
|
||||
cpointsCount := (C.int)(len(points))
|
||||
ccolor := colorCptr(col)
|
||||
C.DrawTriangleFan(cpoints, cpointsCount, *ccolor)
|
||||
}
|
||||
|
@ -346,6 +346,160 @@ func DrawPolyLinesEx(center Vector2, sides int32, radius float32, rotation float
|
|||
C.DrawPolyLinesEx(*ccenter, csides, cradius, crotation, clineThick, *ccolor)
|
||||
}
|
||||
|
||||
// DrawSplineLinear - Draw spline: Linear, minimum 2 points
|
||||
func DrawSplineLinear(points []Vector2, thick float32, col color.RGBA) {
|
||||
cpoints := (*C.Vector2)(unsafe.Pointer(&points[0]))
|
||||
cpointCount := (C.int)(len(points))
|
||||
cthick := (C.float)(thick)
|
||||
ccolor := colorCptr(col)
|
||||
C.DrawSplineLinear(cpoints, cpointCount, cthick, *ccolor)
|
||||
}
|
||||
|
||||
// DrawSplineBasis - Draw spline: B-Spline, minimum 4 points
|
||||
func DrawSplineBasis(points []Vector2, thick float32, col color.RGBA) {
|
||||
cpoints := (*C.Vector2)(unsafe.Pointer(&points[0]))
|
||||
cpointCount := (C.int)(len(points))
|
||||
cthick := (C.float)(thick)
|
||||
ccolor := colorCptr(col)
|
||||
C.DrawSplineBasis(cpoints, cpointCount, cthick, *ccolor)
|
||||
}
|
||||
|
||||
// DrawSplineCatmullRom - Draw spline: Catmull-Rom, minimum 4 points
|
||||
func DrawSplineCatmullRom(points []Vector2, thick float32, col color.RGBA) {
|
||||
cpoints := (*C.Vector2)(unsafe.Pointer(&points[0]))
|
||||
cpointCount := (C.int)(len(points))
|
||||
cthick := (C.float)(thick)
|
||||
ccolor := colorCptr(col)
|
||||
C.DrawSplineCatmullRom(cpoints, cpointCount, cthick, *ccolor)
|
||||
}
|
||||
|
||||
// DrawSplineBezierQuadratic - Draw spline: Quadratic Bezier, minimum 3 points (1 control point): [p1, c2, p3, c4...]
|
||||
func DrawSplineBezierQuadratic(points []Vector2, thick float32, col color.RGBA) {
|
||||
cpoints := (*C.Vector2)(unsafe.Pointer(&points[0]))
|
||||
cpointCount := (C.int)(len(points))
|
||||
cthick := (C.float)(thick)
|
||||
ccolor := colorCptr(col)
|
||||
C.DrawSplineBezierQuadratic(cpoints, cpointCount, cthick, *ccolor)
|
||||
}
|
||||
|
||||
// DrawSplineBezierCubic - Draw spline: Cubic Bezier, minimum 4 points (2 control points): [p1, c2, c3, p4, c5, c6...]
|
||||
func DrawSplineBezierCubic(points []Vector2, thick float32, col color.RGBA) {
|
||||
cpoints := (*C.Vector2)(unsafe.Pointer(&points[0]))
|
||||
cpointCount := (C.int)(len(points))
|
||||
cthick := (C.float)(thick)
|
||||
ccolor := colorCptr(col)
|
||||
C.DrawSplineBezierCubic(cpoints, cpointCount, cthick, *ccolor)
|
||||
}
|
||||
|
||||
// DrawSplineSegmentLinear - Draw spline segment: Linear, 2 points
|
||||
func DrawSplineSegmentLinear(p1, p2 Vector2, thick float32, col color.RGBA) {
|
||||
cp1 := p1.cptr()
|
||||
cp2 := p2.cptr()
|
||||
cthick := (C.float)(thick)
|
||||
ccolor := colorCptr(col)
|
||||
C.DrawSplineSegmentLinear(*cp1, *cp2, cthick, *ccolor)
|
||||
}
|
||||
|
||||
// DrawSplineSegmentBasis - Draw spline segment: B-Spline, 4 points
|
||||
func DrawSplineSegmentBasis(p1, p2, p3, p4 Vector2, thick float32, col color.RGBA) {
|
||||
cp1 := p1.cptr()
|
||||
cp2 := p2.cptr()
|
||||
cp3 := p2.cptr()
|
||||
cp4 := p2.cptr()
|
||||
cthick := (C.float)(thick)
|
||||
ccolor := colorCptr(col)
|
||||
C.DrawSplineSegmentBasis(*cp1, *cp2, *cp3, *cp4, cthick, *ccolor)
|
||||
}
|
||||
|
||||
// DrawSplineSegmentCatmullRom - Draw spline segment: Catmull-Rom, 4 points
|
||||
func DrawSplineSegmentCatmullRom(p1, p2, p3, p4 Vector2, thick float32, col color.RGBA) {
|
||||
cp1 := p1.cptr()
|
||||
cp2 := p2.cptr()
|
||||
cp3 := p2.cptr()
|
||||
cp4 := p2.cptr()
|
||||
cthick := (C.float)(thick)
|
||||
ccolor := colorCptr(col)
|
||||
C.DrawSplineSegmentCatmullRom(*cp1, *cp2, *cp3, *cp4, cthick, *ccolor)
|
||||
}
|
||||
|
||||
// DrawSplineSegmentBezierQuadratic - Draw spline segment: Quadratic Bezier, 2 points, 1 control point
|
||||
func DrawSplineSegmentBezierQuadratic(p1, p2, p3 Vector2, thick float32, col color.RGBA) {
|
||||
cp1 := p1.cptr()
|
||||
cp2 := p2.cptr()
|
||||
cp3 := p2.cptr()
|
||||
cthick := (C.float)(thick)
|
||||
ccolor := colorCptr(col)
|
||||
C.DrawSplineSegmentBezierQuadratic(*cp1, *cp2, *cp3, cthick, *ccolor)
|
||||
}
|
||||
|
||||
// DrawSplineSegmentBezierCubic - Draw spline segment: Cubic Bezier, 2 points, 2 control points
|
||||
func DrawSplineSegmentBezierCubic(p1, p2, p3, p4 Vector2, thick float32, col color.RGBA) {
|
||||
cp1 := p1.cptr()
|
||||
cp2 := p2.cptr()
|
||||
cp3 := p2.cptr()
|
||||
cp4 := p2.cptr()
|
||||
cthick := (C.float)(thick)
|
||||
ccolor := colorCptr(col)
|
||||
C.DrawSplineSegmentBezierCubic(*cp1, *cp2, *cp3, *cp4, cthick, *ccolor)
|
||||
}
|
||||
|
||||
// GetSplinePointLinear - Get (evaluate) spline point: Linear
|
||||
func GetSplinePointLinear(p1, p2 Vector2, t float32) Vector2 {
|
||||
cp1 := p1.cptr()
|
||||
cp2 := p2.cptr()
|
||||
ct := (C.float)(t)
|
||||
ret := C.GetSplinePointLinear(*cp1, *cp2, ct)
|
||||
v := newVector2FromPointer(unsafe.Pointer(&ret))
|
||||
return v
|
||||
}
|
||||
|
||||
// GetSplinePointBasis - Get (evaluate) spline point: B-Spline
|
||||
func GetSplinePointBasis(p1, p2, p3, p4 Vector2, t float32) Vector2 {
|
||||
cp1 := p1.cptr()
|
||||
cp2 := p2.cptr()
|
||||
cp3 := p2.cptr()
|
||||
cp4 := p2.cptr()
|
||||
ct := (C.float)(t)
|
||||
ret := C.GetSplinePointBasis(*cp1, *cp2, *cp3, *cp4, ct)
|
||||
v := newVector2FromPointer(unsafe.Pointer(&ret))
|
||||
return v
|
||||
}
|
||||
|
||||
// GetSplinePointCatmullRom - Get (evaluate) spline point: Catmull-Rom
|
||||
func GetSplinePointCatmullRom(p1, p2, p3, p4 Vector2, t float32) Vector2 {
|
||||
cp1 := p1.cptr()
|
||||
cp2 := p2.cptr()
|
||||
cp3 := p2.cptr()
|
||||
cp4 := p2.cptr()
|
||||
ct := (C.float)(t)
|
||||
ret := C.GetSplinePointCatmullRom(*cp1, *cp2, *cp3, *cp4, ct)
|
||||
v := newVector2FromPointer(unsafe.Pointer(&ret))
|
||||
return v
|
||||
}
|
||||
|
||||
// GetSplinePointBezierQuad - Get (evaluate) spline point: Quadratic Bezier
|
||||
func GetSplinePointBezierQuad(p1, p2, p3 Vector2, t float32) Vector2 {
|
||||
cp1 := p1.cptr()
|
||||
cp2 := p2.cptr()
|
||||
cp3 := p2.cptr()
|
||||
ct := (C.float)(t)
|
||||
ret := C.GetSplinePointBezierQuad(*cp1, *cp2, *cp3, ct)
|
||||
v := newVector2FromPointer(unsafe.Pointer(&ret))
|
||||
return v
|
||||
}
|
||||
|
||||
// GetSplinePointBezierCubic - Get (evaluate) spline point: Cubic Bezier
|
||||
func GetSplinePointBezierCubic(p1, p2, p3, p4 Vector2, t float32) Vector2 {
|
||||
cp1 := p1.cptr()
|
||||
cp2 := p2.cptr()
|
||||
cp3 := p2.cptr()
|
||||
cp4 := p2.cptr()
|
||||
ct := (C.float)(t)
|
||||
ret := C.GetSplinePointBezierCubic(*cp1, *cp2, *cp3, *cp4, ct)
|
||||
v := newVector2FromPointer(unsafe.Pointer(&ret))
|
||||
return v
|
||||
}
|
||||
|
||||
// CheckCollisionRecs - Check collision between two rectangles
|
||||
func CheckCollisionRecs(rec1, rec2 Rectangle) bool {
|
||||
crec1 := rec1.cptr()
|
||||
|
@ -409,10 +563,10 @@ func CheckCollisionPointTriangle(point, p1, p2, p3 Vector2) bool {
|
|||
// CheckCollisionPointPoly - Check if point is within a polygon described by array of vertices
|
||||
//
|
||||
// NOTE: Based on http://jeffreythompson.org/collision-detection/poly-point.php
|
||||
func CheckCollisionPointPoly(point Vector2, points []Vector2, pointCount int32) bool {
|
||||
func CheckCollisionPointPoly(point Vector2, points []Vector2) bool {
|
||||
cpoint := point.cptr()
|
||||
cpoints := (&points[0]).cptr()
|
||||
cpointCount := C.int(pointCount)
|
||||
cpointCount := C.int(len(points))
|
||||
ret := C.CheckCollisionPointPoly(*cpoint, cpoints, cpointCount)
|
||||
v := bool(ret)
|
||||
return v
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue