예제 #1
0
void Picture::render(int w, int h )
{
//while(true){
    // Get BasicObjects
    BasicObject* obj = new BasicObject( OBJ_FILE );

    Vertex* eye = new Vertex( 0,0,0 );
    Vertex* at = new Vertex(0,0,0);
    Matrix* camera = buildCamera( CMRA_FILE, eye, at );

    // Scene creation
    Scene* scene = new Scene();

    // Set up lighting
    double shading[8];
    getShadingInfo( SHADE_FILE, shading );

    Light* light = new Light();
    Vertex* light_loc = new Vertex( shading[0], shading[1], shading[2] );
    Color* light_clr = new Color( LGHT_CLR );

    light->setLocation( light_loc );
    light->setColor( light_clr );

    Color* amb = new Color( AMB_CLR );

    // Add objects to the scene.
    InstanceObject* sp = buildInstanceObject( TRS_FILE, obj );
    sp->setShininess( shading[7] );

    scene->addNode( sp );

    scene->render( w, h, light, eye, at, amb );

    delete eye;
    delete at;
    delete amb;
    delete light;
    delete scene;
//}
}
예제 #2
0
void Picture::render(Pixel* pix)
{
//while(true){
    // Get BasicObjects
    BasicObject* obj = readObject( OBJ_FILE );

    double z[3];
    getZValues( FOV_FILE, z );

    //WNACI
    Matrix* wnd = AffineTransforms::windowingTransform(pix->getWidth(),
        pix->getHeight());
    Matrix* aspct = AffineTransforms::aspectRatio(pix->getWidth(),
        pix->getHeight(), z[0]);    // Matrix for aspect ratio.

    Vertex* eye = new Vertex( 0,0,0 );
    Matrix* camera = buildCamera( CMRA_FILE, eye );
    Matrix* normal = AffineTransforms::perspective( z[1], z[2] );

    Matrix* tmp = aspct->multiply(camera);
    delete camera;
    delete aspct;

    Matrix* tmp2 = normal->multiply( tmp );
    delete tmp;
    delete normal;

    Matrix* wnca = wnd->multiply(tmp2);
    delete tmp2;
    delete wnd;
    // END WNACI

    // Scene creation
    Scene* scene = new Scene(wnca);

    // Set up lighting
    double shading[8];
    getShadingInfo( SHADE_FILE, shading );

    Light* light = new Light();
    Vertex* light_loc = new Vertex( shading[0], shading[1], shading[2] );
    Color* light_clr = new Color( LGHT_CLR );
    
    light->setLocation( light_loc );
    light->setColor( light_clr );
    
    Color* amb = new Color( AMB_CLR );
    
    // Add objects to the scene.
    InstanceObject* sp = buildInstanceObject( TRS_FILE, obj );
    sp->setShininess( shading[7] );

    scene->addNode( sp );

    scene->render( pix, light, eye, amb, shading[6] );

    delete eye;
    delete amb;
    delete light;
    delete scene;
//}
}
예제 #3
0
파일: Picture.cpp 프로젝트: alwalker/TTU
InstanceObject* Picture::buildInstanceObject(char* fileName, BasicObject* obj)
{
   InstanceObject* io = new InstanceObject(obj);
   FileIO* inputFile = new FileIO(fileName, 1);  //for reading

   //scale transformation
   string line = inputFile->readLine();  //skip this line
   line = inputFile->readLine();
   double sx = atof(line.c_str());
   line = inputFile->readLine();
   double sy = atof(line.c_str());
   line = inputFile->readLine();
   double sz = atof(line.c_str());
   Matrix* scale = AffineTransforms::scale(sx, sy, sz);

   //rotation transformations
   line = inputFile->readLine();  //skip this line
   line = inputFile->readLine();
   double rx = atof(line.c_str());
   Matrix* rotX = AffineTransforms::rotateX(rx);
   line = inputFile->readLine();
   double ry = atof(line.c_str());
   Matrix* rotY = AffineTransforms::rotateY(ry);
   line = inputFile->readLine();
   double rz = atof(line.c_str());
   Matrix* rotZ = AffineTransforms::rotateZ(rz);

   //translation transformation
   line = inputFile->readLine();  //skip this line
   line = inputFile->readLine();
   double tx = atof(line.c_str());
   line = inputFile->readLine();
   double ty = atof(line.c_str());
   line = inputFile->readLine();
   double tz = atof(line.c_str());
   Matrix* translate = AffineTransforms::translate(tx, ty, tz);

   //material
   line = inputFile->readLine();  //skip this line
   line = inputFile->readLine();
   double mr = atof(line.c_str());
   line = inputFile->readLine();
   double mg = atof(line.c_str());
   line = inputFile->readLine();
   double mb = atof(line.c_str());
   Color* mat = new Color(mr, mg, mb);
   io->setDiffuseMaterial(mat);

   //standard TRS form
   io->buildTransform(scale);  //deletes the matrix when done
   io->buildTransform(rotX);  
   io->buildTransform(rotY);  
   io->buildTransform(rotZ); 
   io->buildTransform(translate);

   //Get shininess
   FileIO* shaderFile = new FileIO("shade.txt", 1);
   line = shaderFile->readLine();
   line = shaderFile->readLine();
   line = shaderFile->readLine();
   line = shaderFile->readLine();
   line = shaderFile->readLine();
   line = shaderFile->readLine();
   line = shaderFile->readLine();
   line = shaderFile->readLine();
   line = shaderFile->readLine();
   line = shaderFile->readLine();
   line = shaderFile->readLine();
   line = shaderFile->readLine();

   io->setShininess(atof(line.c_str()));

   delete shaderFile;
   delete inputFile;
   return io;
}