Example #1
0
        /// <summary>
        /// This event will be fired immediately after the Direct3D device has been
        /// created, which will happen during application initialization and windowed/full screen
        /// toggles. This is the best location to create Pool.Managed resources since these
        /// resources need to be reloaded whenever the device is destroyed. Resources created
        /// here should be released in the Disposing event.
        /// </summary>
        private void OnCreateDevice(object sender, DeviceEventArgs e)
        {
            // Initialize the stats font
            //statsFont = ResourceCache.GetGlobalInstance().CreateFont(e.Device, 15, 0, FontWeight.Bold, 1, false, CharacterSet.Default,
            //    Precision.Default, FontQuality.Default, PitchAndFamily.FamilyDoNotCare | PitchAndFamily.DefaultPitch
            //    , "Arial");
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

            SoundManager.Initialize(Framework.Instance.Window);
            inputManager = new Bonsai.Input.InputManager(Framework.Instance.Window);

            transparentObjectManager = new TransparentObjectManager();
            weather = new Weather(this);

            //modelControl = new ModelControl("Data/cessna/cessna.par");
            modelControl = new ModelControl();

            rotationAxisMesh = new LineMesh();

            sky = new GameObject();
            DomeMesh skyDome = new DomeMesh(5000, 10, 16);

            skyDome.Texture = new Bonsai.Objects.Textures.TextureBase("data\\sky2.JPG");
            sky.Position    = new Vector3(0, -5f, 0);
            sky.Mesh        = skyDome;

            scenery = new GameObject();
            SquareMesh sceneryMesh = new SquareMesh(5000, 10, 10, 1000f);

            sceneryMesh.Texture  = new Bonsai.Objects.Textures.TextureBase("data\\scenery\\default\\grass1.jpg");
            scenery.Mesh         = sceneryMesh;
            scenery.Position     = new Vector3(0, -5f, 0);
            scenery.RotateXAngle = (float)Math.PI / 2;

            cameraEditor      = new CameraBase("ObserverCamera");
            cameraEditor.Near = 0.05f;

            cameraPilot          = new ObserverCamera("PilotCamera", modelControl.AirplaneModel);
            cameraPilot.LookFrom = new Vector3(5f, -3.3f, 5f);

            //camera.LookAt = modelControl.AirplaneModel.Position;
            //camera.LookFrom = modelControl.AirplaneModel.Position + new Vector3(cameraDistance, 0f, 0f);
            //camera.AutoZoom = true;
            cameraEditor.AspectRatio = (float)(e.BackBufferDescription.Width) / e.BackBufferDescription.Height;
            cameraPilot.AspectRatio  = (float)(e.BackBufferDescription.Width) / e.BackBufferDescription.Height;


            Framework.Instance.CurrentCamera = cameraEditor;

            sun       = new DirectionalLight(new Vector3(-0.5f, -0.707f, 0.5f));
            sun.Color = System.Drawing.Color.FromArgb(148, 148, 148);

            collisionPoints = new CollisionPoints();

            cursor3d  = new Cursor3d();
            cursor3d2 = new Cursor3d();
        }
Example #2
0
 public void SetSkyTexture(string fileName)
 {
     if ((sky != null) && (sky.Mesh != null) && (fileName != null))
     {
         DomeMesh skyDome = sky.Mesh as DomeMesh;
         if (skyDome != null)
         {
             if (skyDome.Texture != null)
             {
                 skyDome.Texture.Dispose();
             }
             string path = Path.GetDirectoryName(parameters.FileName);
             skyDome.Texture = new Bonsai.Objects.Textures.TextureBase(string.Concat(path, "\\", fileName));
             SkyTexture      = fileName;
         }
     }
 }
Example #3
0
        private void Initialize()
        {
            if (parameters.SceneryType == SceneryParameters.SceneryTypeEnum.Photofield)
            {
                if (parameters.HeightMapFile != null)
                {
                    heightMap = new Heightmap(parameters.SceneryFolder + parameters.HeightMapFile,
                                              (float)parameters.HeightMapSize, parameters.HeightMapResolution, parameters.HeightMapResolution);
                    heightMap.MinHeight = parameters.MinimumHeight;
                    heightMap.MaxHeight = parameters.MaximumHeight;
                }
                else
                {
                    heightMap = new Heightmap(1000);
                }
                photoScenery = new PhotoScenery(parameters);
                // Set lighting conditions
                if (definition != null)
                {
                    if (definition.SkyTable.Rows.Count > 0)
                    {
                        DataRow dataRow       = definition.SkyTable.Rows[0];
                        Vector3 ambientVector = (Vector3)dataRow["AmbientLight"];
                        Vector3 sunVector     = (Vector3)dataRow["SunLight"];
                        SetSky(null, (Vector3)dataRow["SunPosition"],
                               Color.FromArgb((int)(255 * ambientVector.X), (int)(255 * ambientVector.Y), (int)(255 * ambientVector.Z)),
                               Color.FromArgb((int)(255 * sunVector.X), (int)(255 * sunVector.Y), (int)(255 * sunVector.Z)),
                               (float)(dataRow["TerrainAmbient"]), (float)(dataRow["TerrainSun"]));
                        lensFlare = new LensFlare();
                    }
                }
            }
            else
            {
                vegetation = new Vegetation(owner);

                ground              = new GameObject();
                heightMap           = new Heightmap(parameters.SceneryFolder + parameters.HeightMapFile, 1000f, 100, 100);
                heightMap.MinHeight = parameters.MinimumHeight;
                heightMap.MaxHeight = parameters.MaximumHeight;
                TerrainMesh sceneryMesh = new TerrainMesh(1.0f, heightMap);
                ground.Mesh = sceneryMesh;

                // Load the detail settings
                currentDetail        = Bonsai.Utils.Settings.GetValue("SceneryDetail", "2");
                dynamicSceneryDetail = Convert.ToInt32(Bonsai.Utils.Settings.GetValue("DynamicScenery", "1"));

                if (currentDetail.Equals("1"))
                {
                    sceneryMesh.Texture = new Bonsai.Objects.Textures.TextureBase(parameters.SplatLowFile);
                }
                else
                {
                    //ground.RotateXAngle = (float)Math.PI / 2;

                    //splatShader = new ShaderBase("splatting", "splatting3.fx");
                    //if (Framework.Instance.DeviceCaps.PixelShaderVersion.Major >= 3)
                    //    splatShader.SetTechnique("TextureSplatting_fx30");
                    //else
                    //    splatShader.SetTechnique("TextureSplatting");

                    splatShader = new ShaderBase("splatting", "splat.fx");
                    splatShader.SetTechnique("TextureSplatting");
                    splatShader.SetVariable("matViewProj", ShaderBase.ShaderParameters.CameraProjection);
                    splatShader.SetVariable("sunPosition", new Vector3(1, 1, 1));
                    splatShader.SetVariable("underwater", 0.0f);
                    splatShader.SetVariable("matWorld", ShaderBase.ShaderParameters.World);
                    splatShader.SetVariable("matInvertTransposeWorld", ShaderBase.ShaderParameters.WorldInvertTranspose);
                    splatShader.SetVariable("cameraPos", ShaderBase.ShaderParameters.CameraPosition);
                    splatShader.SetVariable("nearRepeat", 64.0f);
                    splatShader.SetVariable("farRepeat", 16.0f);
                    splatShader.SetVariable("nearFactor2", 1.0f);
                    splatShader.SetVariable("farFactor2", 1.0f);
                    splatShader.SetVariable("nearFactor3", 1.0f);
                    splatShader.SetVariable("farFactor3", 1.0f);
                    splatShader.SetVariable("nearFactor4", 5.0f);
                    splatShader.SetVariable("farFactor4", 5.0f);
                    splatShader.SetVariable("blendSqDistance", 50f * 50f);
                    splatShader.SetVariable("blendSqWidth", 1.0f / (200f * 200f));
                    TextureBase normalMap = new TextureBase(parameters.NormalMapFile);
                    TextureBase alphaMap  = new TextureBase(parameters.SplatHighFile);
                    //TextureBase grassTexture = new TextureBase("data/grass_zoomout.png");
                    TextureBase grassTexture = new TextureBase(parameters.Texture1File);
                    TextureBase rockTexture  = new TextureBase(parameters.Texture2File);
                    //TextureBase rockNormal = new TextureBase("data/splat_rock_normal.jpg");
                    TextureBase sandTexture     = new TextureBase(parameters.Texture3File);
                    TextureBase concreteTexture = new TextureBase(parameters.Texture4File);

                    splatShader.SetVariable("NormalMapTexture", normalMap);
                    splatShader.SetVariable("AlphaTexture", alphaMap);
                    splatShader.SetVariable("DetailTexture1", grassTexture);
                    splatShader.SetVariable("DetailTexture2", rockTexture);
                    //splatShader.SetVariable("DetailTexture2NormalMap", rockNormal);
                    splatShader.SetVariable("DetailTexture3", sandTexture);
                    splatShader.SetVariable("DetailTexture4", concreteTexture);

                    ground.Shader = splatShader;
                }

                CreateSurroundings();

                // Load the trees
                vegetation.LoadTrees(heightMap, definition);

                // Load the simple trees
                LoadSimpleTrees(definition);

                // Load the simple tall trees
                LoadSimpleTallTrees(definition);

                // Load the simple small trees
                LoadSimpleSmallTrees(definition);

                // Load the scenery objects
                LoadSceneryObjects(definition);

                // Load the windmills
                LoadWindmills(definition);

                // Load the weather
                LoadWeather(definition);

                // Load the dynamic scenery
                if (dynamicSceneryDetail > 0)
                {
                    LoadDynamicScenery(definition);
                }

                // Load the sky
                sky = new GameObject();
                DomeMesh skyDome = new DomeMesh(4500, 16, 16);
                sky.Mesh = skyDome;
                DataRow dataRow = definition.SkyTable.Rows[0];
                foreach (DataRow skyRow in definition.SkyTable.Rows)
                {
                    string skyName = skyRow["Name"].ToString();
                    if (skyName.Equals(Bonsai.Utils.Settings.GetValue("Sky")))
                    {
                        dataRow = skyRow;
                        break;
                    }
                }

                // Load the water
                LoadWater(definition);
                //water = new Water(new Vector3(90, 0, 180), 100f, Bonsai.Objects.Terrain.Water.QualityLevelEnum.Low);

                if (dataRow != null)
                {
                    Vector3 ambientVector = (Vector3)dataRow["AmbientLight"];
                    Vector3 sunVector     = (Vector3)dataRow["SunLight"];
                    SetSky(dataRow["Texture"].ToString(), (Vector3)dataRow["SunPosition"],
                           Color.FromArgb((int)(255 * ambientVector.X), (int)(255 * ambientVector.Y), (int)(255 * ambientVector.Z)),
                           Color.FromArgb((int)(255 * sunVector.X), (int)(255 * sunVector.Y), (int)(255 * sunVector.Z)),
                           (float)(dataRow["TerrainAmbient"]), (float)(dataRow["TerrainSun"]));
                }

                // Apply the ads
                if (Utility.MediaExists("ads/ad1.jpg"))
                {
                    ApplyAds("ad.jpg", "ads/ad1.jpg");
                }
                if (Utility.MediaExists("ads/ad2.jpg"))
                {
                    ApplyAds("ad2.jpg", "ads/ad2.jpg");
                }

                lensFlare = new LensFlare();
            }

#if EDITOR
            // Load the racing pylons
            LoadGates(definition);
#else
            if (Program.Instance.Player != null)
            {
                Program.Instance.Player.Heightmap            = heightMap;
                Program.Instance.Player.DefaultStartPosition = parameters.DefaultStartPosition;
                Program.Instance.Player.WaterStartPosition   = parameters.WaterStartPosition;
            }

            SetWaterCallback(Program.Instance.OnFrameRenderWater);
            // Rerender the reflection
            if (Effects.Reflection.Instance != null)
            {
                Effects.Reflection.Instance.Invalidate();
            }
#endif
        }