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


C++ Vector3r::setZero方法代码示例

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


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

示例1: solveDensityConstraint

// ----------------------------------------------------------------------------------------------
bool PositionBasedFluids::solveDensityConstraint(
	const unsigned int particleIndex,
	const unsigned int numberOfParticles,
	const Vector3r x[],	
	const Real mass[],
	const Vector3r boundaryX[],
	const Real boundaryPsi[],
	const unsigned int numNeighbors,
	const unsigned int neighbors[],
	const Real density0,
	const bool boundaryHandling,
	const Real lambda[],
	Vector3r &corr)
{
	// Compute position correction
	corr.setZero();
	for (unsigned int j = 0; j < numNeighbors; j++)
	{
		const unsigned int neighborIndex = neighbors[j];
		if (neighborIndex < numberOfParticles)		// Test if fluid particle
		{
			const Vector3r gradC_j = -mass[neighborIndex] / density0 * CubicKernel::gradW(x[particleIndex] - x[neighborIndex]);
			corr -= (lambda[particleIndex] + lambda[neighborIndex]) * gradC_j;
		}
		else if (boundaryHandling)
		{
			// Boundary: Akinci2012
			const Vector3r gradC_j = -boundaryPsi[neighborIndex - numberOfParticles] / density0 * CubicKernel::gradW(x[particleIndex] - boundaryX[neighborIndex - numberOfParticles]);
			corr -= (lambda[particleIndex]) * gradC_j;
		}
	}

	return true;
}
开发者ID:PeterZs,项目名称:PositionBasedDynamics,代码行数:35,代码来源:PositionBasedFluids.cpp

示例2: ProjectEdgeConstraints

bool  PositionBasedElasticRod::ProjectEdgeConstraints(
    const Vector3r& pA, const float wA,
    const Vector3r& pB, const float wB,
    const Vector3r& pG, const float wG,
    const float edgeKs, const float edgeRestLength, const float ghostEdgeRestLength,
    Vector3r& corrA, Vector3r&  corrB, Vector3r&  corrC)
{
    corrA.setZero();
    corrB.setZero();
    corrC.setZero();

    //Edge distance constraint
    Vector3r dir = pA - pB;
    float len = dir.norm();

    float wSum = wA + wB;
    if (len > EPSILON && wSum > EPSILON)
    {
        Vector3r dP = (1.0f / wSum) * (len - edgeRestLength) * (dir / len) * edgeKs;

        corrA -= dP * wA;
        corrB += dP * wB;
        corrC = Vector3r(0, 0, 0);
    }

    //Bisector constraint
    Vector3r pm = 0.5f * (pA + pB);
    Vector3r p0p2 = pA - pG;
    Vector3r p2p1 = pG - pB;
    Vector3r p1p0 = pB - pA;
    Vector3r p2pm = pG - pm;
    float lambda;

    wSum = wA * p0p2.squaredNorm() + wB * p2p1.squaredNorm() + wG * p1p0.squaredNorm();
    if (wSum > EPSILON)
    {
        lambda = p2pm.dot(p1p0) / wSum * edgeKs;

        corrA -= p0p2 * lambda * wA;
        corrB -= p2p1 * lambda * wB;
        corrC -= p1p0 * lambda * wG;
    }

    ////Ghost-Edge constraint
    wSum = 0.25f * wA + 0.25f * wB + 1.0f * wG;

    if (wSum > EPSILON)
    {
        //need to use updated positions
        pm = 0.5f * (pA + corrA + pB + corrB);
        p2pm = pG + corrC - pm;

        float p2pm_mag = p2pm.norm();
        p2pm *= 1.0f / p2pm_mag;

        lambda = (p2pm_mag - ghostEdgeRestLength) / wSum * edgeKs;

        corrA += 0.5f * wA * lambda * p2pm;
        corrB += 0.5f * wB * lambda * p2pm;
        corrC -= 1.0f * wG * lambda * p2pm;
    }


    return true;
}
开发者ID:termi3,项目名称:PositionBasedDynamics,代码行数:65,代码来源:PositionBasedElasticRod.cpp


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