Example #1
0
void nuiLayout::DoLayout(const nuiRect& rRect)
{
  nuiRect r(GetRect());
  float width = r.GetWidth();
  float height = r.GetHeight();

  SetHorizontalAnchor("left", 0, eAnchorAbsolute);
  SetHorizontalAnchor("right", width, eAnchorAbsolute);
  SetVerticalAnchor("top", 0, eAnchorAbsolute);
  SetVerticalAnchor("bottom", height, eAnchorAbsolute);
  auto it = mConstraints.begin();
  while (it != mConstraints.end())
  {
    nuiWidget* pWidget = it->first;
    float left = 0, right = width, top = 0, bottom = height;
    nuiRect ideal(pWidget->GetIdealRect());
    float l = ideal.Left(), r = ideal.Right(), t = ideal.Top(), b = ideal.Bottom();
    const nuiLayoutConstraint& rH(it->second.first);
    const nuiLayoutConstraint& rV(it->second.second);

    // Horizontal Layout:
    ComputeConstraint(rH, l, r, left, right, ideal.GetWidth(), 0);

    // Vertical Layout:
    ComputeConstraint(rV, t, b, top, bottom, ideal.GetHeight(), 1);

    pWidget->SetLayout(nuiRect(l, t, r, b, false));

    ++it;
  }
}
Example #2
0
void Physics::RigidConstraint::Solve(int iterationCount)
{
	if (ComputeConstraint() >= 0)
		return;

	float kp = 1 - std::powf(1 - m_stiffness, 1.f / iterationCount);
	glm::vec3 correction = -ComputeScalingFactor() * m_points[0]->m_invMass * m_nc * kp;

	if (glm::length(correction) > EPS)
		m_points[0]->m_projection += correction;
}
Example #3
0
float Physics::RigidConstraint::ComputeScalingFactor()
{
	float deriv = glm::dot(glm::vec3(1), m_nc);
	return ComputeConstraint() / (m_points[0]->m_invMass * deriv * deriv);
}