gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Particles question...

#3314 - Jer1400 - Sat Feb 22, 2003 6:06 pm

Does anyone know how to sort of "shatter" the screen into particles? Also, does anyone have a random number program? One more thing...a simple function that can just put plain white text on the screen. Okay, that's all from me. These would all be in C++.
_________________
http://saoghal.cywh.com/Jer1400/index.html

*Note that the site is still in early development.

#3316 - darkcloud - Sat Feb 22, 2003 6:47 pm

Jer1400 wrote:
does anyone have a random number program?

The Mersenne Twister generator seems to work pretty well and fast.
You can download a .C file from this site: http://www.math.keio.ac.jp/~matumoto/emt.html

It's near the bottom. Just include it in your project and you have a nice little genrand() function.
_________________
Maybe in order to understand mankind, we have to look at the word itself: "Mankind". Basically, it's made up of two separate words - "mank" and "ind". What do these words mean ? It's a mystery, and that's why so is mankind.

#3344 - tepples - Sun Feb 23, 2003 4:20 am

darkcloud wrote:
The Mersenne Twister generator seems to work pretty well and fast.

Yeah, until you generate the 623rd number. The main loop of a real-time application such as a GBA game has to fit within a certain amount of time (in the GBA's case, 280896 cycles) during the worst case path. The MT implementation has to generate a block of 623 random numbers all at the same time, which could cause your program to overflow frame time irregularly. I'd suggest using the good old linear congruential generator, which runs in constant time, and discarding the low-order bits that aren't very random:
Code:
unsigned int seed;

unsigned int ayn()
{
  seed = 69069 * seed + 1;
  return seed >> 16;
}

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#3347 - Jer1400 - Sun Feb 23, 2003 6:27 am

nm about the random function and the fading. I found out earlier about hardware fading and the rand()% command in C++. That shatter effect still puzzles me, though. So if anyone could figure that out it would be very much appriciated.
_________________
http://saoghal.cywh.com/Jer1400/index.html

*Note that the site is still in early development.

#3349 - Daikath - Sun Feb 23, 2003 7:00 am

Any hints on how to do a particle effect on one sprite? A effect wich makes the sprite look like he is turned to dust or something (with then the dust bits flying accros the screen).
_________________
?There are no stupid questions but there are a LOT of inquisitive idiots.?

#3373 - CoolMan - Sun Feb 23, 2003 7:00 pm

Off of the top of my head...

What about dividing the screen (or sprite) into multiple sprites that have transparent, jagged edges. Then shooting them scross the screen in a random manner? Would take some thought to actually implement it though...
_________________
Moron! You don't herd chickens with a shotgun!

--CoolMan

#3399 - Jer1400 - Mon Feb 24, 2003 1:30 am

Hmm...you know, I just though of a way to do it using cosh(), rand()%, and the video buffer. I hope it works....
_________________
http://saoghal.cywh.com/Jer1400/index.html

*Note that the site is still in early development.

#3430 - Daikath - Mon Feb 24, 2003 5:51 pm

CoolMan wrote:
Off of the top of my head...

What about dividing the screen (or sprite) into multiple sprites that have transparent, jagged edges. Then shooting them scross the screen in a random manner? Would take some thought to actually implement it though...


Thanks though :) Gonna try that later.
_________________
?There are no stupid questions but there are a LOT of inquisitive idiots.?

#3442 - mantrid - Tue Feb 25, 2003 1:09 am

Quote:

unsigned int seed;

unsigned int ayn()
{
seed = 69069 * seed + 1;
return seed >> 16;
}


Hey tepples,

Where did you learn all those big words? :-) I know random number generation can be tricky if you want statistically flat numbers.

What initial seed might we use to get good results - brearing in mind I want to reproduce the same results later.

#3449 - tepples - Tue Feb 25, 2003 4:39 am

mantrid wrote:
Where did you learn all those big words?

From reading web pages about real-time apps and PRNGs and from a college education in computer science, which I'll complete in two days. The "ayn()" was a dig at Ayn Rand.

Quote:
I know random number generation can be tricky if you want statistically flat numbers.

Which is why I suggested dropping the most predictable (i.e. lowest order) bits. The LCG won't generate random numbers that are secure enough for crypto, but on the GBA, you're probably not doing crypto; you're doing an interactive simulation, and most players won't be able to distinguish tiny flaws in your PRNG's statistical flatness. In fact, the MT implementation uses exactly the LCG I quoted (called the modified Super-Duper LCG) to expand the initial seed.

However, that page seems to claim that the BCPL library's LCG(2^32, 2147001325, 715136305, 0) gives a flatter sequence.

Quote:
What initial seed might we use to get good results

Try 0xC90FDAA2, which is 2^30*Pi, or good old 0xDEADBEEF.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.