Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 Uniform Volume Distribution ? Optimization
 New Topic  Reply to Topic
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 09 2004 :  10:36:54 AM  Show Profile  Visit game_maker's Homepage  Reply with Quote
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. Guapo
Swordmaster

USA
272 Posts

Posted - Jun 09 2004 :  11:37:23 AM  Show Profile  Reply with Quote
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...

Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 09 2004 :  5:39:08 PM  Show Profile  Visit game_maker's Homepage  Reply with Quote
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 ?
Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Jun 09 2004 :  9:53:41 PM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
I'm not really sure what you're trying to do either.

If you want a uniform distribution of particles, then simply pick random coordinates in the volume.

If you want a box, then use
  
For n = 1 to NumberOfParticles  
    X = (maxX - minX) * Rnd + minX  
    Y = (maxY - minY) * Rnd + minY  
    Z = (maxZ - minZ) * Rnd + minZ  
Next

or if you want a sphere, then use
  
For n = 1 to NumberOfParticles  
    X = (maxX - minX) * Rnd + minX  
    Y = (maxY - minY) * Rnd + minY  
    Z = (maxZ - minZ) * Rnd + minZ  
    If (X * X) + (Y * Y) + (Z * Z) <= Radius * Radius Then
        'Use particle coordinates  
    Else
        'don't use particle coordinates, out of bounds of the sphere.  
    End If
Next
Go to Top of Page

cjb0087
Knave

Australia
76 Posts

Posted - Jun 10 2004 :  04:25:33 AM  Show Profile  Visit cjb0087's Homepage  Reply with Quote
use x ^ .5, always pre-pointify you fractions

www.bugsplat.tk
Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 10 2004 :  07:17:22 AM  Show Profile  Visit game_maker's Homepage  Reply with Quote
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)
Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Jun 10 2004 :  08:35:41 AM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
If you want to optimize your original loop, then you might want to calculate G1 and G2 before the loop begins because their values don't change in the loop.

Actually, the code I gave does give a "uniform" distribution of particles. The particle density (versus particle location) is what is uniform in my example. A "non-uniform" distribution would be where the density of the particles is different in different locations of the volume. For example, the following bit of code would generate a non-uniform particle distribution with a higher concentration of particles along the plane Z = minZ

  
For n = 1 to NumberOfParticles  
    X = (maxX - minX) * Rnd + minX  
    Y = (maxY - minY) * Rnd + minY  
    Z = (maxZ - minZ) * Rnd + minZ  
    Z = ((Z - minZ) / (maxZ - minZ))^2 * Z + minZ  
Next
  


Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 10 2004 :  3:25:05 PM  Show Profile  Visit game_maker's Homepage  Reply with Quote
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
Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Jun 10 2004 :  6:41:14 PM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
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.
Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 11 2004 :  09:00:53 AM  Show Profile  Visit game_maker's Homepage  Reply with Quote
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
Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Jun 11 2004 :  4:28:28 PM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
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.
Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 12 2004 :  4:57:38 PM  Show Profile  Visit game_maker's Homepage  Reply with Quote
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 ?
Go to Top of Page

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - Jun 12 2004 :  7:03:02 PM  Show Profile  Reply with Quote
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
Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 13 2004 :  7:49:24 PM  Show Profile  Visit game_maker's Homepage  Reply with Quote
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
  
Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 13 2004 :  7:58:42 PM  Show Profile  Visit game_maker's Homepage  Reply with Quote
another qeustion


  
if (condition1 and condition2) then ....  
  


if condition1 is False does vb check condition2 !!!

if Not then I should write it as

  
if condition1 then
  if condition2 then
  
or
  
if condition2 then
  if condition1 then
  
  


what to put inside and what to put outside depens on 2 things (%possibility to be flase or ture and faster to perform)

What do you think ?
Go to Top of Page

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - Jun 13 2004 :  10:18:55 PM  Show Profile  Reply with Quote
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...
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.29 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.