Exemple #1
0
            public void Execute(int idA)
            {
                //Vector3 predPosA = positions[idA];
                //float lambda = lambdas[idA];
                //Vector3 deltaP = new Vector3();

                //for (int nId = 0; nId < particlesNeighboursCount[idA]; nId++)
                //{
                //    int idB = particlesNeighbours[idA * maxNeighboursPerParticle + nId];

                //    Vector3 predPosB = positions[idB];

                //    float lambdaSum = lambda + lambdas[idB];
                //    float sCorr = kernels.sCorrCalc(predPosA, predPosB);

                //    deltaP += kernels.WSpiky(predPosA, predPosB) * (lambdaSum + sCorr);
                //}

                //deltaPositions[idA] = deltaP / restDensity;

                float4 predPosA = positions[idA];
                float  lambda   = lambdas[idA];
                float4 deltaP   = new float4();

                for (int nId = 0; nId < particlesNeighboursCount[idA]; nId++)
                {
                    int idB = particlesNeighbours[idA * maxNeighboursPerParticle + nId];

                    float4 predPosB = positions[idB];

                    float lambdaSum = lambda + lambdas[idB];
                    float sCorr     = kernels.sCorrCalc(predPosA, predPosB);

                    deltaP += kernels.WSpiky(predPosA, predPosB) * (lambdaSum + sCorr);
                }

                deltaPositions[idA] = deltaP / restDensity;
            }
Exemple #2
0
        public static void ProjectFluidConstraints(Vector4[] particles, float[] densities, float[] lambdas, int particlesCount, int[] particlesNeighbours, int[] particlesNeighboursCount, int maxNeighboursPerParticle, float restDensity, PBFKernels kernels, Vector4[] deltaPositions)
        {
            for (int idA = 0; idA < particlesCount; idA++)
            {
                Vector3 predPosA = particles[idA];
                float   lambda   = lambdas[idA];
                Vector3 deltaP   = new Vector3();

                for (int nId = 0; nId < particlesNeighboursCount[idA]; nId++)
                {
                    int idB = particlesNeighbours[idA * maxNeighboursPerParticle + nId];

                    Vector3 predPosB = particles[idB];

                    float lambdaSum = lambda + lambdas[idB];
                    float sCorr     = kernels.sCorrCalc(predPosA, predPosB);

                    deltaP += kernels.WSpiky(predPosA, predPosB) * (lambdaSum + sCorr);
                }

                deltaPositions[idA] = deltaP / restDensity;
            }
        }