Random Float code like BlitzBasic (C# using SDK)

Übersicht Ressourcen Andere Programme oder Tools

Neue Antwort erstellen

mcunha98

Betreff: Random Float code like BlitzBasic (C# using SDK)

BeitragDi, März 31, 2009 14:59
Antworten mit Zitat
Benutzer-Profile anzeigen
Hello,

I convert an old system of particles from BlitzBasic to C# using Blitz SDK, but the Random Float I wrote dont work exactly like Blitz.

Some idea ?

Code: [AUSKLAPPEN]

private float RandomFloat(float min, float max)
{
        float resultx = (float)(myRandom.NextDouble() * (max - min)) + min;
        return resultx;
}


See the results between the 2 tools, the parameters is the same, but when the RandomFloat is called the result is very different...
user posted image
Mauricio Cunha
http://mcunha98.blogspot.com

Noobody

BeitragDi, März 31, 2009 17:53
Antworten mit Zitat
Benutzer-Profile anzeigen
I don't really know C#, but assuming that myRandom.nextDouble() returns a random Double in range 0 to 1, your code would be right.
However, if it just returns any random Double, your code would be:
Code: [AUSKLAPPEN]
private float RandomFloat(float min, float max)
{
        float resultx = (float)(myRandom.NextDouble() % (max - min)) + min;
        return resultx;
}

Where % is the modulo - operator.

Either way, these forums are only for German-speaking users. Next time, post on the English board (found here)
Man is the best computer we can put aboard a spacecraft ... and the only one that can be mass produced with unskilled labor. -- Wernher von Braun

mcunha98

BeitragMi, Apr 01, 2009 15:25
Antworten mit Zitat
Benutzer-Profile anzeigen
Using your suggestion, the values really is very diferent...

Blitz3D > Random value between -10 and 10 : -9.92813
Blitz3D > Random value between -10 and 10 : -4.1011
Blitz3D > Random value between -10 and 10 : 1.97098
Blitz3D > Random value between -10 and 10 : 5.78293
Blitz3D > Random value between -10 and 10 : 7.08145
Blitz3D > Random value between -10 and 10 : 2.51541
Blitz3D > Random value between -10 and 10 : -4.0419
Blitz3D > Random value between -10 and 10 : 9.70047
Blitz3D > Random value between -10 and 10 : 5.06424
Blitz3D > Random value between -10 and 10 : -3.37814
Blitz3D > Random value between -10 and 10 : -2.62436
Blitz3D > Random value between -10 and 10 : 4.48135
Blitz3D > Random value between -10 and 10 : 3.09921

C# > Random value between -10 and 10 : 9,330357
C# > Random value between -10 and 10 : -9,232029
C# > Random value between -10 and 10 : 0,8192587
C# > Random value between -10 and 10 : 8,866722
C# > Random value between -10 and 10 : 6,788763
C# > Random value between -10 and 10 : -9,012728
C# > Random value between -10 and 10 : -6,965828
C# > Random value between -10 and 10 : 2,521488
C# > Random value between -10 and 10 : 2,254827
Mauricio Cunha
http://mcunha98.blogspot.com

Noobody

BeitragDo, Apr 02, 2009 13:31
Antworten mit Zitat
Benutzer-Profile anzeigen
I think your function returns different values, because Blitz uses a different algorithm to create random numbers than C# does.
That doesn't really matter - as long the random values remain in your specified interval, everything's fine.
In your screenshot it looks much like the random numbers were on a highly different scale than your min/max - values, causing all the particles to fly downwards really fast.
Just give it a try using my code, it should work.
Man is the best computer we can put aboard a spacecraft ... and the only one that can be mass produced with unskilled labor. -- Wernher von Braun

ChaosCoder

BeitragDo, Apr 02, 2009 13:56
Antworten mit Zitat
Benutzer-Profile anzeigen
Why is the gravityvalue in BMax between 0.02 and 0.07 and in C# between 1 and 4? that would cause a 100 times greater acceleration downwards and would lead to exactly this behaviour of the particles...

Or is this exactly the problem, that C# generates these higher double values for the gravity? Then I have no idea Wink
Projekte: Geolaria | aNemy
Webseite: chaosspace.de

mcunha98

BeitragDo, Apr 02, 2009 15:50
Antworten mit Zitat
Benutzer-Profile anzeigen
Noobody

I did.
I put your "modulo" in function, the results really improve, but not is the spected effect.

ChaosCoder
This is it, the problem is how I give random values to the particle system in same standard of Blitz.
Mauricio Cunha
http://mcunha98.blogspot.com

Neue Antwort erstellen


Übersicht Ressourcen Andere Programme oder Tools

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group