protected IObject DefaultSphereObj(String modelName, Vector3 position, float radius, float scale = 1, float mass = 10)
 {
     SimpleModel simpleModel = new SimpleModel(GraphicFactory, modelName);            
     SphereObject tmesh = new SphereObject(position, radius, mass, scale);
     ForwardMaterial fmaterial = ForwardMaterial.DefaultForwardMaterial();
     return new IObject(fmaterial, simpleModel, tmesh);
 }
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);

            SerializatorWrapper SerializatorWrapper = new SerializatorWrapper();
            SerializatorWrapper.Serialize(new Vector3(10, 20, 30), "vetor.xml");
            Vector3 vec = (Vector3) SerializatorWrapper.Desserialize<Vector3>("vetor.xml", null);
            Debug.Assert(vec.X == 10);
            Debug.Assert(vec.Y == 20);
            Debug.Assert(vec.Z == 30);


            ObjectMock ObjectMock = new ObjectMock(GraphicFactory, "Model/cenario", Vector3.Zero, Matrix.Identity, Vector3.One);
            SerializatorWrapper.Serialize(ObjectMock, "cena.xml");
            ObjectMock mloaded = (ObjectMock)SerializatorWrapper.Desserialize<ObjectMock>("cena.xml", GraphicFactory);
            this.World.AddObject(mloaded);

            
            IObject obj;
            {
                SimpleModel simpleModel = new SimpleModel(factory, "Model//ball");
                simpleModel.SetTexture(factory.CreateTexture2DColor(1,1,Color.Green),TextureType.DIFFUSE);
                SphereObject tmesh = new SphereObject(new Vector3(100, 200, 10), 1 ,10, 5, MaterialDescription.DefaultBepuMaterial());
                ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default());
                ForwardMaterial fmaterial = new ForwardMaterial(shader);
                obj = new IObject(fmaterial, simpleModel, tmesh);
                this.World.AddObject(obj);
            }


            this.BindInput(new SimpleConcreteKeyboardInputPlayable(StateKey.PRESS, Keys.Space,
                (a) =>
                {
                    this.World.RemoveObject(obj);
                    DynamicObjectSaver DynamicObjectSaver = new Serialization.DynamicObjectSaver(obj.Modelo.Name, obj.PhysicObject.Position, obj.PhysicObject.Rotation, obj.PhysicObject.Scale, obj.PhysicObject.Velocity, obj.PhysicObject.AngularVelocity);
                    SerializatorWrapper.Serialize(DynamicObjectSaver, "dyn.xml");
                    
                    DynamicObjectSaver dloaded = (DynamicObjectSaver)SerializatorWrapper.Desserialize<DynamicObjectSaver>("dyn.xml");
                    SimpleModel simpleModel = new SimpleModel(factory, dloaded.modelName);
                    simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Green), TextureType.DIFFUSE);
                    SphereObject tmesh = new SphereObject(dloaded.position, 1, 10, dloaded.scale.X, MaterialDescription.DefaultBepuMaterial());                    
                    tmesh.Rotation = dloaded.orientation;
                    tmesh.Velocity = dloaded.LinearVelocity;
                    tmesh.AngularVelocity = dloaded.AngularVelocity;
                    ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default());
                    ForwardMaterial fmaterial = new ForwardMaterial(shader);
                    obj = new IObject(fmaterial, simpleModel, tmesh);
                    this.World.AddObject(obj);
                    saved++;
                }
                ));


            
            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));

        }
 /// <summary>
 /// Create a simple Sphere object
 /// </summary>
 /// <param name="pos"></param>
 /// <param name="ori"></param>
 /// <returns></returns>
 private IObject SpawnPrimitive(Vector3 pos, Matrix ori)
 {
     ///Load a Model with a custom texture
     SimpleModel sm2 = new SimpleModel(factory,"Model\\ball");
     sm2.SetTexture(factory.CreateTexture2DColor(1,1,Color.White,false), TextureType.DIFFUSE);
     ForwardXNABasicShader nd = new ForwardXNABasicShader();                        
     IMaterial m = new ForwardMaterial(nd);
     SphereObject  pi2 = new SphereObject(pos, 1,0.5f,1,MaterialDescription.DefaultBepuMaterial());
     IObject o = new IObject(m,sm2,pi2);            
     return o;
 }
        protected override void LoadContent(PloobsEngine.Engine.GraphicInfo GraphicInfo, PloobsEngine.Engine.GraphicFactory factory, IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);

            {
                SimpleModel sm = new SimpleModel(factory, "..\\Content\\Model\\ball");
                sm.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Blue), TextureType.DIFFUSE);
                IPhysicObject pi = new SphereObject(new Vector3(0, 0, 0), 1, 10, 30, MaterialDescription.DefaultBepuMaterial());
                pi.isMotionLess = true;
                ForwardXNABasicShader shader = new ForwardXNABasicShader();
                IMaterial mat = new ForwardMaterial(shader);
                IObject obj3 = new IObject(mat, sm, pi);
                this.World.AddObject(obj3);
                shader.BasicEffect.EnableDefaultLighting();

                BepuPhysicWorld physicWorld;
                physicWorld = this.World.PhysicWorld as BepuPhysicWorld;
                System.Diagnostics.Debug.Assert(physicWorld != null);
                var field = new GravitationalFieldObject(new InfiniteForceFieldShape(), obj3.PhysicObject.Position, 66730 / 2f, 10000, physicWorld);
                ///This Method is from BepuPhysicWorld not from th IPhysicObject
                ///You can use everithing from Bepu using this object instead of the interface
                ///but take care, the engine dont know about THIS !!! it does not manage these things
                physicWorld.Space.Add(field);

            }

            int numColumns = 7;
            int numRows = 7;
            int numHigh = 7;
            float separation = 3;
            {
                ///reuse instances that does not change
                SimpleModel sm = new SimpleModel(factory, "..\\Content\\Model\\cubo");
                sm.SetTexture(factory.CreateTexture2DColor(1, 1, Color.White), TextureType.DIFFUSE);
                ForwardXNABasicShader shader = new ForwardXNABasicShader();
                IMaterial mat = new ForwardMaterial(shader);

                for (int i = 0; i < numRows; i++)
                {
                    for (int j = 0; j < numColumns; j++)
                    {
                        for (int k = 0; k < numHigh; k++)
                        {
                            BoxObject pi = new BoxObject(new Vector3(separation * i - numRows * separation / 2, 40 + k * separation, separation * j - numColumns * separation / 2), 1, 1, 1, 5, new Vector3(1), Matrix.Identity, MaterialDescription.DefaultBepuMaterial());
                            pi.Entity.LinearDamping = 0;
                            pi.Entity.AngularDamping = 0;                            
                            IObject obj3 = new IObject(mat, sm, pi);
                            this.World.AddObject(obj3);
                            pi.Entity.LinearVelocity = new Vector3(30, 0, 0);                            
                        }
                    }
                }

                shader.BasicEffect.EnableDefaultLighting();
            }

            //cam = new CameraFirstPerson(GraphicInfo);
            //cam.FarPlane = 3000;

            #region NormalLight
            DirectionalLightPE ld1 = new DirectionalLightPE(Vector3.Left, Color.White);
            DirectionalLightPE ld2 = new DirectionalLightPE(Vector3.Right, Color.White);
            DirectionalLightPE ld3 = new DirectionalLightPE(Vector3.Backward, Color.White);
            DirectionalLightPE ld4 = new DirectionalLightPE(Vector3.Forward, Color.White);
            DirectionalLightPE ld5 = new DirectionalLightPE(Vector3.Down, Color.White);
            float li = 0.4f;
            ld1.LightIntensity = li;
            ld2.LightIntensity = li;
            ld3.LightIntensity = li;
            ld4.LightIntensity = li;
            ld5.LightIntensity = li;
            this.World.AddLight(ld1);
            this.World.AddLight(ld2);
            this.World.AddLight(ld3);
            this.World.AddLight(ld4);
            this.World.AddLight(ld5);
            #endregion

            RotatingCamera cam = new RotatingCamera(this,new Vector3(0,0,-300));
            this.World.CameraManager.AddCamera(cam);

        }
        private void CreateBall(Vector3 pos)
        {
            ///Create a Simple Model
            SimpleModel model = new SimpleModel(GraphicFactory,"..\\Content\\Model\\ball");
            model.SetTexture(GraphicFactory.CreateTexture2DColor(1, 1, StaticRandom.RandomColor()), TextureType.DIFFUSE);            

            ///Create a Physic Object
            IPhysicObject pobj = new SphereObject(pos,1, 10,1,MaterialDescription.DefaultBepuMaterial());
            pobj.isMotionLess = true;
            ///Create a shader   
            IShader nd = new DeferredNormalShader();
            
            ///Create a Material                
            IMaterial material = new DeferredMaterial(nd);
            ///Create a an Object that englobs everything and add it to the world
            IObject obj = new IObject(material, model, pobj);
            this.World.AddObject(obj);
            objects.Add(obj);
        }
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);

            {
                {
                    ///Create the xml file model extractor
                    ///Loads a XML file that was export by our 3DS MAX plugin
                    ExtractXmlModelLoader ext = new ExtractXmlModelLoader("Content//ModelInfos//", "Model//", "Textures//");
                    this.AttachCleanUpAble(ext);
                    ///Extract all the XML info (Model,Cameras, ...)
                    ModelLoaderData data = ext.Load(factory, GraphicInfo, "ilha");
                    ///Create the WOrld Loader
                    ///Convert the ModelLoaderData in World Entities
                    WorldLoader wl = new WorldLoader(); ///all default                
                    wl.LoadWorld(factory, GraphicInfo, World, data);
                }
            }

            {
                SimpleModel sm2 = new SimpleModel(factory, "Model\\ball");
                sm2.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Red, false), TextureType.DIFFUSE);
                DeferredNormalShader nd = new DeferredNormalShader();
                IMaterial m = new DeferredMaterial(nd);
                SphereObject pi2 = new SphereObject(new Vector3(100,50,0), 1, 10, 10, MaterialDescription.DefaultBepuMaterial());
                IObject o = new IObject(m, sm2, pi2);
                this.World.AddObject(o);

                sound2 = new ObjectFollower3DSound(factory, "Songs/pianosong", o);                
                this.World.AddSoundEmitter(sound2,true);                
            }

            lt = new LightThrowBepu(this.World, factory);

            #region NormalLight
            DirectionalLightPE ld1 = new DirectionalLightPE(Vector3.Left, Color.White);
            DirectionalLightPE ld2 = new DirectionalLightPE(Vector3.Right, Color.White);
            DirectionalLightPE ld3 = new DirectionalLightPE(Vector3.Backward, Color.White);
            DirectionalLightPE ld4 = new DirectionalLightPE(Vector3.Forward, Color.White);
            DirectionalLightPE ld5 = new DirectionalLightPE(Vector3.Down, Color.White);
            float li = 0.5f;
            ld1.LightIntensity = li;
            ld2.LightIntensity = li;
            ld3.LightIntensity = li;
            ld4.LightIntensity = li;
            ld5.LightIntensity = li;
            this.World.AddLight(ld1);
            this.World.AddLight(ld2);
            this.World.AddLight(ld3);
            this.World.AddLight(ld4);
            this.World.AddLight(ld5);
            #endregion


            CameraFirstPerson cam = new CameraFirstPerson(MathHelper.ToRadians(30), MathHelper.ToRadians(-10), new Vector3(200, 150, 250), GraphicInfo);
            this.World.CameraManager.AddCamera(cam);

            SkyBoxSetTextureCube stc = new SkyBoxSetTextureCube("Textures//grassCube");
            CommandProcessor.getCommandProcessor().SendCommandAssyncronous(stc);

        }
        protected IObject CreateSphereMeshModelU(String fileName, Vector3 position, Matrix orientation, float raio, float scale = 1, float mass = 10)
        {
            CreateInternalModel(fileName);
            SimpleModel simpleModel = new SimpleModel(graphicFactory, "Loaded/" + modelLoaded[fileName]);

            ///Physic info (position, rotation and scale are set here)
            SphereObject tmesh = new SphereObject(position, raio, mass, scale, MaterialDescription.DefaultBepuMaterial());
            ///Shader info (must be a deferred type)
            DeferredNormalShader shader = new DeferredNormalShader();
            ///Material info (must be a deferred type also)
            DeferredMaterial fmaterial = new DeferredMaterial(shader);
            ///The object itself
            return new IObject(fmaterial, simpleModel, tmesh);
        }
 private IObject CreateSphere(Vector3 pos, Matrix ori, Color Color)
 {
     ///Load a Model with a custom texture
     SimpleModel sm2 = new SimpleModel(GraphicFactory, "Model\\ball");
     sm2.SetTexture(GraphicFactory.CreateTexture2DColor(1, 1, Color, false), TextureType.DIFFUSE);
     DeferredNormalShader nd = new DeferredNormalShader();
     IMaterial m = new DeferredMaterial(nd);
     SphereObject pi2 = new SphereObject(pos, 1, 0.05f, 10, MaterialDescription.DefaultBepuMaterial());
     IObject o = new IObject(m, sm2, pi2);
     return o;
 }
        public static IObject[] CreateOBJ(IWorld world, GraphicFactory factory, GraphicInfo ginfo, ObjectInformation[] mi)
        {            

            IModelo model = new CustomModel(factory, mi);            

            MaterialDescription material;
            if (mi[0].staticfriction == -1 || mi[0].dinamicfriction == -1 || mi[0].ellasticity == -1)
            {
                material = MaterialDescription.DefaultBepuMaterial();
            }
            else
            {
                material = new MaterialDescription(mi[0].staticfriction, mi[0].dinamicfriction, mi[0].ellasticity);
            }

            IPhysicObject po;

            bool massflag = false;
            if (mi[0].mass == 0)
            {
                massflag = true;
                mi[0].mass = 0.5f;
            }

            BatchInformation binf = model.GetBatchInformation(0)[0];            

            BoundingBox bb;

            switch (mi[0].collisionType)
            {

                case "Ghost":

                   
                    po = new GhostObject(mi[0].position,Matrix.CreateFromQuaternion(mi[0].rotation), mi[0].scale);

                    break;
                case "Cylinder":

                    binf.ModelLocalTransformation = Matrix.Identity;
                    bb = ModelBuilderHelper.CreateBoundingBoxFromModel(binf);
                    Vector3 len = bb.Max - bb.Min;

                    po = new CylinderObject(mi[0].position, len.Y, len.X / 2,Vector3.Up ,mi[0].mass, Matrix.CreateFromQuaternion(mi[0].rotation), material);
                    
                    break;


                case "Sphere":
                    binf.ModelLocalTransformation = Matrix.Identity;
                    po = new SphereObject(mi[0].position, model.GetModelRadius(), mi[0].mass, mi[0].scale.X, material);
                    po.Rotation = Matrix.CreateFromQuaternion(mi[0].rotation);

                    break;


                case "Box":

                    bb = ModelBuilderHelper.CreateBoundingBoxFromModel(binf);

                    len = bb.Max - bb.Min;

                    po = new BoxObject(mi[0].position, len.X, len.Y, len.Z, mi[0].mass, mi[0].scale, Matrix.CreateFromQuaternion(mi[0].rotation), material);

                    break;

                case "Water":
                    po = new GhostObject(mi[0].position, Matrix.CreateFromQuaternion(mi[0].rotation), mi[0].scale);
                    break;
                case "TriangleMesh":
                default:
                    po = new TriangleMeshObject(model, Vector3.Zero, Matrix.Identity, new Vector3(1), material);
                    break;
            }

            po.isMotionLess = massflag;

            IShader shader = null;
#if !REACH && !WINDOWS_PHONE
            
            if (mi[0].HasTexture(TextureType.ENVIRONMENT))
            {
                shader = new DeferredEMReflectiveShader();
                (shader as DeferredEMReflectiveShader).TextureCube = mi[0].textureInformation.getCubeTexture(TextureType.ENVIRONMENT);
                
            }
            else if (mi[0].collisionType != null && mi[0].collisionType.Contains("Water"))
            {
                Vector3 position = (Vector3)(mi[0].extra["position"]);
                var width = (mi[0].extra["width"]);
                var height = (mi[0].extra["length"]);
                shader = new DeferredWaterCompleteShader((int)width,(int)height, new Plane(position.X, position.Y, position.Z, 1),10.0f);
            }
            
            else
            {
                shader = new DeferredCustomShader(mi[0].HasTexture(TextureType.GLOW), mi[0].HasTexture(TextureType.BUMP), mi[0].HasTexture(TextureType.SPECULAR), mi[0].HasTexture(TextureType.PARALAX)); 
            }
          
            DeferredMaterial dm = new DeferredMaterial(shader);
#else
            shader = new ForwardXNABasicShader();
            ForwardMaterial dm = new ForwardMaterial(shader);

#endif
            IObject ob = new IObject(dm, model, po);

            ob.Name = mi[0].modelName;

            return new IObject[] { ob };
        }