当前位置: 首页>>代码示例>>C#>>正文


C# SolverData.GetMass方法代码示例

本文整理汇总了C#中SolverData.GetMass方法的典型用法代码示例。如果您正苦于以下问题:C# SolverData.GetMass方法的具体用法?C# SolverData.GetMass怎么用?C# SolverData.GetMass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SolverData的用法示例。


在下文中一共展示了SolverData.GetMass方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnUpdatePlugin

        protected override void OnUpdatePlugin(SolverData solverData, int particleIndex, int neighborIndex)
        {
            // Get fluid IDs
            var particleFluid = solverData.GetFluid(particleIndex).GetFluidID();
            var neighborFluid = solverData.GetFluid(neighborIndex).GetFluidID();

            var particleIsA = particleFluid == m_FluidAID;

            if ((m_MixingFluidsAreTheSame || particleFluid !=  neighborFluid) && // Fluids are not the same, unless A and B are the same
                (particleIsA || particleFluid == m_FluidBID) && // First fluid is A or B
                (neighborFluid == m_FluidAID || neighborFluid == m_FluidBID)) // Second fluid is A or B
            {
                var position = solverData.GetPosition(particleIndex);
                var neighborPosition = solverData.GetPosition(neighborIndex);

                // Make sure the particles are actually close
                if ((position - neighborPosition).sqrMagnitude > m_MixingDistanceSq)
                    return;

                var velocity = solverData.GetVelocity(particleIndex);
                var invMass = 1.0f/solverData.GetMass(particleIndex);

                var emitC = false;

                // Despawn the current particle, unless Fluid C is null and the particle is from Fluid A
                if (m_FluidCID != 0 || !particleIsA)
                {
                    emitC = true;
                    solverData.SetLifetime(particleIndex, -1);
                }

                // Emit a particle. We don't emit from the neighbor position, that gets handled in the opposite pair
                // We handle actual emission on the main thread.
                if (m_FluidDID == 0 || particleIsA)
                {
                    if (emitC)
                    {
                        // Set the system to Fluid C
                        m_ParticleSystems[particleIndex] = 1;
                    }
                    else
                    {
                        m_ParticleSystems[particleIndex] = 0;
                    }
                }
                else
                {
                    // Set the system to Fluid D
                    m_ParticleSystems[particleIndex] = 2;
                }

                // Set emit position and velocity. These must be manually integrated since they won't be applied until after the solver has run.
                // The below is a standard Euler explicit integrator.
                var acceleration = m_Gravity + solverData.GetForce(particleIndex)*invMass;

                for (var iter = 0; iter < m_TimeStep.solverIterations; ++iter)
                {
                    var t = (m_TimeStep.dtIter)*acceleration;

                    // Ignore very large velocity changes
                    if (Vector3.Dot(t, t) > (FluvioSettings.kMaxSqrVelocityChange * m_SimulationScale))
                    {
                       t *= 0;
                    }

                    velocity += t;
                }

                m_EmitVelocities[particleIndex] = velocity;
                m_EmitPositions[particleIndex] = position + velocity * m_TimeStep.deltaTime;
            }
        }
开发者ID:Togene,项目名称:BeCalm,代码行数:72,代码来源:FluidMixer.cs


注:本文中的SolverData.GetMass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。