Exemple #1
0
        /// <summary>Load resources here.</summary>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            GL.ClearColor(System.Drawing.Color.Blue);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Texture2D);
            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
            GL.Enable(EnableCap.CullFace);
            GL.ShadeModel(ShadingModel.Smooth);

            Light.Enable();
            light.Position = new Vector3(80, 20, 0);
            light.UpdateColor();
            light.SetLight(true);
            light.Rotation = new Vector3(0, 0, -40);

            toonBall = new ObjModel("ball", "ball.obj");
            toonStar = new ObjModel("star", "star.obj");

            world.Add(light); // lisää valo (aurinko)
            light.Add(toonBall.Clone()); // lisää valoon pallo, liikkuu valon mukana

            Random random = new Random();
            for (int q = 0; q < OBJS; q++)
            {
                // nämä käyttää toon shaderia (kirjoitettu .mtl tiedostoon)
                if (q < OBJS / 2) objs[q] = toonBall.Clone();
                else objs[q] = toonStar.Clone();

                objs[q].Position.X = random.Next(20) - 10;
                objs[q].Position.Y = random.Next(20) - 10;
                objs[q].Position.Z = random.Next(20) - 10;

                // arvotaan, käytetäänkö lightingiä vai ei mitään
                if (random.Next(10) < 5) objs[q].LoadShader("lighting.vert", "lighting.frag");
                else objs[q].LoadShader("", ""); // ei shaderia
            }

            for (int q = 0; q < OBJS; q++) toonBall.Add(objs[q]);

            world.Add(toonBall);

            cam.Position.Y = 1;
            cam.Position.Z = 2;

            Util.Set3DMode();
        }
Exemple #2
0
        void CloneTree(Mesh clone)
        {
            for (int q = 0; q < objects.Count; q++)
            {
                Mesh child = (Mesh)objects[q];
                clone.objects[q] = child.Clone();

                if (child.objects.Count > 0)
                {
                    child.CloneTree(child);
                }
            }
        }