Ejemplo n.º 1
0
vect vect::project(const vect &other) const {
	return (x * other.x + y * other.y + z * other.z)*other.normalize();
}
Ejemplo n.º 2
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;
}