/** * Reads a file to build an InstanceObject object. * Written by Dr. Boshart * Modified by Thomas Shaffer */ InstanceObject* Picture::buildInstanceObject(char* fileName, BasicObject* obj) { InstanceObject* io = new InstanceObject(obj); FileIO* inputFile = new FileIO(fileName, 1); //for reading char* f1 = (char*)malloc(255*sizeof(char)); char* f2 = (char*)malloc(255*sizeof(char)); //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); //standard TRS form io->buildTransform(scale); //deletes the matrix when done io->buildTransform(rotX); io->buildTransform(rotY); io->buildTransform(rotZ); io->buildTransform(translate); // Material line = inputFile->readLine(); line = inputFile->readLine(); double red = atof(line.c_str()); line = inputFile->readLine(); double green = atof(line.c_str()); line = inputFile->readLine(); double blue = atof(line.c_str()); Color* color = new Color( red, green, blue ); io->setColor( color ); // Texture string t_string = string("texture"); line = inputFile->readLine(); //if ( strcmp( line.c_str(), t_string.c_str() ) ) { line = inputFile->readLine(); const char* file = line.c_str(); strcpy( f1, file ); line = inputFile->readLine(); const char* file2 = line.c_str(); strcpy( f2, file2 ); line = inputFile->readLine(); int width = atoi( line.c_str() ); line = inputFile->readLine(); int height = atoi( line.c_str() ); Texture *tex = new Texture( f1, width, height ); Texture *norm = new Texture( f2, width, height ); io->setTexture( tex ); io->setNormal( norm ); //} delete inputFile; return io; }
/** * Reads a file to build an InstanceObject object. * Written by Dr. Boshart * Modified by Thomas Shaffer */ 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); //standard TRS form io->buildTransform(scale); //deletes the matrix when done io->buildTransform(rotX); io->buildTransform(rotY); io->buildTransform(rotZ); io->buildTransform(translate); // Material line = inputFile->readLine(); line = inputFile->readLine(); double red = atof(line.c_str()); line = inputFile->readLine(); double green = atof(line.c_str()); line = inputFile->readLine(); double blue = atof(line.c_str()); io->setColor( red, green, blue ); // Texture line = inputFile->readLine(); line = inputFile->readLine(); char* file = (char*)line.c_str(); line = inputFile->readLine(); int width = atoi( line.c_str() ); line = inputFile->readLine(); int height = atoi( line.c_str() ); Texture *tex = new Texture( file, width, height ); io->setTexture( tex ); delete inputFile; return io; }