protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);

            #region Models
            {
                SimpleModel simpleModel = new SimpleModel(factory, "..\\Content\\Model\\teapot");
                simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Red), TextureType.DIFFUSE);
                //TriangleMeshObject tmesh = new TriangleMeshObject(simpleModel, Vector3.Zero, Matrix.Identity, Vector3.One, MaterialDescription.DefaultBepuMaterial());

                GhostObject tmesh = new GhostObject(Vector3.Zero, Matrix.Identity, Vector3.One);
                ///Environment Map Shader, there are 2 options, the first is a fully reflective surface (dont use the object texture) and the second
                ///is a mix of the object texture and the environment texture
                ///Used to fake ambient reflection, give metal appearence to an object ....
                DeferredEMReflectiveShader shader    = new DeferredEMReflectiveShader("Textures\\grassCUBE", 0.9f);
                DeferredMaterial           fmaterial = new DeferredMaterial(shader);
                tea = new IObject(fmaterial, simpleModel, tmesh);

                tea.OnUpdate += new OnUpdate(tea_OnUpdate);
                this.World.AddObject(tea);
            }

            //{
            //    SimpleModel simpleModel = new SimpleModel(factory, "Model//block");
            //    simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.White), TextureType.DIFFUSE);
            //    BoxObject tmesh = new BoxObject(new Vector3(0,-20,0), 1, 1, 1, 10, new Vector3(200, 1, 200), Matrix.Identity, MaterialDescription.DefaultBepuMaterial());
            //    tmesh.isMotionLess = true;
            //    DeferredNormalShader shader = new DeferredNormalShader();
            //    DeferredMaterial fmaterial = new DeferredMaterial(shader);
            //    IObject obj = new IObject(fmaterial, simpleModel, tmesh);
            //    this.World.AddObject(obj);
            //}


            #endregion

            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

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

            CameraFirstPerson cam = new CameraFirstPerson(MathHelper.ToRadians(30), MathHelper.ToRadians(-30), new Vector3(30, 30, 50), GraphicInfo);
            cam.FarPlane  = 500;
            cam.NearPlane = 1;
            this.World.CameraManager.AddCamera(cam);

            //AntiAliasingPostEffectTabula aa = new AntiAliasingPostEffectTabula();
            //aa.Weights = 2;
            //this.RenderTechnic.AddPostEffect(aa);
        }
Пример #2
0
        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 });
        }