Esempio n. 1
0
        int inputTimer = 0;                      // used for a small delay after input

        // initialize
        public void Init()
        {
            // load a texture
            wood = new Texture("../../assets/wood.jpg");
            porcelain = new Texture("../../assets/porcelain_texture.jpg");
            ornate = new Texture("../../assets/ornate.jpg");
            ornate2 = new Texture("../../assets/ornate2.jpg");

            c = new Camera(new Vector3(0, 0, 10), new Vector3(0, 0, 1));

            // load teapot
            floor = new Mesh("../../assets/floor.obj");
            floor.mTransform = Matrix4.CreateTranslation(new Vector3(0, 0, 0));
            floorNode = new SceneGraph(null, floor, wood);

            teapot = new Mesh("../../assets/teapot.obj");
            teapot.mTransform = Matrix4.CreateTranslation(new Vector3(0, 0, 0));
            SceneGraph teapotNode = new SceneGraph(floorNode, teapot, ornate2);

            teacup = new Mesh("../../assets/Cup.obj");
            teacup.mTransform = Matrix4.CreateTranslation(new Vector3(10, 0, -5));
            SceneGraph teacupNode = new SceneGraph(floorNode, teacup, wood);

            teacup2 = new Mesh("../../assets/Cup.obj");
            teacup2.mTransform = Matrix4.CreateTranslation(new Vector3(-10, 0, 5));
            SceneGraph teacup2Node = new SceneGraph(floorNode, teacup2, ornate);

            teacup3 = new Mesh("../../assets/Cup.obj");
            teacup3.mTransform = Matrix4.CreateTranslation(new Vector3(0, 7, 0)) * Matrix4.CreateFromAxisAngle(new Vector3(0, 1, 0), 4f);
            SceneGraph teacup3Node = new SceneGraph(teacup2Node, teacup3, porcelain);

            teacup4 = new Mesh("../../assets/Cup.obj");
            teacup4.mTransform = Matrix4.CreateTranslation(new Vector3(0, -13, 0)) * Matrix4.CreateFromAxisAngle(new Vector3(1, 0, 0), PI);
            SceneGraph teacup4Node = new SceneGraph(teapotNode, teacup4, porcelain);

            // initialize stopwatch
            timer = new Stopwatch();
            timer.Reset();
            timer.Start();
            
            // create shaders
            shader = new Shader("../../shaders/vs.glsl", "../../shaders/fs.glsl");
            postproc = new Shader("../../shaders/vs_post.glsl", "../../shaders/fs_post.glsl");

            // create the render target
            target = new RenderTarget(screen.width, screen.height);
            quad = new ScreenQuad();

            // set the lights
            int ambientColor = GL.GetUniformLocation(shader.programID, "ambientColor");
            lights = new List<Light>();
            lights.Add(new Light(new Vector3(10, 5, -10), new Vector3(1f, 1f, 1f), new Vector3(1f, 1f, 1f), "lightPos", "lightCol", "specCol", 0, shader, true));
            lights.Add(new Light(new Vector3(-3, 3, 5), new Vector3(0, 1, 1), new Vector3(0.5f, 0.5f, 0.5f), "lightPos", "lightCol", "specCol", 1, shader, false));
            lights.Add(new Light(new Vector3(0, 20, 14), new Vector3(0.4f, 0.4f, 0.4f), new Vector3(0.1f, 0.5f, 0.1f), "lightPos", "lightCol", "specCol", 2, shader, true));
            lights.Add(new Light(new Vector3(5, 0, 0), new Vector3(0, 0, 1), new Vector3(0.1f, 0.1f, 0.1f), "lightPos", "lightCol", "specCol", 3, shader, false));

            // Defining the arrays for use in the fragment shader
            lightPoss = new Vector3[4];
            lightCols = new Vector3[4];
            specCols = new Vector3[4];

            // filling the arrays so they can be used in the fragment shader
            for (int i = 0; i < lights.Count; i++)
            {
                lightPoss[i] = lights[i].lightPosition;
                lightCols[i] = lights[i].lightColor;
                specCols[i] = lights[i].specularLightColor;
            }

            // setting the values in the fragment shader
            GL.UseProgram(shader.programID);
            GL.Uniform3(ambientColor, new Vector3(0.1f, 0.1f, 0.1f));
            for (int i = 0; i < lights.Count; i++)
            {
                GL.Uniform3(lights[i].lightIDp, lightPoss[i]);
                GL.Uniform3(lights[i].lightIDc, lightCols[i]);
                GL.Uniform3(lights[i].lightIDs, specCols[i]);
            }
        }