示例#1
0
        /// <summary>
        ///  Initial setup of the Game Engine
        /// </summary>
        /// <param name="pd3dDevice"></param>
        public void Initialize(System.Windows.Forms.Form form, Microsoft.DirectX.Direct3D.Device pd3dDevice)
        {
            // capture a reference to the window handle
            m_WinForm = form;
            // For now just capture a reference to the DirectX device for future use
            m_pd3dDevice = pd3dDevice;

            m_GameInput = new GameInput(m_WinForm);

            m_Skybox = new SkyBox(@"..\..\Resources\Dunes_Front.tga",
                                  @"..\..\Resources\Dunes_Right.tga",
                                  @"..\..\Resources\Dunes_Back.tga",
                                  @"..\..\Resources\Dunes_Left.tga",
                                  @"..\..\Resources\Dunes_Top.tga",
                                  @"..\..\Resources\Dunes_Bottom.tga");
            m_Camera  = new Camera();
            m_Cameras = new ArrayList();
            m_Cameras.Add(m_Camera);

            m_Objects = new ArrayList();

            m_pd3dDevice.RenderState.Ambient = System.Drawing.Color.Gray;
            // Set light #0 to be a simple, faint grey directional light so
            // the walls and floor are slightly different shades of grey
            m_pd3dDevice.RenderState.Lighting = true;              // was true

            GameLights.InitializeLights();

            //			SetDefaultStates(  );
        }
示例#2
0
        public static GameLights AddPointLight(Vector3 position, Color color, string name)
        {
            GameLights light = new GameLights(name);

            light.m_Diffuse = color;
            light.Position  = position;
            light.m_Type    = LightType.Point;
            m_ActiveLights.Add(light);
            return(light);
        }
示例#3
0
        public static GameLights AddDirectionalLight(Vector3 direction, Color color, string name)
        {
            GameLights light = new GameLights(name);

            light.m_Diffuse   = color;
            light.m_Direction = direction;
            light.m_Type      = LightType.Directional;
            m_ActiveLights.Add(light);
            return(light);
        }
示例#4
0
        public static GameLights AddSpotLight(Vector3 position, Vector3 direction, Color color, string name)
        {
            GameLights light = new GameLights(name);

            light.m_Diffuse    = color;
            light.m_Direction  = direction;
            light.Position     = position;
            light.m_Type       = LightType.Spot;
            light.Attenuation0 = 0.0f;
            light.Attenuation1 = 1.0f;
            m_ActiveLights.Add(light);
            return(light);
        }
示例#5
0
        public static GameLights GetLight(string name)
        {
            GameLights light_found = null;

            foreach (GameLights light in m_ActiveLights)
            {
                if (light.Name == name)
                {
                    light_found = light;
                }
            }
            foreach (GameLights light in m_InactiveLights)
            {
                if (light.Name == name)
                {
                    light_found = light;
                }
            }
            return(light_found);
        }
示例#6
0
        /// <summary>
        ///  Display the latest game frame
        /// </summary>
        public void Render(  )
        {
            m_Camera.Render();

            m_QuadTree.Cull(m_Camera);

            GameLights.CheckCulling(m_Camera);

            // test code
            Model ownship = (Model)GetObject("car1");

            if (ownship != null && ownship.IsCulled)
            {
                Console.AddLine("ownship culled at " + ownship.North + " " + ownship.East + " H " + ownship.Heading);
            }

            GameLights.DeactivateLights();

            if (m_Skybox != null)
            {
                m_Skybox.Render(m_Camera);
            }

            GameLights.SetupLights();

            if (m_Terrain != null)
            {
                m_Terrain.Render(m_Camera);
            }

            BillBoard.RenderAll(m_Camera);

            foreach (Object3D obj in m_Objects)
            {
                if (!obj.IsCulled)
                {
                    obj.Render(m_Camera);
                }
            }
        }
示例#7
0
        public int CompareTo(object other)
        {
            GameLights other_light = (GameLights)other;

            return((int)(Range - other_light.Range));
        }
示例#8
0
        public void LoadOptions()
        {
            try
            {
                System.Random rand = new System.Random();
                // loading of options will happen here
                m_Engine.SetTerrain(200, 200, @"..\..\Resources\heightmap.jpg", @"..\..\Resources\sand1.jpg", 10.0f, 0.45f);

                for (int i = 0; i < 150; i++)
                {
                    float north = (float)(rand.NextDouble() * 1900.0);
                    float east  = (float)(rand.NextDouble() * 1900.0);
                    BillBoard.Add(east, north, 0.0f, "cactus" + i, @"..\..\Resources\cactus.dds", 1.0f, 1.0f);
                }
                for (int i = 0; i < 150; i++)
                {
                    float north = (float)(rand.NextDouble() * 1900.0);
                    float east  = (float)(rand.NextDouble() * 1900.0);
                    BillBoard.Add(east, north, 0.0f, "tree" + i, @"..\..\Resources\palmtree.dds", 6.5f, 10.0f);
                }
                GameEngine.Console.AddLine("all trees loaded");

                //			m_Engine.AddObject( new ParticleGenerator("Spray1", 2000, 2000, Color.Yellow, "Particle.bmp", new ParticleUpdate(Gravity)));

                double j        = 0.0;
                double center_x = 1000.0;
                double center_z = 1000.0;
                double radius   = 700.0;
                double width    = 20.0;

                m_flag         = new Cloth("flag", @"..\..\Resources\flag.jpg", 2, 2, 0.1, 1.0f);
                m_flag.Height  = 0.6f;
                m_flag.North   = 2.0f;
                m_flag.East    = 0.1f;
                Cloth.EastWind = -3.0f;

                for (double i = 0.0; i < 360.0; i += 1.5)
                {
                    float north = (float)(center_z + Math.Cos(i / 180.0 * Math.PI) * radius
                                          );
                    float east = (float)(center_x + Math.Sin(i / 180.0 * Math.PI) * radius
                                         );
                    BillBoard.Add(east, north, 0.0f, "redpost" + (int)(i * 2), @"..\..\Resources\redpost.dds", 0.25f, 1.0f);
                    j += 5.0;
                    if (j > 360.0)
                    {
                        j -= 360.0;
                    }
                }

                j = 0.0;
                for (double i = 0.5; i < 360.0; i += 1.5)
                {
                    float north = (float)(center_z + Math.Cos(i / 180.0 * Math.PI) * (radius + width)
                                          );
                    float east = (float)(center_x + Math.Sin(i / 180.0 * Math.PI) * (radius + width)
                                         );
                    BillBoard.Add(east, north, 0.0f, "bluepost" + (int)(i * 2), @"..\..\Resources\bluepost.dds", 0.25f, 1.0f);
                    j += 5.0;
                    if (j >= 360.0)
                    {
                        j -= 360.0;
                    }
                }

                m_ownship = new Ownship(this, "car1", @"..\..\Resources\SprintRacer.x", new Vector3(0.0f, 0.8f, 0.0f), new Attitude(0.0f, (float)Math.PI, 0.0f));
                m_ownship.AddChild(m_flag);

                SoundEffect.Volume = 0.25f;

                m_Engine.AddObject(m_ownship);

/*				Opponent opp1 = new Opponent("car2", @"..\..\Resources\SprintRacer.x", new Vector3(0.0f, 0.8f, 0.0f),
 *                                      new Attitude(0.0f, (float)Math.PI, 0.0f), "knowledge.xml");
 *                              opp1.SetLOD( 10, 3000.0f );
 *                              m_opponents.Add( opp1 );
 *                              m_Engine.AddObject( opp1 );
 */
                m_ownship.North = 298.0f;
                m_ownship.East  = 1000.0f;
                m_Engine.Cam.Attach(m_ownship, new Vector3(0.0f, 0.85f, -4.5f));
                m_Engine.Cam.LookAt(m_ownship);
                m_ownship.Heading = (float)Math.PI * 1.5f;
                m_ownship.SetLOD(10, 3000.0f);

                //			Car car2 = (Car)m_Engine.GetObject("car2");
                //			car2.North = 295.0f;
                //			car2.East  = 1000.0f;
                //			car2.Height = 0.0f;
                //			car2.Heading = (float)Math.PI * 1.5f;
                //			car2.SetLOD( 10, 300.0f );
                //			car2.SetUpdateMethod( new ObjectUpdate(OpponentUpdate));

                GameEngine.GameLights.Ambient = Color.White;

                //			GameEngine.GameLights light1 = GameEngine.GameLights.AddPointLight( new Vector3(130.0f,35.0f,130.0f),Color.White,"light1");
                //					light1.Attenuation1 = 0.11f;
                //			GameEngine.GameLights light2 = GameEngine.GameLights.AddPointLight( new Vector3(40.0f,25.0f,40.0f),Color.White,"light2");
                //					light2.Attenuation1 = 0.11f;
                //			GameEngine.GameLights light3 = GameEngine.GameLights.AddPointLight( new Vector3(130.0f,35.0f,230.0f),Color.White,"light3");
                //					light3.Attenuation1 = 0.11f;
                //			GameEngine.GameLights light4 = GameEngine.GameLights.AddPointLight( new Vector3(230.0f,40.0f,230.0f),Color.White,"light4");
                //					light4.Attenuation1 = 0.11f;
                //			GameEngine.GameLights light5 = GameEngine.GameLights.AddPointLight( new Vector3(70.0f,25.0f,70.0f),Color.White,"light5");
                //					light5.Attenuation1 = 0.11f;
                GameEngine.GameLights headlights = GameEngine.GameLights.AddSpotLight(new Vector3(0.0f, 0.0f, 0.0f),
                                                                                      new Vector3(1.0f, 0.0f, 1.0f), Color.White, "headlight");
                headlights.EffectiveRange  = 200.0f;
                headlights.Attenuation0    = 1.0f;
                headlights.Attenuation1    = 0.0f;
                headlights.InnerConeAngle  = 1.0f;
                headlights.OuterConeAngle  = 1.5f;
                headlights.PositionOffset  = new Vector3(0.0f, 2.0f, 1.0f);
                headlights.DirectionOffset = new Vector3(0.0f, 0.00f, 1.0f);
                m_ownship.AddChild(headlights);
                headlights.Enabled = false;

                CGameEngine.FogColor     = Color.Beige;
                CGameEngine.FogDensity   = 0.5f;
                CGameEngine.FogEnable    = true;
                CGameEngine.FogStart     = 100.0f;
                CGameEngine.FogEnd       = 900.0f;
                CGameEngine.FogTableMode = FogMode.Linear;
            }
            catch (Exception e)
            {
                GameEngine.Console.AddLine("Exception");
                GameEngine.Console.AddLine(e.Message);
            }
        }