snelle 3D punten grafiek

Algemene discussies en vragen omtrent Liberty BASIC programma's. Stuur zoveel mogelijk delen van listings (snippets) in als je hulp wilt.

Moderators: anthonio, Abcott

snelle 3D punten grafiek

Berichtdoor bluatigro » wo okt 29, 2014 1:34 pm

Code: Selecteer alles
''bluatigro 29-okt-2014
''point world 3D
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , pi , max
max = 500
dim p( max , 2 )
winx = WindowWidth
winy = WindowHeight
pi = atn( 1 ) * 4
nomainwin
open "3D point world 1.0" for graphics as #m
  #m "trapclose [quit]"
  #m "goto 0 0"
  #m "backcolor black"
  #m "down"
  #m "boxfilled 2 4"
  #m "up"
  #m "getbmp point 0 0 2 4"
  prompt "scene [ 0 , 1 ] = " ; q$
  scene = val( q$ )
  for i = 0 to max
    #m "addsprite spr" ; i ; " point"
    #m "spritescale spr" ; i ; " 200"
    if scene = 1 then
      p( i , 0 ) = sin( rad( i * 360 / max * 2 ) ) * 300
      p( i , 1 ) = sin( rad( i * 360 / max * 3 ) ) * 300
      p( i , 2 ) = sin( rad( i * 360 / max * 5 ) ) * 300
    else
      for t = 0 to 2
        p( i , t ) = range( -300 , 300 )
      next t
    end if
  next i
  #m "setfocus"
  #m "when characterInput [key]"
  timer 40 , [tmr]
wait
[key]
  key$ = Inkey$
  if key$ = chr$( 27 ) then
    close #m
    end
  end if
wait
[tmr]
  scan
  for i = 0 to max
    x = p( i , 0 )
    y = p( i , 1 )
    z = p( i , 2 )
    call rotate x , z , 5
    call rotate y , z , 4
    call rotate x , y , 3
    p( i , 0 ) = x
    p( i , 1 ) = y
    p( i , 2 ) = z
    #m "spritexy spr" ; i ; " " _
    ; winx / 2 + p( i , 0 ) ; " " _
    ; winy / 2 - p( i , 1 )
  next i
  #m "drawsprites"
wait
[quit]
  close #m
end
sub rotate byref k , byref l , deg
  s = sin( rad( deg ) )
  c = cos( rad( deg ) )
  hk = k * c - l * s
  hl = k * s + l * c
  k = hk
  l = hl
end sub
function rad( deg )
  rad = deg * pi / 180
end function
function range( l , h )
  range = rnd(0) * ( h - l ) + l
end function
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: snelle 3D punten grafiek

Berichtdoor bluatigro » do okt 30, 2014 4:14 pm

update :
- nog sneller
- je kan nu zelf de vehoudingen kiezen
Code: Selecteer alles
''bluatigro 29-okt-2014
''point world 3D
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , pi , max
max = 500
dim p( max , 2 ) , s( 10 ) , c( 10 )
winx = WindowWidth
winy = WindowHeight
pi = atn( 1 ) * 4
for i = 1 to 5
  s( i ) = sin( rad( i ) )
  c( i ) = cos( rad( i ) )
next i
nomainwin
open "3D point world 1.0" for graphics as #m
  #m "trapclose [quit]"
  #m "goto 0 0"
  #m "backcolor black"
  #m "down"
  #m "boxfilled 2 4"
  #m "up"
  #m "getbmp point 0 0 2 4"
  x$ = "3"
  prompt "speed x = "; x$
  x = val( x$ )
  y$ = "4"
  prompt "speed y = "; y$
  y = val( y$ )
  z$ = "5"
  prompt "speed z = "; z$
  z = val( z$ )
  for i = 0 to max
    #m "addsprite spr" ; i ; " point"
    #m "spritescale spr" ; i ; " 200"
    p( i , 0 ) = sin( rad( i * 360 / max * x ) ) * 300
    p( i , 1 ) = sin( rad( i * 360 / max * y ) ) * 300
    p( i , 2 ) = sin( rad( i * 360 / max * z ) ) * 300
  next i
  #m "setfocus"
  #m "when characterInput [key]"
  timer 40 , [tmr]
wait
[key]
  key$ = Inkey$
  if key$ = chr$( 27 ) then
    close #m
    end
  end if
wait
[tmr]
  scan
  for i = 0 to max
    x = p( i , 0 )
    y = p( i , 1 )
    z = p( i , 2 )
    call rotate x , z , 5
    call rotate y , z , 4
    call rotate x , y , 3
    p( i , 0 ) = x
    p( i , 1 ) = y
    p( i , 2 ) = z
    #m "spritexy spr" ; i ; " " _
    ; int( winx / 2 + p( i , 0 ) ) ; " " _
    ; int( winy / 2 - p( i , 1 ) )
  next i
  #m "drawsprites"
wait
[quit]
  close #m
end
sub rotate byref k , byref l , deg
  s = s( deg )
  c = c( deg )
  hk = k * c - l * s
  hl = k * s + l * c
  k = hk
  l = hl
end sub
function rad( deg )
  rad = deg * pi / 180
end function
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: snelle 3D punten grafiek

Berichtdoor bluatigro » vr okt 31, 2014 1:18 pm

update :
- nu is t n simpel race spel
Code: Selecteer alles
''bluatigro 29-okt-2014
''point world 3D race
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , pi , max , tel , key$ , cx , cy , cz , cangle
winx = WindowWidth
winy = WindowHeight
cx = 280
cy = winy / 2 - 100
cz = 0
cangle = 0
max = 500
dim p( max , 2 )
pi = atn( 1 ) * 4
nomainwin
open "3D point world race 1.0" for graphics as #m
  #m "trapclose [quit]"
  #m "goto 0 0"
  #m "backcolor black"
  #m "down"
  #m "boxfilled 2 4"
  #m "up"
  #m "getbmp point 0 0 2 4"
  for i = 0 to max / 2
    #m "addsprite road" ; i ; " point"
    #m "spritescale road" ; i ; " 200"
    #m "addsprite road" ; i + max / 2 ; " point"
    #m "spritescale road" ; i + max / 2 ; " 200"
    p( i , 0 ) = sin( rad( i * 360 / max * 2 ) ) _
    * ( 300 + sin( rad( i * 360 / max * 6 ) ) * 100 )
    p( i , 1 ) = 0
    p( i , 2 ) = cos( rad( i * 360 / max * 2 ) ) _
    * ( 300 + cos( rad( i * 360 / max * 6 ) ) * 100 )
    p( i + max / 2 , 0 ) = sin( rad( i * 360 / max * 2 ) ) _
    * ( 500 + sin( rad( i * 360 / max * 6 ) ) * 500 / 3 )
    p( i + max / 2 , 1 ) = 0
    p( i + max / 2 , 2 ) = cos( rad( i * 360 / max * 2 ) ) _
    * ( 500 + cos( rad( i * 360 / max * 6 ) ) * 500 / 3 )
  next i
  #m "cls"
  #m "goto 0 0"
  #m "down"
  #m "boxfilled 70 40"
  #m "up"
  #m "getbmp car 0 0 70 40"
  #m "addsprite car car"
  #m "spritexy car " ; winx / 2 - 35 ; " " ; winy - 100
  #m "setfocus"
  #m "when characterInput [key]"
  timer 40 , [tmr]
wait
[key]
  key$ = Inkey$
  if key$ = chr$( 27 ) then
    close #m
    end
  end if
wait
[tmr]
  scan
  select case right$( key$ , 1 )
    case chr$( _VK_UP )
      dx = 0
      dz = 5
      call rotate dx , dz , 0 - cangle
      cx = cx + dx
      cz = cz + dz
    case chr$( _VK_LEFT )
      cangle = cangle - 5
    case chr$( _VK_RIGHT )
      cangle = cangle + 5
    case else
  end select
  key$ = ""
  for i = 0 to max
    x = p( i , 0 ) - cx
    y = p( i , 1 ) - cy
    z = p( i , 2 ) - cz
    call rotate x , z , cangle
''    if z < -990 then
      sx = winx / 2 + x / ( z + 1000 ) * 1000
      sy = winy / 2 - y / ( z + 1000 ) * 1000
      #m "spritexy road" ; i ; " " _
      ; int( sx ) ; " " ; int( sy )
''    else
''      #m "spritexy road" ; i ; " -10 -10"
''    end if
  next i
  #m "spritecollides car list$"
  if len( list$ ) <> 0 then
    notice "GAME OVER !!"
    close #m
    end
  end if
  #m "drawsprites"
wait
[quit]
  close #m
end
sub rotate byref k , byref l , deg
  s = sin( rad( deg ) )
  c = cos( rad( deg ) )
  hk = k * c - l * s
  hl = k * s + l * c
  k = hk
  l = hl
end sub
function rad( deg )
  rad = deg * pi / 180
end function
function range( l , h )
  range = rnd(0) * ( h - l ) + l
end function
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm


Keer terug naar Liberty BASIC Code

Wie is er online

Gebruikers op dit forum: Geen geregistreerde gebruikers. en 1 gast

cron