Esempio n. 1
0
int		inter_cone_shadow(t_object *obj, t_spobject *lum)
{
  t_inter	i;

  protate(lum, obj);
  translate1(obj, lum);
  obj->xrot *= -1;
  obj->yrot *= -1;
  obj->zrot *= -1;
  rotate(lum, obj);
  i.d = 0;
  if (cos(obj->angle) != 0)
    i.d = sin(obj->angle) / cos(obj->angle);
  i.a = pow(lum->vx, 2) + pow(lum->vy, 2) - pow(lum->vz, 2) * pow(i.d, 2);
  i.b = 2 * (lum->x * lum->vx + lum->y * lum->vy -
	     (lum->z * (lum->vz) * pow(i.d, 2)));
  i.c = pow(lum->x, 2) + pow(lum->y, 2) - pow(lum->z, 2) * pow(i.d, 2);
  i.delta = i.b * i.b - 4 * i.a * i.c;
  i.k = (i.b - sqrt(i.delta)) / (2 * i.a);
  i.k2 = (i.b + sqrt(i.delta)) / (2 * i.a);
  translate2(obj, lum);
  punrotate(lum);
  unrotate(lum);
  obj->xrot *= -1;
  obj->yrot *= -1;
  obj->zrot *= -1;
  return (inter_cone_shadow_delta(&i));
}
Esempio n. 2
0
void		inter_plan(t_all *all, t_object *plan)
{
    double	k;

    translate1(plan, &all->eye);
    rotate(all, plan);
    if (all->eye.vz != 0)
        k = -all->eye.z / all->eye.vz;
    else
        k = -1;
    if (k > 0.00001)
    {
        plan->k = k;
        my_cos(all, k, 2, plan);
        translate2(plan, &all->eye);
        unrotate(all);
        calc_lum_vector(all, plan);
    }
    else
    {
        printf("inside plan\n");
        plan->k = -1;
        unrotate(all);
        translate2(plan, &all->eye);
    }
}
Esempio n. 3
0
int		inter_cone_shadow(t_all *all, t_object *cone)
{
  t_inter	i;

  translate1(cone, &all->lum);
  rotatel(all, cone);
  if (cos(cone->angle) != 0)
    i.d = sin(cone->angle) / cos(cone->angle);
  else
    i.d = 0;
  i.a = pow(all->lum.vx, 2) + pow(all->lum.vy, 2) - pow(all->lum.vz, 2) * pow(i.d, 2);
  i.b = 2 * (all->lum.x * all->lum.vx + all->lum.y * all->lum.vy
             - (all->lum.z * (all->lum.vz) * pow(i.d, 2)));
  i.c = pow(all->lum.x, 2) + pow(all->lum.y, 2) - pow(all->lum.z, 2)
    * pow(i.d, 2);
  i.delta = i.b * i.b - 4 * i.a * i.c;
  i.k = -(-i.b - sqrt(i.delta)) / (2 * i.a);
  i.k2 = -(-i.b + sqrt(i.delta)) / (2 * i.a);
  translate2(cone, &all->lum);
  unrotatel(all);
  if (i.delta >= 0)
    if ((i.k2 < 1 && i.k2 > 0.00001) || (i.k < 1 && i.k > 0.00001))
      return (-1);
  return (0);
}
Esempio n. 4
0
int		inter_cyl_shadow(t_object *obj, t_spobject *lum)
{
  t_inter	i;

  protate(lum, obj);
  obj->xrot *= -1;
  obj->yrot *= -1;
  obj->zrot *= -1;
  translate1(obj, lum);
  rotate(lum, obj);
  i.a = pow(lum->vx, 2) + pow(lum->vy, 2);
  i.b = 2 * (lum->x * lum->vx + lum->y * lum->vy);
  i.c = pow(lum->x, 2) + pow(lum->y, 2) - pow(obj->ray, 2);
  i.delta = i.b * i.b - 4 * i.a * i.c;
  i.k = (i.b - sqrt(i.delta)) / (2 * i.a);
  i.k2 = (i.b + sqrt(i.delta)) / (2 * i.a);
  translate2(obj, lum);
  punrotate(lum);
  unrotate(lum);
  obj->xrot *= -1;
  obj->yrot *= -1;
  obj->zrot *= -1;
  if (i.delta >= 0)
    if ((i.k2 < 0.9999 && i.k2 > 0.00001) || (i.k < 0.9999 && i.k > 0.00001))
      return (-1);
  return (0);
}
Esempio n. 5
0
void	my_cos(t_all *all, double k, int obj, t_object *object)
{
  translate1(object, &all->lum);
  rotatel(all, object);
  all->n.px = all->eye.x + (k * all->eye.vx);
  all->n.py = all->eye.y + (k * all->eye.vy);
  all->n.pz = all->eye.z + (k * all->eye.vz);
  my_normal(all, obj);
  object->normx = all->n.nx;
  object->normy = all->n.nx;
  object->normz = all->n.nx;
  all->n.cos = (all->n.nx * (all->lum.x - all->n.px))
    + (all->n.ny * (all->lum.y - all->n.py))
    + (all->n.nz * (all->lum.z - all->n.pz));
  /* all->n.cos = all->n.nx * all->lum.x2 + all->n.ny * all->lum.y2 */
  /*   + all->n.nz * all->lum.z2; */
  all->n.a2 = /* sqrt( */(all->lum.x - all->n.px) * (all->lum.x - all->n.px)
    + (all->lum.y - all->n.py) * (all->lum.y - all->n.py)
    + (all->lum.z - all->n.pz) * (all->lum.z - all->n.pz);//);
  //  object->z2 = sqrt(all->n.a2);
  if (all->n.cos < 0)
    all->n.cos = 0;
  else
    {
      all->n.a1 = /* sqrt( */all->n.nx * all->n.nx + all->n.ny * all->n.ny
	+ all->n.nz * all->n.nz;//);
      all->n.cos = all->n.cos / sqrt(all->n.a1 * all->n.a2);
    }
  if (object->bright == 0)
    {
      object->color_tmp[0] = all->n.cos * object->color[0];
      object->color_tmp[1] = all->n.cos * object->color[1];
      object->color_tmp[2] = all->n.cos * object->color[2];
    }
  else if (object->bright > 0)
    {
      object->color_tmp[0] = all->n.cos * (object->color[0] *
                                           (1 - object->bright) +
                                           all->lum.color[0] * object->bright);
      object->color_tmp[1] = all->n.cos * (object->color[1] *
                                           (1 - object->bright) +
                                           all->lum.color[1] * object->bright);
      object->color_tmp[2] = all->n.cos * (object->color[2] *
                                           (1 - object->bright) +
                                           all->lum.color[2] * object->bright);
    }
  /* if (object->color[0] > 255) */
  /*   object->color_tmp[0] = 255; */
  /* if (object->color_tmp[1] > 255) */
  /*   object->color_tmp[1] = 255; */
  /* if (object->color_tmp[2] > 255) */
  /*   object->color_tmp[2] = 255; */
  unrotatel(all);
  translate2(object, &all->lum);
}
Esempio n. 6
0
void		inter_sphere(t_all *all, t_object *sphere)
{
    t_inter	i;

    /* printf("************************************************************************************************************************************************************************************************\n"); */
    /* printf("x %G\n", sphere->x); */
    /* printf("y %G\n", sphere->y); */
    /* printf("z %G\n", sphere->z); */
    /* printf("eyex %G\n", all->eye.x); */
    /* printf("eyey %G\n", all->eye.y); */
    /* printf("eyez %G\n", all->eye.z); */
    /* printf("eyevx %G\n", all->eye.vx); */
    /* printf("eyevy %G\n", all->eye.vy); */
    /* printf("eyevz %G\n", all->eye.vz); */
    /* printf("ray %G\n", sphere->ray); */
    /* printf("xrot %G\n", sphere->xrot); */
    /* printf("yrot %G\n", sphere->yrot); */
    /* printf("zrot %G\n", sphere->zrot); */
    /* printf("type %d\n", sphere->type); */
    /* printf("bright %G\n", sphere->bright); */
    /* printf("color R %d\n", sphere->color[0]); */
    /* printf("color G %d\n", sphere->color[1]); */
    /* printf("color B %d\n", sphere->color[2]); */
    translate1(sphere, &all->eye);
    i.a = pow(all->eye.vx, 2) + pow(all->eye.vy, 2) + pow(all->eye.vz, 2);
    i.b = 2 * (all->eye.x * all->eye.vx + all->eye.y
               * all->eye.vy + all->eye.z * all->eye.vz);
    i.c = all->eye.x * all->eye.x + all->eye.y *
          all->eye.y + all->eye.z * all->eye.z - sphere->ray * sphere->ray;
    i.delta = i.b * i.b - 4 * i.a * i.c;
    i.k = (-i.b - sqrt(i.delta)) / (2 * i.a);
    i.k2 = (-i.b + sqrt(i.delta)) / (2 * i.a);
    if (i.k < i.k2 && i.k > 0.00001)
    {
        sphere->k = i.k;
        my_cos(all, i.k, 1, sphere);
        translate2(sphere, &all->eye);
        calc_lum_vector(all, sphere);
    }
    else if (i.k2 < i.k && i.k2 > 0.00001)
    {
        sphere->k = i.k2;
        my_cos(all, i.k2, 1, sphere);
        translate2(sphere, &all->eye);
        calc_lum_vector(all, sphere);
    }
    else
        translate2(sphere, &all->eye);
    if (i.delta <= 0)
    {
        printf("inside sphere\n");
        sphere->k = -1;
    }
}
Esempio n. 7
0
int		inter_plan_shadow(t_all *all, t_object *plan)
{
  double	k;

  translate1(plan, &all->lum);
  rotatel(all, plan);
  k = all->lum.z / all->lum.vz;
  translate2(plan, &all->lum);
  unrotatel(all);
  if (k < 1 && k > 0.00001)
    return (-1);
  return (0);
}
Esempio n. 8
0
void		inter_cone(t_all *all, t_object *cone)
{
    t_inter	i;

    translate1(cone, &all->eye);
    rotate(all, cone);
    if (cos(cone->angle) != 0)
        i.d = sin(cone->angle) / cos(cone->angle);
    else
        i.d = 0;
    i.a = pow(all->eye.vx, 2) + pow(all->eye.vy, 2) - pow(all->eye.vz, 2) * pow(i.d, 2);
    i.b = 2 * (all->eye.x * all->eye.vx + all->eye.y * all->eye.vy
               - (all->eye.z * (all->eye.vz) * pow(i.d, 2)));
    i.c = pow(all->eye.x, 2) + pow(all->eye.y, 2) - pow(all->eye.z, 2)
          * pow(i.d, 2);
    i.delta = i.b * i.b - 4 * i.a * i.c;
    i.k = (-i.b - sqrt(i.delta)) / (2 * i.a);
    i.k2 = (-i.b + sqrt(i.delta)) / (2 * i.a);
    inter_cone2(all, cone, &i);
}
Esempio n. 9
0
int		inter_cyl_shadow(t_all *all, t_object *cyl)
{
  t_inter	i;

  translate1(cyl, &all->lum);
  rotatel(all, cyl);
  i.a = pow(all->lum.vx, 2) + pow(all->lum.vy, 2);
  i.b = 2 * (all->lum.x * all->lum.vx + all->lum.y * all->lum.vy);
  i.c = pow(all->lum.x, 2) + pow(all->lum.y, 2) - pow(cyl->ray, 2);
  i.delta = i.b * i.b - 4 * i.a * i.c;
  i.k = -(-i.b - sqrt(i.delta)) / (2 * i.a);
  i.k2 = -(-i.b + sqrt(i.delta)) / (2 * i.a);
  unrotatel(all);
  translate2(cyl, &all->lum);
  if (i.delta >= 0)
    {
      if ((i.k2 < 1 && i.k2 > 0.00001) || (i.k < 1 && i.k > 0.00001))
	return (-1);
    }
  return (0);
}
Esempio n. 10
0
int		inter_sphere_shadow(t_all *all, t_object *sphere)
{
  t_inter	i;

  translate1(sphere, &all->lum);
  i.a = pow(all->lum.vx, 2) + pow(all->lum.vy, 2) + pow(all->lum.vz, 2);
  i.b = 2 * (all->lum.x * all->lum.vx + all->lum.y
	     * all->lum.vy + all->lum.z * all->lum.vz);
  i.c = all->lum.x * all->lum.x + all->lum.y *
    all->lum.y + all->lum.z * all->lum.z - sphere->ray * sphere->ray;
  i.delta = i.b * i.b - 4 * i.a * i.c;
  translate2(sphere, &all->lum);
  if (i.delta >= 0)
    {
      i.k = -(-i.b - sqrt(i.delta)) / (2 * i.a);
      i.k2 = -(-i.b + sqrt(i.delta)) / (2 * i.a);
      if ((i.k2 < 1 && i.k2 > 0.00001) || (i.k < 1 && i.k > 0.00001))
	return (-1);
    }
  return (0);
}
Esempio n. 11
0
//Scale triangle, used for improve do_intersect results: scale the triangle on its plane, centred in its barycenter
inline Triangle triangleScale(Triangle t)
{
	Plane p = t.supporting_plane();
	KPoint2 a = p.to_2d(t.vertex(0));
	KPoint2 b = p.to_2d(t.vertex(1));
	KPoint2 c = p.to_2d(t.vertex(2));
	KPoint2 baryc((a.x() + b.x() +c.x())/3.0, (a.y() + b.y() +c.y())/3.0);
	//TODO: usare margine invece di scale
	CGAL::Aff_transformation_2<Kernel> translate1(CGAL::TRANSLATION, CGAL::Vector_2<Kernel>(-baryc.x(), -baryc.y()));
	CGAL::Aff_transformation_2<Kernel> translate2(CGAL::TRANSLATION, CGAL::Vector_2<Kernel>(baryc.x(), baryc.y()));
	CGAL::Aff_transformation_2<Kernel> scale(CGAL::SCALING, DISJOINTMESH_TRIANGLE_SCALE_VALUE);
	CGAL::Aff_transformation_2<Kernel> transform = translate2 * (scale * translate1);
	KPoint2 an = transform(a);
	KPoint2 bn = transform(b);
	KPoint2 cn = transform(c);
	Point an3 = p.to_3d(an);
	Point bn3 = p.to_3d(bn);
	Point cn3 = p.to_3d(cn);
	Triangle tn(an3, bn3, cn3);
	return tn;
}
Esempio n. 12
0
int		inter_plan_shadow(t_object *obj, t_spobject *lum)
{
  double	k;

  protate(lum, obj);
  translate1(obj, lum);
  obj->xrot *= -1;
  obj->yrot *= -1;
  obj->zrot *= -1;
  rotate(lum, obj);
  obj->xrot *= -1;
  obj->yrot *= -1;
  obj->zrot *= -1;
  k = lum->z / lum->vz;
  translate2(obj, lum);
  punrotate(lum);
  unrotate(lum);
  if (k < 0.9999 && k > 0.00001)
    return (-1);
  return (0);
}
Esempio n. 13
0
void		inter_cyl(t_all *all, t_object *cyl)
{
    t_inter	i;

    translate1(cyl, &all->eye);
    rotate(all, cyl);
    i.a = pow(all->eye.vx, 2) + pow(all->eye.vy, 2);
    i.b = 2 * (all->eye.x * all->eye.vx + all->eye.y * all->eye.vy);
    i.c = pow(all->eye.x, 2) + pow(all->eye.y, 2) - pow(cyl->ray, 2);
    i.delta = i.b * i.b - 4 * i.a * i.c;
    i.k = (-i.b - sqrt(i.delta)) / (2 * i.a);
    i.k2 = (-i.b + sqrt(i.delta)) / (2 * i.a);
    if (i.k < i.k2 && i.k > 0.00001)
    {
        cyl->k = i.k;
        my_cos(all, i.k, 3, cyl);
        unrotate(all);
        translate2(cyl, &all->eye);
        calc_lum_vector(all, cyl);
    }
    else if (i.k2 < i.k && i.k2 > 0.00001)
    {
        cyl->k = i.k2;
        my_cos(all, i.k2, 3, cyl);
        unrotate(all);
        translate2(cyl, &all->eye);
        calc_lum_vector(all, cyl);
    }
    else
    {
        unrotate(all);
        translate2(cyl, &all->eye);
    }
    if (i.delta <= 0)
        cyl->k = -1;
}
Esempio n. 14
0
void GLImageDrawable::updateShadow()
{
	if(!m_shadowDrawable)
		return;
		
	QImage sourceImg = m_imageWithBorder.isNull() ? m_image : m_imageWithBorder;
	
	QSizeF originalSizeWithBorder = sourceImg.size();
	
	QPointF scale = m_glw ? QPointF(m_glw->transform().m11(), m_glw->transform().m22()) : QPointF(1.,1.);
	
	if(scale.x() < 1.25 && scale.y() < 1.25)
		scale = QPointF(1,1);
	
	double radius = m_shadowBlurRadius;
	
	// create temporary pixmap to hold a copy of the text
	double radiusSpacing = radius;// / 1.75;// * 1.5;
	double radius2 = radius * 2;
// 	double offx = 0; //fabs(m_shadowOffset.x());
// 	double offy = 0; //fabs(m_shadowOffset.y());
	double newWidth  = originalSizeWithBorder.width() 
			 + radius2 * scale.x();// blur on both sides
			 //+ offx * scale.x();
	
	double newHeight = originalSizeWithBorder.height() 
			 + radius2 * scale.y();// blur on both sides
			 //+ offy * scale.y();
			
	QSizeF blurSize(newWidth,newHeight);
// 	blurSize.rwidth()  *= scale.x();
// 	blurSize.rheight() *= scale.y();
	
	//qDebug() << "GLImageDrawable::applyBorderAndShadow(): Blur size:"<<blurSize<<", originalSizeWithBorder:"<<originalSizeWithBorder<<", radius:"<<radius<<", radius2:"<<radius2<<", m_shadowOffset:"<<m_shadowOffset<<", offx:"<<offx<<", offy:"<<offy<<", scale:"<<scale;
	QImage tmpImage(blurSize.toSize(),QImage::Format_ARGB32_Premultiplied);
	memset(tmpImage.scanLine(0),0,tmpImage.byteCount());
	
	// render the source image into a temporary buffer for bluring
	QPainter tmpPainter(&tmpImage);
	//tmpPainter.scale(scale.x(),scale.y());
	
	tmpPainter.save();
	QPointF translate1(radiusSpacing, 
			   radiusSpacing);
	translate1.rx() *= scale.x();
	translate1.ry() *= scale.y();
	//qDebug() << "stage1: radiusSpacing:"<<radiusSpacing<<", m_shadowOffset:"<<m_shadowOffset<<", translate1:"<<translate1;
	//qDebug() << "GLImageDrawable::updateShadow(): translate1:"<<translate1<<", scale:"<<scale; 
	
	tmpPainter.translate(translate1);
	tmpPainter.drawImage(0,0,sourceImg);
	
	tmpPainter.restore();
	
	// color the orignal image by applying a color to the copy using a QPainter::CompositionMode_DestinationIn operation. 
	// This produces a homogeneously-colored pixmap.
	QRect imgRect = tmpImage.rect();
	tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
	
	QColor color = m_shadowColor;
	// clamp m_shadowOpacity to 1.0 because we handle values >1.0 by repainting the blurred image over itself (m_shadowOpacity-1) times.
	color.setAlpha((int)(255.0 * (m_shadowOpacity > 1.0 ? 1.0 : m_shadowOpacity)));
	tmpPainter.fillRect(imgRect, color);
	
	tmpPainter.end();

	// blur the colored text
	ImageFilters::blurImage(tmpImage, (int)(radius * scale.x()));
	
	if(m_shadowOpacity > 1.0)
	{
		QPainter painter2(&tmpImage);
	
		int times = (int)(m_shadowOpacity - 1.0);
		// Cap at 10 - an arbitrary cap just to prevent the user from taxing the CPU too much.
		if(times > 10)
			times = 10;
			
		double finalOpacity = m_shadowOpacity - ((int)m_shadowOpacity);
		if(finalOpacity < 0.001)
			finalOpacity = 1.0;
		
		QImage copy = tmpImage.copy();
		for(int i=0; i<times-1; i++)
			painter2.drawImage(0,0,copy);
		
		//qDebug() << "Overpaint feature: times:"<<times<<", finalOpacity:"<<finalOpacity;
		painter2.setOpacity(finalOpacity);
		painter2.drawImage(0,0,copy);
		painter2.setOpacity(1.0);
	}
	
// 	{
// 		QPainter painter2(&tmpImage);
// 		painter2.setPen(Qt::yellow);
// 		
// 		QPointF translate1(radiusSpacing, 
// 				radiusSpacing);
// 		translate1.rx() *= scale.x();
// 		translate1.ry() *= scale.y();
// 		//qDebug() << "stage1: radiusSpacing:"<<radiusSpacing<<", m_shadowOffset:"<<m_shadowOffset<<", translate1:"<<translate1;
// 		//qDebug() << "GLImageDrawable::updateShadow(): translate1:"<<translate1<<", scale:"<<scale; 
// 		
// 		painter2.translate(translate1);
// 		painter2.drawImage(0,0,sourceImg);
// 		painter2.drawRect(sourceImg.rect());
// 	
// 	}
	
	
	// Notice: Older versions of this shadow code drew the sourceImg back on top of the shadow -
	// Since we are drawaing the drop shadow as a separate texture below the real image in the 
	// m_shadowDrawable, we are not going to draw the sourceImg on top now.
	
	//qDebug() << "GLImageDrawable::updateShadow(): shadow location:"<<point<<", size:"<<tmpImage.size()<<", rect().topLeft():"<<rect().topLeft()<<", m_shadowOffset:"<<m_shadowOffset<<", radiusSpacing:"<<radiusSpacing;
	bool scaleFlag = dynamic_cast<GLTextDrawable*>(this) == NULL;
// 	double scale_w = scaleFlag ? fabs((double)(rect().width()  - sourceImg.width()))  / sourceImg.width()  : 1.0;
// 	double scale_h = scaleFlag ? fabs((double)(rect().height() - sourceImg.height())) / sourceImg.height() : 1.0;
	double scale_w = scaleFlag ? m_targetRect.width()  / m_sourceRect.width()  : 1.0;
	double scale_h = scaleFlag ? m_targetRect.height() / m_sourceRect.height() : 1.0;
	
// 	scale_w *= 2;
// 	scale_h *= 2;
	
	QSizeF size(((double)tmpImage.width()) * scale_w, ((double)tmpImage.height()) * scale_h);
	QPointF point = rect().topLeft() + QPointF(m_shadowOffset.x() * scale_w, m_shadowOffset.y() * scale_h) - QPointF(m_shadowBlurRadius * scale_w,m_shadowBlurRadius * scale_h);
	
	//qDebug() << "GLImageDrawable::updateShadow: "<<(QObject*)this<<" m_targetRect:"<<m_targetRect.size()<<", m_sourceRect:"<<m_sourceRect.size()<<", scale:"<<scale_w<<"x"<<scale_h<<", tmpImage:"<<tmpImage.size()<<", new size:"<<size<<", point:"<<point;
	
	m_shadowDrawable->setRect(QRectF(point, size));
	
	m_shadowDrawable->setImage(tmpImage);
	//updateGL();
}