示例#1
0
 // initialize
 public void Init()
 {
     // load teapot
     mesh = new Mesh("../../assets/teapot.obj");
     floor = new Mesh("../../assets/floor.obj");
     // 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");
     // load a texture
     wood = new Texture("../../assets/wood.jpg");
     // create the render target
     target = new RenderTarget(screen.width, screen.height);
     quad = new ScreenQuad();
     // set the light 
     int ambientColor = GL.GetUniformLocation(shader.programID, "ambientColor");
     Light L = new Light(new Vector3(20, 0, 0), new Vector3(0.1f, 0.1f, 0.1f), "lightPos", "lightCol", shader, true);
     //int lightID = GL.GetUniformLocation(shader.programID, "lightPos");
     GL.UseProgram(shader.programID);
     GL.Uniform3(ambientColor, new Vector3(0.1f, 0.1f, 0.1f));
     GL.Uniform3(L.lightIDp, L.lightPos);
     GL.Uniform3(L.lightIDc, L.lightCol);
 }
示例#2
0
        // initialize
        public void Init()
        {
            cam = new Camera();
            // create shaders
            shader = new Shader("../../shaders/vs.glsl", "../../shaders/fs.glsl");
            postproc = new Shader("../../shaders/vs_post.glsl", "../../shaders/fs_post.glsl");

            colorCube = new Texture3d("../../assets/ColorLookupTexture.jpg");

            // load a texture
            Texture wood = new Texture("../../assets/wood.jpg");
            // create the render target
            Mesh teapot = new Mesh("../../assets/teapot.obj") { texture = wood };

            scene = new SceneGraph();
            Node bigteapot = new Node()
            {
                mesh = teapot,
                localTranslate = new Vector3(0, -4, -15),
                localRotate = new Vector3(0, 1, 0)
            };

            Node babyTeapot = new Node() {
                mesh = teapot,
                localTranslate = new Vector3(-5, 2, -7),
                scale = 0.3f,
                localRotate = new Vector3(0, 1, 0)
            };

            bigteapot.AddChild(babyTeapot);
            Node world = new Node();

            world.AddChild(new Node {
                mesh = new Mesh("../../assets/floor.obj") { texture = wood },
                localTranslate = new Vector3(0, -4, -15)
            });
            world.AddChild(bigteapot);
            scene.world = world;

            // initialize stopwatch
            timer = new Stopwatch();
            timer.Reset();
            timer.Start();

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

            GL.UseProgram(shader.programID);
            // Ambient light
            GL.Uniform3(shader.uniform_ambientLight, new Vector3(0.2f, 0.1f, 0.1f));
            
            // A bright lamp
            Light lamp = new Light(new Vector3(0f, 2f, 10f), new Vector3(10f, 10f, 8f));
            GL.Uniform3(shader.lightPosition, lamp.localTranslate);
            GL.Uniform3(shader.lightColor, lamp.color);

        }
示例#3
0
 public SceneGraph(Shader shader, Shader postproc, RenderTarget target, ScreenQuad quad)
 {
     meshes = new List <Mesh>();
     // taken directly from game.cs
     this.shader   = shader;
     this.postproc = postproc;
     this.target   = target;
     this.quad     = quad;
 }
示例#4
0
        // initialize
        public void Init()
        {
            // load a texture
            wood = new Texture("../../assets/wood.jpg");
            paint = new Texture("../../assets/paint.jpg");
            wol = new Texture("../../assets/wol.jpg");

            // load teapot basis and floor
            // public Mesh(string fileName, Mesh ouder, float transx, float transy, float transz, float rotx, float roty, float rotz, Texture texture, float rotatiefactor)
            Mesh theepot_basis = new Mesh("../../assets/teapot.obj", null, 0, -3, -15, 0, 1, 0, paint, 0.05f);
            Mesh floor = new Mesh("../../assets/floor.obj", null, 0, -7, -15, 0, 1, 0, wood, 0);

            // create scenegraph and add meshes
            scenegraph = new sceneGraph();
            scenegraph.objecten.Add(theepot_basis);
            scenegraph.objecten.Add(floor);

            // create several teapots in layers 
            for(int i = 0; i < 2; i++)
            {
                for(int j = 0; j < 2; j++)
                {
                    Mesh theepot_eerste_laag = new Mesh("../../assets/teapot_half.obj", theepot_basis, -3.5f + 7 * i, 6, -3.5f + 7 * j, 0, 1, 0, wood, (i+j) * 0.2f + 0.1f);
                    scenegraph.objecten.Add(theepot_eerste_laag);

                    // maak de tweede laag bovenop de eerste laag
                    for (int k = 0; k < 2; k++)
                    {
                        for (int l = 0; l < 2; l++)
                        {
                            Mesh theepot_tweede_laag = new Mesh("../../assets/teapot_kwart.obj", theepot_eerste_laag, -2.0f + 4 * k, 4, -2.0f + 4 * l, 0, 1, 0, wol, (k+l) * 0.25f + 0.1f);
                            scenegraph.objecten.Add(theepot_tweede_laag);
                        }
                    }
                }
            }

            // 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");
            // load a texture
            wood = new Texture("../../assets/wood.jpg");
            paint = new Texture("../../assets/paint.jpg");
            wol = new Texture("../../assets/wol.jpg");
            // create the render target
            target = new RenderTarget(screen.width, screen.height);
            quad = new ScreenQuad();

            camera = new Camera();
        }
示例#5
0
        // initialize
        public void Init()
        {
            // create the render target
            target = new RenderTarget(screen.width, screen.height);
            quad = new ScreenQuad();

            camera = new Camera();

            SwitchScene(new Scene1());

            // initialize stopwatch
            timer = new Stopwatch();
            timer.Reset();
        }
示例#6
0
 // initialize
 public void Init()
 {
     // 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();
     // create inputmanager
     inputManager = new InputManager();
     // add objects to scenegraph
     AddObjects();
 }
示例#7
0
 // initialize
 public void Init()
 {
     // load teapot
     teapot = new Mesh("../../assets/teapot.obj");
     floor = new Mesh("../../assets/floor.obj");
     dummy = new Mesh("../../assets/dummy_obj.obj");
     // create shaders
     shader = new Shader("../../shaders/vs.glsl", "../../shaders/fs.glsl");
     postproc = new Shader("../../shaders/vs_post.glsl", "../../shaders/fs_post.glsl");
     // load a texture
     wood = new Texture("../../assets/wood.jpg");
     glass = new Texture("../../assets/glass.jpg");
     // create the render target
     target = new RenderTarget(screen.width, screen.height);
     quad = new ScreenQuad();
     scenegraph = new scenegraph();
     scenegraph.Init(shader);
 }
示例#8
0
	// initialize
	public void Init()
	{
		// load teapot
		mesh = new Mesh( "../../assets/teapot.obj" );
		floor = new Mesh( "../../assets/floor.obj" );
		// 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" );
		// load a texture
		wood = new Texture( "../../assets/wood.jpg" );
		// create the render target
		target = new RenderTarget( screen.width, screen.height );
		quad = new ScreenQuad();
	}
示例#9
0
        // initialize
        public void Init()
        {
            // load teapot
            //mesh = new Mesh( "../../assets/teapot.obj" ,Vector3.Zero,Vector3.Zero);
            //Mesh mesh2 = new Mesh("../../assets/teapot.obj", new Vector3(0, 0, 0), new Vector3(0, 0, 0));
            //floor = new Mesh("../../assets/floor.obj", new Vector3(0, 0, 0), new Vector3(0, 0, 0));
            // 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");
            // load a texture
            wood = new Texture("../../assets/wood.jpg");
            // create the render target
            target = new RenderTarget(screen.width, screen.height);
            quad   = new ScreenQuad();

            sceneGraph.Init();

            fxId = GL.GetUniformLocation(postproc.programID, "fx");
        }
示例#10
0
        Texture wood, jacco, white, metal, wood2, floor1, glass, ceramic;                // texture to use for rendering

        // initialize
        public void Init()
        {
            // Begindirection of the camera.
            camera = Matrix4.CreateFromAxisAngle(new Vector3(0, 1, 0), 0);

            // 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();
            // create the scenegraph
            scenegraph = new SceneGraph(shader, postproc, target, quad);

            // load the textures
            jacco = new Texture("../../assets/jacco.png");
            white = new Texture("../../assets/white.jpg");
            wood = new Texture("../../assets/wood.jpg");
            wood2 = new Texture("../../assets/wood2.jpg");
            metal = new Texture("../../assets/metal.jpg");
            floor1 = new Texture("../../assets/floor.jpg");
            glass = new Texture("../../assets/glass.jpg");
            ceramic = new Texture("../../assets/ceramic.jpg");

            // load the meshes
            mesh = new Mesh("../../assets/teapot.obj");
            floor = new Mesh("../../assets/floor.obj");
            table = new Mesh("../../assets/table.obj");
            cup = new Mesh("../../assets/cup.obj");
            lamp = new Mesh("../../assets/lamp.obj");
            fan = new Mesh("../../assets/blades.obj");
            chair = new Mesh("../../assets/chair.obj");

            // Add the meshes to the scenegraph. (Mesh, relatieve positie naar parent, relatieve rotatie naar parent, Texture, size, Parent).
            //parent floor
            scenegraph.Add(floor, new Vector3(0, 0, 0), new Vector3(0, rotatefloor, 0), floor1, 2);

            scenegraph.Add(table, new Vector3(0, 0, 0), new Vector3(0, 0, 0), wood, 0.1f, floor);
            //for a nice game of beerpong
            scenegraph.Add(cup, new Vector3(-2, 5, 9), Vector3.Zero, glass, 0.2f, table);
            scenegraph.Add(new Mesh("../../assets/cup.obj"), new Vector3(-1, 5, 9), Vector3.Zero, glass, 0.2f, table);
            scenegraph.Add(new Mesh("../../assets/cup.obj"), new Vector3(0, 5, 9), Vector3.Zero, glass, 0.2f, table);
            scenegraph.Add(new Mesh("../../assets/cup.obj"), new Vector3(1, 5, 9), Vector3.Zero, glass, 0.2f, table);
            scenegraph.Add(new Mesh("../../assets/cup.obj"), new Vector3(2, 5, 9), Vector3.Zero, glass, 0.2f, table);
            scenegraph.Add(new Mesh("../../assets/cup.obj"), new Vector3(-1.5f, 5, 8), Vector3.Zero, glass, 0.2f, table);
            scenegraph.Add(new Mesh("../../assets/cup.obj"), new Vector3(-0.5f, 5, 8), Vector3.Zero, glass, 0.2f, table);
            scenegraph.Add(new Mesh("../../assets/cup.obj"), new Vector3(0.5f, 5,8), Vector3.Zero, glass, 0.2f, table);
            scenegraph.Add(new Mesh("../../assets/cup.obj"), new Vector3(1.5f, 5, 8), Vector3.Zero, glass, 0.2f, table);
            scenegraph.Add(new Mesh("../../assets/cup.obj"), new Vector3(1, 5, 7), Vector3.Zero, glass, 0.2f, table);
            scenegraph.Add(new Mesh("../../assets/cup.obj"), new Vector3(0, 5, 7), Vector3.Zero, glass, 0.2f, table);
            scenegraph.Add(new Mesh("../../assets/cup.obj"), new Vector3(-1, 5, 7), Vector3.Zero, glass, 0.2f, table);
            scenegraph.Add(new Mesh("../../assets/cup.obj"), new Vector3(-0.5f, 5, 6), Vector3.Zero, glass, 0.2f, table);
            scenegraph.Add(new Mesh("../../assets/cup.obj"), new Vector3(0.5f, 5, 6), Vector3.Zero, glass, 0.2f, table);
            scenegraph.Add(new Mesh("../../assets/cup.obj"), new Vector3(0, 5, 5), Vector3.Zero, glass, 0.2f, table);
            
            //what's on the other parts of the table
            scenegraph.Add(lamp, new Vector3(2, 5, -5), new Vector3(0, 25, 0), metal, 1, table);
            scenegraph.Add(chair, new Vector3(-5, -5, -5), new Vector3(0, 90, 0), wood2, 10, floor);
            scenegraph.Add(new Mesh("../../assets/chair.obj"), new Vector3(-5, -5, 5), new Vector3(0, 90, 0), wood2, 10, floor);
            scenegraph.Add(new Mesh("../../assets/chair.obj"), new Vector3(5, -5, -5), new Vector3(0, 270, 0), wood2, 10, floor);
            scenegraph.Add(new Mesh("../../assets/chair.obj"), new Vector3(5, -5, 5), new Vector3(0, 270, 0), wood2, 10, floor);
            
            // Some other objects
            scenegraph.Add(fan, new Vector3(0, 30, 0), new Vector3(0, rotatefan, 0), white, 0.8f);
            scenegraph.Add(mesh, new Vector3(-3, 5, -7), new Vector3(0, rotatepot, 0), ceramic, 0.25f, table);
            scenegraph.Add(new Mesh("../../assets/floor.obj"), new Vector3(0, 5.75f, 0), Vector3.Zero, jacco, 0.5f, table);

            // set the light
            int lightID = GL.GetUniformLocation(shader.programID,"lightPos");
            int colorID = GL.GetUniformLocation(shader.programID, "lightColor");
            int ambientID = GL.GetUniformLocation(shader.programID, "ambientColor");
            Light light = new Light(lightID, new Vector3(0, 25, 15));
            GL.UseProgram(shader.programID);
            GL.Uniform3(light.lightID, light.position);
            GL.Uniform3(colorID, lightcolor);
            GL.Uniform3(ambientID, ambient);
        }
示例#11
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]);
            }
        }