/* Create a scene to render! */ Scene *SceneSetupTest2( void ) { // Create the main scene data structure Scene *scn = new Scene(); // Set the scene's background color scn->backgroundColor = Color( 0.462f, 0.725f, 0.0f ); // Create a camera for the scene //scn->camera = new Camera( vec3(-5,3,3), vec3(0,0,0), vec3(0,1,0), 60.0, 512, 512 ); scn->camera = new Camera( vec3(0,5,5), vec3(0,0,0), vec3(0,1,0), 60.0, 512, 512 ); // Create a group to contain all the scene geometry, tell the scene about it Group *grp = new Group(); scn->geometry = grp; // Create a material type for our geometry Material *aoMtl = new AmbientOcclusionMaterial( 20 ); Material *redMtl = new LambertianMaterial( Color( 1, 0, 0 ) ); Material *yellowMtl = new LambertianMaterial( Color( 1, 1, 0 ) ); Material *greenMtl = new LambertianMaterial( Color( 0, 1, 0 ) ); Material *blueMtl = new LambertianMaterial( Color( 0, 0, 1 ) ); // Create a red sphere //left eye Primitive *prm = new Sphere( new ConstantColorMaterial(Color::Black()), vec3( -.2, 2.1, 1 ), .15 ); grp->Add( prm ); //right eye prm = new Sphere( new ConstantColorMaterial(Color::Black()), vec3( 0.2, 2.1, 1 ), .15 ); grp->Add( prm ); //nose prm = new Triangle( new ConstantColorMaterial(Color::Black()), vec3( 0, 1.8, 1 ), vec3( 0, 1.5, 1 ), vec3( 0.1, 1.55, 1 ) ); grp->Add( prm ); prm = new Triangle( new ConstantColorMaterial(Color::Black()), vec3( -.2, 1.3, 1 ), vec3( .2, 1.3, 1 ), vec3( 0, 1.15, 1 ) ); grp->Add( prm ); Color brown = Color(.54,.27,.075); prm = new InfinitePlane( new ConstantColorMaterial(brown), vec3( 0, 1, 0 ), vec3( 0, -3.5, 0 ) ); grp->Add( prm ); Color blue = Color(0,0,1); prm = new InfinitePlane( new ConstantColorMaterial(blue), vec3( 0, 0, 1 ), vec3( 0, 0, -1 ) ); grp->Add( prm ); //Begin to read in an object file and create triangles GLMmodel *model; model = glmReadOBJ( "al.obj" ); // Filename should be a char[] or a constant string static GLMgroup* group; static GLMtriangle* triangle; static GLMmaterial* material; group = model->groups; //Go through all the groups and create triangles while (group) { //Go through the group and get all the triangles in the group for (int i = 0; i < group->numtriangles; i++) { //Get a specific triangle triangle = &model->triangles[group->triangles[i]]; //Get the material of the specific triangle material = &model->materials[group->material]; //Get the color, and the 4th item is the alpha value //which i believe is the opacity value float *color = material->diffuse; //Create a color object Color tempColor = Color(color[0],color[1],color[2]); //Get the 3 vertices of the triangle float *vertex1 = &model->vertices[3 * triangle->vindices[0]]; float *vertex2 = &model->vertices[3 * triangle->vindices[1]]; float *vertex3 = &model->vertices[3 * triangle->vindices[2]]; //Create 3 new vec3 objects, which are the vertices vec3 v0 = vec3(vertex1[0], vertex1[1], vertex1[2]); vec3 v1 = vec3(vertex2[0], vertex2[1], vertex2[2]); vec3 v2 = vec3(vertex3[0], vertex3[1], vertex3[2]); //Create a new triangle prm = new Triangle( new ConstantColorMaterial(tempColor), v0,v1,v2 ); //Add the triangle to the group that we are using. grp->Add( prm ); } group = group->next; } glmDelete(model); return scn; }