Ejemplo n.º 1
0
float Cylindre::quantityIntersected(const qglviewer::Vec& _depart, const qglviewer::Vec& _arrivee, float _light_radius) const
{
	// On va construire un cylindre de taille br=br+rlr/2, tr = tr+rlr/2, h = h +rlr/2
	// on va créer un rayon d'origine depart et de direction arrivee - depart 
	// et vérifier si ce rayon intersecte les cylindres
	float penombre;


	Cylindre cylindre_penombre;
	cylindre_penombre.setTopRadius(topradius()+_light_radius/2);
	cylindre_penombre.setBottomRadius(bottomradius()+_light_radius/2);
	cylindre_penombre.setHeight(height()+_light_radius/2);
	
	Disque* disque_top = new Disque(cylindre_penombre.topradius());
	Disque* disque_bottom = new Disque(cylindre_penombre.bottomradius());

	disque_bottom->setMaterial(cylindre_penombre.material());
	disque_top->setMaterial(cylindre_penombre.material());

	Frame* frame_topdisque = new Frame();
	*frame_topdisque = cylindre_penombre.frame();
	frame_topdisque->setPosition(frame_topdisque->position()+Vec(0.0,0.0,cylindre_penombre.height()));
	disque_top->setFrame(*frame_topdisque);
	disque_bottom->setFrame(frame());	

	
	cylindre_penombre.setBottomDisque(disque_bottom);
	cylindre_penombre.setTopDisque(disque_top);

	Ray ray;
	Vec dir = (_arrivee-_depart);
	dir = dir / (dir.norm());
	ray.setStart(_depart);
	ray.setDirection(dir);

	Hit hit;

	if (this->intersect(ray,hit))
	{
		penombre = 1;
	}
	else
	{
		if (cylindre_penombre.intersect(ray,hit))
		{
			Vec I = hit.intersection();
			I = cylindre_penombre.frame().coordinatesOf(I);
			penombre = I.z/cylindre_penombre.height();		
		}
		else
		{			
			penombre = 0;
		}
	}

	return penombre;
}
Ejemplo n.º 2
0
void Cylindre::computeUV(Hit& hit) const
{

	float u,v;
	qglviewer::Vec inter = hit.intersection();
	u = atan2(inter.y,inter.x);
	// mettre sur [0 1] 
	if ( u < 0 ){
		u = u + 2*M_PI;
	}
	u = u/(2*M_PI);
	
	v = inter.z/height();
	hit.setCoord(u,v);
}
Ejemplo n.º 3
0
void Cylindre::displayIntersectionDebug(const Ray& ray,
				      Hit& hit,
				      const qglviewer::Vec& O,
				      const qglviewer::Vec& I,
				      float t) const{
	std::cout << "\nINTERSECTION du cylindre :" << std::endl;
	std::cout << *this << std::endl;
	
	std::cout << "Avec le rayon :" << std::endl;
	std::cout << ray << std::endl;

	std::cout << "TEMPS  : " << hit.time() << std::endl;
	std::cout << "Point d'intersection : " << hit.intersection() << std::endl;
	std::cout << "O  : " << O << std::endl;
	std::cout << "I  : " << I << std::endl;
	std::cout << "t : " << t << std::endl;
}