Exemple #1
0
void Simulation::updatePosAndVel(const VectorX& new_pos)
{	
	m_mesh->m_previous_velocities = m_mesh->m_current_velocities;
    m_mesh->m_current_velocities = (new_pos - m_mesh->m_current_positions)/m_h;
    m_mesh->m_current_positions = new_pos;

	
	m_mesh->m_current_positions.block_vector(0) = GLM2Eigen(m_mesh->m_positions[0]);
	m_mesh->m_current_velocities.block_vector(0) = EigenVector3(0, 0, 0);

	m_mesh->m_current_positions.block_vector(59) = GLM2Eigen(m_mesh->m_positions[59]);
	m_mesh->m_current_velocities.block_vector(59) = EigenVector3(0, 0, 0);
}
bool Plane::StaticIntersectionTest(const EigenVector3& p, EigenVector3& normal, ScalarType& dist)
{
	ScalarType height = m_pos[1];
	dist = p(1) - height - COLLISION_EPSILON;
	normal = EigenVector3(m_normal[0], m_normal[1], m_normal[2]);

	if (dist < 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
bool Sphere::StaticIntersectionTest(const EigenVector3& p, EigenVector3& normal, ScalarType& dist)
{
	EigenVector3 center = EigenVector3(m_pos[0], m_pos[1], m_pos[2]);
	EigenVector3 diff = p - center;
	dist = diff.norm() - m_radius - COLLISION_EPSILON;
	if (dist < 0)
	{
		normal = diff.normalized();

		return true;
	}
	else
	{
		return false;
	}
}