Ejemplo n.º 1
0
void		inter_cone2(t_all *all, t_object *cone, t_inter *i)
{
    if (i->k < i->k2 && i->k > 0.00001)
    {
        cone->k = i->k;
        my_cos(all, i->k, 4, cone);
        translate2(cone, &all->eye);
        unrotate(all);
        calc_lum_vector(all, cone);
    }
    else if (i->k2 < i->k && i->k2 > 0.00001)
    {
        cone->k = i->k2;
        my_cos(all, i->k2, 4, cone);
        translate2(cone, &all->eye);
        unrotate(all);
        calc_lum_vector(all, cone);
    }
    else
    {
        unrotate(all);
        translate2(cone, &all->eye);
    }
    if (i->delta <= 0)
        cone->k = -1;
}
Ejemplo 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);
    }
}
Ejemplo n.º 3
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;
    }
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
0
void drawColorBox(struct RenderData *rd, float red,float green,float blue,float alpha,float x, float y,float z, float w, float h) {

    //printf("r%f g%f b%f a%f w%f h%f\n", red,green,blue,alpha, w, h);
    
    x -= WIDTH * 0.66;
    y -= HEIGHT * 0.66;

    identity(rd->model);
    translate2(rd->model,x*SCALEXY,-y*SCALEXY,Z+z);
    scale(rd->model, w*SCALE,h*SCALE,0);

    glUniform4f(rd->colorLocation, red,green,blue,alpha);
    
    if (rd->setalpha != 0) {
        glUniform1f(rd->imgAlphaLocation,0); 
        rd->setalpha = 0;
    } 
    glUniform1f(rd->alphaLocation, 1); 

    glUniformMatrix4fv(rd->mvLocation, 1, GL_FALSE, rd->model); 
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    

    rd->drawState = 0;


}
Ejemplo n.º 6
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));
}
Ejemplo n.º 7
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);
}
Ejemplo n.º 8
0
TEST(Matrix, TransformPoint)
{
	Vector3 v(Vector3::Zero);
	float trans[4][4] = { 1.0f, 0.0f, 0.0f, -5.0f,
		0.0f, 1.0f, 0.0f, -10.0f,
		0.0f, 0.0f, 1.0f, 4.0f,
		0.0f, 0.0f, 0.0f, 1.0f };
	Matrix4 translate(trans);

	v.Transform(translate);
	EXPECT_NEAR(-5.0f, v.GetX(), 0.01f);
	EXPECT_NEAR(-10.0f, v.GetY(), 0.01f);
	EXPECT_NEAR(4.0f, v.GetZ(), 0.01f);

	float trans2[4][4] = { 1.0f, 0.0f, 0.0f, 5.0f,
		0.0f, 1.0f, 0.0f, 10.0f,
		0.0f, 0.0f, 1.0f, -4.0f,
		0.0f, 0.0f, 0.0f, 1.0f };
	Matrix4 translate2(trans2);
	v.Transform(translate2);

	EXPECT_NEAR(0.0f, v.GetX(), 0.01f);
	EXPECT_NEAR(0.0f, v.GetY(), 0.01f);
	EXPECT_NEAR(0.0f, v.GetZ(), 0.01f);
}
Ejemplo n.º 9
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);
}
Ejemplo n.º 10
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);
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
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);
}
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
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);
}
Ejemplo n.º 15
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);
}
Ejemplo n.º 16
0
		//METHOD
		void draw(){
			if(type == 0){//BOX
				if(y<=10){
					
					Matrix3x3 ms;//SCALE
					Matrix3x3 mt;//TRANSLASI
					
					//TITIK PENGGAMBARAN
					int drawx1;//X1 SETELAH DITRANSFORMASI
					int drawy1;//Y1 SETELAH DITRANSFORMASI
					int drawx2;//X2 SETELAH DITRANSFORMASI
					int drawy2;//Y2 SETELAH DITRANSFORMASI
					int drawfx;//X UNTUK FILL
					int drawfy;//Y UNTUK FILL
					
					scale2(0.1*y,0.1*y,x*213+112,mobilY-10,ms);
					
					translate2(-(x-1)*(213)*(10-y)/10,-(mobilY-40-(maxy+1)/8-1)*(10-y)/10,mt);
					
					transformPoints2(ms,x*213+82,&drawx1,mobilY+20,&drawy1);
					transformPoints2(ms,x*213+142,&drawx2,mobilY+20,&drawy2);
					transformPoints2(mt,drawx1,&drawx1,drawy1,&drawy1);
					transformPoints2(mt,drawx2,&drawx2,drawy2,&drawy2);
					lineDDA(drawx1, drawy1, drawx2, drawy2); //BAWAH LUAR
					
					transformPoints2(ms,x*213+82,&drawx1,mobilY-40,&drawy1);
					transformPoints2(ms,x*213+142,&drawx2,mobilY-40,&drawy2);
					transformPoints2(mt,drawx1,&drawx1,drawy1,&drawy1);
					transformPoints2(mt,drawx2,&drawx2,drawy2,&drawy2);
					lineDDA(drawx1, drawy1, drawx2, drawy2);//ATAS LUAR
					
					transformPoints2(ms,x*213+82,&drawx1,mobilY+20,&drawy1);
					transformPoints2(ms,x*213+82,&drawx2,mobilY-40,&drawy2);
					transformPoints2(mt,drawx1,&drawx1,drawy1,&drawy1);
					transformPoints2(mt,drawx2,&drawx2,drawy2,&drawy2);
					lineDDA(drawx1, drawy1, drawx2, drawy2); //KIRI LUAR
					
					transformPoints2(ms,x*213+142,&drawx1,mobilY+20,&drawy1);
					transformPoints2(ms,x*213+142,&drawx2,mobilY-40,&drawy2);
					transformPoints2(mt,drawx1,&drawx1,drawy1,&drawy1);
					transformPoints2(mt,drawx2,&drawx2,drawy2,&drawy2);
					lineDDA(drawx1, drawy1, drawx2, drawy2); //KANAN LUAR
					
					//AREA FILLNYA
					if(y>0){//KALO Y 0 JADI TITIK, GA AMAN BUAT FILL
						transformPoints2(ms,x*213+82,&drawfx,mobilY-40,&drawfy);
						transformPoints2(mt,drawfx,&drawfx,drawfy,&drawfy);
						boundaryFill4(drawfx+2,drawfy+1,BLUE,WHITE);
					}
					// lineDDA(x*213+82, yFactor()*(mobilY+20), x*213+142, yFactor()*(mobilY+20)); //BAWAH LUAR
					// lineDDA(x*213+88, yFactor()*(mobilY+15), x*213+137, yFactor()*(mobilY+15)); //BAWAH DALAM
					// lineDDA(x*213+82, yFactor()*(mobilY-40),x*213+142, yFactor()*(mobilY-40));//ATAS LUAR
					// lineDDA(x*213+87, yFactor()*(mobilY-35), x*213+137, yFactor()*(mobilY-35)); //ATAS DALAM
					// lineDDA(x*213+82, yFactor()*(mobilY+20), x*213+82, yFactor()*(mobilY-40)); //KIRI LUAR
					// lineDDA(x*213+87, yFactor()*(mobilY+15), x*213+87, yFactor()*(mobilY-35)); //KIRI DALAM
					// lineDDA(x*213+142, yFactor()*(mobilY+20), x*213+142, yFactor()*(mobilY-40)); //KANAN LUAR
					// lineDDA(x*213+137, yFactor()*(mobilY+15), x*213+137, yFactor()*(mobilY-35)); //KANAN DALAM
					// lineDDA(x*213+92, yFactor()*(mobilY+15), x*213+137, yFactor()*(mobilY-30));
					// lineDDA(x*213+87, yFactor()*(mobilY+10), x*213+132, yFactor()*(mobilY-35));
					// lineDDA(x*213+132, yFactor()*(mobilY+15), x*213+87, yFactor()*(mobilY-30));
					// lineDDA(x*213+137, yFactor()*(mobilY+10), x*213+92, yFactor()*(mobilY-35));
				}else{

					Matrix3x3 mr;//ROTASI
					Matrix3x3 mt;//TRANSLASI
				
					//TITIK PENGGAMBARAN
					int drawx1;//X1 SETELAH DITRANSFORMASI
					int drawy1;//Y1 SETELAH DITRANSFORMASI
					int drawx2;//X2 SETELAH DITRANSFORMASI
					int drawy2;//Y2 SETELAH DITRANSFORMASI
					int drawfx;//X UNTUK FILL
					int drawfy;//Y UNTUK FILL
					
					// cout << "kiri " << x*213+82 << "\n";
					// cout << "kanan " << x*213+142 << "\n";
					// cout << "atas " << 70+(mobilY-40) << "\n";
					// cout << "bawah " << 70+(mobilY+20) << "\n";
					// cout << "Tengah " << x*213+112 << " " << 70+(mobilY-10) <<"\n";
					
					
					rotate2(22.5*(y-11),x*213+112,70+(mobilY-10),mr);
					translate2((y-11)*(maxx-(x*213))/8,0,mt);
					
					transformPoints2(mr,x*213+82,&drawx1,70+(mobilY+20),&drawy1);
					transformPoints2(mr,x*213+142,&drawx2,70+(mobilY+20),&drawy2);
					transformPoints2(mt,drawx1,&drawx1,drawy1,&drawy1);
					transformPoints2(mt,drawx2,&drawx2,drawy2,&drawy2);
					lineDDA(drawx1, drawy1, drawx2, drawy2); //BAWAH LUAR

					transformPoints2(mr,x*213+82,&drawx1,70+(mobilY-40),&drawy1);
					transformPoints2(mr,x*213+142,&drawx2,70+(mobilY-40),&drawy2);
					transformPoints2(mt,drawx1,&drawx1,drawy1,&drawy1);
					transformPoints2(mt,drawx2,&drawx2,drawy2,&drawy2);
					lineDDA(drawx1, drawy1, drawx2, drawy2);//ATAS LUAR
					
					transformPoints2(mr,x*213+82,&drawx1,70+(mobilY+20),&drawy1);
					transformPoints2(mr,x*213+82,&drawx2,70+(mobilY-40),&drawy2);
					transformPoints2(mt,drawx1,&drawx1,drawy1,&drawy1);
					transformPoints2(mt,drawx2,&drawx2,drawy2,&drawy2);
					lineDDA(drawx1, drawy1, drawx2, drawy2); //KIRI LUAR
					
					transformPoints2(mr,x*213+142,&drawx1,70+(mobilY+20),&drawy1);
					transformPoints2(mr,x*213+142,&drawx2,70+(mobilY-40),&drawy2);
					transformPoints2(mt,drawx1,&drawx1,drawy1,&drawy1);
					transformPoints2(mt,drawx2,&drawx2,drawy2,&drawy2);
					lineDDA(drawx1, drawy1, drawx2, drawy2); //KANAN LUAR
	
					//AREA FILLNYA
					transformPoints2(mr,x*213+82+5,&drawfx,70+(mobilY-37),&drawfy);
					transformPoints2(mt,drawfx,&drawfx,drawfy,&drawfy);
					boundaryFill4(drawfx,drawfy,BLUE,WHITE);
	
					// lineDDA(x*213+82, 70+(mobilY+20), x*213+142, 70+(mobilY+20)); //BAWAH LUAR
					// lineDDA(x*213+88, 70+(mobilY+15), x*213+137, 70+(mobilY+15)); //BAWAH DALAM
					// lineDDA(x*213+82, 70+(mobilY-40),x*213+142, 70+(mobilY-40));//ATAS LUAR
					// lineDDA(x*213+87, 70+(mobilY+-35), x*213+137, 70+(mobilY-35)); //ATAS DALAM
					// lineDDA(x*213+82, 70+(mobilY+20), x*213+82, 70+(mobilY-40)); //KIRI LUAR
					// lineDDA(x*213+87, 70+(mobilY+15), x*213+87, 70+(mobilY-35)); //KIRI DALAM
					// lineDDA(x*213+142, 70+(mobilY+20), x*213+142, 70+(mobilY-40)); //KANAN LUAR
					//lineDDA(x*213+137, 70+(mobilY+15), x*213+137, 70+(mobilY-35)); //KANAN DALAM
					//lineDDA(x*213+92, 70+(mobilY+15), x*213+137, 70+(mobilY-30));
					//lineDDA(x*213+87, 70+(mobilY+10), x*213+132, 70+(mobilY-35));
					//lineDDA(x*213+132, 70+(mobilY+15), x*213+87, 70+(mobilY-30));
					//lineDDA(x*213+137, 70+(mobilY+10), x*213+92, 70+(mobilY-35));
				}
			}else if(type == 1){//STONE
				lineDDA(40, 80, 90, 80);
				lineDDA(40, 80, 50, 60);
				lineDDA(50, 60, 55, 55);
				lineDDA(55, 55, 75, 65);
				lineDDA(75, 65, 90, 80);
			}
		}
Ejemplo n.º 17
0
static void makeProgram( RenderData *renderData) {

    GLint ok;

    const char *vertexShader =  "attribute vec3 position;\n"
                                "attribute vec2 texCoord0;\n"
                                "varying vec2 v_texCoord0;\n"
                                "varying float dist;\n"
                                "uniform mat4 modelView;\n"
                                "uniform mat4 projection;\n"
                                "void main(void)\n"
                                "{\n"
                                "    vec4 p = modelView*vec4(position,1.0);\n"
                                "    gl_Position = projection*p;\n"
                                "    v_texCoord0 = texCoord0;\n"
                                "    dist = gl_Position.z*0.1;\n"
                                "}\n";


    const char *fragmentShader =
                                //"precision mediump float;\n"
                                "varying vec2 v_texCoord0;\n"
                                "varying float dist;\n"
                                "uniform sampler2D texUnit0;\n"
                                "uniform float alpha;\n"
                                "uniform float imgAlpha;\n"
                                "uniform vec4 color;\n"
                                "void main()\n"
                                "{\n"
                                "    vec4 txt = texture2D(texUnit0, v_texCoord0)*imgAlpha;\n"
                                "    gl_FragColor =vec4(1.0,1.0,1.0,1.0)*(1.0-dist);\n"
                                "    gl_FragColor.a =1.0;\n"
                                "}\n";



    GLuint vs = glCreateShader(GL_VERTEX_SHADER);
    
    glShaderSource(vs, 1, &vertexShader, NULL);
    glCompileShader(vs);
    glGetShaderiv(vs, GL_COMPILE_STATUS, &ok);
    
    assert(ok);

    GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
    
    glShaderSource(fs, 1, &fragmentShader, NULL);
    glCompileShader(fs);
    glGetShaderiv(fs, GL_COMPILE_STATUS, &ok);


    assert(ok);

    GLuint program = glCreateProgram();
    renderData->program = program;
    
    glAttachShader(program, vs);
    glAttachShader(program, fs);
    glLinkProgram(program);
    glGetProgramiv(program, GL_LINK_STATUS, &ok);
    assert(ok);

    glUseProgram(program);

    identity(renderData->model);
    translate2(renderData->model,-0.2, 0.2, -50.6);

    perspective(renderData->model_view_projection, 90.0, WIDTH/HEIGHT, 1.0, 500.0);

    renderData->mvLocation = glGetUniformLocation(program, "modelView");
    glUniformMatrix4fv(renderData->mvLocation, 1, GL_FALSE, renderData->model); 

    GLint projectionLocation = glGetUniformLocation(program, "projection");
    glUniformMatrix4fv(projectionLocation, 1, GL_FALSE, renderData->model_view_projection); 

    GLint texLocation = glGetUniformLocation(program, "texUnit0");
    glUniform1i(texLocation, 0);

    GLint alphaLocation = glGetUniformLocation(program, "alpha");
    glUniform1f(alphaLocation, 1.0);

    GLint imgAlphaLocation = glGetUniformLocation(program, "imgAlpha");
    glUniform1f(imgAlphaLocation, 1.0);

    GLint colorLocation = glGetUniformLocation(program, "color");
    

    renderData->texCoordLocation = glGetAttribLocation(program, "texCoord0");
    renderData->positionLocation = glGetAttribLocation(program, "position");
    renderData->alphaLocation = alphaLocation;
    renderData->imgAlphaLocation = imgAlphaLocation;
    renderData->colorLocation = colorLocation;

    GLfloat vVertices[] = {1.0, -1.0, 0.0,
                            0.0, -1.0, 0.0,
                           1.0,  0.0, 0.0,
                            0.0,  0.0, 0.0};

    GLfloat vTexCoord[] = {1.0, 1.0,
                           0.0, 1.0,
                           1.0, 0.0,
                           0.0, 0.0};

    GLuint vbo;

    glEnableVertexAttribArray(renderData->positionLocation);
    glEnableVertexAttribArray(renderData->texCoordLocation);

    glGenBuffers(1, &renderData->texBufferId);
    glBindBuffer(GL_ARRAY_BUFFER, renderData->texBufferId);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vTexCoord), vTexCoord, GL_STATIC_DRAW);
    glVertexAttribPointer(renderData->texCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, 0);
    
    glGenBuffers(1, &renderData->vertBufferId);
    glBindBuffer(GL_ARRAY_BUFFER, renderData->vertBufferId);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vVertices), vVertices, GL_STATIC_DRAW);
    glVertexAttribPointer(renderData->positionLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
    
 
}