コード例 #1
0
ファイル: SceneGraph.cs プロジェクト: tiekestel/rasterizer
 public Pointlight(Vector4 _position, float _strength, Vector3 _color, ParentMesh _parent)
 {
     localPosition = _position;
     strength      = _strength;
     color         = _color;
     parent        = _parent;
     shadowMap     = new cubeDepthmap();
 }
コード例 #2
0
ファイル: SceneGraph.cs プロジェクト: tiekestel/rasterizer
 public DirectionalLight(Vector4 _direction, float _strength, Vector3 _color, ParentMesh _parent)
 {
     direction = _direction;
     strength  = _strength;
     color     = _color;
     parent    = _parent;
     shadowMap = new depthmap(this);
 }
コード例 #3
0
 public car(ParentMesh carbody, ParentMesh leftWheel, ParentMesh rightWheel)
 {
     parent = carbody;
     wheels = new wheel[2]
     {
         new wheel(leftWheel),
         new wheel(rightWheel)
     };
 }
コード例 #4
0
ファイル: SceneGraph.cs プロジェクト: tiekestel/rasterizer
 public Spotlight(Vector4 _position, Vector4 _direction, float _strength, Vector3 _color, ParentMesh _parent, float _angle)
 {
     localPosition  = _position;
     localDirection = _direction;
     strength       = _strength;
     color          = _color;
     parent         = _parent;
     angle          = _angle;
 }
コード例 #5
0
ファイル: parentMesh.cs プロジェクト: tiekestel/rasterizer
        public ParentMesh(Mesh _mesh, Texture _texture, Matrix4 _localTransform, Matrix4 _localScale, Matrix4 _localRotation, ParentMesh _parent = null, float hdr = 0, int _cubemap = 0, Texture _normalMap = null)
        {
            mesh             = _mesh;
            texture          = _texture;
            localTranslation = _localTransform;
            localScale       = _localScale;
            localRotation    = _localRotation;
            normalMap        = _normalMap;
            parent           = _parent;

            intensity = hdr;
            if (_cubemap != 0)
            {
                cubemap = new cubemap(_cubemap);
            }
        }
コード例 #6
0
ファイル: cubemap.cs プロジェクト: tiekestel/rasterizer
        // render cubemap
        public void Render(Shader shader, Vector3 transform, SceneGraph scene, ParentMesh parent)
        {
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, framebuffer);
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.TextureCubeMap, id);
            Matrix4 cameraPosition = Matrix4.CreateTranslation(-transform);

            GL.Viewport(0, 0, programValues.cubemapres, programValues.cubemapres);
            GL.Enable(EnableCap.DepthTest);
            for (int i = 0; i < 6; ++i)
            {
                GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.TextureCubeMapPositiveX + i, id, 0);
                GL.Clear(ClearBufferMask.ColorBufferBit);
                GL.Clear(ClearBufferMask.DepthBufferBit);
                GL.ClearColor(0, 0, 0, 0);
                scene.RenderSkyBox(cameraPosition, cameraRotations[i], cameraFOV, programValues.skyboxshader);
                scene.SimpleRender(cameraPosition * cameraRotations[i] * cameraFOV, cameraPosition, programValues.cubemapshader, parent);
            }
            GL.Disable(EnableCap.DepthTest);
            GL.Viewport(0, 0, programValues.screenwidth, programValues.screenheight);
        }
コード例 #7
0
ファイル: parentMesh.cs プロジェクト: tiekestel/rasterizer
        public void SimpleRender(Matrix4 parentMatrix, Matrix4 camera, Matrix4 cameraPosition, Shader shader, List <Pointlight> pointlights, List <DirectionalLight> directionalLights, List <Spotlight> spotlights, ParentMesh parentMesh)
        {
            //Combine matrices
            Matrix4 finalTransform = localScale * localRotation * localTranslation * parentMatrix;

            //dont render the object because it cant reflect/refract itself
            if (parentMesh != this)
            {
                mesh.Render(shader, finalTransform, camera, cameraPosition, texture, pointlights, directionalLights, spotlights);
            }

            //Render child meshes
            foreach (ParentMesh p in child_meshes)
            {
                p.SimpleRender(finalTransform, camera, cameraPosition, shader, pointlights, directionalLights, spotlights, parentMesh);
            }
        }
コード例 #8
0
ファイル: parentMesh.cs プロジェクト: tiekestel/rasterizer
 //Add child meshes to parent mesh
 public void Add(ParentMesh child_mesh)
 {
     child_meshes.Add(child_mesh);
 }
コード例 #9
0
ファイル: SceneGraph.cs プロジェクト: tiekestel/rasterizer
        public SceneGraph()
        {
            primaryMeshes = new List <ParentMesh>();
            gameObjects   = new List <gameObject>();
            //floor
            primaryMeshes.Add(new ParentMesh(new Mesh("../../assets/floor.obj"), new Texture("../../assets/grass/grassfloor.jpg", false), Matrix4.Identity, Matrix4.CreateScale(8f), Matrix4.Identity, null, 0, 0, new Texture("../../assets/grass/grassnormal.jpg", true)));

            // textures
            Texture black = new Texture("../../assets/black.jpg", false);

            //traintracks
            Mesh rail = new Mesh("../../assets/traintracks/rail_straight.obj");

            primaryMeshes[0].Add(new ParentMesh(rail, black, Matrix4.CreateTranslation(1, -2, 3), Matrix4.CreateScale(0.1f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(rail, black, Matrix4.CreateTranslation(-1.02f, -2, 3), Matrix4.CreateScale(0.1f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(rail, black, Matrix4.CreateTranslation(-3.04f, -2, 3), Matrix4.CreateScale(0.1f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(rail, black, Matrix4.CreateTranslation(-5.06f, -2, 3), Matrix4.CreateScale(0.1f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(rail, black, Matrix4.CreateTranslation(-7.08f, -2, 3), Matrix4.CreateScale(0.1f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(rail, black, Matrix4.CreateTranslation(3.02f, -2, 3), Matrix4.CreateScale(0.1f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(rail, black, Matrix4.CreateTranslation(5.04f, -2, 3), Matrix4.CreateScale(0.1f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(rail, black, Matrix4.CreateTranslation(7.06f, -2, 3), Matrix4.CreateScale(0.1f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            ParentMesh train = new ParentMesh(new Mesh("../../assets/train/train.obj"), new Texture("../../assets/train/color.png", false), Matrix4.CreateTranslation(10, -2, 3), Matrix4.CreateScale(0.1f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0], 0, 0, new Texture("../../assets/train/normal.png", false));

            gameObjects.Add(new train(train));
            primaryMeshes[0].Add(train);

            //roads
            Mesh    road      = new Mesh("../../assets/roads/Road.obj");
            Mesh    roadtr    = new Mesh("../../assets/roads/Road_tr.obj");
            Texture roadTex   = new Texture("../../assets/roads/Road.png", false);
            Texture roadtrTex = new Texture("../../assets/roads/Road_tr.png", false);

            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(-7.5f, -1.99f, 1), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(-6.5f, -1.99f, 1), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));

            primaryMeshes[0].Add(new ParentMesh(roadtr, roadtrTex, Matrix4.CreateTranslation(-5.6f, -1.99f, 0.99f), Matrix4.CreateScale(0.47f), Matrix4.Identity, primaryMeshes[0]));

            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(-4.7f, -1.99f, 1), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(-3.7f, -1.99f, 1), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(-2.7f, -1.99f, 1), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(-1.7f, -1.99f, 1), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(-0.7f, -1.99f, 1), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(0.3f, -1.99f, 1), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(1.3f, -1.99f, 1), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(2.3f, -1.99f, 1), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(3.3f, -1.99f, 1), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));

            primaryMeshes[0].Add(new ParentMesh(new Mesh("../../assets/roads/Road_sq.obj"), new Texture("../../assets/roads/Road_sq.png", false), Matrix4.CreateTranslation(4.2f, -1.99f, 0.99f), Matrix4.CreateScale(0.47f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));

            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(5.1f, -1.99f, 1), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(6.1f, -1.99f, 1), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(7.1f, -1.99f, 1), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(8.1f, -1.99f, 1), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));

            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(4.2f, -1.99f, 1.9f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(4.2f, -1.99f, 2.9f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(4.2f, -1.99f, 3.9f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(4.2f, -1.99f, 4.9f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(4.2f, -1.99f, 5.9f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(4.2f, -1.99f, 6.9f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(4.2f, -1.99f, 7.9f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));

            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(4.2f, -1.99f, 0.1f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(4.2f, -1.99f, -0.9f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(4.2f, -1.99f, -1.9f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(4.2f, -1.99f, -2.9f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(4.2f, -1.99f, -3.9f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));

            primaryMeshes[0].Add(new ParentMesh(roadtr, roadtrTex, Matrix4.CreateTranslation(4.21f, -1.99f, -4.8f), Matrix4.CreateScale(0.47f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));

            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(4.2f, -1.99f, -5.7f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(4.2f, -1.99f, -6.7f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(4.2f, -1.99f, -7.7f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));

            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(3.3f, -1.99f, -4.8f), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(2.3f, -1.99f, -4.8f), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(1.3f, -1.99f, -4.8f), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(0.3f, -1.99f, -4.8f), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(-0.7f, -1.99f, -4.8f), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(-1.7f, -1.99f, -4.8f), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(-2.7f, -1.99f, -4.8f), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(-3.7f, -1.99f, -4.8f), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(-4.7f, -1.99f, -4.8f), Matrix4.CreateScale(0.5f), Matrix4.CreateRotationY((float)(0.5f * Math.PI)), primaryMeshes[0]));

            primaryMeshes[0].Add(new ParentMesh(new Mesh("../../assets/roads/Road_ro.obj"), new Texture("../../assets/roads/Road_ro.png", false), Matrix4.CreateTranslation(-5.6f, -1.99f, -4.8f), Matrix4.CreateScale(0.47f), Matrix4.CreateRotationY((float)(-0.5f * Math.PI)), primaryMeshes[0]));

            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(-5.6f, -1.99f, 0.1f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(-5.6f, -1.99f, -0.9f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(-5.6f, -1.99f, -1.9f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(-5.6f, -1.99f, -2.9f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(road, roadTex, Matrix4.CreateTranslation(-5.6f, -1.99f, -3.9f), Matrix4.CreateScale(0.5f), Matrix4.Identity, primaryMeshes[0]));

            //buildings
            Mesh    igloo = new Mesh("../../assets/buildings/igloo.obj");
            Texture tiles = new Texture("../../assets/tiles.jpg", false);
            Texture wood  = new Texture("../../assets/wood.jpg", false);

            primaryMeshes[0].Add(new ParentMesh(new Mesh("../../assets/buildings/part1model.obj"), black, Matrix4.CreateTranslation(5.1f, -1.99f, -3.4f), Matrix4.CreateScale(0.05f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(new Mesh("../../assets/buildings/KinderGarten.obj"), black, Matrix4.CreateTranslation(3.5f, -1.99f, 5.4f), Matrix4.CreateScale(1f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(igloo, tiles, Matrix4.CreateTranslation(2.5f, -1.99f, -2.8f), Matrix4.CreateScale(0.02f), Matrix4.CreateRotationY((float)(0.25 * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(igloo, wood, Matrix4.CreateTranslation(1.5f, -1.99f, -0.9f), Matrix4.CreateScale(0.02f), Matrix4.CreateRotationY((float)(-0.15 * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(igloo, black, Matrix4.CreateTranslation(0.2f, -1.99f, -3.4f), Matrix4.CreateScale(0.02f), Matrix4.CreateRotationY((float)(0.5 * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(igloo, tiles, Matrix4.CreateTranslation(-1f, -1.99f, -0.4f), Matrix4.CreateScale(0.02f), Matrix4.CreateRotationY((float)(-0.55 * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(igloo, wood, Matrix4.CreateTranslation(-2f, -1.99f, -3.4f), Matrix4.CreateScale(0.02f), Matrix4.CreateRotationY((float)(0.65 * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(igloo, black, Matrix4.CreateTranslation(-3f, -1.99f, -0.9f), Matrix4.CreateScale(0.02f), Matrix4.CreateRotationY((float)(0.65 * Math.PI)), primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(igloo, tiles, Matrix4.CreateTranslation(-4f, -1.99f, -2.8f), Matrix4.CreateScale(0.02f), Matrix4.CreateRotationY((float)(0.25 * Math.PI)), primaryMeshes[0]));

            //campfire
            pointlights = new List <Pointlight>();
            ParentMesh campfire = new ParentMesh(new Mesh("../../assets/campfire.obj"), new Texture("../../assets/campfire.jpg", false), Matrix4.CreateTranslation(-1, -1.99f, -2f), Matrix4.CreateScale(3), Matrix4.Identity, primaryMeshes[0]);

            primaryMeshes[0].Add(campfire);
            pointlights.Add(new Pointlight(new Vector4(0, 1.5f, 0, 1), 500, new Vector3(1, 0.3f, 0.3f), campfire));

            //trees
            Mesh    popular = new Mesh("../../assets/trees/Popular_tree.obj");
            Mesh    fir     = new Mesh("../../assets/trees/Fir_Tree.obj");
            Mesh    palm    = new Mesh("../../assets/trees/Palm_tree.obj");
            Texture firTex  = new Texture("../../assets/trees/Fir_tree.png", false);

            primaryMeshes[0].Add(new ParentMesh(new Mesh("../../assets/trees/Carrot.obj"), new Texture("../../assets/trees/carrot.png", false), Matrix4.CreateTranslation(-1f, -1f, 5.5f), Matrix4.CreateScale(5), Matrix4.CreateRotationZ((float)(0.5 * Math.PI)), primaryMeshes[0], 0, 1));
            primaryMeshes[0].Add(new ParentMesh(popular, firTex, Matrix4.CreateTranslation(-7f, -1.99f, -2f), Matrix4.CreateScale(0.2f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(fir, firTex, Matrix4.CreateTranslation(-6.7f, -1.99f, -6.6f), Matrix4.CreateScale(0.2f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(palm, firTex, Matrix4.CreateTranslation(-4f, -1.99f, -5.5f), Matrix4.CreateScale(0.2f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(popular, firTex, Matrix4.CreateTranslation(-1f, -1.99f, -6.3f), Matrix4.CreateScale(0.2f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(popular, firTex, Matrix4.CreateTranslation(-0.5f, -1.99f, -6f), Matrix4.CreateScale(0.2f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(fir, firTex, Matrix4.CreateTranslation(2f, -1.99f, -6.6f), Matrix4.CreateScale(0.2f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(palm, firTex, Matrix4.CreateTranslation(5f, -1.99f, -6f), Matrix4.CreateScale(0.2f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(popular, firTex, Matrix4.CreateTranslation(6.6f, -1.99f, -1.9f), Matrix4.CreateScale(0.2f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(fir, firTex, Matrix4.CreateTranslation(5.6f, -1.99f, 2f), Matrix4.CreateScale(0.2f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(palm, firTex, Matrix4.CreateTranslation(6f, -1.99f, 6f), Matrix4.CreateScale(0.2f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(palm, firTex, Matrix4.CreateTranslation(6.5f, -1.99f, 5.8f), Matrix4.CreateScale(0.2f), Matrix4.Identity, primaryMeshes[0]));
            primaryMeshes[0].Add(new ParentMesh(palm, firTex, Matrix4.CreateTranslation(6.7f, -1.99f, 6.5f), Matrix4.CreateScale(0.2f), Matrix4.Identity, primaryMeshes[0]));

            //streetlamps
            Mesh streetlamp = new Mesh("../../assets/streetlamp.obj");

            ParentMesh[] streetlamps = new ParentMesh[5]
            {
                new ParentMesh(streetlamp, black, Matrix4.CreateTranslation(-5.7f, -1.99f, -5.2f), Matrix4.CreateScale(0.3f), Matrix4.CreateRotationY((float)(0.75 * Math.PI)), primaryMeshes[0]),
                new ParentMesh(streetlamp, black, Matrix4.CreateTranslation(-5.5f, -1.99f, 1.5f), Matrix4.CreateScale(0.3f), Matrix4.CreateRotationY((float)(-0.5 * Math.PI)), primaryMeshes[0]),
                new ParentMesh(streetlamp, black, Matrix4.CreateTranslation(4.7f, -1.99f, -4.9f), Matrix4.CreateScale(0.3f), Matrix4.Identity, primaryMeshes[0]),
                new ParentMesh(streetlamp, black, Matrix4.CreateTranslation(-1f, -1.99f, 1.5f), Matrix4.CreateScale(0.3f), Matrix4.CreateRotationY((float)(-0.5 * Math.PI)), primaryMeshes[0]),
                new ParentMesh(streetlamp, black, Matrix4.CreateTranslation(4.7f, -1.99f, 5.5f), Matrix4.CreateScale(0.3f), Matrix4.Identity, primaryMeshes[0])
            };

            spotlights = new List <Spotlight>();
            for (int i = 0; i < streetlamps.Length; ++i)
            {
                spotlights.Add(new Spotlight(new Vector4(0, 4, 0, 1), Vector4.Normalize(new Vector4(-1, -1, 0, 0)), 100, new Vector3(1, 1, 1), streetlamps[i], 0.9f));
                primaryMeshes[0].Add(streetlamps[i]);
            }

            //car
            carbody = new ParentMesh(new Mesh("../../assets/car/Cars.obj"), black, Matrix4.CreateTranslation(0, -1.99f, 1.17f), Matrix4.CreateScale(0.05f), Matrix4.CreateRotationY((float)(0.5 * Math.PI)), primaryMeshes[0]);
            ParentMesh leftWheel  = new ParentMesh(new Mesh("../../assets/car/Left_Wheel.obj"), black, Matrix4.CreateTranslation(0.7f, 0.3f, 1.4f), Matrix4.CreateScale(1f), Matrix4.Identity, primaryMeshes[0]);
            ParentMesh rightWheel = new ParentMesh(new Mesh("../../assets/car/Right_Wheel.obj"), black, Matrix4.CreateTranslation(-0.7f, 0.3f, 1.4f), Matrix4.CreateScale(1f), Matrix4.Identity, primaryMeshes[0]);

            primaryMeshes[0].Add(carbody);
            carbody.Add(leftWheel);
            carbody.Add(rightWheel);
            gameObjects.Add(new car(carbody, leftWheel, rightWheel));

            //sun
            directionalLights = new List <DirectionalLight>();
            directionalLights.Add(new DirectionalLight(new Vector4(-1f, 1, 0, 1), 1, new Vector3(1, 1, 1), null));

            //create skybox
            float[] skyboxVertices = new float[] {
                // positions
                -1.0f, 1.0f, -1.0f,
                -1.0f, -1.0f, -1.0f,
                1.0f, -1.0f, -1.0f,
                1.0f, -1.0f, -1.0f,
                1.0f, 1.0f, -1.0f,
                -1.0f, 1.0f, -1.0f,

                -1.0f, -1.0f, 1.0f,
                -1.0f, -1.0f, -1.0f,
                -1.0f, 1.0f, -1.0f,
                -1.0f, 1.0f, -1.0f,
                -1.0f, 1.0f, 1.0f,
                -1.0f, -1.0f, 1.0f,

                1.0f, -1.0f, -1.0f,
                1.0f, -1.0f, 1.0f,
                1.0f, 1.0f, 1.0f,
                1.0f, 1.0f, 1.0f,
                1.0f, 1.0f, -1.0f,
                1.0f, -1.0f, -1.0f,

                -1.0f, -1.0f, 1.0f,
                -1.0f, 1.0f, 1.0f,
                1.0f, 1.0f, 1.0f,
                1.0f, 1.0f, 1.0f,
                1.0f, -1.0f, 1.0f,
                -1.0f, -1.0f, 1.0f,

                -1.0f, 1.0f, -1.0f,
                1.0f, 1.0f, -1.0f,
                1.0f, 1.0f, 1.0f,
                1.0f, 1.0f, 1.0f,
                -1.0f, 1.0f, 1.0f,
                -1.0f, 1.0f, -1.0f,

                -1.0f, -1.0f, -1.0f,
                -1.0f, -1.0f, 1.0f,
                1.0f, -1.0f, -1.0f,
                1.0f, -1.0f, -1.0f,
                -1.0f, -1.0f, 1.0f,
                1.0f, -1.0f, 1.0f
            };

            string[] faces = new string[]
            {
                "../../assets/bluecloud_rt.jpg",
                "../../assets/bluecloud_lf.jpg",
                "../../assets/bluecloud_up.jpg",
                "../../assets/bluecloud_dn.jpg",
                "../../assets/bluecloud_ft.jpg",
                "../../assets/bluecloud_bk.jpg"
            };

            //create skybox buffer
            skyboxbuffer = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, skyboxbuffer);
            GL.BufferData(BufferTarget.ArrayBuffer, skyboxVertices.Length * sizeof(float), skyboxVertices, BufferUsageHint.StaticDraw);
            GL.VertexAttribPointer(2, 3, VertexAttribPointerType.Float, false, 0, 0);

            skybox = LoadCubemap(faces);

            foreach (ParentMesh p in primaryMeshes)
            {
                p.RenderCubemap(Matrix4.Identity, this);
            }
        }
コード例 #10
0
ファイル: SceneGraph.cs プロジェクト: tiekestel/rasterizer
 // simply render scene
 public void SimpleRender(Matrix4 camera, Matrix4 cameraPosition, Shader shader, ParentMesh parentMesh = null)
 {
     foreach (ParentMesh p in primaryMeshes)
     {
         p.SimpleRender(Matrix4.Identity, camera, cameraPosition, shader, pointlights, directionalLights, spotlights, parentMesh);
     }
 }
コード例 #11
0
ファイル: wheel.cs プロジェクト: tiekestel/rasterizer
 public wheel(ParentMesh wheel)
 {
     parent = wheel;
 }
コード例 #12
0
 public train(ParentMesh _parent)
 {
     parent           = _parent;
     beginTranslation = parent.localTranslation;
 }