
-----------------------------------
Cervantes
Fri Apr 23, 2004 5:31 pm

[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. :D


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.

-----------------------------------
shorthair
Fri Apr 23, 2004 7:27 pm


-----------------------------------
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
Fri Apr 23, 2004 7:33 pm


-----------------------------------
Wow, Im surprised it wasn't longer. The formula prolly  has something to do with gravity and such right? would u mind explaining?

-----------------------------------
Cervantes
Sat Apr 24, 2004 5:02 am


-----------------------------------
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:


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
Sun Apr 25, 2004 4:19 pm


-----------------------------------
:think:  in Blitz, how do you make a global array from a type?


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
Tue Apr 27, 2004 2:32 pm


-----------------------------------
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.


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,

	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:

You can also define TYPEs as global as well.

and yet, I cannot find how to do it :(

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.  :x

-----------------------------------
Cervantes
Fri Apr 30, 2004 4:26 pm

local arrays.  prog done though!
-----------------------------------
well then, turns out I couldn't get global types working even though it told me how.  :?

anywho, Cervantes has resorted to using LOCAL ARRAYS, instead of his aspiring GLOBAL TYPEs.  for shame.  


Graphics3D 640, 480
SetBuffer BackBuffer()
WBuffer True

camera = CreateCamera()
SeedRnd MilliSecs()

Const bn = 50;ball number  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
Sat May 01, 2004 7:32 am


-----------------------------------
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
Sat May 01, 2004 9:08 am


-----------------------------------
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. :lol:
have you not done any 3D stuff in turing yet?  when you open blitz check out the 3D tutorials section to learn the basics. :)
