Ejemplo n.º 1
0
    // XXX: this breaks if s = t
    bool intersects (const line<cood> & ot, cood eps = 0) const {
        int a = s.clockwise(t, ot.s, eps); int b = s.clockwise(t, ot.t, eps);

        if (a == 0 && b == 0) { // colinear corner
            if (!interval<cood>(s.x, t.x).intersects(interval<cood>(ot.s.x, ot.t.x), eps)) return 0;
            if (!interval<cood>(s.y, t.y).intersects(interval<cood>(ot.s.y, ot.t.y), eps)) return 0;
            return 1;
        }

        if (a == b) return 0;
        if (ot.s.clockwise(ot.t, s, eps) == ot.s.clockwise(ot.t, t, eps)) return 0;
        return 1;
    }
Ejemplo n.º 2
0
void task4_5::solution::search_max(const vect &subVect)
{
	if(!subVect.empty())
	{
		int locMax = subVect.at(0);

		for( vect::const_iterator it = subVect.begin() + 1; it != subVect.end(); ++it)
			if(*it > locMax) locMax = *it;

		boost::mutex::scoped_lock lock(mutex);
		{
			if(locMax > max) max = locMax;
		}
	}
}
Ejemplo n.º 3
0
void task4_5::solution::search_min(const vect &subVect)
{
	if(!subVect.empty())
	{
		int locMin = subVect.at(0);

		for( vect::const_iterator it = subVect.begin() + 1; it != subVect.end(); ++it)
			if(*it < locMin) locMin = *it;

		boost::mutex::scoped_lock lock(mutex);
		{
			if(locMin < min) min = locMin;
		}
	}
}
Ejemplo n.º 4
0
	trit vect::operator < (vect param)
	{ /*if this is to the left of param*/
		vect temp=(*this);
		param.y=param.y*-1;
		param.swap();
		temp=param*temp;trit temp2;
		return temp2= (temp.y+temp.x);
	}
Ejemplo n.º 5
0
 inline cood sq_dist (const vect<cood> & ot) const // squared distance to a vector
 { return min(s.sq(ot), t.sq(ot)); }
Ejemplo n.º 6
0
 inline line<cood> flip () const
 { return line<cood>(s.flip(), t.flip()); }
Ejemplo n.º 7
0
vect vect::project(const vect &other) const {
	return (x * other.x + y * other.y + z * other.z)*other.normalize();
}
Ejemplo n.º 8
0
 void set_min_holding_max_constant(which_dimension_type dim, coord min) { min_.set(dim, min); }
Ejemplo n.º 9
0
 void set_max_holding_min_constant(which_dimension_type dim, coord max) { max_.set(dim, max); }
Ejemplo n.º 10
0
vect vmlpt(const vect &a, const vect &b)
{
    return vect(((a.ready()*b.readz()) - (a.readz()*b.ready())),
                ((a.readz()*b.readx()) - (a.readx()*b.readz())),
                ((a.readx()*b.ready()) - (a.ready()*b.readx())));
}
Ejemplo n.º 11
0
bool is_coplanar(const vect<T>& ab, const vect<T>& ac, const vect<T>& ad){
    return abs(ab.cross(ac).dot(ad)) > 0;
}
Ejemplo n.º 12
0
vect sub(const vect &a, const vect &b)
{
    return vect(a.readx() - b.readx(), a.ready() - b.ready(), a.readz() - b.readz());
}
Ejemplo n.º 13
0
double smlpt(const vect& a, const vect& b)
{
    return a.readx()*b.readx() + a.ready()*b.ready() + a.readz()*b.readz();
}
Ejemplo n.º 14
0
double sinvect(const vect& a, const vect& b)
{
    return vmlpt(a, b).modul() / (a.modul()*b.modul());
}
Ejemplo n.º 15
0
double cosvect(const vect& a, const vect& b)
{
    return smlpt(a, b) / (a.modul()*b.modul());
}
Ejemplo n.º 16
0
int main(int argc, char** argv) {

    TGAImage image(width, height, TGAImage::RGB);
    TGAImage image_shdr(width, height, TGAImage::RGB);





    std::vector<string> names;
    std::vector<string> diffs;
    std::vector<string> nm;
    std::vector<string> gls;
    std::vector<coeffs> coeff;

    names.push_back("african_head.obj");
    //names.push_back("floor.obj");
    names.push_back("african_head_eye_inner.obj");
    //names.push_back("african_head_eye_outer.obj");
    //names.push_back("diablo3_pose.obj");


    diffs.push_back("african_head_diffuse.tga");
    //diffs.push_back("floor_diffuse.tga");
    diffs.push_back("african_head_eye_inner_diffuse.tga");
    //diffs.push_back("african_head_eye_outer_diffuse.tga");
    //diffs.push_back("diablo3_pose_diffuse.tga");


    nm.push_back("african_head_nm.tga");
    //nm.push_back("floor_nm_tangent.tga");
    nm.push_back("african_head_eye_inner_nm.tga");
    //nm.push_back("african_head_eye_outer_nm.tga");
    //nm.push_back("diablo3_pose_nm.tga");



    gls.push_back("african_head_spec.tga");
    //gls.push_back("floor_nm_tangent.tga");
    gls.push_back("african_head_eye_inner_spec.tga");
    //gls.push_back("african_head_eye_outer_spec.tga");
    //gls.push_back("diablo3_pose_spec.tga");


    coeff.push_back(coeffs(20,1.2f,0.6f));
    //coeff.push_back(coeffs(10,1.f,0.6f));
    coeff.push_back(coeffs(20,1.2f,0.6f));
    //coeff.push_back(coeffs(10,1.f,4.6f));
    //coeff.push_back(coeffs(20,1.2f,0.6f));

    char name_file[40];
    char name_file_diff[40];
    char name_file_norm[40];
    char name_file_spec[40];

    ViewPortMtx=viewport(width/8,height/8 , width*3/4, height*3/4, zeight);
    //width/8, height/8, width*3/4, height*3/4
    //PerspMtx=perspective((eye-center).norm());
    PerspMtx=perspective((eye-center).norm());
    view = lookat(eye, center,up);



    shdw=ViewPortMtx*lookat(light_vec,center,up);
    shdw_adj=shdw.Adjacent();

    vect<4,float> gl_light_shdw;
    gl_light_shdw[0]=light_vec[0];
    gl_light_shdw[1]=light_vec[1];
    gl_light_shdw[2]=light_vec[2];

    gl_light_shdw=shdw*gl_light_shdw;

    printf("gl_light_shdw %f %f %f\n",gl_light_shdw[0],gl_light_shdw[1],gl_light_shdw[2]);


    light_vec_shdw=vect<3,float>(gl_light_shdw[0],gl_light_shdw[1],gl_light_shdw[2]);

    light_vec_shdw=light_vec_shdw.normalize();

    fin_mtrx=ViewPortMtx*PerspMtx*view;
    fin_mtrx_adj=(ViewPortMtx*view).invert_transpose();


    uniform_Mshadow=shdw*fin_mtrx.invert();


    //light_dir = proj<3>((Projection*ModelView*embed<4>(light_dir, 0.f))).normalize();
    vect<4,float> gl_light;
    gl_light[0]=light_vec[0];
    gl_light[1]=light_vec[1];
    gl_light[2]=light_vec[2];

    gl_light=ViewPortMtx*PerspMtx*view*gl_light;
    light_vec=vect<3,float>(gl_light[0],gl_light[1],gl_light[2]);

    light_vec=light_vec.normalize();


    for (int i =0; i<names.size(); i++) {


        coeff_cur=coeff[i];

        strcpy(name_file,names[i].c_str());
        strcpy(name_file_diff,diffs[i].c_str());
        strcpy(name_file_norm,nm[i].c_str());
        strcpy(name_file_spec,gls[i].c_str());
        printf("file %s %s %s %s\n",name_file,name_file_diff,name_file_norm,name_file_spec);



        Model mdl;





        parser(name_file_diff,name_file,name_file_norm,name_file_spec,mdl);
        Shaderer shader;
        ShaderGuro2 shaderer;


        //printf("OKI DOKI!\n");

        for(std::vector<int>::size_type i = 0; i != mdl.coords_tri.size(); i++) {

            for (int j=0; j<3; j++) {
                shader.vertex(i, j,&mdl);
            }

            color_triangle(shader, image_shdr, z_shdr);

        }





        for(std::vector<int>::size_type i = 0; i != mdl.coords_tri.size(); i++) {

            for (int j=0; j<3; j++) {
                shaderer.vertex(i, j,&mdl);
            }

            color_triangle(shaderer, image, z_buffer);

        }

    }


    image_shdr.flip_vertically(); // i want to have the origin at the left bottom corner of the image
    image_shdr.write_tga_file("output_shr.tga");

    image.flip_vertically(); // i want to have the origin at the left bottom corner of the image
    image.write_tga_file("output.tga");

    return 0;
}