Water

  • lolzy
    4th Aug 2010 Former Staff 0 Permalink
    tmo97
    What the hell do you think you are doing! You come on here and act like an idiot AND you delete half the wiki and try and put the balme on a moderator! I bet you didnt know we could track IP's did you?
  • triclops200
    4th Aug 2010 Former Staff 0 Permalink
    tmo97
    and the fact that I can still fix the wiki perfectly...
    and btw: I am a coder, I know what I am saying when I say it's too hard, so... STFU
  • seehp
    4th Aug 2010 Member 0 Permalink
    EDIT: Deleted content to prevent flamewar
  • Felix
    4th Aug 2010 Member 0 Permalink
    This would make the game run severely slower, as pressure would need to be distributed way further.
  • Aizria
    4th Aug 2010 Member 0 Permalink
    An efficient way to do this would be to check the relative heights of several points along the surface of a fluid, once it is introduced, and to then smooth these out to an average over a period of time correspondent with it leveling out due to the action of gravity. Pseudocode:

    #include <time.h>
    #include <math.h>
    int h1 = height point 1;
    int h2 = height point 2;
    if (h2 != h1) {
    float avg = h1 + h2 / 2;
    if (h2 > h1) {
    float gravTime = sqrt(h2/9.8);
    }
    else {
    float gravTime = sqrt(h1/9.8);
    }
    float time;
    float initTime = clock();
    while (time - initTime < gravTime) {
    time = clock();
    h1, h2 = avg / gravTime;
    }
    }
    else {
    }

    This assumes, of course that gravity in PT is approximately Earth gravity. The gravTime calculation is based on the equation, t = sqrt(2*(y-yo)/ay), which is, in turn, derived from y = yo + voyt + .5ayt^2 for vertical movement. Forgive me if the C syntax is a little off as I haven't really worked with C in over a month, during which time I have been busy with Python instead.

    EDIT: This doesn't take pressure into account, though it could be taken into account with a similar check method.
  • seehp
    4th Aug 2010 Member 0 Permalink
    But how would you define h1 and h2? What if there are air holes in the water? The simple change in h1 and h2 as you describe is indeed simple. Defining a number of particles as one body with a shared surface is something completely different.
  • Aizria
    4th Aug 2010 Member 0 Permalink
    Very true. I suppose that the example I gave is a bit over-generalized. A similar principle could be used, I suppose, but it would need to be quite a lot more complex than what I offered.

    EDIT: Keep in mind that what I gave is pseudocode, nothing definitive. Also, the way TPT works right now, air bubbles in the fluid could be left to float to the surface of the fluid where they would create a slight height difference which would then be compensated for by the leveling code. Also, I'll try to post pseudocode for one that also compensates for pressure, just I'll have to remember some of my water pressure equations from physics.
  • seehp
    4th Aug 2010 Member 0 Permalink
    Excimer-Sun-Software
    Sure, but you use h1 and h2 as a given value. But that value does not exist. If you have large CLN array producing water and the water falls from large height into a vessel. How do you get a h1 from that?

    Also, you would have to move water pixels from one surface to a position above the other surface, or you would have holes in your water, moving the material through pixel by pixel. Quite a complicated thing!
  • Aizria
    4th Aug 2010 Member 0 Permalink
    I understand this and admit that what I posted is over-generalized, I was just giving a pseudocode example of a possible way of levelling the fluid after it has been introduced into the game and has settled into a semi-stable position of sorts. h1 and h2 are assumed to be the y positions, in the game window, of two different points on the surface of the fluid.

    EDIT: Keep in mind that it is nothing definitive, just a generalized example that could potentially be built off of.
  • ssc4k
    4th Aug 2010 Member 0 Permalink
    How do you propose to find surface points of each liquid each frame while keeping the simulation real time?
Locked by cracker64: Necrooo