Petr Schreiber
23-01-2007, 21:06
Hi kryton9,
thanks for nice words. It is almost just trial an error :)
Optimize your and Eros version of effect makes my head really pressed ;)
100 x 136 objects/points = 13 600 as Eros said. If I will do it by polygons, I can get 13 600 quads, which does mean quite high number of vertices. And now set them properties dynamically ... trouble.
It is very interesting problem. When optimized using lists, you will get super framerate ( thousands of FPS ).
But it is static. I tried to do the same effect via virtual model, but it was still quite slow.
Meanwhile, I will continue in stream of "script associations" and add another variation : Crazy electrons/photons/...
You will see how fast are cached points and how to perform fake blur of points using ... lines :)
On my box it runs at 53 FPS
'
' More crazy points 1.1
'
Uses "TBGL"
Uses "UI"
randomize timer ' -- Seed for random number is given by time
DIM hWnd as dword
' TBGL 0.1.8 shiny new window creation, just change 0 to 1 to get fullscreen ;)
hWnd = tbgl_CreateWindowex ("Crazy points", 800, 600, 32, 0)
tbgl_ShowWindow ' This will display the window on the screen
tbgl_SetDrawDistance 500
dim cx,cy,cz as long
dim squareSideHalf as long = 50
tbgl_NewList 1
tbgl_BeginPoly %GL_points
for cx = -squareSideHalf to squareSideHalf
for cz = -squareSideHalf to squareSideHalf
tbgl_color 0, 75 + rnd(1, 130), 0
tbgl_Vertex cx, SurfaceEquation( cx, cz ), cz
next
next
tbgl_EndPoly
tbgl_EndList
type electronXY
x as single
y as single
z as single
dx as single ' Destination
dy as single
dz as single
end type
dim NumElectrons as long = 64
dim Electron(NumElectrons) as electronXY
dim i as long
for i = 1 to NumElectrons
BornParticle (i, rnd(-squareSideHalf, squareSideHalf), 100, rnd(-squareSideHalf, squareSideHalf))
next
dim FrameRate as single
dim Distance as single
GetAsyncKeyState %VK_ESCAPE ' Reset status of the ESCAPE to prevent immediate quit
dim oldx, oldy, oldz as single
dim CountSheeps as long
tbgl_LineWidth 3
while IsWindow (hWnd) ' While window exists, we will draw and check for ESCAPE
FrameRate = tbgl_getFrameRate
incr CountSheeps
if CountSheeps = 250 then
win_settitle(hWnd, "Crazy points: " & FrameRate & " FPS")
CountSheeps = 0
end if
tbgl_ClearFrame ' This clears the frame and prepares it for drawing
tbgl_Camera 0, 60, 100, 0, 10, 0
TBGL_Rotate GetTickCount/80, 0, 1, 0
tbgl_CallList 1
tbgl_UseBlend 1 ' Because of particle tail fading out
tbgl_BeginPoly %GL_LINES
for i = 1 to NumElectrons
oldx = Electron(i).x
oldy = Electron(i).y
oldz = Electron(i).z
' Is electron in its destination ?
if Electron(i).x + 1 > Electron(i).dx and Electron(i).x - 1 < Electron(i).dx and _
Electron(i).y + 1 > Electron(i).dy and Electron(i).y - 1 < Electron(i).dy and _
Electron(i).z + 1 > Electron(i).dz and Electron(i).z - 1 < Electron(i).dz then
Electron(i).dx = rnd(-squareSideHalf, squareSideHalf)
Electron(i).dz = rnd(-squareSideHalf, squareSideHalf)
Electron(i).dy = SurfaceEquation( Electron(i).dx, Electron(i).dz )
end if
' ... if not, he must approach
if Electron(i).x < Electron(i).dx then
Electron(i).x += abs(Electron(i).dx - Electron(i).x)/FrameRate*2
elseif Electron(i).x > Electron(i).dx then
Electron(i).x -= abs(Electron(i).x - Electron(i).dx)/FrameRate*2
end if
if Electron(i).z < Electron(i).dz then
Electron(i).z += abs(Electron(i).dz - Electron(i).z)/FrameRate*2
elseif Electron(i).z > Electron(i).dz then
Electron(i).z -= abs(Electron(i).z - Electron(i).dz)/FrameRate*2
end if
' Surface equation
Electron(i).y = SurfaceEquation( Electron(i).x, Electron(i).z )
' Tail
tbgl_Color 0,0,0
tbgl_Vertex Electron(i).x + (oldx-Electron(i).x)*5, Electron(i).y + (oldy-Electron(i).y)*5, Electron(i).z + (oldz-Electron(i).z)*5
' Head
tbgl_Color 255,128,0
tbgl_Vertex Electron(i).x, Electron(i).y, Electron(i).z
next
tbgl_EndPoly
tbgl_UseBlend 0
tbgl_DrawFrame ' This will display the scene
' -- Key checking
IF GetWindowKeyState( hWnd, %VK_ESCAPE ) THEN EXIT while
sleep 0
Wend
tbgl_DestroyWindow ' This will destroy the window
function SurfaceEquation( byval x as single, byval z as single ) as single
x /= 10
z /= 10
'function = x^4 - z^4
'function = x^4 + z^4
'function = cos(x^2 + z^2)*4
'function = sin(abs(x^2) - abs(z^4))
function = -1 / iif(x^2 + z^2=0, 1, x^2 + z^2)*50
'function = X^2 + z^2 + Z^3 - x^3
'function = cos(x+z)*5
'function = (cos(x^2 - z)*5)
'function = (cos(abs( x ) + abs( z ))*5)
'function = (cos(x/10*abs( x) + abs( z))*5)*z
'function = (x^2+x+1+z^3+10)/(z+x+6.1)
end function
sub BornParticle( e as long, x as single, y as single, z as single)
Electron(e).x = x
Electron(e).y = y
Electron(e).z = z
Electron(e).dx = rnd(-squareSideHalf, squareSideHalf)
Electron(e).dz = rnd(-squareSideHalf, squareSideHalf)
Electron(e).dy = SurfaceEquation( Electron(e).dx, Electron(e).dz )
end sub
Bye,
Petr
thanks for nice words. It is almost just trial an error :)
Optimize your and Eros version of effect makes my head really pressed ;)
100 x 136 objects/points = 13 600 as Eros said. If I will do it by polygons, I can get 13 600 quads, which does mean quite high number of vertices. And now set them properties dynamically ... trouble.
It is very interesting problem. When optimized using lists, you will get super framerate ( thousands of FPS ).
But it is static. I tried to do the same effect via virtual model, but it was still quite slow.
Meanwhile, I will continue in stream of "script associations" and add another variation : Crazy electrons/photons/...
You will see how fast are cached points and how to perform fake blur of points using ... lines :)
On my box it runs at 53 FPS
'
' More crazy points 1.1
'
Uses "TBGL"
Uses "UI"
randomize timer ' -- Seed for random number is given by time
DIM hWnd as dword
' TBGL 0.1.8 shiny new window creation, just change 0 to 1 to get fullscreen ;)
hWnd = tbgl_CreateWindowex ("Crazy points", 800, 600, 32, 0)
tbgl_ShowWindow ' This will display the window on the screen
tbgl_SetDrawDistance 500
dim cx,cy,cz as long
dim squareSideHalf as long = 50
tbgl_NewList 1
tbgl_BeginPoly %GL_points
for cx = -squareSideHalf to squareSideHalf
for cz = -squareSideHalf to squareSideHalf
tbgl_color 0, 75 + rnd(1, 130), 0
tbgl_Vertex cx, SurfaceEquation( cx, cz ), cz
next
next
tbgl_EndPoly
tbgl_EndList
type electronXY
x as single
y as single
z as single
dx as single ' Destination
dy as single
dz as single
end type
dim NumElectrons as long = 64
dim Electron(NumElectrons) as electronXY
dim i as long
for i = 1 to NumElectrons
BornParticle (i, rnd(-squareSideHalf, squareSideHalf), 100, rnd(-squareSideHalf, squareSideHalf))
next
dim FrameRate as single
dim Distance as single
GetAsyncKeyState %VK_ESCAPE ' Reset status of the ESCAPE to prevent immediate quit
dim oldx, oldy, oldz as single
dim CountSheeps as long
tbgl_LineWidth 3
while IsWindow (hWnd) ' While window exists, we will draw and check for ESCAPE
FrameRate = tbgl_getFrameRate
incr CountSheeps
if CountSheeps = 250 then
win_settitle(hWnd, "Crazy points: " & FrameRate & " FPS")
CountSheeps = 0
end if
tbgl_ClearFrame ' This clears the frame and prepares it for drawing
tbgl_Camera 0, 60, 100, 0, 10, 0
TBGL_Rotate GetTickCount/80, 0, 1, 0
tbgl_CallList 1
tbgl_UseBlend 1 ' Because of particle tail fading out
tbgl_BeginPoly %GL_LINES
for i = 1 to NumElectrons
oldx = Electron(i).x
oldy = Electron(i).y
oldz = Electron(i).z
' Is electron in its destination ?
if Electron(i).x + 1 > Electron(i).dx and Electron(i).x - 1 < Electron(i).dx and _
Electron(i).y + 1 > Electron(i).dy and Electron(i).y - 1 < Electron(i).dy and _
Electron(i).z + 1 > Electron(i).dz and Electron(i).z - 1 < Electron(i).dz then
Electron(i).dx = rnd(-squareSideHalf, squareSideHalf)
Electron(i).dz = rnd(-squareSideHalf, squareSideHalf)
Electron(i).dy = SurfaceEquation( Electron(i).dx, Electron(i).dz )
end if
' ... if not, he must approach
if Electron(i).x < Electron(i).dx then
Electron(i).x += abs(Electron(i).dx - Electron(i).x)/FrameRate*2
elseif Electron(i).x > Electron(i).dx then
Electron(i).x -= abs(Electron(i).x - Electron(i).dx)/FrameRate*2
end if
if Electron(i).z < Electron(i).dz then
Electron(i).z += abs(Electron(i).dz - Electron(i).z)/FrameRate*2
elseif Electron(i).z > Electron(i).dz then
Electron(i).z -= abs(Electron(i).z - Electron(i).dz)/FrameRate*2
end if
' Surface equation
Electron(i).y = SurfaceEquation( Electron(i).x, Electron(i).z )
' Tail
tbgl_Color 0,0,0
tbgl_Vertex Electron(i).x + (oldx-Electron(i).x)*5, Electron(i).y + (oldy-Electron(i).y)*5, Electron(i).z + (oldz-Electron(i).z)*5
' Head
tbgl_Color 255,128,0
tbgl_Vertex Electron(i).x, Electron(i).y, Electron(i).z
next
tbgl_EndPoly
tbgl_UseBlend 0
tbgl_DrawFrame ' This will display the scene
' -- Key checking
IF GetWindowKeyState( hWnd, %VK_ESCAPE ) THEN EXIT while
sleep 0
Wend
tbgl_DestroyWindow ' This will destroy the window
function SurfaceEquation( byval x as single, byval z as single ) as single
x /= 10
z /= 10
'function = x^4 - z^4
'function = x^4 + z^4
'function = cos(x^2 + z^2)*4
'function = sin(abs(x^2) - abs(z^4))
function = -1 / iif(x^2 + z^2=0, 1, x^2 + z^2)*50
'function = X^2 + z^2 + Z^3 - x^3
'function = cos(x+z)*5
'function = (cos(x^2 - z)*5)
'function = (cos(abs( x ) + abs( z ))*5)
'function = (cos(x/10*abs( x) + abs( z))*5)*z
'function = (x^2+x+1+z^3+10)/(z+x+6.1)
end function
sub BornParticle( e as long, x as single, y as single, z as single)
Electron(e).x = x
Electron(e).y = y
Electron(e).z = z
Electron(e).dx = rnd(-squareSideHalf, squareSideHalf)
Electron(e).dz = rnd(-squareSideHalf, squareSideHalf)
Electron(e).dy = SurfaceEquation( Electron(e).dx, Electron(e).dz )
end sub
Bye,
Petr