private void AddObjects() { // create SceneGraph sceneGraph = new SceneGraph(); // create sceneGraphObjects floor = new SceneGraphObject(); teapot = new SceneGraphObject(); // load meshes and add them to actors floor.setMesh("assets/floor.obj"); teapot.setMesh("assets/teapot.obj"); // load a texture teapot.Mesh.Texture = "assets/wood.jpg"; floor.Mesh.Texture = "assets/wood.jpg"; // create camera var camera = new Camera(); camera.transform.RotateModel(new Vector3(1, 0, 0), 0.2f * PI); camera.transform.TranslateModel(new Vector3(0, 0, -20)); // setup lights var light = new Light(); var light2 = new Light(); light2.transform.TranslateModel(new Vector3(0, 5, 9)); light.transform.TranslateModel(new Vector3(-12, 10, 0)); light.color = new Vector3(.9f, .2f, .1f); light2.color = new Vector3(1f); light.intensity = 200f; light2.intensity = 50f; // add scenegraphobjects to scenegraph sceneGraph.Add(floor); sceneGraph.Add(teapot); sceneGraph.Add(camera); sceneGraph.Add(light); sceneGraph.Add(light2); }
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); }