ok, I posted this code in the thread about sin waves (it got off topic I think)
Basically, I was wondering what kinda speed "3d lines" have if you use a triangle with 2 points on the same spot.
sync on
sync rate 0
randomize timer()
backdrop on
color backdrop 0
set text font "Courier New"
set text size 18
CURVE_COUNT = 3
CURVE_SEGMENTS = 8
#constant ARENA_SIZE 10.0
#constant LINE_SPEED 10.0
make object cube 1, ARENA_SIZE * 2.0
position object 1, 0, 0 ,0
color object 1, rgb(128,128,128)
set alpha mapping on 1, 10
set object transparency 1, 3
Status = 1
camDist# = ARENA_SIZE * 4.0
mouseDown = 0
START:
dim Curves(CURVE_COUNT) as CurveData
temp = make vector3(1)
for i = 1 to CURVE_COUNT + 1
curveOffset = i * 100
if i <= CURVE_COUNT
`SET RANDOM START POINT
Curves(i).A.Pos.X# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).A.Pos.Y# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).A.Pos.Z# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).B.Pos.X# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).B.Pos.Y# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).B.Pos.Z# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).C.Pos.X# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).C.Pos.Y# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).C.Pos.Z# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).D.Pos.X# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).D.Pos.Y# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
Curves(i).D.Pos.Z# = rnd(ARENA_SIZE+ARENA_SIZE)-ARENA_SIZE
`SET RANDOM VELOCITY
Curves(i).A.Vel.X# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).A.Vel.Y# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).A.Vel.Z# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).B.Vel.X# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).B.Vel.Y# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).B.Vel.Z# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).C.Vel.X# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).C.Vel.Y# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).C.Vel.Z# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).D.Vel.X# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).D.Vel.Y# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).D.Vel.Z# = rnd(LINE_SPEED+LINE_SPEED)-LINE_SPEED
Curves(i).col = rgb(rnd(255),rnd(255),rnd(255))
for j = 0 to CURVE_SEGMENTS
obj = j + curveOffset
if j < CURVE_SEGMENTS
t# = j * 1.0 / CURVE_SEGMENTS
x1# = CubicBezier(Curves(i).A.Pos.X#, Curves(i).B.Pos.X#, Curves(i).C.Pos.X#, Curves(i).D.Pos.X#, t#)
y1# = CubicBezier(Curves(i).A.Pos.Y#, Curves(i).B.Pos.Y#, Curves(i).C.Pos.Y#, Curves(i).D.Pos.Y#, t#)
z1# = CubicBezier(Curves(i).A.Pos.Z#, Curves(i).B.Pos.Z#, Curves(i).C.Pos.Z#, Curves(i).D.Pos.Z#, t#)
t# = (j+1.0) * 1.0 / CURVE_SEGMENTS
x2# = CubicBezier(Curves(i).A.Pos.X#, Curves(i).B.Pos.X#, Curves(i).C.Pos.X#, Curves(i).D.Pos.X#, t#)
y2# = CubicBezier(Curves(i).A.Pos.Y#, Curves(i).B.Pos.Y#, Curves(i).C.Pos.Y#, Curves(i).D.Pos.Y#, t#)
z2# = CubicBezier(Curves(i).A.Pos.Z#, Curves(i).B.Pos.Z#, Curves(i).C.Pos.Z#, Curves(i).D.Pos.Z#, t#)
if object exist(obj) then delete object obj
set vector3 1, x1# - x2#, y1# - y2#, z1# - z2#
make object triangle obj, 0,0,0, 0,0,0, 0, 0, 1.0
scale object obj, 100.0, 100.0, 100.0 * length vector3(1)
position object obj, x1#, y1#, z1#
point object obj, x2#, y2#, z2#
set object wireframe obj,1
set object emissive obj, Curves(i).col
`color object obj, Curves(i).col
else
if object exist(obj) then delete object obj
endif
next j
else
for j = 0 to CURVE_SEGMENTS-1
obj =j + curveOffset
if object exist(obj) then delete object obj
next j
endif
next i
autocam off
positionCamera(wrapvalue(mousex()), wrapvalue(mousey()), camDist#,)
frameTime# = 1.0
startTime = timer()
do
frameTime# = (frameTime# * 0.8) + ((timer() - startTime) * 0.2)
startTime = timer()
text 10, 10, "FPS: " + str$(screen fps())
text 30, 30, "Curves: " + str$(CURVE_COUNT)
text 30, 50, "Number of Segments Per Curve: " + str$(CURVE_SEGMENTS)
text 30, 70, "Camera Distance: " + str$(camDist#)
text 5, 10 + (Status * 20), "->"
mmz = mousemovez()
if mmz <> 0
if mmz > 0
dec Status
if Status < 1 then Status = 3
endif
if mmz < 0
inc Status
if Status > 3 then Status = 1
endif
endif
if mouseclick() > 0
restart = 0
select Status
case 1
if mouseDown = 0
restart = 1
if mouseclick() = 1 then inc CURVE_COUNT else if mouseclick() = 2 AND CURVE_COUNT > 1 then dec CURVE_COUNT else restart = 0
mouseDown = 1
endif
endcase
case 2
if mouseDown = 0
restart = 1
if mouseclick() = 1 then inc CURVE_SEGMENTS else if mouseclick() = 2 AND CURVE_SEGMENTS > 1 then dec CURVE_SEGMENTS else restart = 0
mouseDown = 1
endif
endcase
case 3
if mouseclick() = 1 then inc camDist#, frameTime# * 0.05 else inc camDist#, frameTime# * -0.05
positionCamera(wrapvalue(mousex()), wrapvalue(mousey()), camDist#,)
endcase
endselect
if restart = 1 then goto START
else
if mouseDown = 1 then mouseDown = 0
endif
if mousemovey()<> 0 OR mousemovex() <> 0 then positionCamera(wrapvalue(mousex()), wrapvalue(mousey()), camDist#,)
gosub ANIMATE_CURVE
sync
loop
end
ANIMATE_CURVE:
for i = 1 to CURVE_COUNT
ft# = frameTime# * 0.001
inc Curves(i).A.Pos.X#, Curves(i).A.Vel.X# * ft#
inc Curves(i).A.Pos.Y#, Curves(i).A.Vel.Y# * ft#
inc Curves(i).A.Pos.Z#, Curves(i).A.Vel.Z# * ft#
inc Curves(i).B.Pos.X#, Curves(i).B.Vel.X# * ft#
inc Curves(i).B.Pos.Y#, Curves(i).B.Vel.Y# * ft#
inc Curves(i).B.Pos.Z#, Curves(i).B.Vel.Z# * ft#
inc Curves(i).C.Pos.X#, Curves(i).C.Vel.X# * ft#
inc Curves(i).C.Pos.Y#, Curves(i).C.Vel.Y# * ft#
inc Curves(i).C.Pos.Z#, Curves(i).C.Vel.Z# * ft#
inc Curves(i).D.Pos.X#, Curves(i).D.Vel.X# * ft#
inc Curves(i).D.Pos.Y#, Curves(i).D.Vel.Y# * ft#
inc Curves(i).D.Pos.Z#, Curves(i).D.Vel.Z# * ft#
if (Curves(i).A.Pos.X# > ARENA_SIZE AND Curves(i).A.Vel.X# > 0) OR (Curves(i).A.Pos.X# < -ARENA_SIZE AND Curves(i).A.Vel.X# < 0) then Curves(i).A.Vel.X# = -Curves(i).A.Vel.X#
if (Curves(i).A.Pos.Y# > ARENA_SIZE AND Curves(i).A.Vel.Y# > 0) OR (Curves(i).A.Pos.Y# < -ARENA_SIZE AND Curves(i).A.Vel.Y# < 0) then Curves(i).A.Vel.Y# = -Curves(i).A.Vel.Y#
if (Curves(i).A.Pos.Z# > ARENA_SIZE AND Curves(i).A.Vel.Z# > 0) OR (Curves(i).A.Pos.Z# < -ARENA_SIZE AND Curves(i).A.Vel.Z# < 0) then Curves(i).A.Vel.Z# = -Curves(i).A.Vel.Z#
if (Curves(i).B.Pos.X# > ARENA_SIZE AND Curves(i).B.Vel.X# > 0) OR (Curves(i).B.Pos.X# < -ARENA_SIZE AND Curves(i).B.Vel.X# < 0) then Curves(i).B.Vel.X# = -Curves(i).B.Vel.X#
if (Curves(i).B.Pos.Y# > ARENA_SIZE AND Curves(i).B.Vel.Y# > 0) OR (Curves(i).B.Pos.Y# < -ARENA_SIZE AND Curves(i).B.Vel.Y# < 0) then Curves(i).B.Vel.Y# = -Curves(i).B.Vel.Y#
if (Curves(i).B.Pos.Z# > ARENA_SIZE AND Curves(i).B.Vel.Z# > 0) OR (Curves(i).B.Pos.Z# < -ARENA_SIZE AND Curves(i).B.Vel.Z# < 0) then Curves(i).B.Vel.Z# = -Curves(i).B.Vel.Z#
if (Curves(i).C.Pos.X# > ARENA_SIZE AND Curves(i).C.Vel.X# > 0) OR (Curves(i).C.Pos.X# < -ARENA_SIZE AND Curves(i).C.Vel.X# < 0) then Curves(i).C.Vel.X# = -Curves(i).C.Vel.X#
if (Curves(i).C.Pos.Y# > ARENA_SIZE AND Curves(i).C.Vel.Y# > 0) OR (Curves(i).C.Pos.Y# < -ARENA_SIZE AND Curves(i).C.Vel.Y# < 0) then Curves(i).C.Vel.Y# = -Curves(i).C.Vel.Y#
if (Curves(i).C.Pos.Z# > ARENA_SIZE AND Curves(i).C.Vel.Z# > 0) OR (Curves(i).C.Pos.Z# < -ARENA_SIZE AND Curves(i).C.Vel.Z# < 0) then Curves(i).C.Vel.Z# = -Curves(i).C.Vel.Z#
if (Curves(i).D.Pos.X# > ARENA_SIZE AND Curves(i).D.Vel.X# > 0) OR (Curves(i).D.Pos.X# < -ARENA_SIZE AND Curves(i).D.Vel.X# < 0) then Curves(i).D.Vel.X# = -Curves(i).D.Vel.X#
if (Curves(i).D.Pos.Y# > ARENA_SIZE AND Curves(i).D.Vel.Y# > 0) OR (Curves(i).D.Pos.Y# < -ARENA_SIZE AND Curves(i).D.Vel.Y# < 0) then Curves(i).D.Vel.Y# = -Curves(i).D.Vel.Y#
if (Curves(i).D.Pos.Z# > ARENA_SIZE AND Curves(i).D.Vel.Z# > 0) OR (Curves(i).D.Pos.Z# < -ARENA_SIZE AND Curves(i).D.Vel.Z# < 0) then Curves(i).D.Vel.Z# = -Curves(i).D.Vel.Z#
curveOffset = i * 100
for j = 0 to CURVE_SEGMENTS-1
t# = j * 1.0 / CURVE_SEGMENTS
x1# = CubicBezier(Curves(i).A.Pos.X#, Curves(i).B.Pos.X#, Curves(i).C.Pos.X#, Curves(i).D.Pos.X#, t#)
y1# = CubicBezier(Curves(i).A.Pos.Y#, Curves(i).B.Pos.Y#, Curves(i).C.Pos.Y#, Curves(i).D.Pos.Y#, t#)
z1# = CubicBezier(Curves(i).A.Pos.Z#, Curves(i).B.Pos.Z#, Curves(i).C.Pos.Z#, Curves(i).D.Pos.Z#, t#)
t# = (j+1.0) * 1.0 / CURVE_SEGMENTS
x2# = CubicBezier(Curves(i).A.Pos.X#, Curves(i).B.Pos.X#, Curves(i).C.Pos.X#, Curves(i).D.Pos.X#, t#)
y2# = CubicBezier(Curves(i).A.Pos.Y#, Curves(i).B.Pos.Y#, Curves(i).C.Pos.Y#, Curves(i).D.Pos.Y#, t#)
z2# = CubicBezier(Curves(i).A.Pos.Z#, Curves(i).B.Pos.Z#, Curves(i).C.Pos.Z#, Curves(i).D.Pos.Z#, t#)
obj = j + curveOffset
set vector3 1, x1# - x2#, y1# - y2#, z1# - z2#
position object obj, x1#, y1#, z1#
point object obj, x2#, y2#, z2#
scale object obj, 100.0, 100.0, 100.0 * length vector3(1)
next j
next i
return
function positionCamera(a#, p#, d#)
position camera cos(a#)*sin(p#)*d#, cos(p#)*d#, sin(a#)*sin(p#)*d#
point camera 0,0,0
endfunction
function CubicBezier(A#, B#, C#, D#, T#)
invT# = 1.0 - T#
result# = (A# * invT# * invT# * invT#) + (3.0 * B# * invT# * invT# * T#) + (3.0 * C# * invT# * T# * T#) + (D# * T# * T# * T#)
endfunction result#
type Coord
X#
Y#
Z#
endtype
type PointData
Pos as Coord
Vel as Coord
endtype
type CurveData
A as PointData
B as PointData
C as PointData
D as PointData
col as DWORD
endtype
This is a little demo of Cubic Bezier curves.
My "benchmark":
Spec: AMD Barton 3200+, 1Gb DDR 400, 9800XT 256Mb RAM (Nothing overclocked)
Settings: 16 curves, 24 segments, 163FPS
Controls:
scroll the mouse up and down to change option on the menu
click left to increase
click right to decrease
move mouse left/right/up/down to move around the "cube" in a spherical way.
What do people think?
Cheers,
Nick
PS: I was thinking of putting this in WIP, but its not.. IT was a little demo, its not really "work"...
edit:
Screeny:
edit 2: btw: those lines are actually in 3D.. They're not 2D lines on the screen
My Website: