Hi,
This is heavily inspired by Shockwave as I love the effect so much.
What the problem is, is that the drawing of the image \ texture isnt being rendered properly. I'd would love to see what's not quite right.
' textured twister.
' based on code kindly produced and written by shockwave^codigos
' uses tinyptc extension++.bi by rbz^codigos
'
option static
option explicit
#include once "tinyptc_ext++.bi"
const as single PI = 3.141593
const as single DEGREES = ( PI / 180.00 )
const as integer MONITOR_SPEED = 60
type graphics_buffer
as integer wwidth, height
as integer wwidth2, height2
as uinteger ptr pixels
end type
declare sub clear_graphics_buffer ( byval buffer as graphics_buffer ptr, byval argb as uinteger=0 )
declare sub run_demo ()
declare sub init_demo ()
declare sub update_twisty ( byval dest as graphics_buffer ptr,_
byval texture as graphics_buffer ptr,_
byval bar_wwidth as integer=150)
declare function create_graphics_buffer( byval wwidth as integer, byval height as integer ) as graphics_buffer ptr
declare function graphics ( byval title as string,_
byval wwidth as integer,_
byval height as integer,_
byval options as integer=0 ) as graphics_buffer ptr
dim shared as single sinus_add1, sinus_add2
dim shared as single old_time, new_time, delta
dim shared as graphics_buffer ptr screen_buffer, image_buffer
init_demo ()
run_demo ()
ptc_close ()
sub clear_graphics_buffer(byval buffer as graphics_buffer ptr, byval argb as uinteger=0 )
dim as uinteger ptr pixel =buffer->pixels
dim as integer length=buffer->wwidth*buffer->height
asm
mov eax,dword ptr[argb]
mov ecx,dword ptr[length]
mov edi,dword ptr[pixel]
rep stosd
end asm
end sub
sub init_demo()
screen_buffer =graphics("twiST aND shOUt", 640, 480 )
image_buffer =create_graphics_buffer( 128, screen_buffer->height )
for y as integer=1 to image_buffer->height-2
for x as integer=1 to image_buffer->wwidth-2
image_buffer->pixels[ x+y*image_buffer->wwidth ]=&hf064f0
next
next
end sub
sub run_demo()
while inkey<>chr(27)
old_time=timer()
clear_graphics_buffer( screen_buffer )
update_twisty ( screen_buffer, image_buffer )
ptc_update ( @screen_buffer->pixels[0] )
new_time = (timer()-old_time)+.01
delta = new_time*MONITOR_SPEED
wend
end sub
sub update_twisty( byval dest as graphics_buffer ptr, byval texture as graphics_buffer ptr, byval bar_wwidth as integer=150 )
dim as integer x, scanline_y,x1,x2,x3,x4, pos_x, v
dim as integer sinus, sinus_wwidth1, sinus_wwidth2, wwidth2
dim as uinteger colour
dim as uinteger ptr dest_ptr
dim as single inc_y, add_y
sinus_add1+=0.32 * delta
sinus_add2+=0.16 * delta
sinus_wwidth1=15+14*sin( sinus_add2 * DEGREES )
sinus_wwidth2=15+14*cos( sinus_add1 * DEGREES )
add_y=0.83*sin( sinus_add1 * DEGREES )
wwidth2=dest->wwidth2
for scanline_y=0 to dest->height-1
sinus=sin(( scanline_y - sinus_add2 ) * DEGREES )*sinus_wwidth1 + cos(( scanline_y+sinus_add1 )*DEGREES )*sinus_wwidth2
x1=wwidth2+sinus+( bar_wwidth * sin(( sinus_add1+ inc_y ) * DEGREES ))
x2=wwidth2+sinus+( bar_wwidth * sin(( sinus_add1+ 90+inc_y ) * DEGREES ))
x3=wwidth2+sinus+( bar_wwidth * sin(( sinus_add1+180+inc_y ) * DEGREES ))
x4=wwidth2+sinus+( bar_wwidth * sin(( sinus_add1+270+inc_y ) * DEGREES ))
if x2>x1 then
dest_ptr=@dest->pixels[ x1 + scanline_y * dest->wwidth ]
pos_x =0
for x=x1 to x2
*dest_ptr=texture->pixels[ pos_x + scanline_y * texture->wwidth ]
dest_ptr +=1
pos_x +=1
next
end if
if x3>x2 then
dest_ptr=@dest->pixels[ x2 + scanline_y * dest->wwidth ]
pos_x=0
for x=x2 to x3
*dest_ptr=texture->pixels[ pos_x + scanline_y * texture->wwidth ]
dest_ptr +=1
pos_x+=1
next
end if
if x4>x3 then
v=(x4-x3) '* 2
colour=rgb(v,0,v)
for x=x3 to x4
dest->pixels[ x+scanline_y*dest->wwidth ]=colour
next
end if
if x1>x4 then
v=(x1-x4) '*2
colour=rgb(0,v,0)
for x=x4 to x1
dest->pixels[ x+scanline_y*dest->wwidth ]=colour
next
end if
inc_y+=add_y
next
end sub
function create_graphics_buffer( byval wwidth as integer, byval height as integer ) as graphics_buffer ptr
dim as graphics_buffer ptr buffer=callocate(len(graphics_buffer)+len(uinteger)*wwidth*height)
buffer->wwidth = wwidth
buffer->height = height
buffer->wwidth2= wwidth \ 2
buffer->height2= height \ 2
buffer->pixels = cast( uinteger ptr, cast( byte ptr, buffer )+len(graphics_buffer))
return buffer
end function
function graphics( byval title as string, byval wwidth as integer, byval height as integer, byval options as integer=0 ) as graphics_buffer ptr
if options=0 then
ptc_setdialog(1,"would you prefer full screen dude?",0,0)
else
ptc_setdialog(0,"",0,1)
end if
ptc_allowclose(1)
if ( ptc_open ( title, wwidth, height ) = 0 ) then
end -1
end if
return create_graphics_buffer(wwidth,height)
end function
Cheers heaps,
Clyde.