Пример #1
0
        void InitProgram()
        {
            lastMousePosition = new Vector2(Mouse.X, Mouse.Y);

            ObjectManager.Instance.Init();

            ShaderManager.Instance.Shaders.AddRange(
                new List <ShaderProgram>()
            {
                new ShaderProgram("color", "Unlit\\Color"),
                new ShaderProgram("texcoord", "Unlit\\TexCoord"),
                new ShaderProgram("normal", "Unlit\\Normal"),
                new ShaderProgram("textured", "Unlit\\Texture"),
                new ShaderProgram("lambert", "Lit\\Lambert", "Lit\\Base"),
                new ShaderProgram("phong", "Lit\\Phong", "Lit\\Base"),
                new ShaderProgram("blinnphong", "Lit\\BlinnPhong", "Lit\\Base"),
            });
            ShaderManager.Instance.Init();

            //LoadMaterials("opentk.mtl");

            ExpandedCube cc1 = new ExpandedCube();

            cc1.Material.DiffuseColor     = Utils.Colors.ToVector(Color.Teal);
            cc1.Material.DiffuseTexture   = new Texture("opentksquare.png", TextureType.DIFFUSE);
            cc1.Material.SpecularExponent = 10.0f;
            cc1.OnUpdate = (GameObject o, float t) =>
            {
                Volume v = (Volume)o;
                v.Position = new Vector3((float)Math.Cos(time), (float)Math.Sin(time), 0);
            };
            cc1.OnStart = (GameObject o) =>
            {
                Volume v = (Volume)o;
                v.Scale = new Vector3(0.5f, 0.5f, 0.5f);
            };
            cc1.Start();
            ObjectManager.Instance.Objects.Add(cc1);

            ExpandedCube cc2 = new ExpandedCube();

            cc2.Material.DiffuseColor = Utils.Colors.ToVector(Color.LightPink);
            cc2.Start();
            cc2.Position = new Vector3(0f, -1.25f, 0f);
            cc2.Scale    = new Vector3(5f, 0.1f, 5f);
            ObjectManager.Instance.Objects.Add(cc2);

            AssimpVolume teapot = AssimpVolume.LoadFromFile("teapot.obj");

            teapot.Material.DiffuseColor     = Utils.Colors.ToVector(Color.Turquoise);
            teapot.Material.SpecularExponent = 30.0f;
            teapot.Scale     = new Vector3(0.3f);
            teapot.Position += new Vector3(0f, -1f, 0f);
            teapot.Start();
            ObjectManager.Instance.Objects.Add(teapot);

            /*PointLight pointLight = new PointLight();
             * pointLight.Data.Color = Utils.Colors.ToVector(Color.LightGoldenrodYellow);
             * pointLight.Data.Intensity = 1f;
             * ObjectManager.Instance.Lights.Add(pointLight);*/

            SpotLight sLight = new SpotLight();

            sLight.ChangePosition(new Vector3(3f, 3f, 0f));
            sLight.Data.Color     = new Vector3(1f, 0f, 0f);
            sLight.Data.ConeAngle = 5f;
            sLight.OnUpdate       = (GameObject o, float t) =>
            {
                SpotLight l = (SpotLight)o;
                l.LookAt(teapot.Position);
            };
            ObjectManager.Instance.Lights.Add(sLight);

            DirectionalLight dirLight = new DirectionalLight();

            dirLight.ChangePosition(new Vector3(0f, 10f, 5f));
            ObjectManager.Instance.Lights.Add(dirLight);

            AmbientLight ambientLight = new AmbientLight(Color.Red, 0.1f);

            ObjectManager.Instance.Lights.Add(ambientLight);

            ExpandedCube ccLight = new ExpandedCube();

            ccLight.Start();
            ccLight.Scale    = new Vector3(0.1f);
            ccLight.OnUpdate = (GameObject o, float t) =>
            {
                Volume v = (Volume)o;
                v.Position = ObjectManager.Instance.Lights[0].Data.Position.Xyz;
            };
            ObjectManager.Instance.Objects.Add(ccLight);

            camera.Position += new Vector3(0f, 0f, 3f);

            Utils.CheckError();
        }