Beispiel #1
0
        /// <summary>Load resources here.</summary>
        protected override void OnLoad(EventArgs 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);
            GL.Enable(EnableCap.Normalize);
            GL.Enable(EnableCap.ColorMaterial);

            Light.Enable();
            Light light=new Light("light");
            light.Position = new Vector3(20, 50, 0);
            light.Ambient = new Vector3(0.8f, 0.8f, 0.8f);
            Light.Add(light, 0);

            light = new Light("light2");
            light.Position = new Vector3(-40, 50, 50);
            light.Ambient = new Vector3(0.8f, 0.8f, 0.8f);
            Light.Add(light, 1);

            obj = new ObjModel("scene", "skene.obj", 20, 20, 20);
            skybox.LoadSkybox("sky/sky2_", "jpg", 100);
            tex = Texture.Load("1.png");

            cam.Position.Y = 10;

            Util.Set3DMode();
        }
Beispiel #2
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);
            GL.Enable(EnableCap.Normalize);
            GL.Disable(EnableCap.Lighting);
            GL.Enable(EnableCap.Texture2D);

            // model.UseExt(".jpg"); // jos .mesh tiedostossa textureilla ei ole päätettä
            model = new AnimatedModel("ugly", "Ugly/Ukko.mesh");
            model.LoadAnim("walk", "Ugly/Ukko_walk.anim");
            model.LoadAnim("act1", "Ugly/Ukko_action1.anim");
            model.LoadAnim("act2", "Ugly/Ukko_action2.anim");
            model.LoadAnim("act3", "Ugly/Ukko_action3.anim");
            model.FixRotation.X = -90; // ukko on "makaavassa" asennossa joten nostetaan se fixRotationilla pystyyn.
            model.FixRotation.Z = 180; // säätöä.. katse eteen päin!

            cam.Position.Y = 3;
            cam.Position.Z = 10;

            Util.Set3DMode();

            Log.WriteDebugLine("Animation test\nkeys:\n arrows, 1,2 : actions");
        }
Beispiel #3
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            GL.ClearColor(0, 0, 0, 0);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Texture2D);
            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
            GL.Enable(EnableCap.CullFace);
            GL.ShadeModel(ShadingModel.Smooth);
            GL.Enable(EnableCap.Lighting);
            GL.Enable(EnableCap.Light0);

            Util.Set3DMode();

            skydome.LoadSkydome("sky/space.jpg", 1f);
            world.Add(skydome); // skydome aina ekana koska se on kaikkien takana

            const float Scale = 100;
            city = new ObjModel("city", "city.obj", Scale, Scale, Scale);
            world.Add(city);

            // lataa reitit
            cameraPath = new Path("path", "camerapath.obj", Scale, Scale, Scale); // sama skaalaus ku cityssä

            cameraPath.MakeCurve(3); // tehdään reitistä spline
            cameraPath.FollowPath(cam, true, true);
        }
Beispiel #4
0
        /// <summary>
        /// käydään path läpi, joka vertexin kohdalla (xz) etsitään y ja lisätään siihen yp.
        /// </summary>
        /// <param name="yp"></param>
        /// <param name="obj"></param>
        public void FixPathY(int yp, ref Mesh obj)
        {
            Vector3 v;
            for (int q = 0; q < path.Length; q++)
            {
                v = path[q];
                v.Y = -10000;  // vektorin toinen pää kaukana alhaalla

                if (Intersection.CheckIntersection(ref path[q], ref v, ref obj))
                {
                    path[q].Y = Intersection.IntersectionPoint.Y + yp;
                }
            }
        }
Beispiel #5
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();
        }
Beispiel #6
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            GL.ClearColor(0, 0, 0, 0);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Texture2D);
            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
            GL.Enable(EnableCap.CullFace);
            GL.ShadeModel(ShadingModel.Smooth);
            GL.Enable(EnableCap.Lighting);
            GL.Enable(EnableCap.Light0);

            Util.Set3DMode();

            skydome.LoadSkydome("sky/space.jpg", 1f);
            world.Add(skydome); // skydome aina ekana koska se on kaikkien takana

            car = new ObjModel("car", "car.obj", 7, 7, 7);
            car.FixRotation.Y = -90;
            world.Add(car);

            const float Scale = 110;
            city = new ObjModel("city", "city.obj", Scale, Scale, Scale);
            world.Add(city);

            // lataa reitit
            carPath = new Path("carpath", "carpath.obj", Scale, Scale, Scale); // sama skaalaus ku cityssä
            carPath.FollowPath(car, true, true);

            cam.Position.Y = 60;
            cam.Front.Z = -10;
            cam.Update6DOF();

            // car path on tehty xz tasossa (tai jotain y arvoja säädetty mutta menee aika pieleen),
            // joten korjataan ne y arvot. tämä katsoo joka vertexin kohdalta y arvon ja lisää siihen yp:n (tässä 0).
            carPath.FixPathY(0, ref city);
        }
        public void CreateBoundingVolume(Mesh mesh)
        {
            for (int q = 0; q < mesh.Vertices.Length; q++)
            {
                if (mesh.Vertices[q].vertex.X < Min.X) Min.X = mesh.Vertices[q].vertex.X;
                if (mesh.Vertices[q].vertex.Y < Min.Y) Min.Y = mesh.Vertices[q].vertex.Y;
                if (mesh.Vertices[q].vertex.Z < Min.Z) Min.Z = mesh.Vertices[q].vertex.Z;

                if (mesh.Vertices[q].vertex.X > Max.X) Max.X = mesh.Vertices[q].vertex.X;
                if (mesh.Vertices[q].vertex.Y > Max.Y) Max.Y = mesh.Vertices[q].vertex.Y;
                if (mesh.Vertices[q].vertex.Z > Max.Z) Max.Z = mesh.Vertices[q].vertex.Z;
            }

            Vector3 v = Max - Min;
            R = v.Length / 2;

            if (mesh.IsRendObj)
            {
                v = Vector3.Multiply(v, 0.5f); // puoleen väliin
                mesh.ObjCenter = Min + v; // objektin keskikohta
            }

            SetCorners();
        }
Beispiel #8
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);
            }
        }
Beispiel #9
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(10, 100, 10);
            light.UpdateColor();
            light.SetLight(true);
            world.Add(light); // lisää valo

            skybox.LoadSkybox("sky/sky_", "jpg", 100);
            world.Add(skybox);

            carinfo.up = 0.2f;
            carinfo.down = 0.1f;
            carinfo.max = 5;

            car = new ObjModel("car", "car.obj", 2, 2, 2);
            car.FixRotation.Y = -90;
            car.Rotation.Y = 90;

            car2 = new ObjModel("truck", "truck.obj", 1, 1, 1);
            car2.Rotation.Y = 90;
            car2.Position.X = -10;
            car2.Position.Y = -0.2f;
            car2.Position.Z = -15;

            groundPlane.Load("2.jpg");
            groundPlane.Position = new Vector3(0, -0.2f, 0);
            groundPlane.Rotation = new Vector3(90, 0, 0);
            world.Add(groundPlane);

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

            // lisätään autot maailmaan että coll.det. onnistuu
            world.Add(car);
            world.Add(car2);

            Util.Set3DMode();

            Fog.CreateFog(FogMode.Exp, 20, 200, 0.02f);
        }
Beispiel #10
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);
            GL.Enable(EnableCap.ColorMaterial);

            Light.Enable();
            light.Position = new Vector3(50, 80, -100);
            light.SetLight(true);
            world.Add(light); // lisää valo (aurinko)

            // Lataukset
            skybox.LoadSkybox("sky/sky2_", "jpg", 100);
            world.Add(skybox); // skybox aina ekana koska se on kaikkien takana

            obj[0] = new ObjModel("head", "Head/head.obj"); // ladataan kerran
            obj[0].Position.Z = 0;

            // tehdään muutama kopio, siirretään vierekkäin
            obj[1] = obj[0].Clone();
            obj[1].Position.X = 5;

            obj[2] = obj[0].Clone();
            obj[2].Position.X = 10;

            obj[3] = obj[0].Clone();
            obj[3].Position.X = 15;

            obj[4] = obj[0].Clone();
            obj[4].Position.X = 20;

            obj[5] = new ObjModel("arm", "Head/arm.obj");
            obj[1].Add(obj[5]); // pää nro 2:seen lisätään käsi

            // lasketaan groupille bounding volume
            obj[1].Boundings.CreateBoundingVolume(obj[1]);

            // lisää kamat worldiin
            for (int q = 0; q < 4; q++) world.Add(obj[q]);

            // rumilus
            uglyModel = new AnimatedModel("ukko", "Ugly/Ukko.mesh");
            uglyModel.LoadAnim("act", "Ugly/Ukko_action2.anim");
            uglyModel.UseAnimation("act");
            uglyModel.Position.X = -4;
            uglyModel.FixRotation.X = -90; // ukko on "makaavassa" asennossa joten nostetaan se fixRotationilla pystyyn.
            world.Add(uglyModel);

            Mesh scene = new ObjModel("scene", "scene1.obj", 20, 20, 20);
            scene.Position.X = 10;
            // katos (sen nimi on toi None_Material__9) pitää pistää 2 puoliseks, muuten se ei näy alhaalta päin
            scene.SetDoubleSided("None_Material__9", true);
            // samoin seinät 2 puolisiks (blenderistä ja tutkimalla .obj tiedostoa selviää nämä nimet)
            scene.SetDoubleSided("None_Material__12", true);
            world.Add(scene); // lisää scene

            cam.Position.Y = 5;
            cam.Position.Z = 15;

            Util.Set3DMode();
        }
Beispiel #11
0
        /// <summary>
        /// palauttaa true jos objektin boundingbox osuu toisen objektin boundingboxiin
        /// </summary>
        /// <param name="group"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="mesh"></param>
        /// <returns></returns>
        /*public static bool CheckCollisionBB_BB(ref Node group, Vector3 start, Vector3 end, ref Mesh obj)
        {
            // TODO: collision bb_bb
            return false;
        }*/
        /// <summary>
        /// palauttaa true jos objektin boundingboxin joku kulma osuu johonkin polyyn groupissa
        /// </summary>
        /// <param name="group"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="mesh"></param>
        /// <returns></returns>
        public static bool CheckCollisionBB_Poly(ref Node group, Vector3 start, Vector3 end, ref Mesh obj)
        {
            Vector3 len = start - end;
            if (Math.Abs(len.X + len.Y + len.Z) < Epsilon) return false;

            // tarkista objektin bbox
            if (CheckBB_Poly(ref group, len, ref obj, ref obj) == true) return true;

            // ei osunut joten tsekataan joka meshin bbox erikseen.
            //TODO: --liian hidas
            /*for (int q = 0; q < obj.Meshes().Count; q++)
            {
                Mesh m = obj.Meshes()[q];
                if (CheckBB_Poly_Rec(ref group, start, end, len, ref m, ref obj ) == true) return true;
            }*/

            return false;
        }
Beispiel #12
0
 /// <summary>
 /// tarkistaa meshin bboxin törmäyksen groupissa oleviin objekteihin. meshillä ei välttämättä ole Positionnia, joten obj -objektia
 /// käytetään antamaan paikka ja tarkistukseen ettei tarkisteta törmäystä itteensä.
 /// </summary>
 /// <param name="group"></param>
 /// <param name="len"></param>
 /// <param name="mesh"></param>
 /// <param name="obj"></param>
 /// <returns></returns>
 private static bool CheckBB_Poly(ref Node group, Vector3 len, ref Mesh mesh, ref Mesh obj)
 {
     for (int q = 0; q < group.Objects.Length; q++)
     {
         if (group.Objects[q] is Mesh) // vain meshit tarkistetaan
         {
             if (group.Objects[q] != mesh && group.Objects[q] != obj)
             {
                 // tarkistetaan bounding boxin kulmat, yrittääkö läpäistä jonkun polyn
                 for (int c = 0; c < 8; c++)
                 {
                     Vector3 v = mesh.Boundings.Corner[c];
                     v += obj.Position; // huom. objektin position, koska meshillä ei välttämättä ole paikkaa.
                     Vector3 endv = v + len;
                     Mesh msh = (Mesh)group.Objects[q];
                     if (CheckIntersection(ref v, ref endv, ref msh) == true)
                     {
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }
Beispiel #13
0
        /// <summary>
        /// tarkista osuuko start->end vektori johonkin polyyn. palauttaa true jos osuu, muuten false.
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="mesh"></param>
        /// <param name="position"></param>
        /// <param name="rotation"></param>
        /// <param name="matrix"></param>
        /// <returns></returns>
        public static bool CheckIntersection(ref Vector3 start, ref Vector3 end, ref Mesh obj, ref Vector3 rotation, ref Matrix4 matrix)
        {
            Vector3 position = obj.Position;
            Vector3 dir = new Vector3();
            dir = end - start;

            // vektorin pituus
            float len = dir.Length + DistAdder;
            dir.Normalize();
            Vector3[] v = new Vector3[3];

            for (int e = 0; e < obj.Vertices.Length; e += 3)
            {
                v[0] = obj.Vertices[e].vertex;
                v[1] = obj.Vertices[e + 1].vertex;
                v[2] = obj.Vertices[e + 2].vertex;

                Vector3 vout;
                if (Math.Abs(rotation.X + rotation.Y + rotation.Z) > 0.001f)
                {
                    vout = MathExt.VectorMatrixMult(ref v[0], ref matrix);
                    v[0] = vout;

                    vout = MathExt.VectorMatrixMult(ref v[1], ref matrix);
                    v[1] = vout;

                    vout = MathExt.VectorMatrixMult(ref v[2], ref matrix);
                    v[2] = vout;
                }
                // TODO: huono ja hidas tapa, käännetään joka polygoni. FIX

                v[0] += position;
                v[1] += position;
                v[2] += position;

                if (IntersectTriangle(ref start, ref dir, ref v[0], ref v[1], ref v[2]) == true)
                {
                    if (Math.Abs(T) > len) continue;
                    return true;
                }
            }
            return false;
        }
Beispiel #14
0
        /// <summary>
        /// tarkista osuuko start->end vektori johonkin polyyn mesh -objektissa. palauttaa true jos osuu, muuten false.
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="mesh"></param>
        /// <returns></returns>
        public static bool CheckIntersection(ref Vector3 start, ref Vector3 end, ref Mesh obj)
        {
            // jos objektia käännetty
            Matrix4 outm = new Matrix4();
            Vector3 rot = -(obj.Rotation + obj.FixRotation);
            if (rot.X != 0 || rot.Y != 0 || rot.Z != 0)
            {
                rot = rot * MathExt.DegToRad;
                Matrix4 mx = Matrix4.CreateRotationX(rot.X);
                Matrix4 my = Matrix4.CreateRotationY(rot.Y);
                Matrix4 mz = Matrix4.CreateRotationZ(rot.Z);
                Matrix4 outm0;
                Matrix4.Mult(ref mx, ref my, out outm0);
                Matrix4.Mult(ref outm0, ref mz, out outm);
            }
            if (CheckIntersection(ref start, ref end, ref obj, ref rot, ref outm) == true) return true;

            return false;
        }
Beispiel #15
0
 public void CheckMove(ref Vector3 orig, ref Vector3 newpos, ref Mesh obj)
 {
     if (Intersection.CheckIntersection(ref orig, ref newpos, ref obj))
         newpos = orig;
 }
        public void CreateBoundingVolume(Mesh mesh, Vector3 min, Vector3 max)
        {
            if (mesh.Vertices.Length == 0) return;

            Min = min;
            Max = max;
            Vector3 v = Max - Min;
            R = v.Length / 2;

            if (mesh.IsRendObj)
            {
                v = Vector3.Multiply(v, 0.5f); // puoleen väliin
                mesh.ObjCenter = Min + v; // objektin keskikohta
            }

            SetCorners();
        }