Particle velocity problem.

  • Videogamer555
    20th Jan 2012 Member 0 Permalink
    Why isn't this code working?
    int update_TEST(UPDATE_FUNC_ARGS) {
    if (parts[i].tmp==0) {
    parts[i].vx=(rand()%21-10);
    parts[i].vy=sqrt(100-(abs(parts[i].vx)*abs(parts[i].vx)))*(((rand()%1)*1.0-0.5)*2);
    parts[i].tmp=1;
    }

    return 0;
    }


    It is meant to create particles traveling at constant speed (10 pixels per frame) no matter what direction they travel in, and the direction is selected randomly.
    However only the upper half of the directions is covered. Even worse, I have some missing lines in my circle. I took this screen cap while spraying in particles with "persistent display" enabled.
    image

    I made sure I did everything right by making sure I kept my operations in floating point math like here:
    (rand()%1)*1.0-0.5
    Where random output is 0 or 1 but I make that integer into a double type by multiplying by 1.0 BEFORE subtracting 0.5 (to make sure it "sees" a floating point subtraction operation instead of an integer subtraction operation.

    What's going wrong here?

    Nevermind the one part I found where I got my code wrong partially. And now it is this code:
    int update_TEST(UPDATE_FUNC_ARGS) {
    if (parts[i].tmp==0) {
    parts[i].vx=(rand()%21-10);
    parts[i].vy=sqrt(100-(abs(parts[i].vx)*abs(parts[i].vx)))*(((rand()%2)*1.0-0.5)*2);
    parts[i].tmp=1;
    }

    return 0;
    }


    But I still have the problem that there seem to be certain missing rays just above and below horizontal, on both the left and right sides of the circle as can be seen in the below screencap.
    image