| game_makerKnave
 
   
 
                Saudi Arabia83 Posts
 | 
                    
                      |  Posted - Jun 09 2004 :  10:36:54 AM       
 |  
                      | Hi 
 if you have a particle system and you want it as a Uniform Volume Distribution (when you set dx and dy and dz (field width) <> 0
 
 so if you put dy = 0 it will be a surface in xz - plane (snow & rain is a good application)
 
 you can do a "Uniform Volume Distribution" in form of three loops
 
 
   N = 125
 dn = n ^ (1/3)
 
 for z = 0 to dn -1
 for y = 0 to dn -1
 for x = 0 to dn -1
 .......statements ...........
 next
 next
 next
 
 
 
 
 But in particle System We can't make three loops ,,, it must be ONE loop ,,, the quastion is HOW to this with Optimization ?
 
 
   Dim N As Long, dN As Long
 Dim Dx As Long, Dy As Long, DZ As Long
 
 Private Sub Form_Load()
 Me.Show: Me.Caption = "Uniform Volume Distribution ; By Yazeed Al-Deligan"
 Me.Width = 11111: Me.Height = 7777
 Me.BackColor = RGB(122, 150, 223)
 N = 100
 Dx = 6000
 Dy = 6000
 DZ = 0
 VD
 End Sub
 
 Private Sub VD()
 Dim Px As Long, Py As Long, Pz As Long
 Dim I As Long, R As Byte, G1 As Long, G2 As Long
 
 
 R = ((Dx <> 0) + (Dy <> 0) + (DZ <> 0)) * -1
 If (R = 0) Then dN = 1 Else dN = Int(N ^ (1 / R))
 
 For I = 0 To N - 1
 
 G1 = IIf(Dx = 0, 1, dN)
 G2 = IIf(Dy = 0, 1, dN)
 
 Px = Dx * (0.5 - (I Mod dN) / dN)
 Py = Dy * (0.5 - ((I \ G1) Mod dN) / dN)
 Pz = DZ * (0.5 - ((I \ (G1 * G2))) / dN)
 
 Me.Circle (5000 + Px, 3000 + Py), 100
 Print I
 
 DoEvents
 
 Next
 End Sub
 
 
 
 
 Is it Optimized .... Is working on all cases ,,,,, I need to be sure 100% becouse Particle System make no jokes you know !!!
 
 second question : i have seen some system have energy , bounce ,,,ect (where this came from and what are the equation or its just an expression for behavior ie( constant or variable with system or particle) ,,,, I mean everyone made his own system or its standard ?!!
 |  
                      | Edited by - game_maker on Jun 09 2004  10:43:35 AM
 |  | 
              
                | Sr. GuapoSwordmaster
 
     
 
                USA272 Posts
 | 
                    
                      |  Posted - Jun 09 2004 :  11:37:23 AM     
 |  
                      | What are you trying to do exactly? Do you just want to make a 3D particle system with random values/coordinates? A little more detail may help...   
 
 |  
                      |  |  | 
              
                | game_makerKnave
 
   
 
                Saudi Arabia83 Posts
 | 
                    
                      |  Posted - Jun 09 2004 :  5:39:08 PM       
 |  
                      | Yes, 
 I am sorry I think that I started to write the code before giving enough information about what I want to do......
 
 Hmmmm.... in particle system there is a shape of source providing particles ....like point, sphere, and box
 
 Usually it's started from point source
 
 And what I want to is Uniformly Volume Distribution (Box)
 
 And I am not so sure about my code because it contains a power calculation witch will slow the performance [(1/3) and square root (1/2)]
 By the way I should use y = sqr(x) instead of y= x ^ (1/2) by logic
 
 Did I clarify my problem ?
  |  
                      |  |  | 
              
                | Eric ColemanGladiator
 
     
 
                USA811 Posts
 |  | 
              
                | cjb0087Knave
 
   
 
                Australia76 Posts
 | 
                    
                      |  Posted - Jun 10 2004 :  04:25:33 AM       
 |  
                      | use x ^ .5, always pre-pointify you fractions |  
                      | www.bugsplat.tk
 |  
                      |  |  | 
              
                | game_makerKnave
 
   
 
                Saudi Arabia83 Posts
 | 
                    
                      |  Posted - Jun 10 2004 :  07:17:22 AM       
 |  
                      | Hi 
 Eric ,Yes your code gives UnUniform Box Distribution becouse your are using random values ,,, I want it to be Uniform becouse it should be uniform ,, I think
 
 cjb0087 : I am using now sqr(x)
  |  
                      |  |  | 
              
                | Eric ColemanGladiator
 
     
 
                USA811 Posts
 |  | 
              
                | game_makerKnave
 
   
 
                Saudi Arabia83 Posts
 | 
                    
                      |  Posted - Jun 10 2004 :  3:25:05 PM       
 |  
                      | hi 
 I understand that if the density is constant (ie does not change with position ) then it is uniform ,,, but I can't see why is your code is uniform !
  becouse : 
 1- rnd
 2- x & y & z has no relation while the should be becouse of the density
 3- i have test it
 
 about G1,G2 you are right
  |  
                      |  |  | 
              
                | Eric ColemanGladiator
 
     
 
                USA811 Posts
 | 
                    
                      |  Posted - Jun 10 2004 :  6:41:14 PM       
 |  
                      | The reason it is uniform is because the RND function is uniform.   If you plot a histogram of the RND function, it will be a horizontal line. |  
                      |  |  | 
              
                | game_makerKnave
 
   
 
                Saudi Arabia83 Posts
 | 
                    
                      |  Posted - Jun 11 2004 :  09:00:53 AM       
 |  
                      | Still not sure  
 OK there is a chance that the rnd function gives 0.5 (assume) then what will be the second number for rnd take make the Distribution Uniform?
 
 i.e. (1, x, 0.5, 0), there is no solution, that's one
 
 If I have the first number of rnd and we assumed it's uniform then I can calculate any further rnd output numbers, right? Witch conflict with the idea of rnd ...... that's two
 
 Third, if you edit my code to your code the result won't be uniform
  |  
                      | Edited by - game_maker on Jun 11 2004  09:04:14 AM
 |  
                      |  |  | 
              
                | Eric ColemanGladiator
 
     
 
                USA811 Posts
 | 
                    
                      |  Posted - Jun 11 2004 :  4:28:28 PM       
 |  
                      | As I said in an earlier post, the code I gave generates uniform "density", not uniform "position". 
 Consider a container that is filled with air.  The atoms are uniformly distributed in the volume, which means the amount of air at the top of the container is the same as the amount of air at the bottom of the container.  However, their positions are not in a grid pattern.
 
 If you want particles in a grid, then use the code you posted.
 |  
                      |  |  | 
              
                | game_makerKnave
 
   
 
                Saudi Arabia83 Posts
 | 
                    
                      |  Posted - Jun 12 2004 :  4:57:38 PM       
 |  
                      | hmmmmm 
 good ,,, the problem is I don't know what is better to use ,,, what do seggest me to choose (uniform density only or with position) for particle system ?
 |  
                      |  |  | 
              
                | Sr. GuapoSwordmaster
 
     
 
                USA272 Posts
 | 
                    
                      |  Posted - Jun 12 2004 :  7:03:02 PM     
 |  
                      | What kind of particle system? Most likely you will want a random system, it would look more realistic, but it depends what you need it for... |  
                      | Edited by - Sr. Guapo on Jun 12 2004  7:03:33 PM
 |  
                      |  |  | 
              
                | game_makerKnave
 
   
 
                Saudi Arabia83 Posts
 | 
                    
                      |  Posted - Jun 13 2004 :  7:49:24 PM       
 |  
                      | you are right .... it's better to use random values 
 Soo , I am going to use Eric code
 
 
   Dim N As Long
 Dim Dx As Long, Dy As Long, DZ As Long
 
 Private Sub Form_Load()
 Me.Show
 Me.Width = 11111: Me.Height = 7777
 Me.BackColor = RGB(122, 150, 223)
 N = 2500
 Dx = 6000
 Dy = 6000
 DZ = 0
 VD True
 End Sub
 
 Private Sub VD(bSphere As Boolean)
 Dim Px As Long, Py As Long, Pz As Long
 Dim I As Long, dM As Single
 
 dM = -IIf(Dx > Dy, (Dx > DZ) * Dx + (DZ > Dx) * DZ, (Dy > DZ) * Dy + (DZ > Dy) * DZ) / 2
 dM = dM * dM
 
 For I = 0 To N - 1
 
 InitP:
 Px = Dx * (0.5 - Rnd)
 Py = Dy * (0.5 - Rnd)
 Pz = DZ * (0.5 - Rnd)
 
 If bSphere Then
 If (Px * Px) + (Py * Py) + (Pz * Pz) > dM Then GoTo InitP:
 End If
 
 Me.Circle (5000 + Px, 3500 + Py), 300
 Print I
 
 DoEvents
 
 Next
 End Sub
 
 
 |  
                      |  |  | 
              
                | game_makerKnave
 
   
 
                Saudi Arabia83 Posts
 |  | 
              
                | Sr. GuapoSwordmaster
 
     
 
                USA272 Posts
 | 
                    
                      |  Posted - Jun 13 2004 :  10:18:55 PM     
 |  
                      | I am not sure how VB does it. I know in c++ and Java, there are seperate operators to do both: 
 & - evaluate both conditions
 && - if the first condition is false, skip the rest
 
 I think VB probably skips, but I am not sure...
 |  
                      |  |  |