# PureBasic Forum

 It is currently Tue Oct 15, 2019 3:55 pm

 All times are UTC + 1 hour

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: How to Vectorstars (C2P)Posted: Wed Sep 16, 2009 2:53 am
 Enthusiast

Joined: Tue Oct 05, 2004 9:05 pm
Posts: 103
Location: germany
another fx, 3d vectorstars
we use the chunky to planar engine
(on winuae with amisys4 and emulated gfxcard is it ultrafast)

Code:
#Width  = 320
#Height = 256

InitChunky(9,1,1)
InitBitMap(0)
InitPalette(0)
initScreen(0)
*TagList = InitTagList(100)

AllocateLinearBitMap(0,#Width,#Height,8)
AllocateChunkyBuffer(0,#Width,#Height)
AllocateChunkyBuffer(1,#Width,#Height)

ResetTagList(#SA_Type, #CUSTOMSCREEN | #CUSTOMBITMAP )
OpenScreen(0,320,256,8,*TagList)

CreatePalette(0,255)
palrgb(0,0,0,0)
palrgb(1,200,200,200)
DisplayPalette(0,ScreenID())

;setup the stars
Structure stars
x.w
y.w
z.w
EndStructure
NewList stars.stars()

For st=0 To 500 Step 2
stars()\x = PeekW(?startablex+st)
stars()\y = PeekW(?startabley+st)
stars()\z = PeekW(?startablez+st)
Next

distance.l=800

cb.l=1

Repeat

cb.l=1-cb.l
UseChunkyBuffer(cb.l)
ChunkyCls(0)

vx + 1; X rotation speed
vy + 2; Y rotation speed
vz + 1; Z rotation speed

If vx>359:vx=1:EndIf
If vy>359:vy=1:EndIf
If vz>359:vz=1:EndIf

ResetList(stars())
While NextElement(stars())

;peek the sinus/cosinus from the tables
;not faster than a array..but arrays does'nt work LOL
cosx=PeekL(?costable+(vx*4))
cosy=PeekL(?costable+(vy*4))
cosz=PeekL(?costable+(vz*4))
sinx=PeekL(?sintable+(vx*4))
siny=PeekL(?sintable+(vy*4))
sinz=PeekL(?sintable+(vz*4))

;"3d-engine" ^^
ty = ((stars()\y * cosx) - (stars()\z * sinx))/1000
tz = ((stars()\y * sinx) + (stars()\z * cosx))/1000
tx = ((stars()\x * cosy) - (tz * siny))/1000
tz = ((stars()\x * siny) + (tz * cosy))/1000

nx  = 200 * (tx) / (distance - (tz)) + 160
ny  = 128 - (200 * ty) / (distance - (tz))

nodraw=0
;shade or "back plot culling" For objects
;If tz<0:nodraw=1:EndIf

;test plot=inside screenkoordinates
If nx > 319 :nodraw=1:EndIf
If ny > 255 :nodraw=1:EndIf
If nx < 1   :nodraw=1:EndIf
If ny < 1   :nodraw=1:EndIf

If nodraw=0
ChunkyPlot(nx,ny,1)
EndIf

Wend

ChunkyToPlanar(ChunkyBufferID(),BitMapID(),#Height)

mb.w=MouseButtons()
Until mb.w=2

CloseScreen(0)
End

DisableDebugger
startablex:
IncludeBinary "dat/2003dstarsx"
startabley:
IncludeBinary "dat/2003dstarsy"
startablez:
IncludeBinary "dat/2003dstarsz"
sintable:
IncludeBinary "dat/sin1000";200word"
costable:
IncludeBinary "dat/cos1000";200word"
EnableDebugger

PB 2.9 source, PB4.0 source and datafields

_________________
Kultstudio

Top

 Post subject: Re: How to Vectorstars (C2P)Posted: Thu Apr 08, 2010 4:40 am
 New User

Joined: Tue Apr 06, 2010 4:01 am
Posts: 3
The Vector class provides the capability to implement a growable array of objects
Latest Answer : A vector implements dynamic array, which can grow and shrink dynamically.It is similar to Arraylist with a difference that vector can be synchronized. it also contain some legacy methods. ...

And you utilise very nicely . All the perimeter of vectors followed correctly and nice logic .

_________________
r4 revolution

Top

 Post subject: Re: How to Vectorstars (C2P)Posted: Thu Apr 08, 2010 8:41 am

Joined: Sat Feb 19, 2005 2:46 pm
Posts: 1793
Location: Pas-de-Calais, France
It would be nice to post an optimised version, because my eyes are hurting when I see that. :'(

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 3 posts ]

 All times are UTC + 1 hour

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite