Exemple #1
0
void IkSolver::applyAllConstraints(const Bone *parent, const Bone &b)
{
	if ((parent == 0) && (b.primaryJointIdx >= 0))
		applyConstraints(b, b.joints[b.primaryJointIdx]);
	else if (parent != 0)
		applyConstraints(b, *b.findJointWith(*parent));

	for (int i = 0; i < (int)b.joints.size(); ++i)
	{
		const Bone::Connection &c = b.joints[i];
		if (c.to != parent)
			applyAllConstraints(&b, *c.to);
	}
}
void VerletParticle::update() {
  if (!isLocked) {
    applyBehaviors();
    applyForce();
    applyConstraints();
  }
}
void Foam::sixDoFRigidBodyMotion::updateForce
(
    const vector& fGlobal,
    const vector& tauGlobal,
    scalar deltaT
)
{
    // Second leapfrog velocity adjust part, required after motion and
    // force calculation

    if (Pstream::master())
    {
        a() = fGlobal/mass_;

        tau() = (Q().T() & tauGlobal);

        applyRestraints();

        applyConstraints(deltaT);

        vector aClip = a();
        scalar aMag = mag(aClip);

        if (aMag > SMALL)
        {
            aClip /= aMag;
        }

        if (aMag > aLim_)
        {
            WarningIn
            (
                "void Foam::sixDoFRigidBodyMotion::updateForce"
                "("
                "const vector& fGlobal, "
                "const vector& tauGlobal, "
                "scalar deltaT"
                ")"
            )
                    << "Limited acceleration " << a()
                    << " to " << aClip*aLim_
                    << endl;
        }

        v() += 0.5*(1 - cDamp_)*deltaT*aClip*min(aMag, aLim_);

        pi() += 0.5*(1 - cDamp_)*deltaT*tau();

        if(report_)
        {
            status();
        }
    }

    Pstream::scatter(motionState_);
}
Exemple #4
0
	void step()
	{
		projectPositions();
		for(int i=0; i<CONSTRAINT_ITERATIONS; ++i)
		{
			applyConstraints();
		}
		unprojectVelocities();
		removeFlagged();
	}
MediaStreamTrack::MediaStreamTrack(ScriptExecutionContext* context, MediaStreamTrackPrivate& privateTrack, const Dictionary* constraints)
    : ActiveDOMObject(context)
    , m_privateTrack(privateTrack)
    , m_eventDispatchScheduled(false)
    , m_stoppingTrack(false)
{
    suspendIfNeeded();

    m_privateTrack->setClient(this);

    if (constraints)
        applyConstraints(*constraints);
}
void Foam::laplaceTetMotionSolver::solve()
{
    // Solve for mesh motion

    if (!frozen_ && !firstMotion_)
    {
        Info << "Correct mesh motion diffusion field." << endl;

        diffusionPtr_->correct();
    }

    tetFemVectorMatrix motionEqn
    (
        tetFem::laplacian
        (
            diffusion().motionGamma(),
            motionU()
        )
    );

    // Apply motion constraints
    applyConstraints(motionEqn);

    // Solve the motion equation
    if (firstMotion_)
    {
        firstMotion_ = false;

        // In the first solution, solve the motion twice to avoid relative
        // tolerance problem
        for (label i = 0; i < 2; i++)
        {
            solverPerf_ = motionEqn.solve();
        }
    }
    else
    {
        solverPerf_ = motionEqn.solve();
    }


    if (needTotDisplacement())
    {
        totDisplacement() += motionU()*tetMesh().time().deltaT();
    }
}
void Foam::pseudoSolidTetMotionSolver::solve()
{
    // Solve for mesh motion

    if (!frozen_ && !firstMotion_)
    {
        Pout << "Correct mesh motion diffusion field." << endl;

        diffusionPtr_->correct();
    }

    int iCorr = 0;
    scalar initialResidual = 0;

    do
    {
        Pout << "Correction: " << ++iCorr << endl;

        tetPointVectorField& U = motionU();
        const elementScalarField& mu = diffusion().motionGamma();

        tetFemVectorMatrix motionEqn
        (
            tetFem::laplacian(mu, U)
          + tetFem::laplacianTranspose(mu, U)
          + tetFem::laplacianTrace
            (
                (2*nu_/(1 - 2*nu_))*mu,
                motionU()
            )
        );

        // Apply motion constraints
        applyConstraints(motionEqn);

        // Solve the motion equation
        initialResidual = motionEqn.solve().initialResidual();

        Pout << "Initial residual: " << initialResidual << endl;
    }
    while (initialResidual > convergenceTolerance_ && iCorr < nCorrectors_);
}
Exemple #8
0
vec3d IkSolver::updateJointByIk(const Bone &b, const Bone::Connection &joint, const vec3d &target, const vec3d &tip)
{
	BoneState &bs = boneStates[b.id];

	const vec3d relTip = tip - joint.pos;
	const vec3d relTarget = target - joint.pos;

	// calculate the required rotation
	mat3d rot = calcDirectRotation(relTip, relTarget);
	if (rot == mat3d(1.0)) return tip;
	
	// apply constraints to the bone's orientation	
	if (mApplyConstraints)
	{
		mat3d oldRot = bs.rot;
		bs.rot = bs.rot * rot;
		applyConstraints(b, joint);
		rot = transpose(oldRot) * bs.rot;
	}
	else // alternatively, just apply the rotation directly
		bs.rot = bs.rot * rot;

	return joint.pos + rot*relTip;
}
Exemple #9
0
bool Charts::Chart::update(void)
{
	preUpdate();
	const glm::float_t width = this->size.width;
	const glm::float_t height = this->size.height;
	if (!TR_VERIFY(width > 0.0 && height > 0.0)) {
		return false;
	}
	bool changed = false;
	if (title) {
		changed = changed || title->versionChanged();
	}
	Margin internalMargin;
	for (auto axis : axisList) {
		addAxisInternalMargin(internalMargin, axis);
	}
	renderArgs.margin = Margin::add(margin, internalMargin);

	if (renderArgs.screenSize.x != width || renderArgs.screenSize.y != height) {
        if(!doRelayout) {
            const glm::vec2 marginProjection(renderArgs.margin.left + renderArgs.margin.right, renderArgs.margin.top + renderArgs.margin.bottom);
            const glm::vec2 newSize(width - marginProjection.x, height - marginProjection.y);
            if (resizeMode == ResizeMode::Rescale) {
                if (renderArgs.screenSize.x > 0.0 && renderArgs.screenSize.y > 0.0) {
                    const glm::vec2 oldSize(renderArgs.screenSize.x - marginProjection.x, renderArgs.screenSize.y - marginProjection.y);
                    scale *= (newSize / oldSize);
                } else {
                    offset = glm::vec2(0.f);
                    scale = newSize;
                }
            } else if (resizeMode == ResizeMode::Relayout) {
                offset = glm::vec2(0.f);
                scale = newSize;
            }
        }
		renderArgs.screenSize = glm::vec2(width, height);
		renderArgs.contentScaleFactor = contentScaleFactor;
		renderArgs.projection = glm::ortho(0.f, renderArgs.screenSize.x, 0.f, renderArgs.screenSize.y, -1000.f, +1000.f);
	}
    
	if (glm::float_t(contentScaleFactor) != renderArgs.contentScaleFactor) {
		renderArgs.contentScaleFactor = contentScaleFactor;
	}

	renderArgs.areaStart = glm::vec2(renderArgs.margin.left, renderArgs.margin.bottom);
	renderArgs.areaSize = renderArgs.screenSize - glm::vec2(renderArgs.margin.left + renderArgs.margin.right, renderArgs.margin.top + renderArgs.margin.bottom);
    
    if (doRelayout) {
        offset = glm::dvec2(0.f);
        scale = renderArgs.areaSize;
        doRelayout = false;
    } else {
        applyAnimations();
        applyConstraints();
    }
    
    // must check this AFTER applying animations and constraints
    changed = changed || versionChanged();

	renderArgs.offset = offset;
	renderArgs.scale = scale;
    
	renderArgs.clearColor = Utils::colorToVec4(backgroundColor);
    
	for (auto axis : axisList) {
		//if (axis->isEnabled()) {
			changed |= axis->update(renderArgs);
		//}
	}
	for (auto series : seriesList) {
		//if (series->isEnabled()) {
			changed |= series->update(renderArgs);
		//}
	}
	for (auto decoration : decorationList) {
		//if (decoration->isEnabled()) {
			changed |= decoration->update(renderArgs);
		//}
	}
	if (!preRendered) {
		// we mark the chart as changed if it has not been pre-rendered, the purpose of the update changed value is
		// conditional rendering and if we update twice before calling render we will still need to render again.
		changed = true;
	}
    if(changed) {
        preRendered = false;
    }
	preUpdated = false;
	markVersion();
	if (title) {
		title->markVersion();
	}
	updated = true;
	return changed;
}