Stratos: Punto de Encuentro de Desarrolladores

¡Bienvenido a Stratos!

Acceder

Foros





Skyboxes And A Input

Iniciado por , 30 de Enero de 2006, 07:22:15 AM

« anterior - próximo »

 Hi,

Great to see that you have finished a version of the 2.0 engine for all us that have been waiting impatiantly for it. And it works great too. I have already gotten the first tutorials working.

How do you create a skybox? Is it just creating a cube and taking it from there, or is there a special way to do it and ensure that it is rendered properly in the scene?

For my project I am trying to reuse a method I have used for other projects for doing the main loop (which actually for some odd reason gives me roughly a 25% increase in fps in tutorial 1), instead of using the one you provide in your empty project. So I am setting the form myself like this:

           Haddd.Form = renderForm;

This works fine with rendering except from one little issue. When I try to call Haddd.CreateInput() I get an exception saying that SetCooperativeLevel could not be called.

Is there anything I should set on the form in order to get it to work?

I reckon that I can control the camera without using DirectInput, but it would of course be better to be able to use the built in cameras instead of rolling my own.

 All right. I found the answer to my own question. (Thanks Reflector).

When you set the form yourself you need to do the following:

           Haddd.Form = renderForm;
           Haddd.Handle = renderForm.Handle;

Perhaps you should set the handle on the setter for the form variable so a situation like this can be avoided?

I still haven't figured out how to make the skybox though...

Haddd

 Uau, i see you are working with the tutorials...but the have not ben published yet... :(

Ok, ok, i seem today the tutorials projects well be published, as one new tutorial and some little bugs and add ons... ;)

About the skybox, maybe we can change some of the tutorials to provide an example... ;)

And finally, please, join your render loop with use, this will be better for Haddd, and for all of us. But i took the render loop proposed by Tom Miller.... ;)  

 Hmmm... The tutorials haven't been released? I could get the source code? But off course there was no explanation... I managed though.

I'd like a tutorial on doing the SkyBox. I found a SkyBox class, but I can't figure out how to get it into the scene....

About the render loop. I cannot remember where I got it from, some DirectX blog/list wherever. But it is working quite well and is easy to use. Everything runs in the OnLoad event handler. Here is an example where I have consolidated all the code from tutorial 1 into the handler... In my project I split it into classes for easier overview, but it will do for example.

Here is a step by step tutorial:
1) Create a new Windows Application project.
2) Add references to the HadddEngine, DirectX (1.0.2902), Direct3D (1.0.2902), DirectInput (1.0.2902)
3) Add the Configuration.xml file from the Haddd project. Set is properties to Build Action = None, Copy To Output = Copy if newer
4) Add a directory called PreShaders and add the shader0001.fx file. Set is properties to Build Action = None, Copy To Output = Copy if newer.
5) Create a OnLoad handler and put this code in - note the BaseDirectory and InHouse directory that must point to where the Haddd resources are. Haven't figured out how to do the same with the config and preshaders - therefore step 3 & 4.  :P

       private void Form1_Load(object sender, EventArgs e)
       {
           bool exitGame = false;
           this.Show();
           this.Focus();

           HadddEngine.Core.HPath.ChangeDirectory();
           HadddEngine.Core.HPath.BaseDirectory = @"..\..\..\..\base\";
           HadddEngine.Core.HPath.InHouseDirectory = @"..\..\..\..\InHouse\";

           HConfiguration.GetConfiguration();
           Haddd.Video.Adapter.Initialization.ReadFromConfig();
           Haddd.Form = this;
           Haddd.Handle = this.Handle;
           Haddd.Video.Adapter.CreateDevice(Haddd.Form);
           Haddd.AfterCreateDevice();
           Haddd.LoadCreateInHouse();
           Haddd.CreateInput();

           #region Create objects
           HMesh cubeMesh = HMesh.CreateCube24Vertices(3, 3, 3);
           HMeshObject cube = Haddd.Scene.MeshObjects.Create("room", false);
           cube.Mesh = cubeMesh;
           #endregion

           #region Material
           HMaterial[] material = new HMaterial[1];
           material[0] = new HMaterial();
           HMaterialLayer layer = new HMaterialLayer();
           material[0].AddLayer(layer);
           layer.DiffuseMap.Texture = Haddd.Video.Textures.Create2D("brick_d", true);
           cube.Material = material;
           #endregion

           #region Luz
           HOmniLight light = (HOmniLight)Haddd.Scene.Lights.Create("light", HLightType.Omni);
           light.Position = new Vector3(0, 0, -2f);
           light.Multiplier = 1f;
           light.AttenuationType = HLightAttenuationType.DualRadius;
           light.FarAttenuationStart = 1f;
           light.FarAttenuationEnd = 2f;
           light.Color = HColor.Yellow;
           light.AffectDiffuse = true;
           light.AffectSpecular = true;
           light.CastShadows = false;
           Haddd.Scene.Lights.Ambient = new HColor(0.4f, 0.4f, 0.4f);
           #endregion

           Haddd.Begin();
           do
           {
               Haddd.BeginUpdate();
               if (Haddd.Input.Keyboard.KeyTouch(Key.G))
                   Haddd.Scene.ShowGizmos = !Haddd.Scene.ShowGizmos;
               if (Haddd.Input.Keyboard.KeyTouch(Key.Escape))
                   exitGame = true;
               Haddd.EndUpdate();

               Haddd.Scene.Begin();
               Haddd.Scene.Render();
               Haddd.Scene.ProcessPostProduction();
               Haddd.Scene.RenderMiscellaneous();
               HFont font = Haddd.Video.Fonts[0];
               Haddd.Video.Fonts.Begin();
               font.RenderLine(Haddd.Version + ". Press ESC to exit", 0, HColor.Yellow);
               font.RenderLine(Haddd.Video.Render.Stats.Fps + " FPS", 0, HColor.White);
               Haddd.Video.Fonts.End();
               Haddd.Scene.End();

               DirectXException.IgnoreExceptions();
               Application.DoEvents();
               DirectXException.EnableExceptions();
           } while (!exitGame);
           Haddd.End();
           Application.Exit();
       }

6) Compile and run... Hopefully I haven't forgotten anything. :D
a

 Ugh. Sorry bout the formatting of the code.... Hope this is better.


       private void Form1_Load(object sender, EventArgs e)
       {
           bool exitGame = false;
           this.Show();
           this.Focus();

           HadddEngine.Core.HPath.ChangeDirectory();
           HadddEngine.Core.HPath.BaseDirectory = @"..\..\..\..\base\";
           HadddEngine.Core.HPath.InHouseDirectory = @"..\..\..\..\InHouse\";

           HConfiguration.GetConfiguration();
           Haddd.Video.Adapter.Initialization.ReadFromConfig();
           Haddd.Form = this;
           Haddd.Handle = this.Handle;
           Haddd.Video.Adapter.CreateDevice(Haddd.Form);
           Haddd.AfterCreateDevice();
           Haddd.LoadCreateInHouse();
           Haddd.CreateInput();

           #region Create objects
           HMesh cubeMesh = HMesh.CreateCube24Vertices(3, 3, 3);
           HMeshObject cube = Haddd.Scene.MeshObjects.Create("room", false);
           cube.Mesh = cubeMesh;
           #endregion

           #region Material
           HMaterial[] material = new HMaterial[1];
           material[0] = new HMaterial();
           HMaterialLayer layer = new HMaterialLayer();
           material[0].AddLayer(layer);
           layer.DiffuseMap.Texture = Haddd.Video.Textures.Create2D("brick_d", true);
           cube.Material = material;
           #endregion

           #region Luz
           HOmniLight light = (HOmniLight)Haddd.Scene.Lights.Create("light", HLightType.Omni);
           light.Position = new Vector3(0, 0, -2f);
           light.Multiplier = 1f;
           light.AttenuationType = HLightAttenuationType.DualRadius;
           light.FarAttenuationStart = 1f;
           light.FarAttenuationEnd = 2f;
           light.Color = HColor.Yellow;
           light.AffectDiffuse = true;
           light.AffectSpecular = true;
           light.CastShadows = false;
           Haddd.Scene.Lights.Ambient = new HColor(0.4f, 0.4f, 0.4f);
           #endregion

           Haddd.Begin();
           do
           {
               Haddd.BeginUpdate();
               if (Haddd.Input.Keyboard.KeyTouch(Key.G))
                   Haddd.Scene.ShowGizmos = !Haddd.Scene.ShowGizmos;
               if (Haddd.Input.Keyboard.KeyTouch(Key.Escape))
                   exitGame = true;
               Haddd.EndUpdate();

               Haddd.Scene.Begin();
               Haddd.Scene.Render();
               Haddd.Scene.ProcessPostProduction();
               Haddd.Scene.RenderMiscellaneous();
               HFont font = Haddd.Video.Fonts[0];
               Haddd.Video.Fonts.Begin();
               font.RenderLine(Haddd.Version + ". Press ESC to exit", 0, HColor.Yellow);
               font.RenderLine(Haddd.Video.Render.Stats.Fps + " FPS", 0, HColor.White);
               Haddd.Video.Fonts.End();
               Haddd.Scene.End();

               DirectXException.IgnoreExceptions();
               Application.DoEvents();
               DirectXException.EnableExceptions();
           } while (!exitGame);
           Haddd.End();
           Application.Exit();
       }


fehaar

 And I forgot this... (yes it is me, I managed to go through the spanish registration with some help from Babelfish).

7) Set the size of the form, I would have expected that to happen when loading the configuration, but it doesn't.

Haddd

 HadddEngine.Core.HPath.ChangeDirectory();

This is a method that looks form the configuration.xml file. You do not need to add it to the project. Yo do not need to set the dirs:

HadddEngine.Core.HPath.BaseDirectory = @"..\..\..\..\base\";
HadddEngine.Core.HPath.InHouseDirectory = @"..\..\..\..\InHouse\";


The engine, looks backwards until found a Configuration.xml file. So the location is very important. Yo must not include it on the project.


/// <summary>
/// Change de current dir until the configuration.xml file is found
/// This is to ensure that the current directory is always at the same
/// level that the file configuration.xml
/// </summary>
 public static void ChangeDirectory()
 {
  string currentDir = System.Windows.Forms.Application.StartupPath;

  // Si no existe este archivo es que estamos en una carpeta de debug o release
  while (!File.Exists("configuration.xml"))
  {
   // Vamos hacia atrás
   currentDir += @"\..";

   Directory.SetCurrentDirectory(currentDir);
  }

 }


fehaar

 Aha. So THAT is how it works. It makes things somewhat easier. Just remove steps 3 & 4 - if you make sure that your project is situated in a directory below the original Haddd directory. Then you can omit these two lines from the code:


HadddEngine.Core.HPath.BaseDirectory = @"..\..\..\..\base\";
HadddEngine.Core.HPath.InHouseDirectory = @"..\..\..\..\InHouse\";


I also made the following code to size the window using the config. Add the red lines in the code below. I included the code before and after so you can see where:


HConfiguration.GetConfiguration();
Haddd.Form = this;
Haddd.Handle = this.Handle;
[COLOR=red]this.Width = HConfiguration.Video.resolution.width;
this.Height = HConfiguration.Video.resolution.height;[/COLOR]
Haddd.Video.Adapter.Initialization.ReadFromConfig();
Haddd.Video.Adapter.CreateDevice(Haddd.Form);

Haddd

 Today i will upload the source code for the projects...Please, be patient.... ;)  

fehaar

 I am very patient... But you know. Boys with toys. :D


Haddd

 The skybox tutorial has been added, and published the projects.. :P  






Stratos es un servicio gratuito, cuyos costes se cubren en parte con la publicidad.
Por favor, desactiva el bloqueador de anuncios en esta web para ayudar a que siga adelante.
Muchísimas gracias.