Note: You must be registered in order to post a reply.
|
game_maker |
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 ?!! |
game_maker |
Posted - Jun 14 2004 : 12:17:49 AM nice ,,,you can test that in c or java by assigning
if (a=5) mean assigning (not comparing)
if(a==5) here it's comparing
soo in C for example
void main (void) { int a = 1; if (0 && (a=2)) a=3; cout << a << }
OutPut is 1 so it's skips as you told me
we can't apply this test for vb becouse = will be taken as comparing ,,, and we can't use a sub (it must be a real condition or a function)
Dim Y As Long Private Sub Form_Load() If False And X Then MsgBox "Mission Impossible" MsgBox IIf(Y = 0, "It's Skipps", "Please No!") End Sub Private Function X() As Boolean Y = 1 End Function
the result is "Please No!" |
Sr. Guapo |
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... |
game_maker |
Posted - Jun 13 2004 : 7:58:42 PM 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 ? |
game_maker |
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
|
Sr. Guapo |
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... |
game_maker |
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 ? |
Eric Coleman |
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_maker |
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 |
Eric Coleman |
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_maker |
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 Coleman |
Posted - Jun 10 2004 : 08:35:41 AM 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
|
game_maker |
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) |
cjb0087 |
Posted - Jun 10 2004 : 04:25:33 AM use x ^ .5, always pre-pointify you fractions |
Eric Coleman |
Posted - Jun 09 2004 : 9:53:41 PM 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 Else End If Next
|
game_maker |
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 ? |
|
|
VBGamer |
© |
|
|
|
|