Ejemplo n.º 1
0
        /**
           * Create and initialize the scene for the rendering picture.
           * @return The scene just created
           */
        Scene createScene()
        {
            int x = 0;
            int y = 0;

            Scene scene = new Scene();

            /* create spheres */

            Primitive p;
            int nx = 4;
            int ny = 4;
            int nz = 4;
            for (int i = 0; i < nx; i++)
            {
                for (int j = 0; j < ny; j++)
                {
                    for (int k = 0; k < nz; k++)
                    {
                        double xx = 20.0 / (nx - 1) * i - 10.0;
                        double yy = 20.0 / (ny - 1) * j - 10.0;
                        double zz = 20.0 / (nz - 1) * k - 10.0;

                        p = new Sphere(new Vec(xx, yy, zz), 3);
                        //p.setColor(i/(double) (nx-1), j/(double)(ny-1), k/(double) (nz-1));
                        p.setColor(0, 0, (i + j) / (double)(nx + ny - 2));
                        p.surf.shine = 15.0;
                        p.surf.ks = 1.5 - 1.0;
                        p.surf.kt = 1.5 - 1.0;
                        scene.addObject(p);
                    }
                }
            }

            /* Creates five lights for the scene */
            scene.addLight(new Light(100, 100, -50, 1.0));
            scene.addLight(new Light(-100, 100, -50, 1.0));
            scene.addLight(new Light(100, -100, -50, 1.0));
            scene.addLight(new Light(-100, -100, -50, 1.0));
            scene.addLight(new Light(200, 200, 0, 1.0));

            /* Creates a View (viewing point) for the rendering scene */
            View v = new View(new Vec(x, 20, -30),
                                new Vec(x, y, 0),
                                new Vec(0, 1, 0),
                                1.0,
                    35.0 * 3.14159265 / 180.0,
                                1.0);
            /*
            v.from = new Vec(x, y, -30);
            v.at = new Vec(x, y, -15);
            v.up = new Vec(0, 1, 0);
            v.angle = 35.0 * 3.14159265 / 180.0;
            v.aspect = 1.0;
            v.dist = 1.0;

            */
            scene.setView(v);

            return scene;
        }
Ejemplo n.º 2
0
        public void setScene(Scene scene)
        {
            // Get the objects count
            int nLights = scene.getLights();
            int nObjects = scene.getObjects();

            lights = new Light[nLights];
            prim = new Primitive[nObjects];

            // Get the lights
            for (int l = 0; l < nLights; l++)
            {
                lights[l] = scene.getLight(l);
            }

            // Get the primitives
            for (int o = 0; o < nObjects; o++)
            {
                prim[o] = scene.getObject(o);
            }

            // Set the view
            view = scene.getView();
        }