public void LookAtEntity3D()
        {
            var entity = new Entity3D(Vector3D.One * 5.0f, Quaternion.Identity);
            var camera = CreateLookAtCamera(Vector3D.Zero, entity);

            Assert.AreEqual(camera.Target, entity.Position);
        }
Beispiel #2
0
        public static Entity3D Quad(int w, int h)
        {
            Entity3D r = new Entity3D();

            Mesh3D mesh = new Mesh3D(6, 4);

            Vector3 v1 = new Vector3(-w, -h, 0);
            Vector3 v2 = new Vector3(w, -h, 0);
            Vector3 v3 = new Vector3(w, h, 0);
            Vector3 v4 = new Vector3(-w, h, 0);

            Vector3 z = new Vector3(0, 0, 0);

            mesh.SetVertex(0, v1, z, z, z, new Vector2(0, 0));
            mesh.SetVertex(1, v2, z, z, z, new Vector2(1, 0));
            mesh.SetVertex(2, v3, z, z, z, new Vector2(1, 1));
            mesh.SetVertex(3, v4, z, z, z, new Vector2(0, 1));

            mesh.SetTri(0, 0, 1, 2);
            mesh.SetTri(1, 2, 3, 0);

            /*
             *          mesh.SetIndex(0, 0);
             * mesh.SetIndex(1, 1);
             * mesh.SetIndex(2, 2);
             * mesh.SetIndex(3, 2);
             * mesh.SetIndex(4, 3);
             * mesh.SetIndex(5, 0);
             */
            mesh.Final( );

            r.AddMesh(mesh);

            return(r);
        }
Beispiel #3
0
        private void ProcessNode(Entity3D root, Assimp.Node s, List <Mesh3D> ml)
        {
            Entity3D r1 = new Entity3D();

            root.Sub.Add(r1);
            r1.Top  = root;
            r1.Name = s.Name;
            if (s.Name.ToLower().Contains("root"))
            {
                r1.Name     = r1.Name + "*";
                r1.BreakTop = true;
            }

            //r1.LocalTurn = new OpenTK.Matrix4(s.Transform.A1, s.Transform.A2, s.Transform.A3, s.Transform.A4, s.Transform.B1, s.Transform.B2, s.Transform.B3, s.Transform.B4, s.Transform.C1, s.Transform.C2, s.Transform.C3, s.Transform.C4, s.Transform.D1, s.Transform.D2, s.Transform.D3, s.Transform.D4);
            r1.LocalTurn = new OpenTK.Matrix4(s.Transform.A1, s.Transform.B1, s.Transform.C1, s.Transform.D1, s.Transform.A2, s.Transform.B2, s.Transform.C2, s.Transform.D2, s.Transform.A3, s.Transform.B3, s.Transform.C3, s.Transform.D3, s.Transform.A4, s.Transform.B4, s.Transform.C4, s.Transform.D4);
            OpenTK.Matrix4 lt = r1.LocalTurn;

            r1.LocalTurn = lt.ClearTranslation();
            r1.LocalTurn = r1.LocalTurn.ClearScale();
            r1.LocalPos  = lt.ExtractTranslation();

            r1.LocalScale = lt.ExtractScale();
            // r1.LocalPos = new OpenTK.Vector3(r1.LocalPos.X + 100, 0, 0);
            for (int i = 0; i < s.MeshCount; i++)
            {
                r1.AddMesh(ml[s.MeshIndices[i]]);
            }
            if (s.HasChildren)
            {
                foreach (Node pn in s.Children)
                {
                    ProcessNode(r1, pn, ml);
                }
            }
        }
Beispiel #4
0
        public Entity3D LightNode(Entity3D node)
        {
            Entity3D res = new Entity3D
            {
                Name = node.Name + "(Lightmapped)"
            };

            if (node.LightMapInfo.ReceiveLight)
            {
                foreach (Data.Mesh3D mesh in node.Meshes)
                {
                    Data.Mesh3D lit_msh = LightMesh(mesh);
                    res.Meshes.Add(lit_msh);
                }
            }
            else
            {
                foreach (Data.Mesh3D mesh in node.Meshes)
                {
                    res.Meshes.Add(mesh.Clone());
                }
            }
            foreach (Node3D subnode in node.Sub)
            {
                res.Add(LightNode((Entity3D)subnode));
            }

            return(res);
        }
Beispiel #5
0
		public void CreateEntity3DPositionAndOrientation()
		{
			var position = new Vector3D(10.0f, -3.0f, 27.0f);
			var orientation = Quaternion.Identity;
			var entity = new Entity3D(position, orientation);
			Assert.AreEqual(position, entity.Position);
			Assert.AreEqual(orientation, entity.Orientation);
		}
Beispiel #6
0
		public void SetAndGetEntity3DComponentsDirectly()
		{
			var entity = new Entity3D(Vector3D.Zero);
			entity.Set(Vector3D.One);
			Assert.AreEqual(Vector3D.One, entity.Get<Vector3D>());
			entity.Set(Quaternion.Identity);
			Assert.AreEqual(Quaternion.Identity, entity.Get<Quaternion>());
		}
Beispiel #7
0
		public void CreateEntity3D()
		{
			var entity = new Entity3D(Vector3D.Zero);
			entity.Add(Rectangle.One);
			Assert.AreEqual(Vector3D.Zero, entity.Position);
			Assert.AreEqual(Quaternion.Identity, entity.Orientation);
			Assert.IsTrue(entity.IsVisible);
			Assert.AreEqual(4, entity.GetComponentsForSaving().Count);
		}
        public void CreateEntity3DPositionAndOrientation()
        {
            var position    = new Vector3D(10.0f, -3.0f, 27.0f);
            var orientation = Quaternion.Identity;
            var entity      = new Entity3D(position, orientation);

            Assert.AreEqual(position, entity.Position);
            Assert.AreEqual(orientation, entity.Orientation);
        }
        public void SetAndGetEntity3DComponentsDirectly()
        {
            var entity = new Entity3D(Vector3D.Zero);

            entity.Set(Vector3D.One);
            Assert.AreEqual(Vector3D.One, entity.Get <Vector3D>());
            entity.Set(Quaternion.Identity);
            Assert.AreEqual(Quaternion.Identity, entity.Get <Quaternion>());
        }
        public void SetPositionProperty()
        {
            var entity = new Entity3D(Vector3D.Zero)
            {
                Position = Vector3D.One
            };

            Assert.AreEqual(Vector3D.One, entity.Position);
        }
        public void SetOrientationProperty()
        {
            var entity = new Entity3D(Vector3D.Zero)
            {
                Orientation = Quaternion.Identity
            };

            Assert.AreEqual(Quaternion.Identity, entity.Orientation);
        }
        public void CreateEntity3D()
        {
            var entity = new Entity3D(Vector3D.Zero);

            entity.Add(Rectangle.One);
            Assert.AreEqual(Vector3D.Zero, entity.Position);
            Assert.AreEqual(Quaternion.Identity, entity.Orientation);
            Assert.IsTrue(entity.IsVisible);
            Assert.AreEqual(4, entity.GetComponentsForSaving().Count);
        }
        protected override void Setup(Model Model, Vector3 Position)
        {
            base.Setup(Model, Position);
            this.Scale = new Vector3(2f, 0.6f, 1f);
            this.defaultLightingEnabled = false;
            this.Position += new Vector3(0f, 0.6f, 8.8f);
            this.VelocityX = 0.2f;

            squareShadow = new Entity3D(Engine.Content.Load<Model>("Content\\Models\\SquareShadow"),
                          new Vector3(Position.X, 0.1f, Position.Z), this.Parent);
            squareShadow.Scale = new Vector3(1.2f,1f,0.6f);
            squareShadow.Alpha = 0.8f;
        }
Beispiel #14
0
        public Entity3D LightNode(Entity3D node)
        {
            Entity3D res = new Entity3D
            {
                Name = node.Name + "(Lightmapped)"
            };

            foreach (Data.Mesh3D mesh in node.Meshes)
            {
                Data.Mesh3D lit_msh = LightMesh(mesh, node.World);
                res.Meshes.Add(lit_msh);
            }

            foreach (Node3D subnode in node.Sub)
            {
                res.Add(LightNode((Entity3D)subnode));
            }

            return(res);
        }
Beispiel #15
0
    public override void InitNode()
    {
        Entity3D ent = Node as Entity3D;

        if (ent == null)
        {
            return;
        }
        switch (_Body)
        {
        case BodyType.Mesh:
            ent.EnablePy(Vivid.Physics.PyType.Mesh);


            break;

        case BodyType.DynamicBox:
            ent.EnablePy(Vivid.Physics.PyType.Box);
            break;
        }
    }
Beispiel #16
0
        public static void Cube(int w, int h, int d)
        {
            Entity3D ent = new Entity3D();

            Mesh3D mesh = new Mesh3D(36, 8);

            Material.Material3D mat = new Material.Material3D( );

            Vector3 p1 = new Vector3(-w / 2, -h / 2, -d / 2);
            Vector3 p2 = new Vector3(w / 2, -h / 2, -d / 2);
            Vector3 p3 = new Vector3(w / 2, h / 2, -d / 2);
            Vector3 p4 = new Vector3(-w / 2, h / 2, -d / 2);

            Vector3 p12 = new Vector3(-w / 2, -h / 2, d / 2);
            Vector3 p22 = new Vector3(w / 2, -h / 2, d / 2);
            Vector3 p32 = new Vector3(w / 2, h / 2, d / 2);
            Vector3 p42 = new Vector3(-w / 2, h / 2, d / 2);

            Vector3 z = new Vector3(0, 0, 0);

            // mesh.SetVertex(0,p1,)
        }
Beispiel #17
0
        public void DoLightMap()
        {
            ResultGraph.Root = LightNode((Entity3D)Graph.Root);

            Texture.Texture2D lm_tex = FinalMap.GetMap();

            void E_SetTex(Node3D node)
            {
                Entity3D ge = node as Entity3D;

                foreach (Data.Mesh3D m in ge.Meshes)
                {
                    m.Material.ColorMap = lm_tex;
                }
                // ge.Renderer = new Visuals.VRLightMap ( );
            }

            ResultGraph.EditGraph(E_SetTex);
            ResultGraph.Root.SetLightmap();

            // ResultGraph.Root.SetMultiPass ( );
        }
        // Initializor=============================================
        public override void Initialize()
        {
            // Initialize the Camera
            camera = new ShakedCamera(this);
            camera.Position = new Vector3(0, 13, 17);
            camera.Target = new Vector3(0, 0, 3);

            if (!Engine.Services.ContainsService(typeof(Camera)))
                Engine.Services.AddService(typeof(Camera), (ShakedCamera)camera);

            // Initialize the keyboard
            keyboard = Engine.Services.GetService<KeyboardDevice>();

            // Initialize the sounds

            music = Engine.Content.Load<Song>("Content\\Sounds\\music1");
            MediaPlayer.Play(music);
            MediaPlayer.Volume = 0.2f;
            MediaPlayer.IsRepeating = true;

            // Inistialize tha black Texture
            black = new Entity2D(Engine.Content.Load<Texture2D>("Content\\Textures\\black"),
                    Vector2.Zero, this);

            // Initialize tha Radar
            radar = new Radar(Engine.Content.Load<Model>("Content\\Models\\Radar"), Vector3.One, this);
            radar.Visible = false;

            // Initialize the Ball
            ball = new Ball(Engine.Content.Load<Model>("Content\\Models\\GameBall"),
                            new Vector3(0f,0f,5f), this);
            ball.defaultLightingEnabled = true;

            // Initialize the Bricks List
            brickLenghtLine = 3;
            brickLenghtColumn = 10;
            totalOfBricks = brickLenghtLine * brickLenghtColumn;
            totalOfBricksLeft = totalOfBricks;
            brickMapArray=new int[brickLenghtLine, brickLenghtColumn];
            brickObjectArray = new Brick[brickLenghtLine, brickLenghtColumn];

            for (int i = 0; i < brickLenghtLine; i++)
            {
                for (int j = 0; j < brickLenghtColumn; j++)
                {
                    brickMapArray[i, j] = Util.random.Next(0, 3);
                }
            }

            // Initialize the Released Object array
            ReleasedObjectArray = new ReleasedObject[totalOfBricks];
            for (int i = 0; i < totalOfBricks; i++)
                ReleasedObjectArray[i] = null;

            ReleasedObjectArrayIndex = 0;

            // initialize the ObjectArray of bricks
            for (int i = 0; i < brickLenghtLine; i++)
            {
                for (int j = 0; j < brickLenghtColumn; j++)
                {
                    Brick brick;
                    Model model;
                    // Type of Brick
                    Vector3 brikPos = new Vector3(-7f + j * 1.5f, 0f, -4f + i*1.5f);
                    switch (brickMapArray[i,j])
                    {
                        case 0:
                            // Type Normal
                            model = Engine.Content.Load<Model>("Content\\Models\\GameBrick1");
                            brick = new Brick(model, brikPos, this);
                            brick.BrickReleaseType = BrickReleaseType.Normal;
                            brickObjectArray[i, j] = brick;

                            model = Engine.Content.Load<Model>("Content\\Models\\ReleasedNormObject");
                            ReleasedObjectArray[brickLenghtColumn * i + j] = new NormalObject(model, brikPos, this);
                            break;
                        case 1:
                            // Type Score
                            model = Engine.Content.Load<Model>("Content\\Models\\GameBrick1");
                            brick = new Brick(model, brikPos, this);
                            brick.BrickReleaseType = BrickReleaseType.Money;
                            brickObjectArray[i, j] = brick;

                            model = Engine.Content.Load<Model>("Content\\Models\\ReleasedMoneyObject");
                            ReleasedObjectArray[brickLenghtColumn * i + j] = new MoneyObject(model, brikPos, this);
                            break;
                        case 2:
                            // Type Life
                            model = Engine.Content.Load<Model>("Content\\Models\\GameBrick1");
                            brick = new Brick(model, brikPos, this);
                            brick.BrickReleaseType = BrickReleaseType.Danger;
                            brickObjectArray[i, j] = brick;

                            model = Engine.Content.Load<Model>("Content\\Models\\ReleasedDangerObject");
                            ReleasedObjectArray[brickLenghtColumn * i + j] = new DangerObject(model, brikPos, this);
                            break;

                        default:
                            // Type Normal
                            model = Engine.Content.Load<Model>("Content\\Models\\GameBrick1");
                            brick = new Brick(model, brikPos, this);
                            brick.BrickReleaseType = BrickReleaseType.Normal;
                            brickObjectArray[i, j] = brick;

                            model = Engine.Content.Load<Model>("Content\\Models\\ReleasedNormObject");
                            ReleasedObjectArray[brickLenghtColumn * i + j] = new NormalObject(model, brikPos, this);
                            break;
                    }

                    // Update the ReleasedObjectArrayIndex
                    if (ReleasedObjectArrayIndex >= totalOfBricks)
                        ReleasedObjectArrayIndex = 0;
                    else
                        ReleasedObjectArrayIndex++;
                }
            }

            // Initialize the Paddle
            paddle = new Paddle(Engine.Content.Load<Model>("Content\\Models\\GamePaddle"), Vector3.Zero, this);
            paddle.defaultLightingEnabled = true;

            // Iniotialize the spiralRod
            paddleSupport = new PaddleSupport(Engine.Content.Load<Model>("Content\\Models\\SpiralRod"),
                                     new Vector3(0f, 0.6f, 9f), this);
            //paddleSupport.Rotation = Matrix.CreateRotationZ(MathHelper.ToRadians(90f));
            paddleSupport.defaultLightingEnabled = true;

            // Initialize the Blur
            blur = new GaussianBlur(Engine.Viewport.Width, Engine.Viewport.Height, this);
            blur.Visible = false;

            // Initialize HUD
            hud = new Hud(this);

            // Initialize the gameMap
            gameMap = new Entity3D(Engine.Content.Load<Model>("Content\\Models\\GameMap"), Vector3.Zero, this);
            gameMap.defaultLightingEnabled = true;

            base.Initialize();
        }
 protected override void Setup(Model Model, Vector3 Position)
 {
     base.Setup(Model, Position);
     sound1 = Engine.Content.Load<SoundEffect>("Content\\Sounds\\ballHit");
     this.Scale = new Vector3(0.1f);
     this.Position += new Vector3(0f, 0.5f, 0f);
     speedFactor = GlobalVariables.speedFactor;
     this.velocityZ = speedFactor;
     this.velocityX = velocityZ / 2;
     this.ballRaduis = 1f;
     radialShadow = new Entity3D(Engine.Content.Load<Model>("Content\\Models\\RadialShadow"),
                 new Vector3(this.Position.X, 0.1f, this.Position.Z), this.Parent);
     radialShadow.Scale = new Vector3(0.5f);
 }
 protected override void Setup(Model Model, Vector3 Position)
 {
     base.Setup(Model, Position);
     this.Scale = new Vector3(0.125f);
     this.Position += new Vector3(0f, 1.2f, 0f);
     this.brickLenght = 1;
     brickReleaseType = BrickReleaseType.Normal;
     squareShadow = new Entity3D(Engine.Content.Load<Model>("Content\\Models\\SquareShadow"),
                               new Vector3(Position.X, 0.2f, Position.Z), this.Parent);
     squareShadow.Scale = new Vector3(0.8f);
     squareShadow.Alpha = 0.5f;
     angle = Util.random.Next(0, 360);
 }
        public void CannotAddTheSameTypeOfComponentTwice()
        {
            var entity = new Entity3D(Vector3D.Zero);

            Assert.Throws <Entity.ComponentOfTheSameTypeAddedMoreThanOnce>(() => entity.Add(Vector3D.One));
        }
Beispiel #22
0
        public override Node3D LoadNode(string path)
        {
            if (NormBlank == null)
            {
                NormBlank = new Texture.Texture2D("data/tex/normblank.png", Texture.LoadMethod.Single, false);
                DiffBlank = new Texture.Texture2D("data/tex/diffblank.png", Texture.LoadMethod.Single, false);
                SpecBlank = new Texture.Texture2D("data/tex/specblank.png", Texture.LoadMethod.Single, false);
            }
            string ip = path;
            int    ic = ip.LastIndexOf("/");

            if (ic < 1)
            {
                ic = ip.LastIndexOf("\\");
            }
            if (ic > 0)
            {
                IPath = ip.Substring(0, ic);
            }

            Entity3D root = new Entity3D();
            string   file = path;

            AssimpContext e = new Assimp.AssimpContext();

            Assimp.Configs.NormalSmoothingAngleConfig c1 = new Assimp.Configs.NormalSmoothingAngleConfig(75);
            e.SetConfig(c1);

            Console.WriteLine("Impporting:" + file);
            Assimp.Scene s = null;
            try
            {
                s = e.ImportFile(file, PostProcessSteps.OptimizeGraph | PostProcessSteps.FindInvalidData | PostProcessSteps.FindDegenerates | PostProcessSteps.Triangulate | PostProcessSteps.ValidateDataStructure | PostProcessSteps.CalculateTangentSpace | PostProcessSteps.GenerateNormals | PostProcessSteps.FixInFacingNormals | PostProcessSteps.GenerateSmoothNormals);
                if (s.HasAnimations)
                {
                    return(LoadAnimNode(path));
                }
            }
            catch (AssimpException ae)
            {
                Console.WriteLine(ae);
                Console.WriteLine("Failed to import");
                Environment.Exit(-1);
            }
            Console.WriteLine("Imported.");
            Dictionary <string, Mesh3D> ml = new Dictionary <string, Mesh3D>();
            List <Mesh3D> ml2 = new List <Mesh3D>();

            Console.WriteLine("animCount:" + s.AnimationCount);

            Matrix4x4 tf = s.RootNode.Transform;

            tf.Inverse();

            root.GlobalInverse = ToTK(tf);

            Dictionary <uint, List <VertexWeight> > boneToWeight = new Dictionary <uint, List <VertexWeight> >();

            //root.Animator = new Animation.Animator();

            //s.Animations[0].NodeAnimationChannels[0].
            //s.Animations[0].anim

            // root.Animator.InitAssImp(model);

            foreach (Mesh m in s.Meshes)
            {
                Console.WriteLine("M:" + m.Name + " Bones:" + m.BoneCount);
                Console.WriteLine("AA:" + m.HasMeshAnimationAttachments);

                Material.Material3D vm = new Material.Material3D
                {
                    ColorMap    = DiffBlank,
                    NormalMap   = NormBlank,
                    SpecularMap = SpecBlank
                };
                Mesh3D m2 = new Mesh3D(m.GetIndices().Length, m.VertexCount);
                ml2.Add(m2);
                // ml.Add(m.Name, m2);
                for (int b = 0; b < m.BoneCount; b++)
                {
                    string name = m.Bones[b].Name;
                }
                m2.Material = vm;
                // root.AddMesh(m2);
                m2.Name = m.Name;
                Assimp.Material mat = s.Materials[m.MaterialIndex];
                TextureSlot     t1;

                int sc = mat.GetMaterialTextureCount(TextureType.Unknown);
                Console.WriteLine("SC:" + sc);
                if (mat.HasColorDiffuse)
                {
                    vm.Diff = CTV(mat.ColorDiffuse);
                    Console.WriteLine("Diff:" + vm.Diff);
                }
                if (mat.HasColorSpecular)
                {
                    // vm.Spec = CTV ( mat.ColorSpecular );
                    Console.WriteLine("Spec:" + vm.Spec);
                }
                if (mat.HasShininess)
                {
                    //vm.Shine = 0.3f+ mat.Shininess;
                    Console.WriteLine("Shine:" + vm.Shine);
                }

                Console.WriteLine("Spec:" + vm.Spec);
                //for(int ic = 0; ic < sc; ic++)
                ///{
                if (sc > 0)
                {
                    TextureSlot tex2 = mat.GetMaterialTextures(TextureType.Unknown)[0];
                    // vm.SpecularMap = new Texture.Texture2D ( IPath + "/" + tex2.FilePath, Texture.LoadMethod.Single, false );
                }

                if (mat.GetMaterialTextureCount(TextureType.Normals) > 0)
                {
                    TextureSlot ntt = mat.GetMaterialTextures(TextureType.Normals)[0];
                    Console.WriteLine("Norm:" + ntt.FilePath);
                    vm.NormalMap = new Texture.Texture2D(IPath + "/" + ntt.FilePath, Vivid.Texture.LoadMethod.Single, false);
                }

                if (mat.GetMaterialTextureCount(TextureType.Diffuse) > 0)
                {
                    t1 = mat.GetMaterialTextures(TextureType.Diffuse)[0];
                    Console.WriteLine("DiffTex:" + t1.FilePath);

                    if (t1.FilePath != null)
                    {
                        //Console.WriteLine ( "Tex:" + t1.FilePath );
                        // Console.Write("t1:" + t1.FilePath);
                        vm.ColorMap = new Texture.Texture2D(IPath + "/" + t1.FilePath.Replace(".dds", ".png"), Texture.LoadMethod.Single, false);
                        if (File.Exists(IPath + "/" + "norm_" + t1.FilePath))
                        {
                            vm.NormalMap = new Texture.Texture2D(IPath + "/" + "norm_" + t1.FilePath, Texture.LoadMethod.Single, false);
                        }
                    }
                }

                for (int i = 0; i < m2.NumVertices; i++)
                {
                    Vector3D v = m.Vertices[i];// * new Vector3D(15, 15, 15);

                    Vector3D n = new Vector3D(0, 1, 0);

                    if (m.Normals != null && m.Normals.Count > i)
                    {
                        n = m.Normals[i];
                    }

                    List <Vector3D> t = m.TextureCoordinateChannels[0];
                    Vector3D        tan, bi;
                    if (m.Tangents != null && m.Tangents.Count > 0)
                    {
                        tan = m.Tangents[i];
                        bi  = m.BiTangents[i];
                    }
                    else
                    {
                        tan = new Vector3D(0, 0, 0);
                        bi  = new Vector3D(0, 0, 0);
                    }
                    if (t.Count() == 0)
                    {
                        m2.SetVertex(i, Cv(v), Cv(tan), Cv(bi), Cv(n), Cv2(new Vector3D(0, 0, 0)));
                    }
                    else
                    {
                        Vector3D tv = t[i];
                        tv.Y = 1.0f - tv.Y;
                        m2.SetVertex(i, Cv(v), Cv(tan), Cv(bi), Cv(n), Cv2(tv));
                    }

                    //var v = new PosNormalTexTanSkinned(pos, norm.ToVector3(), texC.ToVector2(), tan.ToVector3(), weights.First(), boneIndices);
                    //verts.Add(v);
                }
                int[]  id = m.GetIndices();
                uint[] nd = new uint[id.Length];
                for (int i = 0; i < id.Length; i += 3)
                {
                    //Tri t = new Tri();
                    //t.V0 = (int)nd[i];
                    // t.V1 = (int)nd[i + 1];
                    // t.v2 = (int)nd[i + 2];

                    // nd[i] = (uint)id[i];
                    if (i + 2 < id.Length)
                    {
                        m2.SetTri(i / 3, id[i], id[i + 1], id[i + 2]);
                    }
                }

                m2.Indices = nd;
                //m2.Scale(AssImpImport.ScaleX, AssImpImport.ScaleY, AssImpImport.ScaleZ);
                //m2.GenerateTangents ( );

                m2.Final();
            }

            ProcessNode(root, s.RootNode, ml2);

            /*
             * while (true)
             * {
             * }
             */
            return(root as Node3D);
        }
 private static LookAtCamera CreateLookAtCamera(Vector3D position, Entity3D target)
 {
     return(CreateLookAtCamera(position, target.Position));
 }
        protected override void Setup(Model Model, Vector3 Position)
        {
            base.Setup(Model, Position);
            this.defaultLightingEnabled = false;
            Alpha = 1f;
            //this.Rotation = Matrix.CreateRotationZ(MathHelper.ToRadians(90f));
            this.isGettingHit = false;
            this.hitDuration = 1000f;
            this.Visible = true;

            ss = new Entity3D(Engine.Content.Load<Model>("Content\\Models\\SquareShadow"),
                          new Vector3(Position.X, 0.2f, Position.Z), this.Parent);
            ss.Scale = new Vector3(16f, 1f, 0.2f);
        }
		private static LookAtCamera CreateLookAtCamera(Vector3D position, Entity3D target)
		{
			return CreateLookAtCamera(position, target.Position);
		}
		public void LookAtEntity3D()
		{
			var entity = new Entity3D(Vector3D.One * 5.0f, Quaternion.Identity);
			var camera = CreateLookAtCamera(Vector3D.Zero, entity);
			Assert.AreEqual(camera.Target, entity.Position);
		}
        protected override void Setup(Model Model, Vector3 Position)
        {
            base.Setup(Model, Position);
            sound1 = Engine.Content.Load<SoundEffect>("Content\\Sounds\\button-9");
            sound2 = Engine.Content.Load<SoundEffect>("Content\\Sounds\\releaseObject");

            this.releasedObjectLenght = 1f;
            isFadingAway = false;
            this.Alpha = 1f;
            this.releaseObjSpeed = GlobalVariables.releaseObjSpeed;
            Visible = false;
            // Setup the image with the arrow
            arrowPosY = (float)Util.random.NextDouble();
            shadow = new Entity3D(Engine.Content.Load<Model>("Content\\Models\\RadialShadow"),
                                      new Vector3(Position.X, 0.2f + (0.1f * arrowPosY), Position.Z), this.Parent);
            shadow.Scale = new Vector3(0.5f);
            shadow.Alpha = 0.6f;
            shadow.Visible = false;
            icon = new Entity2D(Engine.Content.Load<Texture2D>("Content\\Textures\\danger"),
                                GraphicsUtil.GetProjectPoint(Position), this.Parent);
            icon.Visible = false;
        }
Beispiel #28
0
		private static void UpdatePositionAndOrientation(Entity3D entity, PhysicsBody physicsBody)
		{
			entity.Position = physicsBody.Position;
			entity.Orientation = physicsBody.GetOrientation();
		}
 private static void UpdatePositionAndOrientation(Entity3D entity, PhysicsBody physicsBody)
 {
     entity.Position    = physicsBody.Position;
     entity.Orientation = physicsBody.GetOrientation();
 }
Beispiel #30
0
		public void SetPositionProperty()
		{
			var entity = new Entity3D(Vector3D.Zero) { Position = Vector3D.One };
			Assert.AreEqual(Vector3D.One, entity.Position);
		}
Beispiel #31
0
		public void CannotAddTheSameTypeOfComponentTwice()
		{
			var entity = new Entity3D(Vector3D.Zero);
			Assert.Throws<Entity.ComponentOfTheSameTypeAddedMoreThanOnce>(() => entity.Add(Vector3D.One));
		}
Beispiel #32
0
		public void SetOrientationProperty()
		{
			var entity = new Entity3D(Vector3D.Zero) { Orientation = Quaternion.Identity };
			Assert.AreEqual(Quaternion.Identity, entity.Orientation);
		}
Beispiel #33
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                // 加载ArcGIS地图
                string fileName = ConfigurationManager.AppSettings["3DDFile"];
                this.globe3DControl1.Load3DDFile(fileName);

                string contentRoot = ConfigurationManager.AppSettings["ContentRoot"];

                // 初始化三维渲染
                this.globe3DControl1.Initialize3D(0.001, 2.5, true, true, contentRoot);

                this.globe3DControl1.ShowSun  = false;
                this.globe3DControl1.ShowMoon = false;

                // Fix me: 这里需要手动初始化一下DetectRange的硬件资源
                // 能否放在一个统一的扩展初始化函数中?
                DetectRange.InitGeometries(globe3DControl1.World.World.ContentManager);

                // 制作雷达范围的测试数据
                // 360个方向,5个高度层?
                // TODO: 先通过完整的圆球来测试,然后再测试有随机遮蔽的情况

                #region P-雷达范围

                // 改为通过添加实体的方式来测试?
                m_RadarLayer = globe3DControl1.World.AddLayer("radarLayer");
                Entity3D radarEntity = m_RadarLayer.AddEntity("radar01");
                // radarEntity.Visible = false;

                radarEntity.Color = Vector4.One;

                GeographicCoordinateTransform transformCmp = new GeographicCoordinateTransform();
                transformCmp.AlwaysFaceGeoCenter = true;
                transformCmp.LocalPose.Scale     = new Vector3d(100, 100, 100);
                transformCmp.Longitude           = 120;
                transformCmp.Latitude            = 30;
                transformCmp.Height = 0;

                radarEntity.AddComponent(transformCmp);

                DetectRangeComponent detectRange = new DetectRangeComponent();

                // DetectRange detectRange = new DetectRange();

                // 创建一个变换矩阵
                // 缩小后放在北极?
                Matrix4d matScale = Matrix4d.Scale(0.0001);
                Matrix4d matTran  = Matrix4d.CreateTranslation(0, 1, 0);

                detectRange.UseSimpleNormal = true;
                // detectRange.Transform = matScale * matTran;
                detectRange.Color     = new Vector4(0.8f, 1, 0.8f, 0.9f);
                detectRange.ScanColor = new Vector4(1.0f, 0.6f, 0.2f, 0.5f);

                // TODO: 创建随机的360度的范围的遮蔽数据
                // 通过Perlin噪声来模拟
                double[]    occlusion = new double[360];
                PerlinNoise noise     = new PerlinNoise(99);

                for (int i = 0; i < 360; i++)
                {
                    double val =
                        (noise.Noise(2 * i / 180.0, 2 * i / 180.0, -0.5)) * 0.7
                        + (noise.Noise(4 * i / 180.0, 4 * i / 180.0, 0)) * 0.2
                        + (noise.Noise(8 * i / 180.0, 8 * i / 180.0, 0.5)) * 0.1;

                    val = Math.Max(val * 3, 0);

                    occlusion[i] = val * 6000 + 800;
                }

                detectRange.Ranges.Add(CreateHorizRange(300, 1000, occlusion));
                detectRange.Ranges.Add(CreateHorizRange(600, 2500, occlusion));
                detectRange.Ranges.Add(CreateHorizRange(800, 3500, occlusion));
                detectRange.Ranges.Add(CreateHorizRange(1500, 4500, occlusion));
                detectRange.Ranges.Add(CreateHorizRange(2000, 4400, occlusion));
                detectRange.Ranges.Add(CreateHorizRange(2500, 4000, occlusion));
                detectRange.Ranges.Add(CreateHorizRange(2300, 800, occlusion));

                detectRange.RefreshGeometry();

                radarEntity.AddComponent(detectRange);

                m_DetectRange = detectRange;

                #endregion

                // 创建雷达范围自定义图元

                // 添加到场景中
                // globe3DControl1.World.World.RenderScene.CustomRenderPrimitives.Add(detectRange);

                #region 扫描范围锥体

                bool useSenceVolumePrim = false;

                if (useSenceVolumePrim)
                {
                    // 直接用自定义图元测试

                    RectSenseVolume senceVolume = new RectSenseVolume();
                    senceVolume.Initialize(globe3DControl1.World.ContentManager);

                    // 属性:变换矩阵
                    Matrix4d matRot = Matrix4d.CreateRotationX(Math.PI * 0.5);

                    senceVolume.Transform      = matRot * Matrix4d.CreateTranslation(0, -5.6, 0);
                    senceVolume.HorizHalfAngle = 5.5;
                    senceVolume.VertiHalfAngle = 10.5;
                    senceVolume.Color          = Vector4.One;

                    globe3DControl1.World.World.RenderScene.CustomRenderPrimitives.Add(senceVolume);
                }
                else
                {
                    // 用实体和组件测试
                    m_SatelliteLayer = globe3DControl1.World.AddLayer("satelliteLayer");
                    Entity3D satelliteEntity = m_SatelliteLayer.AddEntity("satellite01");

                    GeographicCoordinateTransform satTran = new GeographicCoordinateTransform();
                    satTran.AlwaysFaceGeoCenter = true;
                    satTran.Longitude           = 120;
                    satTran.Latitude            = 0;
                    satTran.Height = 35800e3;
                    satelliteEntity.AddComponent(satTran);

                    Vector3d satellitePos = Globe3DCoordHelper.GraphicToCentric(satTran.Longitude, satTran.Latitude, satTran.Height);

                    // 注意:卫星模型的视觉放大需要通过再加一个卫星模型子实体来实现,否则会影响传感器子实体

                    #region 大视场传感器


                    Entity3D sensorEntity = m_SatelliteLayer.AddEntity("sensor01");
                    sensorEntity.Parent = satelliteEntity;

                    SRTTransformComponent sensorTran = new SRTTransformComponent();
                    // sensorTran.RotationX = 10;
                    sensorEntity.AddComponent(sensorTran);

                    CustomController.SensorAutoScanController sensorCtrl = new CustomController.SensorAutoScanController();
                    sensorEntity.AddComponent(sensorCtrl);

                    RectSenseVolumeComponent sensorRange = new RectSenseVolumeComponent(globe3DControl1.World.ContentManager);
                    sensorRange.HorizHalfAngle = 5.5;
                    sensorRange.VertiHalfAngle = 10.5;
                    sensorRange.Pickable       = false;
                    sensorRange.Color          = new Vector4(1, 0.4f, 0, 0.2f);// Vector4.One;

                    sensorRange.ScanPlanes.Add(new RectSenseVolume.ScanPlane()
                    {
                        CurrAngle   = 0,
                        Orientation = RectSenseVolume.ScanPlane.ScanOrientations.Vertical,
                        Visible     = true,
                        Color       = new Vector4(1, 0.2f, 0, 0.25f)
                    });

                    //sensorRange.ScanPlanes.Add(new RectSenseVolume.ScanPlane()
                    //{
                    //    CurrAngle = 0,
                    //    Orientation = RectSenseVolume.ScanPlane.ScanOrientations.Horizontal,
                    //    Visible = true,
                    //    Color = new Vector4(0, 1, 0, 0.4f)
                    //});

                    sensorRange.InvalidateScanPlanes();

                    sensorEntity.AddComponent(sensorRange);

                    #endregion

                    #region 小视场传感器

                    Entity3D smallSensorEntity = m_SatelliteLayer.AddEntity("sensor02");
                    smallSensorEntity.Parent = satelliteEntity;

                    CustomController.SensorGridScanController sensorGridCtrl = new CustomController.SensorGridScanController();
                    sensorGridCtrl.MinHorizAngle = 2;
                    sensorGridCtrl.MaxHorizAngle = 4;

                    sensorGridCtrl.MinVertiAngle = 2;
                    sensorGridCtrl.MaxVertiAngle = 4;

                    sensorGridCtrl.NumHorizGrids = 2;
                    sensorGridCtrl.NumVertiGrids = 2;

                    sensorGridCtrl.MoveInterval = 0.75;
                    sensorGridCtrl.StayInterval = 0.25;

                    sensorGridCtrl.ScanSequence.Add(new System.Drawing.Point(0, 0));
                    sensorGridCtrl.ScanSequence.Add(new System.Drawing.Point(0, 1));
                    sensorGridCtrl.ScanSequence.Add(new System.Drawing.Point(1, 1));
                    sensorGridCtrl.ScanSequence.Add(new System.Drawing.Point(1, 0));

                    smallSensorEntity.AddComponent(sensorGridCtrl);

                    SRTTransformComponent smallSensorTran = new SRTTransformComponent();
                    smallSensorEntity.AddComponent(smallSensorTran);

                    RectSenseVolumeComponent smallSensorRange = new RectSenseVolumeComponent(globe3DControl1.World.ContentManager);
                    smallSensorRange.HorizHalfAngle = 0.5;
                    smallSensorRange.VertiHalfAngle = 0.5;
                    smallSensorRange.Pickable       = false;
                    smallSensorRange.Color          = new Vector4(0, 1, 0, 0.4f);

                    smallSensorEntity.AddComponent(smallSensorRange);

                    #endregion

                    //////////////////////////////////////

                    uint   precision = 30;
                    double theta     = 6.5;
                    double range     = 11;

                    List <Vector3d> points = RadarIntersect((Vector3d)satellitePos, theta, range, precision);

                    m_PackedMarkStyle         = new PackedBillboardMaterialStyle(globe3DControl1.World.ContentManager);
                    m_PackedMarkStyle.Texture = globe3DControl1.World.ContentManager.LoadTexture(@".\Resources\Textures\PackedIcons.png");

                    using (FileStream fs = new FileStream(@".\Resources\Textures\PackedIcons.xml", FileMode.Open, FileAccess.Read))
                    {
                        XmlSerializer xs = new XmlSerializer(typeof(List <PackedImage>));
                        m_PackedMarkStyle.PackedImages = xs.Deserialize(fs) as List <PackedImage>;

                        fs.Close();

                        // 如果加载失败怎么办
                        if (m_PackedMarkStyle.PackedImages == null)
                        {
                            throw new InvalidDataException("Failed loading packed image definition");
                        }
                    }
                    for (int i = 0; i < points.Count; i++)
                    {
                        Vector3d p   = points[i];
                        Vector3d pos = Globe3DCoordHelper.CentricToGraphic(p.X, p.Y, p.Z);

                        Entity3D markEntity = m_SatelliteLayer.AddEntity(i.ToString());

                        GeographicCoordinateTransform geoTf = new GeographicCoordinateTransform();
                        geoTf.Longitude = pos.X;
                        geoTf.Latitude  = pos.Y;
                        geoTf.Height    = pos.Z;

                        markEntity.AddComponent(geoTf);

                        BillboardComponent bgIcon = new BillboardComponent();
                        bgIcon.Pickable = true;
                        bgIcon.Color    = Vector4.One;
                        bgIcon.Visible  = true;
                        bgIcon.Width    = 20;
                        bgIcon.Height   = 20;
                        // Fix me: 本billboard的偏移量在哪里进行比较好?
                        bgIcon.Offset        = new Vector2d(0, 0);
                        bgIcon.MaterialStyle = m_PackedMarkStyle;
                        // Fix me: 通过名称获得packed image index的操作在哪里进行比较好?
                        bgIcon.PackID = m_PackedMarkStyle.GetPackIndexByName("bg.fw.png");
                        // 所有的组成部分使用统一的组ID
                        bgIcon.GroupID = markEntity.ID;
                        // 背景最先绘制
                        bgIcon.RenderOrder = 0;
                        markEntity.AddComponent(bgIcon);
                    }
                }

                #endregion

                // 摄像机操作
                // 设置摄像机跟随预警机实体
                globe3DControl1.CameraController.ObserveMode = Controls.GIS3D.Core.EntityComponent.Controller.GlobeCameraControllerComponent.CameraObserveMode.Free;

                // 修改摄像机的oriantationmode为surface
                globe3DControl1.CameraController.OrientationMode = GlobeCameraControllerComponent.CameraOrientationMode.NorthPole;

                globe3DControl1.CameraController.MinDistanceMeter = 200;// 30000;
                globe3DControl1.CameraController.CurViewDistance  = 11400000;
                //this.globe3DControl1.World.GlobeCameraController.LowRange = 200000;
                this.globe3DControl1.World.GlobeCameraController.LowRange           = 20000;
                this.globe3DControl1.World.GlobeCameraController.LowRangeLeanFactor = 0.2;
                //this.globe3DControl1.World.GlobeCameraController.LowRangeLeanFactor = 4;
                this.globe3DControl1.World.GlobeCameraController.AutoRotate = false;

                m_Simulator = new GlobeSimulator();

                m_Simulator.Updated += new GlobeSimulator.UpdateEventHandler(m_Simulator_Updated);
                m_Simulator.StartSimulation();

                m_SimTimer.Interval = 40;
                m_SimTimer.Tick    += new EventHandler(m_SimTimer_Tick);
                m_SimTimer.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                Debug.WriteLine(ex.ToString());
                throw;
            }
        }