Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [Blitz][Submission] Particle Engine
Index -> Programming, Visual Basic and Other Basics -> Other Basics
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Cervantes




PostPosted: Fri Apr 23, 2004 5:31 pm   Post subject: [Blitz][Submission] Particle Engine

I got this idea when I was talking to Paul yesterday.. I've never made a particle engine, but thought it would be extremely easy. Put my knowledge of parabolas to work and presto! Here's the result. Very Happy

code:

Graphics 200, 200
SetBuffer BackBuffer()

Dim a# (200)
Dim p# (200)
Dim q# (200)
Dim x# (200)
Dim y# (200)

SeedRnd MilliSecs()
For i = 1 To 200

        x (i) = Rnd (-200, -10)
        a (i) = Rnd (0.009, 0.013)
        p (i) = -10
        q (i) = 60
       
Next


While Not KeyHit (1)
       
        Cls

        For d = 1 To 200

                If y (d) > GraphicsHeight() Then x (d) = Rnd (-50, -10)

                x (d) = x (d) + 1
       
                y (d) = ((a (d) * (( x (d) - p (d) )^2)) + q (d) )

                Color 255, 255, 255
                Plot x (d), y (d)
       
        Next
       
        Flip
        Delay (2)

Wend
End


This is really just the basis for a nicer looking prog im planning on making (3D too). Enjoy.
comments / questions / suggestions.
Sponsor
Sponsor
Sponsor
sponsor
shorthair




PostPosted: Fri Apr 23, 2004 7:27 pm   Post subject: (No subject)

Well done , looks like you really understand how to apply math to the blitz world , im impresed to say the least keep it up
Paul




PostPosted: Fri Apr 23, 2004 7:33 pm   Post subject: (No subject)

Wow, Im surprised it wasn't longer. The formula prolly has something to do with gravity and such right? would u mind explaining?
Cervantes




PostPosted: Sat Apr 24, 2004 5:02 am   Post subject: (No subject)

have you learned parabolas in math yet?
the formula is really messy because I had to use (d) everywhere. without those it looks like this:

code:

y = a (x - p)^2 + q


(in case you haven't learned parabolas yet, and for anyone else)
a represents the steepness of the parabola. if a is 1, it'll be a standard parabola. if 0 < a < 1 then it'll be less steep. if a > 1 then it'll be steeper. if a is negative, the parabola will be 'reflected' (turned upside down).

the vertex of the parabola is the exact point where it 'turns around' and starts coming back up, or down, in the case of my program.
p represents the horizontal shift of the vertex. if p is negative, it will shift right. if p is positive, it will shift left.
q represents the vertical shift of the vertex. if q > 0 it'll shift up, if q < 0 it'll shift down.

I was looking at other particle engines yesterday, specifically the "blood" one. it didn't use parabolas. is parabolas the way to go? I think a different approach would be more versitile.
Cervantes




PostPosted: Sun Apr 25, 2004 4:19 pm   Post subject: (No subject)

Thinking in Blitz, how do you make a global array from a type?

code:

Type sphere
        Field x#
        Field y#
        Field z#
        Field dx#
        Field dy#
        Field dz#
        Field ent
End Type

Global ball.sphere = New sphere

that much works, but i need it to be an array. and yes it has to be global.
Cervantes




PostPosted: Tue Apr 27, 2004 2:32 pm   Post subject: (No subject)

mmkaaay, shorthair appears to be dead. Well, I'll update anyone who cares on my progress thus far.

I have discovered how to make the TYPE an array. It's not really an array, however, its a bunch of objects accessed using the EACH command.

code:

Type some_type
        Field something
        Field somethingelse
End Type

For i = 1 To 50
        object.some_type = New some_type
                object\something = -25
                object\somethingelse = 15
Next

that'll create it.
then to use it,
code:

        For object.some_type = Each some_type

                ;Whatever code you want here.  you don't have to define which         
                ;element you're accessing like you would an array
               
        Next


my trouble now is making the TYPE a GLOBAL TYPE. the blitz command reference says this:
Blitz Command Reference wrote:

You can also define TYPEs as global as well.

and yet, I cannot find how to do it Sad

Cheers!

EDIT: UGH! I just found out how to create a GLOBAL ARRAY from a TYPE in the Language reference, but now i want to keep the NEW and EACH style! arrrgh. Mad
Cervantes




PostPosted: Fri Apr 30, 2004 4:26 pm   Post subject: local arrays. prog done though!

well then, turns out I couldn't get global types working even though it told me how. Confused

anywho, Cervantes has resorted to using LOCAL ARRAYS, instead of his aspiring GLOBAL TYPEs. for shame.

code:

Graphics3D 640, 480
SetBuffer BackBuffer()
WBuffer True

camera = CreateCamera()
SeedRnd MilliSecs()

Const bn = 50;ball number <-- number of balls
Dim x# (bn)
Dim y# (bn)
Dim z# (bn)
Dim dx# (bn)
Dim dy# (bn)
Dim dz# (bn)
Dim ent (bn)
       
        brush = CreateBrush (145, 30, 40)
        BrushShininess brush, 0.1

For i = 1 To bn
        x (i)   = Rnd (0, 25)
        y (i)   = -50
        z (i)   = 0
        dx (i)  = 0.1
        dy (i)  = 0
        dz (i)  = 0
        ent (i) = CreateSphere()
        PaintEntity ent (i), brush
Next
       
AmbientLight 0, 0, 0
light = CreateLight()
        LightColor light, 180, 180, 180
        PositionEntity light, 0, 0, 0
        PointEntity light, camera
       

Const bounciness# = 2 ;inversely proportional
Const gravity# = 0.015

While Not KeyHit (1)
       
        For b = 1 To bn

                x (b) = x (b) + dx (b)
                y (b) = y (b) + dy (b)
                z (b) = z (b) + dz (b)
       
                dy (b) = dy (b) - gravity
                PositionEntity ent(b), x (b), y (b), z (b)
               
                If y (b) < -20 Then
                        dy (b) = -1 * (dy (b) - (dy (b) / bounciness))
                EndIf

                If x (b) > 25 Then
                        x  (b)= -30
                        y  (b)= 15
                        z  (b)= 30
                        dx (b)= Rnd (0.2, 0.4)
                        dy (b)= 0.3
                        dz (b)= Rnd (-0.1, 0.1)
                EndIf
       
        Next

        UpdateWorld
        RenderWorld
        Flip
       
        Delay 5
       
Wend
End


Cheers
Paul




PostPosted: Sat May 01, 2004 7:32 am   Post subject: (No subject)

Ooo, its all 3D ish textures and stuff, is it easy to do that in blitz? by that I mean easier than in turing. is it the createsphere ()?
Cervantes




PostPosted: Sat May 01, 2004 9:08 am   Post subject: (No subject)

yes, it is extraordinarily easy to do in blitz, and insanely hard to do in Turing. well, turing can run a 3d engine, but to make a 3d particle engine in turing (with 50 balls bouncing all around) would likely cause your computer to explode. Laughing
have you not done any 3D stuff in turing yet? when you open blitz check out the 3D tutorials section to learn the basics. Smile
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Other Basics
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: