Beispiel #1
0
        private static Vector2 computeVelocity(ref computeVelocityParams computeVelocityParams)
        {
            Vector4 flowC = computeVelocityParams.OldFlowMap[computeVelocityParams.Position.X, computeVelocityParams.Position.Y];
            Vector4 flowL = computeVelocityParams.OldFlowMap[computeVelocityParams.Position.X - 1, computeVelocityParams.Position.Y];
            Vector4 flowR = computeVelocityParams.OldFlowMap[computeVelocityParams.Position.X + 1, computeVelocityParams.Position.Y];
            Vector4 flowT = computeVelocityParams.OldFlowMap[computeVelocityParams.Position.X, computeVelocityParams.Position.Y - 1];
            Vector4 flowB = computeVelocityParams.OldFlowMap[computeVelocityParams.Position.X, computeVelocityParams.Position.Y + 1];

            Vector2 velocityData = new Vector2();

            velocityData.X = -(flowL.Y + flowC.Y - flowR.X - flowC.X) / 2.0f;
            velocityData.Y = -(flowT.W + flowC.W - flowB.Z - flowC.Z) / 2.0f;

            float velocityMax    = computeVelocityParams.Size * (computeVelocityParams.NewWaterMap[computeVelocityParams.Position.X, computeVelocityParams.Position.Y] + computeVelocityParams.GetOldWaterMap[computeVelocityParams.Position.X, computeVelocityParams.Position.Y]) * 0.5f;
            float velocityFactor = velocityData.Length();

            if (velocityFactor > velocityMax)
            {
                velocityFactor = velocityMax / velocityFactor;
                if (velocityFactor > 1.0f)
                {
                    velocityFactor = 1.0f;
                }
                velocityData *= velocityFactor;
            }
            return(velocityData);
        }
Beispiel #2
0
        public void ComputeVelocityMap()
        {
            Vector4[,] oldFlowMap = GetOldFlowMap();
            float[,] newWaterMap  = GetNewWaterMap();
            var computeVelocityParams = new computeVelocityParams(new IndexStruct(0, 0), oldFlowMap, newWaterMap, GetOldWaterMap(), gridSize);

            for (int i = 1; i < width - 1; i++)
            {
                for (int j = 1; j < length - 1; j++)
                {
                    //if (GetOldWaterMap()[i,j]>0.001f)
                    //{

                    computeVelocityParams.Position = new IndexStruct(i, j);

                    velocityMap[i, j] = computeVelocity(ref computeVelocityParams);
                    //}
                }
            }
        }