Page 2 of 2
Posted: Fri Sep 05, 2003 11:04 pm
by Dreglor
back to the topic...
no offence but, i seen better i made up one real quick to show i hvae no webhost right now so i just post the code here so you can copy it
btw i can't seam to find the projection code. is that even inculded?
Code: Select all
If InitSprite()=0
MessageRequester("Fatal Error!","Could not initalize directX",0)
End
EndIf
#screen_width.w=1024
#screen_height.w=768
If OpenScreen(#screen_width,#screen_height,16,"")=0
MessageRequester("Fatal Error!","Could not initalize the screen",0)
End
EndIf
If InitKeyboard()=0
MessageRequester("Fatal Error!","Could not initalize the keyboard",0)
End
EndIf
SetFrameRate(60) ;i put this in to keep the frame rate constant
xmax.w=10000
ymax.w=10000
zmax.w=2000
sspeed.w=-10
zmin.w=10
num.w=2000 ;get slow around 2500-3000 and i have 2.66 cpu
centerx.w=#screen_width/2
centery.w=#screen_height/2
zoom.w=60
shade.w=0
Dim sx(num)
Dim sy(num)
Dim sz(num)
For i=0 To num
sx(i)=Random(xmax)-xmax/2
sy(i)=Random(ymax)-ymax/2
sz(i)=Random(zmax)
Next i
Repeat
For i=0 To num
sz(i)=sz(i)+sspeed
If sz(i)<=zmin
sz(i)=zmax
sx(i)=Random(xmax)-xmax/2
sy(i)=Random(ymax)-ymax/2
EndIf
screenx.w=(sx(i)*zoom)/sz(i)+centerx
screeny.w=(-sy(i)*zoom)/sz(i)+centery
shade=Int(255/zmax* -sz(i))
If screenx < #screen_width
If screeny < #screen_height
If screenx > 0
If screeny > 0
StartDrawing(ScreenOutput())
Plot(screenx,screeny,RGB(shade,shade,shade))
StopDrawing()
EndIf
EndIf
EndIf
EndIf
Next i
ExamineKeyboard()
FlipBuffers()
ClearScreen(0,0,0)
Until KeyboardReleased(#PB_Key_Escape)
CloseScreen()
End
hopes that works
even has a nice fading affect
Posted: Sat Sep 06, 2003 8:56 am
by benny
@Dreglor:
Have you seen my (rather old) version
Change "SSum.l" for the amount of stars. I put it to 500, because I personally think it looks nicer. However, try to set it to 5000 or whatever to see the speed-differences.
My fading rountine is less complicated [and maybe doesn't look that nice].
Anyway,
Best wishes, benny!
Code: Select all
; some stars
; benny! 2oo2
#scrw = 640
#scrh = 480
#centerofscrw = #scrw/2
#centerofscrh = #scrh/2
#scrd = 16
SSum.l = 500 ; Amount of Stars
Gosub InitStarField
;-------- Init all needed Stuff --------
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageBox_ (0,"Can't open DirectX 7 or later", "blahhhh", #MB_ICONINFORMATION|#MB_OK)
End
EndIf
If OpenScreen(#scrw,#scrh,#scrd,"benny's code") = 0
MessageBox_ (0,"Could not open screen", "blahhh blaa", #MB_ICONINFORMATION|#MB_OK)
End
EndIf
SetFrameRate(90)
;-------- MainLoop --------
Repeat
ClearScreen(0,0,0)
StartDrawing(ScreenOutput())
DrawingMode(1)
Gosub DoStarField
StopDrawing()
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
End
;--------- Procs / Subs -------------
; #### INITSTARFIELD ####
InitStarField:
; Structure of a star ...
Structure 3DStar
x.f ; X-Coordinate
y.f ; Y-Coordinate
z.f ; Z-Coordinate
zv.f ; Z-Velocity
EndStructure
; Init Starfield ...
Dim Stars.3DStar(SSum)
For dummy = 0 To SSum
Stars(dummy)\x = Random(1000)-500
Stars(dummy)\y = Random(1000)-500
Stars(dummy)\z = 100 + Random(900)
Stars(dummy)\zv = 0.5 + Random (45)/10
Next dummy
Return
; #### DoStarField ####
DoStarField:
For dummy = 0 To SSum
Stars(dummy)\z = Stars(dummy)\z - Stars(dummy)\zv ; Star comes closer ....
SX = Stars(dummy)\x / Stars(dummy)\z * 100 + #centerofscrw
SY = Stars(dummy)\y / Stars(dummy)\z * 100 + #centerofscrh
If SX < 0 Or SY < 0 Or SX >= #scrw Or SY >= #scrh Or Stars(dummy)\z < 1
Stars(dummy)\x = Random(1000)-500
Stars(dummy)\y = Random(1000)-500
Stars(dummy)\z = 100 + Random(900)
Stars(dummy)\zv = 0.5 + ( Random(45) / 10 )
Else
b = 255-(Stars(dummy)\z *(255./1000.)) ; Calc the color of star
Plot ( SX, SY, RGB ( b,b,b ) )
EndIf
Next dummy
Return
For Dreglor startfield
Posted: Sat Sep 06, 2003 9:30 am
by VIRTUALYS
Dreglor,
It is stake badly, but very slow.
Look at, I changed a trick on your code…
Code: Select all
If InitSprite()=0
MessageRequester("Fatal Error!","Could not initalize directX",0)
End
EndIf
#screen_width.w=1024
#screen_height.w=768
If OpenScreen(#screen_width,#screen_height,16,"")=0
MessageRequester("Fatal Error!","Could not initalize the screen",0)
End
EndIf
If InitKeyboard()=0
MessageRequester("Fatal Error!","Could not initalize the keyboard",0)
End
EndIf
SetFrameRate(60) ;i put this in to keep the frame rate constant
xmax.w=10000
ymax.w=10000
zmax.w=2000
sspeed.w=-10
zmin.w=10
num.w=5000 ;get slow around 2500-3000 and i have 2.66 cpu
centerx.w=#screen_width/2
centery.w=#screen_height/2
zoom.w=60
shade.w=0
Dim sx(num)
Dim sy(num)
Dim sz(num)
For i=0 To num
sx(i)=Random(xmax)-xmax/2
sy(i)=Random(ymax)-ymax/2
sz(i)=Random(zmax)
Next i
Repeat
StartDrawing(ScreenOutput())
For i=0 To num
sz(i)=sz(i)+sspeed
If sz(i)<=zmin
sz(i)=zmax
sx(i)=Random(xmax)-xmax/2
sy(i)=Random(ymax)-ymax/2
EndIf
screenx.w=(sx(i)*zoom)/sz(i)+centerx
screeny.w=(-sy(i)*zoom)/sz(i)+centery
shade=Int(255/zmax* -sz(i))
If screenx < #screen_width
If screeny < #screen_height
If screenx > 0
If screeny > 0
Plot(screenx,screeny,RGB(shade,shade,shade))
EndIf
EndIf
EndIf
EndIf
Next i
stopDrawing()
FlipBuffers()
ClearScreen(0,0,0)
ExamineKeyboard()
Until KeyboardReleased(#PB_Key_Escape)
CloseScreen()
End
I simply changed StartDrawing(ScreenOutput()) & stopDrawing() of place.
It is a little faster.
VIRTUALYS for U

Posted: Sun Sep 07, 2003 5:23 am
by Dreglor
hmm well i still new to pb and i need to get some more tricks add to my memory

thanks i might be able to speed it up even more bye changeing it even more
but as i can see it has been speed up alot by your code, VIRTUALYS
edit thanks to VIRTUALYS i was able to make it work with 50000 stars before it started to slow down
also i add a cheap frame rate counter that doea not work correctly it shows 26 when it suppose to to show 60 :/
nothing really change beside that
i tryed 1,000,000 stars to see how fast it when. wel;l it when around 0.5 fps
even though the fps showed 2-3 :roll:
this sound about right to any normal 3d game becasue they can only display 100,000 to 200,000 in the view
if you think about it something like morrowind (fps-rpg hybrid) has a high ploygon target ( bit o high espaclly outdoors) and if you look and guess at how many are in your view it would be around that 100k-300k guess
i hate it when i go off like that lol
Posted: Mon Sep 22, 2003 9:00 pm
by Johan_Haegg
Added a FPS-counter to VIRTUALYS example, and that .w got changed to a .l
It runs at about 25fps on my 800MHz... not bad!
Code: Select all
If InitSprite()=0
MessageRequester("Fatal Error!","Could not initalize directX",0)
End
EndIf
#screen_width.w=1024
#screen_height.w=768
If OpenScreen(#screen_width,#screen_height,16,"")=0
MessageRequester("Fatal Error!","Could not initalize the screen",0)
End
EndIf
If InitKeyboard()=0
MessageRequester("Fatal Error!","Could not initalize the keyboard",0)
End
EndIf
;SetFrameRate(60) ;i put this in to keep the frame rate constant
xmax.w=10000
ymax.w=10000
zmax.w=2000
sspeed.w=-10
zmin.w=10
num.l=50000 ;get slow around 2500-3000 and i have 2.66 cpu
centerx.w=#screen_width/2
centery.w=#screen_height/2
zoom.w=60
shade.w=0
Dim sx(num)
Dim sy(num)
Dim sz(num)
For i=0 To num
sx(i)=Random(xmax)-xmax/2
sy(i)=Random(ymax)-ymax/2
sz(i)=Random(zmax)
Next i
start.l = GetTickCount_()
Repeat
StartDrawing(ScreenOutput())
For i=0 To num
sz(i)=sz(i)+sspeed
If sz(i)<=zmin
sz(i)=zmax
sx(i)=Random(xmax)-xmax/2
sy(i)=Random(ymax)-ymax/2
EndIf
screenx.w=(sx(i)*zoom)/sz(i)+centerx
screeny.w=(-sy(i)*zoom)/sz(i)+centery
shade=Int(255/zmax* -sz(i))
If screenx < #screen_width
If screeny < #screen_height
If screenx > 0
If screeny > 0
Plot(screenx,screeny,RGB(shade,shade,shade))
EndIf
EndIf
EndIf
EndIf
Next i
loop.l + 1
If GetTickCount_() - start.l > 1000
fps = loop.l
loop.l = 0
start.l = GetTickCount_()
EndIf
DrawText(Str(fps))
StopDrawing()
FlipBuffers()
ClearScreen(0,0,0)
ExamineKeyboard()
Until KeyboardReleased(#PB_Key_Escape)
CloseScreen()
End
Posted: Tue Oct 21, 2003 5:40 pm
by kenet
where are the x/y rotations ? ^^
Posted: Sat Oct 25, 2003 2:27 am
by MisterDr
Code: Select all
Structure stars
x.l
y.l
c.l
EndStructure
Dim Star.stars(400)
For i=0 To 399
star(i)\x=Random(640)
star(i)\y=Random(225)+212
star(i)\c=Random(200)+50
Next i
StartDrawing(ScreenOutput())
For i=0 To 399
star(i)\x+star(i)\c/50
If star(i)\x>640
star(i)\x=0
EndIf
Plot(star(i)\x,star(i)\y,star(i)\c*$ff)
Next
StopDrawing()
why aynbody don't uses this code I didn't see better on net.