void SceneCache::initDefault() { Color errorColor = Color::Magenta; ColorTexturePtr errorCTexture(new ConstantTexture<Color>(errorColor)); addColorTexture(mErrorCode, errorCTexture); FloatTexturePtr errorFTexture(new ConstantTexture<float>(0.5f)); addFloatTexture(mErrorCode, errorFTexture); MaterialPtr errorMaterial(new LambertMaterial(errorCTexture)); addMaterial(mErrorCode, errorMaterial); Geometry* errorGeometry = new Sphere(1.0f); errorGeometry->init(); addGeometry(mErrorCode, errorGeometry); ParamSet modelParams; modelParams.setString("geometry", mErrorCode); modelParams.setString("material", mErrorCode); const Primitive* errorPrimitive = ModelPrimitiveCreator().create(modelParams, *this); addPrimitive(mErrorCode, errorPrimitive); addAreaLight(mErrorCode, NULL); }
void buildScene(void) { // Sets up all objects in the scene. This involves creating each object, // defining the transformations needed to shape and position it as // desired, specifying the reflectance properties (albedos and colours) // and setting up textures where needed. // Light sources must be defined, positioned, and their colour defined. // All objects must be inserted in the object_list. All light sources // must be inserted in the light_list. // // To create hierarchical objects: // You must keep track of transformations carried out by parent objects // as you move through the hierarchy. Declare and manipulate your own // transformation matrices (use the provided functions in utils.c to // compound transformations on these matrices). When declaring a new // object within the hierarchy // - Initialize the object // - Apply any object-level transforms to shape/rotate/resize/move // the object using regular object transformation functions // - Apply the transformations passed on from the parent object // by pre-multiplying the matrix containing the parent's transforms // with the object's own transformation matrix. // - Compute and store the object's inverse transform as usual. // // NOTE: After setting up the transformations for each object, don't // forget to set up the inverse transform matrix! // struct object3D *o; // Simple scene for Assignment 3: // Insert a couple of objects. A plane and two spheres // with some transformations. // Note the parameters: ra, rd, rs, rg, R, G, B, alpha, r_index, and shinyness) // // struct object3D *newSphere(double ra, double rd, double rs, double rg, // double r, double g, double b, // double alpha, double r_index, double shiny) // Intialize a new sphere with the specified parameters: // ra, rd, rs, rg - Albedos for the components of the Phong model // r, g, b, - Colour for this plane // alpha - Transparency, must be set to 1 unless you are doing refraction // r_index - Refraction index if you are doing refraction. // shiny -Exponent for the specular component of the Phong model // // This is assumed to represent a unit sphere centered at the origin. // struct object3D *o; struct pointLS *l; struct point3D p; o=newSphere(0.15,.05,.25,0.25,0.75,0.75,0.75,0.25,1.52,6); // Initialize a sphere Scale(o,2,2,2); // Apply a few transforms (Translate * Rotate * Scale) RotateZ(o,PI/4); Translate(o,0,-3,6); // Scale(o,2,2,2); invert(&o->T[0][0],&o->Tinv[0][0]); // loadTexture(o, "./textures/grass.ppm", 1, &texture_list); loadTexture(o, "./data/textures/ppm/window_n.ppm", 2, &texture_list); insertObject(o,&object_list); // <-- If you don't insert the object into the object list, // nothing happens! your object won't be rendered. // That's it for defining a single sphere... let's add a couple more objects o=newSphere(.05,.25,.55,0.55,.95,.55,0.35,0.1,1.77,6); Scale(o,.95,1.65,.65); RotateZ(o,-PI/1.5); Translate(o,0,0,6); // Scale(o,2,2,2); invert(&o->T[0][0],&o->Tinv[0][0]); // loadTexture(o, "./textures/grass.ppm", 1, &texture_list); // loadTexture(o, "./textures/grass_n.ppm", 2, &texture_list); insertObject(o,&object_list); o=newPlane(.05,.75,0,0.25,.55,.8,.75,1,1,2); Scale(o,11,11,11); // RotateZ(o,PI/4); RotateX(o,PI/4); Translate(o,0,-4,5); invert(&o->T[0][0],&o->Tinv[0][0]); loadTexture(o, "./data/textures/ppm/sintfloor01.ppm", 1, &texture_list); loadTexture(o, "./data/textures/ppm/sintfloor01_n.ppm", 2, &texture_list); insertObject(o,&object_list); // o=newPlane(.65,.75,.00,.00,.55,.8,1,1,1,5); // Scale(o,500,500,11); // RotateZ(o, PI/4); // RotateX(o,PI); // Translate(o,0,-10,8); // invert(&o->T[0][0],&o->Tinv[0][0]); // insertObject(o,&object_list); // Insert a single point light source. We set up its position as a point structure, and specify its // colour in terms of RGB (in [0,1]). NUM_LIGHTS = 250; addAreaLight(1.5,1.5,0,-1,0, 0,25.5,-3.5,NUM_LIGHTS, 0.71372549,0.796078431,0.815686275, &object_list, &light_list); // addAreaLight(25.0, 25.0, 0, -1, -1, 0.0, 600, 135, NUM_LIGHTS, 0.71372549,0.796078431,0.815686275, &object_list, &light_list); // struct pointLS *l1; // struct point3D p1; // p1.px=0; // p1.py=500; // p1.pz=140; // p1.pw=1; // l1=newPLS(&p1,0.71372549,0.796078431,0.815686275); // insertPLS(l1,&light_list); // struct pointLS *l2; // struct point3D p2; // p2.px=0; // p2.py=490; // p2.pz=170; // p2.pw=1; // l2=newPLS(&p2,0.71372549/1.25,0.796078431/1.25,0.815686275/1.25); // insertPLS(l2,&light_list); // End of simple scene for Assignment 3 // Keep in mind that you can define new types of objects such as cylinders and parametric surfaces, // or, you can create code to handle arbitrary triangles and then define objects as surface meshes. // // Remember: A lot of the quality of your scene will depend on how much care you have put into defining // the relflectance properties of your objects, and the number and type of light sources // in the scene. /////////////////////////////////////////////////////////////////////////////////////////////////////////// // TO DO: For Assignment 4 you *MUST* define your own cool scene. // We will be looking for the quality of your scene setup, the use of hierarchical or composite // objects that are more interesting than the simple primitives from A3, the use of textures // and other maps, illumination and illumination effects such as soft shadows, reflections and // transparency, and the overall visual quality of your result. Put some work into thinking // about these elements when designing your scene. /////////////////////////////////////////////////////////////////////////////////////////////////////////// }