10-06-2024, 05:08 PM
After playing around with some other Bezier code it would seem this is normal. I streamlined the program above to be much faster and yield different numbers of points when using AND or OR in line 30 of the code.
When using AND the curve is very smooth when connected with lines. However, some detail is lost if successive X or Y coordinates are equal, not ideal for enemy ship path following but great when connecting the points with lines.
When using OR the data points are perfect for path following.
When using AND the curve is very smooth when connected with lines. However, some detail is lost if successive X or Y coordinates are equal, not ideal for enemy ship path following but great when connecting the points with lines.
When using OR the data points are perfect for path following.
Code: (Select All)
TYPE POINT
x AS INTEGER
y AS INTEGER
END TYPE
DIM Curve(3) AS POINT
REDIM Path(1) AS POINT
DIM p AS POINT
Curve(0).x = 0
Curve(0).y = 479
Curve(1).x = 639
Curve(1).y = 239
Curve(2).x = 0
Curve(2).y = 239
Curve(3).x = 639
Curve(3).y = 0
SCREEN _NEWIMAGE(640, 480, 32)
Detail = .0001
t = 0
DO
CurvePoint Curve(), p, t
IF p.x <> Path(UBOUND(Path) - 1).x OR p.y <> Path(UBOUND(Path) - 1).y THEN ' OR can be changed to AND for different results
Path(UBOUND(Path)) = p
REDIM _PRESERVE Path(UBOUND(Path) + 1) AS POINT
PSET (p.x, p.y)
END IF
t = t + Detail
LOOP UNTIL t > 1
'PSET (Path(1).x, Path(1).y) ' Draw lines instead when using AND above (very smooth)
'FOR i = 2 TO UBOUND(Path) - 1 ' OR yeilds 1102 points
' LINE -(Path(i).x, Path(i).y) ' AND yields 368 points that need to be connected with lines
'NEXT i
PRINT UBOUND(Path) - 1
SLEEP
SUB CurvePoint (c() AS POINT, p AS POINT, t AS SINGLE)
'Quick and dirty Bezier point calculator
'Note: only works for 4 points
DIM a AS SINGLE
DIM b AS SINGLE
DIM c AS SINGLE
DIM d AS SINGLE
a = (1 - t) * (1 - t) * (1 - t)
b = 3 * (1 - t) * (1 - t) * t
c = 3 * (1 - t) * t * t
d = t * t * t
p.x = a * c(0).x + b * c(1).x + c * c(2).x + d * c(3).x
p.y = a * c(0).y + b * c(1).y + c * c(2).y + d * c(3).y
'p.x = (1 - t) * (1 - t) * (1 - t) * c(0).x + 3 * (1 - t) * (1 - t) * t * c(1).x + 3 * (1 - t) * t * t * c(2).x + t * t * t * c(3).x
'p.y = (1 - t) * (1 - t) * (1 - t) * c(0).y + 3 * (1 - t) * (1 - t) * t * c(1).y + 3 * (1 - t) * t * t * c(2).y + t * t * t * c(3).y
END SUB