Axiom.Demos.WaterMesh.PushDown C# (CSharp) Method

PushDown() public method

Emulates an object pushing water out of its way (usually down)
public PushDown ( float fx, float fy, float depth ) : void
fx float
fy float
depth float
return void
		public void PushDown( float fx, float fy, float depth )
		{
			// Ogre Wave Generation Logic - scale pressure according to time passed
			for ( int addx = (int)fx; addx <= (int)fx + 1; addx++ )
			{
				for ( int addy = (int)fy; addy <= (int)fy + 1; addy++ )
				{
					float diffy = fy - (float)System.Math.Floor( fy + addy );
					float diffx = fx - (float)System.Math.Floor( fx + addx );
					float dist = (float)System.Math.Sqrt( diffy * diffy + diffx * diffx );
					float power = 1 - dist;

					if ( power < 0 )
					{
						power = 0;
					}

					vBuf[ addy, addx ].y -= depth * power;
				}
			}
		}

Usage Example

Ejemplo n.º 1
0
 protected void ProcessRain()
 {
     foreach (Particle p in particleSystem.Particles)
     {
         Vector3 ppos = p.Position;
         if (ppos.y <= 0 && p.timeToLive > 0)
         {
             // hits the water!
             p.timeToLive = 0.0f;                     // delete particle
             // push the water
             float x = ppos.x / PLANE_SIZE * CMPLX;
             float y = ppos.z / PLANE_SIZE * CMPLX;
             float h = (float)RAND.NextDouble() % RAIN_HEIGHT_RANDOM + RAIN_HEIGHT_CONSTANT * 2;
             if (x < 1)
             {
                 x = 1;
             }
             if (x > CMPLX - 1)
             {
                 x = CMPLX - 1;
             }
             if (y < 1)
             {
                 y = 1;
             }
             if (y > CMPLX - 1)
             {
                 y = CMPLX - 1;
             }
             waterMesh.PushDown(x, y, -h);
             //TODO: to implement WaterCircles, this is where you would create each new WaterCircle
         }
     }
 }