Ejemplo n.º 1
0
void
Viewer::drawSweptVolume(const rl::plan::VectorList& path)
{
	this->sweptGroup->enableNotify(false);
	
	this->sweptGroup->removeAllChildren();
	
	rl::math::Real length = 0;
	
	rl::plan::VectorList::const_iterator i = path.begin();
	rl::plan::VectorList::const_iterator j = ++path.begin();
	
	for (; i != path.end() && j != path.end(); ++i, ++j)
	{
		length += this->model->distance(*i, *j);
	}
	
	rl::math::Real delta = length / static_cast<std::size_t>(std::ceil(length / this->deltaSwept));
	
	rl::math::Vector inter(this->model->getDofPosition());
	
	rl::math::Real x0 = 0;
	rl::math::Real x1 = x0;
	rl::math::Real x = 0;
	
	i = path.begin();
	j = ++path.begin();
	
	for (; i != path.end() && j != path.end(); ++i, ++j)
	{
		x1 += this->model->distance(*i, *j);
		
		for (; x < x1; x += delta)
		{
			this->model->interpolate(*i, *j, (x - x0) / (x1 - x0), inter);
			
			this->model->setPosition(inter);
			this->model->updateFrames();
			
			SoVRMLGroup* model = new SoVRMLGroup();
			
			for (std::size_t k = 0; k < this->model->model->getNumBodies(); ++k)
			{
				SoVRMLTransform* frame = new SoVRMLTransform();
				frame->copyFieldValues(static_cast<rl::sg::so::Body*>(this->model->model->getBody(k))->root);
				
				for (std::size_t l = 0; l < this->model->model->getBody(k)->getNumShapes(); ++l)
				{
					SoVRMLTransform* transform = new SoVRMLTransform();
					transform->copyFieldValues(static_cast<rl::sg::so::Shape*>(this->model->model->getBody(k)->getShape(l))->root);
					transform->addChild(static_cast<rl::sg::so::Shape*>(this->model->model->getBody(k)->getShape(l))->shape);
					frame->addChild(transform);
				}
				
				model->addChild(frame);
			}
			
			this->sweptGroup->addChild(model);
		}
		
		x0 = x1;
		
		if (j == --path.end())
		{
			this->model->interpolate(*i, *j, 1, inter);
			
			this->model->setPosition(inter);
			this->model->updateFrames();
			
			SoVRMLGroup* model = new SoVRMLGroup();
			
			for (std::size_t k = 0; k < this->model->model->getNumBodies(); ++k)
			{
				SoVRMLTransform* frame = new SoVRMLTransform();
				frame->copyFieldValues(static_cast<rl::sg::so::Body*>(this->model->model->getBody(k))->root);
				
				for (std::size_t l = 0; l < this->model->model->getBody(k)->getNumShapes(); ++l)
				{
					SoVRMLTransform* transform = new SoVRMLTransform();
					transform->copyFieldValues(static_cast<rl::sg::so::Shape*>(this->model->model->getBody(k)->getShape(l))->root);
					transform->addChild(static_cast<rl::sg::so::Shape*>(this->model->model->getBody(k)->getShape(l))->shape);
					frame->addChild(transform);
				}
				
				model->addChild(frame);
			}
			
			this->sweptGroup->addChild(model);
		}
	}
	
	this->sweptGroup->enableNotify(true);
	
	this->sweptGroup->touch();
}