public void T06_OBJParserIgnoring()
        {
            ObjLoader loader = new ObjLoader();

            loader.Load(@"ObjFiles\Gibberish.obj");
            Assert.AreEqual(5, loader.GetLinesIgnored());
        }
        public void T10_OBJToGroup()
        {
            ObjLoader loader = new ObjLoader();

            loader.Load(@"ObjFiles\Groups.obj");
            Assert.AreEqual(2, loader.root.GetChildren().Count);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Window window = new Window(1024, 576, "castle");

            window.EnableDepthTest();

            Mesh3[] meshes = ObjLoader.Load("Assets/Castle.obj", Vector3.One * 5);

            PerspectiveCamera camera = new PerspectiveCamera(new Vector3(0, 250, 750), new Vector3(10, 180, 0), 60, 0.1f, 1000);

            Console.WriteLine(meshes.Length);

            DirectionalLight sun = new DirectionalLight(new Vector3(-0.5f, 0, -1).Normalized());

            float rot = 0;

            while (window.IsOpened)
            {
                rot += 10 * window.deltaTime;

                foreach (Mesh3 mesh in meshes)
                {
                    mesh.EulerRotation3 = new Vector3(0, rot, 0);
                    //mesh.DrawWireframe(new Vector4(1, 0, 0, 1));
                    mesh.DrawPhong(new Vector4(1, 0, 0, 1), sun, new Vector3(0.1f, 0.1f, 0.1f));
                }

                window.Update();
            }
        }
        public void T17_VertexNormalOBJ()
        {
            ObjLoader loader = new ObjLoader();

            loader.Load(@"ObjFiles\VertexNormal.obj");
            Assert.AreEqual(new Vector(0, 0, 1), loader.n[0]);
            Assert.AreEqual(new Vector(0.707, 0, -0.707), loader.n[1]);
            Assert.AreEqual(new Vector(1, 2, 3), loader.n[2]);
        }
Esempio n. 5
0
        public ObjFile Load(string name)
        {
            if (!resources.ContainsKey(name))
            {
                this[name] = ObjLoader.Load(name);
            }

            return(this[name]);
        }
        public void T07_OBJParserVertices()
        {
            ObjLoader loader = new ObjLoader();

            loader.Load(@"ObjFiles\Vertices.obj");
            Assert.AreEqual(new Point(-1, 1, 0), loader.v[0]);
            Assert.AreEqual(new Point(-1, 0.5, 0), loader.v[1]);
            Assert.AreEqual(new Point(1, 0, 0), loader.v[2]);
            Assert.AreEqual(new Point(1, 1, 0), loader.v[3]);
        }
Esempio n. 7
0
        public static void Teapot(Camera camera, Scene scene)
        {
            AddSkybox(scene);
            AddFloor(scene);
            AddLight(scene);
            var path   = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..\\..\\Meshes\\teapot.obj");
            var teapot = ObjLoader.Load(path, Vector3.Zero, Material.Metal);

            scene.Add(teapot);
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            //Object scale
            float size = 4f;

            #region InstanceWindow
            //Instance new window
            Window window = new Window(1024, 768, "Test", false, 16, 4);
            #endregion

            #region DecompressTexture

            /*
             * Decompress Texture from single file
             * This method has to be called only once,
             * because it could slows down the game,
             * do decompression in single project which is not
             * a part of your own working project.
             */
            TextureHelper.GenerateDecompressedTextureFromFile("Assets/drum1_ambient.png", "NewAssets");

            //Decompress Textures from list of files (Has to be called only once)
            //bool bRecursive = false;
            //string sExtension = "tex";
            //TextureHelper.GenerateDecompressedTexturesFromFolder("Assets", "NewAssets", bRecursive, sExtension);
            #endregion

            #region LoadDecompressedTexture
            //Return decompressed texture and save it.
            Texture loadedTexture = TextureHelper.LoadDecompressedTexture("GasFuel.txt");
            #endregion

            #region LoadOBJModel
            //Create a Mesh3[] to load custo ".obj"'s model
            Mesh3 mesh = ObjLoader.Load("Assets/GasFuel.obj", Vector3.One * size)[0];
            #endregion

            #region GameLoop
            while (window.opened)
            {
                //draw the mesh
                mesh.DrawTexture(loadedTexture);

                //Break while loop
                if (window.GetKey(KeyCode.Esc))
                {
                    break;
                }

                window.Update();
            }
            #endregion
        }
Esempio n. 9
0
    private void LoadAndPlaceModel(string url, Vector3 pos)
    {
        GameObject parent = new GameObject("Model Anchor");
        GameObject model  = new GameObject("Model");

        model.transform.SetParent(parent.transform);
        parent.transform.position = pos;
        ObjLoader objLoader = model.AddComponent <ObjLoader>();

        model.transform.Rotate(-90, 0, 0);
        model.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
        objLoader.Load(url);
    }
        public void T08_OBJParserFaces()
        {
            ObjLoader loader = new ObjLoader();

            loader.Load(@"ObjFiles\TriangleFaces.obj");

            Assert.AreEqual(loader.v[0], loader.t[0].GetP1());
            Assert.AreEqual(loader.v[1], loader.t[0].GetP2());
            Assert.AreEqual(loader.v[2], loader.t[0].GetP3());

            Assert.AreEqual(loader.v[0], loader.t[1].GetP1());
            Assert.AreEqual(loader.v[2], loader.t[1].GetP2());
            Assert.AreEqual(loader.v[3], loader.t[1].GetP3());
        }
Esempio n. 11
0
        public static Dictionary <string, Mesh> Load(string filename)
        {
            Debug.Assert(File.Exists(Paths.Meshes + filename), $"Missing mesh '{filename}'.");

            if (filename.EndsWith(".obj"))
            {
                return(ObjLoader.Load(filename));
            }

            var mesh = DaeLoader.Load(filename);

            return(new Dictionary <string, Mesh>
            {
                { "", mesh }
            });
        }
        public void T09_TriangulatingPolygons()

        {
            ObjLoader loader = new ObjLoader();

            loader.Load(@"ObjFiles\PolygonData.obj");

            Assert.AreEqual(loader.v[0], loader.t[0].GetP1());
            Assert.AreEqual(loader.v[1], loader.t[0].GetP2());
            Assert.AreEqual(loader.v[2], loader.t[0].GetP3());

            Assert.AreEqual(loader.v[0], loader.t[1].GetP1());
            Assert.AreEqual(loader.v[2], loader.t[1].GetP2());
            Assert.AreEqual(loader.v[3], loader.t[1].GetP3());

            Assert.AreEqual(loader.v[0], loader.t[2].GetP1());
            Assert.AreEqual(loader.v[3], loader.t[2].GetP2());
            Assert.AreEqual(loader.v[4], loader.t[2].GetP3());
        }
        public void T18_FacesWithNormalVectors()
        {
            ObjLoader loader = new ObjLoader();

            loader.Load(@"ObjFiles\FacesVertexNormal.obj");

            List <RayObject> g = loader.root.GetChildren();

            Triangle t1 = ((Triangle)g[0]);
            Triangle t2 = ((Triangle)g[1]);

            Assert.AreEqual(new Vector(0, 1, 0), t1.n1);
            Assert.AreEqual(new Vector(-1, 0, 0), t1.n2);
            Assert.AreEqual(new Vector(1, 0, 0), t1.n3);

            Assert.AreEqual(new Vector(0, 1, 0), t2.n1);
            Assert.AreEqual(new Vector(-1, 0, 0), t2.n2);
            Assert.AreEqual(new Vector(1, 0, 0), t2.n3);
        }
Esempio n. 14
0
        public override bool ImportAsset(string path, string ext)
        {
            ModelGeometry[] MG = new ModelGeometry[1];

            if (ext == "obj")
            {
                MG[0] = ObjLoader.Load(path);
            }
            else if (ext == "fbx")
            {
                MG = FbxLoader.Load(path);
                if (MG.Length > 1)
                {
                    subAssets = new MeshAsset[MG.Length - 1];
                    for (int i = 1; i < MG.Length; i++)
                    {
                        subAssets[i - 1] = new MeshAsset()
                        {
                            Name            = this.Name + "_" + i,
                            FileScale       = FileScale,
                            Pivot           = Vector3.Zero,
                            Vertices        = MG[i].Points,
                            Indexes         = MG[i].Indexes,
                            BoundingMinimum = MG[i].BoundingMinimum,
                            BoundingMaximum = MG[i].BoundingMaximum,
                        };
                    }
                }
            }
            else
            {
                Console.WriteLine("Unknown mesh extension: {0}", ext);
                return(false);
            }

            Pivot           = Vector3.Zero;
            Vertices        = MG[0].Points;
            Indexes         = MG[0].Indexes;
            BoundingMinimum = MG[0].BoundingMinimum;
            BoundingMaximum = MG[0].BoundingMaximum;
            return(true);
        }
        public void T11_MayaOBJFile()
        {
            if (Scene.current == null)
            {
                new Scene();
            }

            Light light  = new Light(new Point(-45, 45, -45), new Color(0.3, 0.6, 0.95));
            Light light2 = new Light(new Point(45, 15, -45), Color.red);

            Camera camera = new Camera(600, 400, Constants.pi / 3.0);

            camera.ViewTransform(new Point(0, 25.0, -105), new Point(0, 15, 10), new Vector(0, 1, 0));

            ObjLoader loader = new ObjLoader();

            loader.Load(@"ObjFiles\Foxy.obj");
            loader.root.SetMatrix(Mat4.RotateYMatrix(5 * Constants.pi / -4.0) *
                                  Mat4.ScaleMatrix(0.13, 0.13, 0.13));
            Canvas canvas = Scene.current.Render(camera);

            Save.SaveCanvas(canvas, "Chapter15_MayaObject");
        }
Esempio n. 16
0
 public static Mesh Load(string filename)
 {
     return(filename.EndsWith(".obj") ? ObjLoader.Load(filename) : DaeLoader.Load(filename));
 }
Esempio n. 17
0
 public Matrix <double> LoadModel(string path)
 {
     objLoader.Load(path);
     return(objLoader.Vertices);
 }
Esempio n. 18
0
        static void Main(string[] args)
        {
            Window window = new Window(1024, 768, "Aiv.Fast3D Perspective Test", false, 24, 0);

            window.SetDefaultOrthographicSize(10);
            //Window window = new Window("Aiv.Fast3D Perspective Test", 24, 4);



            window.EnableDepthTest();
            //window.CullBackFaces();

            window.SetCursor(false);

            PerspectiveCamera camera = new PerspectiveCamera(new Vector3(0, 6, 30), new Vector3(-10, 180, 0), 60, 0.01f, 1000);

            Texture crate = new Texture("Assets/crate.jpg");

            Texture floorTexture = new Texture("Assets/floor.jpg");

            floorTexture.SetRepeatX();
            floorTexture.SetRepeatY();

            Texture stormTrooperTexture = new Texture("Assets/Stormtrooper.png");

            stormTrooperTexture.SetRepeatX();
            stormTrooperTexture.SetRepeatY();

            Cube cube = new Cube();

            Cube floor = new Cube();

            floor.Scale3    = new Vector3(150, 50f, 150);
            floor.Position3 = new Vector3(0, -25, 0);

            // tiling texture
            for (int i = 0; i < floor.uv.Length; i++)
            {
                floor.uv[i] *= 10;
            }
            floor.UpdateUV();

            Mesh3 stormTrooper = ObjLoader.Load("Assets/Stormtrooper.obj", Vector3.One)[0];

            //stormTrooper.RegenerateNormals();

            Pyramid pyramid = new Pyramid();

            Texture logoAiv = new Texture("Assets/LogoAIV.png");
            Sprite  logo    = new Sprite(1 * logoAiv.Ratio, 1);

            Camera hudCamera = new Camera();

            logo.Camera = hudCamera;

            float lightRotation = -30;


            DepthTexture shadowTexture = new DepthTexture(4096, 4096, 24);

            Sprite shadow = new Sprite(5, 5);

            shadow.Camera = hudCamera;

            float shadow_left   = -30;
            float shadow_right  = 30;
            float shadow_bottom = -30;
            float shadow_top    = 30;
            float shadow_near   = -30;
            float shadow_far    = 30;

            DirectionalLight directionalLight = new DirectionalLight(Utils.EulerRotationToDirection(new Vector3(lightRotation, 180, 0)));

            directionalLight.SetShadowProjection(shadow_left, shadow_right, shadow_bottom, shadow_top, shadow_near, shadow_far);

            //directionalLight.Color = new Vector3(0.5f, 1, 0.5f);

            float crateRotation = 0;

            Mesh3[] botMesh = FbxLoader.Load("Assets/running.fbx", new Vector3(0.02f, 0.02f, 0.02f));

            SkeletalAnimation[] animations = FbxLoader.LoadAnimations("Assets/running.fbx", new Vector3(0.02f, 0.02f, 0.02f));


            int numFrames = 0;

            Mesh3 movingTrooper = ObjLoader.Load("Assets/Stormtrooper.obj", Vector3.One)[0];

            movingTrooper.Position3 = new Vector3(0, 0, 2);

            foreach (SkeletalAnimation animation in animations)
            {
                Console.WriteLine(animation.Name);
                foreach (string subject in animation.KeyFrames.Keys)
                {
                    Console.WriteLine(subject);
                    int currentFrames = 0;
                    foreach (SkeletalAnimation.KeyFrame frame in animation.KeyFrames[subject])
                    {
                        Console.WriteLine(frame.Time + " " + frame.Position + " " + frame.Rotation + " " + frame.Scale);
                        currentFrames++;
                    }
                    if (currentFrames > numFrames)
                    {
                        numFrames = currentFrames;
                    }
                }
            }

            float neckRotation = 0;

            int   animationIndex = 0;
            float animationTimer = 1f / animations[0].Fps;

            movingTrooper.SetParent(cube);

            Mesh3[] tank         = ObjLoader.Load("Assets/T34.obj", Vector3.One);
            Texture tankDiffuse  = new Texture("Assets/T-34.png");
            Texture tankSpecular = new Texture("Assets/T-34_S.png");



            //window.AddPostProcessingEffect(new DepthViewer());

            window.AddPostProcessingEffect(new Fog());

            //window.AddPostProcessingEffect(new Sobel());

            Vector3 pyramidRotation = Vector3.Zero;

            PostProcessingEffect fxaa = window.AddPostProcessingEffect(new FXAA());

            Plane plane = new Plane();

            Vector3 shadowOffset = new Vector3(0, 0, 0.22f);

            Sphere  sphere = new Sphere();
            Texture world  = new Texture("Assets/world.jpg");

            while (window.IsOpened)
            {
                if (window.GetKey(KeyCode.Esc))
                {
                    break;
                }

                if (window.GetKey(KeyCode.W))
                {
                    camera.Position3 += camera.Forward * 10 * window.deltaTime;
                }

                if (window.GetKey(KeyCode.S))
                {
                    camera.Position3 += -camera.Forward * 10 * window.deltaTime;
                }

                if (window.GetKey(KeyCode.D))
                {
                    camera.Position3 += camera.Right * 10 * window.deltaTime;
                }

                if (window.GetKey(KeyCode.A))
                {
                    camera.Position3 += -camera.Right * 10 * window.deltaTime;
                }

                if (window.GetKey(KeyCode.Up))
                {
                    camera.Position3 += camera.Up * 10 * window.deltaTime;
                }

                if (window.GetKey(KeyCode.Down))
                {
                    camera.Position3 += -camera.Up * 10 * window.deltaTime;
                }

                if (window.HasFocus)
                {
                    // currently broken, the mouse is too flaky
                    //float yaw = MouseX(window) * (90 + 45f);
                    //float pitch = MouseY(window) * 90f;
                    //camera.EulerRotation3 += new Vector3(pitch, yaw, 0) * window.deltaTime;
                }

                if (window.GetKey(KeyCode.Right))
                {
                    camera.EulerRotation3 += new Vector3(0, 90 + 45, 0) * window.deltaTime;
                }

                if (window.GetKey(KeyCode.Left))
                {
                    camera.EulerRotation3 -= new Vector3(0, 90 + 45, 0) * window.deltaTime;
                }

                if (window.GetKey(KeyCode.P))
                {
                    camera.EulerRotation3 += new Vector3(90 + 45, 0, 0) * window.deltaTime;
                }

                if (window.GetKey(KeyCode.L))
                {
                    camera.EulerRotation3 -= new Vector3(90 + 45, 0, 0) * window.deltaTime;
                }


                //fxaa.enabled = window.GetKey(KeyCode.X);

                if (window.GetKey(KeyCode.Num1))
                {
                    shadowOffset += Vector3.UnitX * 2 * window.deltaTime;
                    Console.WriteLine(shadowOffset);
                }

                if (window.GetKey(KeyCode.Num2))
                {
                    shadowOffset -= Vector3.UnitX * 2 * window.deltaTime;
                    Console.WriteLine(shadowOffset);
                }

                if (window.GetKey(KeyCode.Num3))
                {
                    shadowOffset += Vector3.UnitY * 2 * window.deltaTime;
                    Console.WriteLine(shadowOffset);
                }

                if (window.GetKey(KeyCode.Num4))
                {
                    shadowOffset -= Vector3.UnitY * 2 * window.deltaTime;
                    Console.WriteLine(shadowOffset);
                }

                if (window.GetKey(KeyCode.Num5))
                {
                    shadowOffset += Vector3.UnitZ * 0.2f * window.deltaTime;
                    Console.WriteLine(shadowOffset);
                }

                if (window.GetKey(KeyCode.Num6))
                {
                    shadowOffset -= Vector3.UnitZ * 2 * window.deltaTime;
                    Console.WriteLine(shadowOffset);
                }



                directionalLight.SetShadowProjection(shadow_left, shadow_right, shadow_bottom, shadow_top, shadow_near, shadow_far);

                animationTimer -= window.deltaTime;
                if (animationTimer <= 0)
                {
                    animationIndex++;
                    if (animationIndex >= numFrames)
                    {
                        animationIndex = 0;
                    }
                    animationTimer = 1f / animations[0].Fps;
                }

                foreach (string subject in animations[0].KeyFrames.Keys)
                {
                    if (botMesh[0].HasBone(subject))
                    {
                        Mesh3.Bone bone = botMesh[0].GetBone(subject);
                        if (animationIndex < animations[0].KeyFrames[subject].Count)
                        {
                            //bone.Position = animations[0].KeyFrames[subject][animationIndex].Position;
                            //bone.Rotation = animations[0].KeyFrames[subject][animationIndex].Rotation;
                        }
                    }
                }

                pyramidRotation += new Vector3(0, 10, 0) * window.deltaTime;
                neckRotation    += window.deltaTime;

                string boneName = "mixamorig:Neck";
                if (botMesh[0].HasBone(boneName))
                {
                    Mesh3.Bone bone = botMesh[0].GetBone(boneName);
                    bone.Rotation = Quaternion.FromEulerAngles(new Vector3(0, (float)Math.Sin(neckRotation) / 2, 0));
                }

                if (botMesh[1].HasBone(boneName))
                {
                    Mesh3.Bone bone = botMesh[1].GetBone(boneName);
                    bone.Rotation = Quaternion.FromEulerAngles(new Vector3(0, (float)Math.Sin(neckRotation) / 2, 0));
                }



                crateRotation += 30 * window.deltaTime;

                //lightRotation += 10 * window.deltaTime;
                //directionalLight.UpdateDirection(Utils.EulerRotationToDirection(new Vector3(lightRotation, 180, 0)));

                window.DisableCullFaces();
                // draw shadow map texture
                window.RenderTo(shadowTexture);
                window.CullFrontFaces();
                floor.DrawShadowMap(directionalLight);
                pyramid.Scale3         = new Vector3(1, 2, 1);
                pyramid.EulerRotation3 = pyramidRotation;
                pyramid.Position3      = new Vector3(-6, 2, 10) + shadowOffset;
                pyramid.DrawShadowMap(directionalLight);

                pyramid.Scale3    = new Vector3(1, 2, 1);
                pyramid.Rotation3 = Vector3.Zero;
                pyramid.Position3 = new Vector3(-30, 2, 10) + shadowOffset;
                pyramid.DrawShadowMap(directionalLight);


                botMesh[0].Position3 = new Vector3(6, 0, 10) + shadowOffset;
                botMesh[0].DrawShadowMap(directionalLight);
                botMesh[1].Position3 = new Vector3(6, 0, 10) + shadowOffset;
                botMesh[1].DrawShadowMap(directionalLight);

                stormTrooper.Position3 = new Vector3(0, 0, 5) + shadowOffset;
                stormTrooper.Rotation3 = Vector3.Zero;
                stormTrooper.DrawShadowMap(directionalLight);
                stormTrooper.Position3 = new Vector3(-5, 0, 5) + shadowOffset;
                stormTrooper.Rotation3 = Vector3.Zero;
                stormTrooper.DrawShadowMap(directionalLight);
                stormTrooper.Position3 = new Vector3(7, 0, 5) + shadowOffset;
                stormTrooper.Rotation3 = Utils.LookAt((camera.Position3 - stormTrooper.Position3).Normalized());
                stormTrooper.DrawShadowMap(directionalLight);
                cube.EulerRotation3 = new Vector3(0, crateRotation, 0);
                cube.Position3      = new Vector3(0, 7, 0) + shadowOffset;
                cube.DrawShadowMap(directionalLight);
                cube.EulerRotation3 = Vector3.Zero;
                cube.Position3      = new Vector3(5, 1, 5) + shadowOffset;
                cube.DrawShadowMap(directionalLight);


                foreach (Mesh3 item in tank)
                {
                    item.Position3 = new Vector3(-10, 0, 20) + shadowOffset;
                    item.DrawShadowMap(directionalLight);
                }

                window.DisableCullFaces();
                window.RenderTo(null);

                window.CullBackFaces();
                //window.DisableCullFaces();

                floor.DrawPhong(floorTexture, directionalLight, new Vector3(0.5f, 0.5f, 0.5f), 0, shadowTexture);

                pyramid.Scale3         = new Vector3(1, 2, 1);
                pyramid.EulerRotation3 = pyramidRotation;
                pyramid.Position3      = new Vector3(-6, 2, 10);
                pyramid.DrawGouraud(new Vector4(1, 0, 0, 1), directionalLight, shadowTexture);

                pyramid.Scale3         = new Vector3(1, 2, 1);
                pyramid.EulerRotation3 = Vector3.Zero;
                pyramid.Position3      = new Vector3(-30, 2, 10);
                pyramid.DrawGouraud(new Vector4(1, 1, 0, 1), directionalLight, shadowTexture);

                botMesh[0].Position3 = new Vector3(6, 0, 10);
                botMesh[0].DrawGouraud(new Vector4(0, 0.8f, 1, 1), directionalLight, shadowTexture, 0.01f);
                botMesh[1].Position3 = new Vector3(6, 0, 10);
                botMesh[1].DrawGouraud(new Vector4(1, 0, 0, 1), directionalLight, shadowTexture, 0.01f);

                stormTrooper.Position3 = new Vector3(0, 0, 5);
                stormTrooper.Rotation3 = Vector3.Zero;
                stormTrooper.DrawGouraud(stormTrooperTexture, directionalLight, shadowTexture);

                stormTrooper.Position3 = new Vector3(-5, 0, 5);
                stormTrooper.Rotation3 = Vector3.Zero;
                stormTrooper.DrawPhong(stormTrooperTexture, directionalLight, new Vector3(0, 0.1f, 0), 0.75f, shadowTexture);

                stormTrooper.Position3 = new Vector3(7, 0, 5);
                stormTrooper.Rotation3 = Utils.LookAt((camera.Position3 - stormTrooper.Position3).Normalized());
                stormTrooper.DrawCel(stormTrooperTexture, directionalLight, new Vector3(0, 0.1f, 0), 0.75f, shadowTexture);


                //cube.DrawColor(new Vector4(1, 0, 0, 1));
                cube.EulerRotation3 = new Vector3(0, crateRotation, 0);
                cube.Position3      = new Vector3(0, 7, 0);
                cube.DrawTexture(crate);

                if (window.GetKey(KeyCode.Space))
                {
                    movingTrooper.Position3 += movingTrooper.Forward * window.deltaTime * 2;
                }

                if (window.GetKey(KeyCode.G))
                {
                    movingTrooper.EulerRotation3 += new Vector3(0, 90, 0) * window.deltaTime;
                }

                if (window.GetKey(KeyCode.H))
                {
                    movingTrooper.EulerRotation3 -= new Vector3(0, 90, 0) * window.deltaTime;
                }

                movingTrooper.DrawGouraud(new Vector4(1, 0, 0, 1), directionalLight);

                cube.EulerRotation3 = Vector3.Zero;
                cube.Position3      = new Vector3(5, 1, 5);
                cube.DrawGouraud(new Vector4(0, 0, 1, 1), directionalLight, shadowTexture);


                foreach (Mesh3 item in tank)
                {
                    item.Position3 = new Vector3(-10, 0, 20);
                    item.DrawPhong(tankDiffuse, directionalLight, new Vector3(0.1f, 0.1f, 0.1f), tankSpecular);
                }

                plane.Position3       = new Vector3(-13, 5, 0);
                plane.EulerRotation3 += Vector3.UnitY * 30 * window.deltaTime;
                plane.DrawColor(new Vector4(1, 1, 0, 1));

                sphere.Position3       = new Vector3(-5, 2, 20);
                sphere.EulerRotation3 += Vector3.UnitY * 10 * window.deltaTime;
                sphere.Scale3          = new Vector3(3);
                sphere.DrawPhong(world, directionalLight, new Vector3(0.2f, 0.2f, 0.2f));
                //sphere.DrawColor(new Vector4(1, 0, 0, 1));

                logo.DrawTexture(logoAiv);

                shadow.DrawTexture(shadowTexture);

                // this ensure postprocessing works
                window.DisableCullFaces();

                plane.Position3       = new Vector3(-10, 5, 0);
                plane.EulerRotation3 += Vector3.UnitY * 30 * window.deltaTime;
                plane.DrawColor(new Vector4(0, 1, 1, 1));

                window.Update();
            }
        }
Esempio n. 19
0
        static void Main(string[] args)
        {
            Window window = new Window(1024, 768, "3D Orthographic Test");

            window.SetDefaultOrthographicSize(200);
            window.SetZNearZFar(-300, 300);

            window.EnableDepthTest();

            window.SetClearColor(0f, 1f, 1f, 1f);

            Texture backgroundTexture = new Texture("Assets/airadventurelevel1.png");

            Sprite background = new Sprite(window.OrthoWidth, window.OrthoHeight);


            Mesh3 mesh3 = new Mesh3();

            Mesh3 suzanne = ObjLoader.Load("Assets/suzanne.obj", new Vector3(50, -50, 50))[0];

            suzanne.Position3 = new Vector3(75, 100, 100);

            suzanne.vc = new float[suzanne.v.Length / 3 * 4];
            int vcPos = 0;

            for (int i = 0; i < suzanne.v.Length; i += 3)
            {
                suzanne.vc[vcPos++] = suzanne.v[i] / 50f;
                suzanne.vc[vcPos++] = suzanne.v[i + 1] / -50f;
                suzanne.vc[vcPos++] = suzanne.v[i + 2] / 50f;
                suzanne.vc[vcPos++] = 0.5f;
            }
            suzanne.UpdateVertexColor();

            Mesh3 stormTrooper = ObjLoader.Load("Assets/Stormtrooper.obj", new Vector3(50, -50, 50))[0];

            stormTrooper.Position3 = new Vector3(200, 200, 100);

            Texture texture = new Texture("Assets/Stormtrooper.png");

            texture.SetRepeatX();
            texture.SetRepeatY();

            mesh3.v = new float[]
            {
                // front face
                0, 0, 0,
                100, 0, 0,
                0, 100, 0,

                100, 0, 0,
                100, 100, 0,
                0, 100, 0,

                // back face
                0, 0, -100,
                100, 0, -100,
                0, 100, -100,

                100, 0, -100,
                100, 100, -100,
                0, 100, -100,

                // bottom face
                0, 100, 0,
                0, 100, -100,
                100, 100, 0,

                0, 100, -100,
                100, 100, -100,
                100, 100, 0,

                // right face
                100, 0, 0,
                100, 0, -100,
                100, 100, 0,

                100, 0, -100,
                100, 100, -100,
                100, 100, 0,

                // left face
                0, 0, 0,
                0, 0, -100,
                0, 100, 0,

                0, 0, -100,
                0, 100, -100,
                0, 100, 0,


                // top face
                0, 0, 0,
                0, 0, -100,
                100, 0, 0,

                0, 0, -100,
                100, 0, -100,
                100, 0, 0,
            };
            mesh3.UpdateVertex();

            mesh3.Pivot3 = new Vector3(50, 50, -50);

            mesh3.Position3 = new Vector3(130, 130, 100);

            mesh3.Scale3 = new Vector3(0.5f, 0.5f, 0.5f);


            while (window.opened)
            {
                if (window.GetKey(KeyCode.Esc))
                {
                    break;
                }

                if (window.GetKey(KeyCode.Up))
                {
                    mesh3.EulerRotation3        += new Vector3(-20 * window.deltaTime, 0, 0);
                    suzanne.EulerRotation3      += new Vector3(0, -30 * window.deltaTime, 0);
                    stormTrooper.EulerRotation3 += new Vector3(0, 30 * window.deltaTime, 0);
                }

                mesh3.Position3       = new Vector3(130, 130, 100);
                mesh3.Scale3          = new Vector3(0.5f, 0.5f, 0.5f);
                mesh3.EulerRotation3 += new Vector3(0, -10 * window.deltaTime, 0);

                background.DrawTexture(backgroundTexture);

                stormTrooper.DrawTexture(texture);

                mesh3.DrawWireframe(1f, 0f, 0f, 1f);

                window.CullBackFaces();
                suzanne.Draw();
                window.DisableCullFaces();

                window.Update();
            }
        }
Esempio n. 20
0
        public static Mesh Load(string filename)
        {
            Debug.Assert(File.Exists(Paths.Meshes + filename), $"Missing mesh '{filename}'.");

            return(filename.EndsWith(".obj") ? ObjLoader.Load(filename) : DaeLoader.Load(filename));
        }