Author Topic: 3D Starfield doing Different Directions  (Read 2895 times)

0 Members and 1 Guest are viewing this topic.

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
3D Starfield doing Different Directions
« on: October 17, 2008 »
I was doing what shockwave did at sundown but I got it wrong...

IF anyone remmy Alien Breed Intro where the starfield come toward( that isnt problem ) but when the starfield go away from ya then it move in different directions to come toward ya then move away from ya another different directions and I dont what is called ...3D Different Diections Starfields....I think shockwave know what I mean

Code: [Select]
; 3D STARFIELD THAT GO TOWARD THE SCREEN AND MOVE AWAY FROM THE SCREEN in different directions !

; constants
Const PRESS_ESCAPE  =1
Const MAX_STARS = 500

Const SCREEN_X = 800
Const SCREEN_Y = 600

Const SCREEN_CENTER_X = (SCREEN_X / 2)
Const SCREEN_CENTER_Y = (SCREEN_Y / 2)

Type TStar
  Field xPos#
  Field yPos#
  Field zPos#
End Type

; ---------------
; -- variables --
; ---------------
Dim Stars.TStar(MAX_STARS) ; array for holding all stars
 
Graphics (SCREEN_X,SCREEN_Y)
SetBuffer BackBuffer()
HidePointer

dly=CreateTimer(60)

InitialiseStarField()

While Not KeyDown(PRESS_ESCAPE)
      Cls         
      update_Stars()
      Flip:Cls
      WaitTimer(dly)
Wend
End


; initialise the star variables   
Function InitialiseStarField()

  For i = 0 To MAX_STARS
      Stars.TStar(i) = New TStar
  Next

  For i = 0 To MAX_STARS
      InitialiseStar(i)
  Next

End Function


; (re)initialise a star variable   --
Function InitialiseStar(Index)

         Stars(Index)\xPos# = Rnd (-500, 500) ; random number between -500 and  500
         Stars(Index)\yPos# = Rnd (-500, 500) ; random number between -500 and  500
         Stars(Index)\zPos# = Rnd (100, 1000) ; random number between  100 and 1000

End Function

; update and display all stars     
Function Update_Stars()

         Color 255, 255, 255

         ; loop through all stars in array
         For i = 0 To MAX_STARS

             ; update star
             Stars(i)\zPos# = Stars(i)\zPos# - 5

             ; calculate x and y pos on 2d screen; divide x or y-vector to z-vector
             ; z-vector is distance to viewer, center of screen is vanishing point
             x# = ((Stars(i)\xPos# / Stars(i)\zPos#) * 100) + SCREEN_CENTER_X
             y# = ((Stars(i)\yPos# / Stars(i)\zPos#) * 100) + SCREEN_CENTER_Y

             ; star went offscreen
             If z# >100  Then
                ; re-initialise star
                InitialiseStar(i)
             
             End If
   
            ; draw star on 2d screen
            Plot x#, y#

         Next

End Function

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: 3D Starfield doing Different Directions
« Reply #1 on: October 17, 2008 »
Kinda: Parallax 3D Sinus Starfield done in 2D ;)
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17423
  • Karma: 499
  • evil/good
    • View Profile
    • My Homepage
Re: 3D Starfield doing Different Directions
« Reply #2 on: October 17, 2008 »
I think he means something else Clyde.

I am sorry if this doesnt work Hotshot, I dont have blitz any more but it shouln't need too many changes.

Code: [Select]
; 3D STARFIELD THAT GO TOWARD THE SCREEN AND MOVE AWAY FROM THE SCREEN in different directions !

; constants
Const PRESS_ESCAPE  =1
Const MAX_STARS = 500

Const SCREEN_X = 800
Const SCREEN_Y = 600

Const SCREEN_CENTER_X = (SCREEN_X / 2)
Const SCREEN_CENTER_Y = (SCREEN_Y / 2)

Type TStar
  Field xPos#
  Field yPos#
  Field zPos#
End Type

; ---------------
; -- variables --
; ---------------
Dim Stars.TStar(MAX_STARS) ; array for holding all stars
 
Graphics (SCREEN_X,SCREEN_Y)
SetBuffer BackBuffer()
HidePointer

dly=CreateTimer(60)

InitialiseStarField()
Global gd#

While Not KeyDown(PRESS_ESCAPE)
gd#=gd#+.5
      Cls         
      update_Stars()
      Flip:Cls
      WaitTimer(dly)
Wend
End


; initialise the star variables   
Function InitialiseStarField()

  For i = 0 To MAX_STARS
      Stars.TStar(i) = New TStar
  Next

  For i = 0 To MAX_STARS
      InitialiseStar(i)
  Next

End Function


; (re)initialise a star variable   --
Function InitialiseStar(Index)

         Stars(Index)\xPos# = Rnd (-500, 500) ; random number between -500 and  500
         Stars(Index)\yPos# = Rnd (-500, 500) ; random number between -500 and  500
         Stars(Index)\zPos# = Rnd (0, 1000) ; random number between  100 and 1000

End Function

; update and display all stars     
Function Update_Stars()

mv#=4*Sin(gd)
         Color 255, 255, 255

         ; loop through all stars in array
         For i = 0 To MAX_STARS

             ; update star
             Stars(i)\zPos# = Stars(i)\zPos# +mv#

             ; calculate x and y pos on 2d screen; divide x or y-vector to z-vector
             ; z-vector is distance to viewer, center of screen is vanishing point
             x# = ((Stars(i)\xPos# / Stars(i)\zPos#) * 100) + SCREEN_CENTER_X
             y# = ((Stars(i)\yPos# / Stars(i)\zPos#) * 100) + SCREEN_CENTER_Y

             ; star went offscreen
If mv#>0 Then
             If Stars(i)\zPos# >1000  Then
                ; re-initialise star
;                InitialiseStar(i)
Stars(i)\zPos# = Stars(i)\zPos#-1000
             
             End If
End If

If mv#<=0 Then
             If Stars(i)\zPos# <0  Then
                ; re-initialise star
;                InitialiseStar(i)
Stars(i)\zPos# = Stars(i)\zPos#+1000
             
             End If
End If
   
            ; draw star on 2d screen
            Plot x#, y#

         Next

End Function
Shockwave ^ Codigos
Challenge Trophies Won: