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); }
// 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); }
public List <SceneGraph> nodeChildren = new List <SceneGraph>(); // a list of children of the mesh public SceneGraph(SceneGraph p, Mesh mesh, Texture texture) { nodeParent = p; nodeMesh = mesh; nodeTexture = texture; if (p != null) { p.nodeChildren.Add(this); // if the mesh has a parent, add the mesh to the parent mesh's children list } }
// initialize public void Init() { // load teapot mesh = new Mesh(new Vector3(0,0,0), 1, "../../assets/teapot.obj"); floor = new Mesh(new Vector3(0, 0, 0), 1, "../../assets/floor.obj"); text = new Mesh(new Vector3(0, 10, 0), 1, "../../assets/text.obj"); // initialize stopwatch timer = new Stopwatch(); timer.Reset(); timer.Start(); // create shaders shader = new Shader("../../shaders/vs.glsl", "../../shaders/fs.glsl"); // load a texture wood = new Texture("../../assets/wood.jpg"); root = new SceneGraph(new Vector3(0,1,0), 1); root.AddChildNode(mesh); mesh.AddChildNode(floor); mesh.AddChildNode(text); AddTeapots(mesh, 1); }
public void AddTeapots(SceneGraph parent, int children) { int childs = children; Mesh m1 = new Mesh(parent.pos + new Vector3(-13/childs, 0, 0), 0.5f/childs, "../../assets/teapot.obj"); Mesh m2 = new Mesh(parent.pos + new Vector3(13/childs, 0, 0), 0.5f/childs, "../../assets/teapot.obj"); Mesh m3 = new Mesh(parent.pos + new Vector3(0, 0, -13/childs), 0.5f/childs, "../../assets/teapot.obj"); Mesh m4 = new Mesh(parent.pos + new Vector3(0, 0, 13/childs), 0.5f/childs, "../../assets/teapot.obj"); parent.AddChildNode(m1); parent.AddChildNode(m2); parent.AddChildNode(m3); parent.AddChildNode(m4); if (childs < 2) { AddTeapots(m1, childs+1); AddTeapots(m2, childs+1); AddTeapots(m3, childs+1); AddTeapots(m4, childs+1); } }
bool automaticRotation; // whether the scene rotates automatically or not // initialize public void Init() { acceleration = 1; automaticRotation = false; // 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" ); // load a texture wood = new Texture( "../../assets/wood.jpg" ); scenegraph = new SceneGraph(new SceneGraph[] { new SceneGraph(null, mesh, shader, wood) }, floor, shader, wood); // load lights lights = new Light[2]; lights[0] = new Light(new Vector4(4, 4, 15 ,1), new Vector4(1, 1,1 , 1), 10); lights[1] = new Light(new Vector4(4, 4, -15, 1), new Vector4(1, 1, 1, 1), 10); // set cam matrix and camera position cam = Matrix4.Identity; camera = new Vector4(0, -4, -15, 1); }
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); }
// initialize public void Init() { scenegraph = new SceneGraph(); scenegraph.screen = screen; scenegraph.Init(); }
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]); } }
//Add child and make this its parent public void AddChildNode(SceneGraph child) { children.Add(child); child.parent = this; }