Rss

A Basic Scene

Basic Square

Creating the Panel class, with a default resolution of 640, 480, and a caption.

using System;
using IRL.Core;               //The Icarus Rendering Layer (For OpenGL/DirectX/OpenGLES selection, or direct OpenGL access)
using ISE.Core;               //For coordinate systems,maths libs, colors
using ISE.Scenes;             //for panels, scenes, animation
using ISE.Scenes.Geometry;    //for some default 3D geometric shapes.
using ISE.Assets;             //for materials, textures, external models.

namespace Test.ISE
{
    /// <summary>
    /// This panel shows how to add some basic objects into a scene.
    /// </summary>
    public class MyPanel : Panel
    {
        public MyPanel() : base("Icarus Scene Engine 3.0 Panel: Basic Rendering", 640, 480) { }

Now we create some default geometry.

All standard 3D shapes included in Icarus are specified using a width, height and depth.

Spheres, Cylinders, Funnels, Boxes, Torus’, Cones, Capsules etc.. The shapes stretch to fit the bounds as specified. Some shapes may require additional parameters to control additional features, like the capsule’s radial percentage, or the funnel, which has two widths and heights, to specify the size of the starting hole and ending hole in the funnel.

Additional parameters indicate wireframe or solid rendering, coordinates for the shape, and may also include shape specific quality settings

        //                                           Width
        //                                             | Height
        //                                             |  |  Depth                                                  
        //                                             |  |  |                Coordinates
        Shape.Box   myBox            = new Shape.Box  (1, 1, 1,          new Vector(1, 0, 0));

        // Create the camera, specifying the Lens to use and the position
        // At least one camera MUST be present on a Panel (or underneath) to properly set the display, otherwise nothing will render.
        Camera myCamera = new Camera(new PerspectiveLens(45),  // 45 Degree Lens, 
                                                                         // default aspect ratio (aspect ratio of 0 means it's dynamic and follows the Window size), 
                                                                         // default Depth range of 1..64

                                                                         // Camera's Position:
                                                                        new Trajectory(new Vector(5, 5, 5),     // Camera's Eye        (where is it positioned)
                                                                                       new Vector(0, 0, 0),     // Camera's target     (where is it looking at)
                                                                                       new Vector(0, 1, 0)));   // Camera's Up Vector  (which way round is it)

Now that some objects are created, we set up the hierarchy of the objects

        public override void Initialise()
        {
            // Set the background color
            BackgroundColor = DefaultColors.blue;

            // Add the Camera to the Panel
            Add(myCamera);

            // Create an untextured flat colored material and assign it to the box.
            myBox.Material = new ColoredMaterial(DefaultColors.red);

            // Add the shapes to the Camera
            myCamera.Add(myBox);

        }        
    }

For the sake of inclusivity, we will also include the main initialisation routine for the panel

        
        ///
        /// The main entry point for the application. 
        ///
        static void Main(params string[] args) 
        {
           // Specify OpenGL2.0 as the Icarus Rendering Layer to use. 
           IR.Engine = new IRL.Core.GL20.RenderEngineGL20(); 

           // Create an OS-specific window 
           window = IR.Engine.NewWindow(640, 480, 1); 
           // The third number, 1, is the SCALE, i.e. for Retina displays, where the resolution is the same for Retina vs non-retina, but the scale is doubled. 

           // Create the Panel 
           AbstractPanel thispanel = new MyPanel(window.Width, window.Height); 

           // IMPORTANT! Assign the panel to the Window, or the window will render nothing. 
           window.Panel = thispanel; 

           window.Show(); // This command is MODAL, and will only return after the window is closed. 

           thispanel.Dispose(); 
           IR.Engine.Close(); 
        }
}

Loading Audio

Supported Formats

For iOS and Android, only WAV and OGG formats are supported.

For PC (Windows, Linux, MacOSX), with the FFMpeg extensions, all audio formats supported by FFMpeg can be loaded.

Loading

Use the following to load an audio file:

Audio mymusic = Audio.Load("myaudiofile.ogg");

This loads in the audio file as a single contiguous stream.

To load a file in pieces, specify an additional parameter, the chunk size:

Audio mymusic = Audio.Load("myaudiofile.ogg",64000);

This will load the audio into the audio playback buffers in chunks of up to 64000 in size. This is useful for longer files, files downloaded from the internet, or ogg files where the decoding takes a relatively long time.

Audio is always loaded in a background thread.

To load audio from the internet, do:

Audio mymusic = Audio.Load("http://www.mywebsite.com/myaudiofile.ogg",64000);

To load audio from an embedded resource, do:

Audio mymusic = Audio.Load("embed://myaudiofile.ogg",64000);

Playback

To initiate playback, do:

mymusic.Play();

This will initiate the playback in a dedicated audio playback background thread, and will play once.

For more advanced functions, don’t just call the Play() method directly. the method returns a specific audio stream class for managing the sound:

AudioStream musicplayback = mymusic.Play();

This represents a specific playback of the file, and the stream class then allows manipulation of the various audio properties:

musicplayback.Pitch = 0.25f;
musicplayback.Gain = 0.5f;    // Volume (0..1)
musicplayback.Looping=true;
musicstream.State = AudioState.Paused;

Loading Geometry

Geometry asteroid = Geometry.Load("Models/Stone_Pack1_Stone_1/Stone_Pack1_Stone_1.obj");

This code loads the Geometry in, in the same thread. Textures will be loaded from the same folder.
To load the geometry dynamically, use:

Geometry asteroid = Geometry.DynamicLoad("Models/Stone_Pack1_Stone_1/Stone_Pack1_Stone_1.obj");

This creates the Geometry class for reference, but then schedules the geometry for background loading, and loads the geometry in a background thread. If the underlying OS does not support background loading (MacOSX or iOS for example)
the geometry is loaded immediately. You may use any of the above variations, embed:// or http:// for dynamic loading as well.

Geometry Textures

Textures are loaded from the same folder by default. To specify a different folder, use the second parameter in the Geometry.Load (or Geometry.DynamicLoad function) to specify an alternate folder to search for textures.

Geometry Scaling

Geometry is loaded as-is in terms of scale. To specify a different scale, use the third and fourth parameters in Geometry.Load to specify the type of scale, and the scalar values:

gmeteor = Geometry.Load(Asset.LocalAssetFolder + "Models/Stone_Pack1_Stone_1/Stone_Pack1_Stone_1.obj", Asset.TexturePath + "Models/",
								ScaleType.Multiplier, new Vector(0.25, 0.25, 0.25));

Geometry Transformations

More advanced than scaling by itself, a Geometry transformation applies a transformation matrix to all coordinates (normals are renormalized):

Matrix rotate = Matrix.Rotation(new Angles(0, -Maths.NINETY, 0), Winding.XYZ);
Matrix scale = Matrix.Scale(new Vector(0.00015f, 0.00015f, 0.00015f));

Matrix transformation = scale * rotate;

Geometry Battleship = Geometry.Load(“space_battleship_5_upgraded.3DS”,””,transformation);

This is a one-time transformation during loading, and is particularly useful with third-party models to reorient and rescale the models for the needs of a scene.

Instancing

Once loaded, call Geometry.Instance to create an instance of the Geometry:

Geometry asteroid1 = Geometry.Instance(asteroid, true);

The second parameter, KeepMaterials will reuse the existing materials from the original class if set to True, so only the Geometry is instanced. If False, copies of the same materials will be created and referenced for the instance, so both the materials and the geometry will be instanced.

 Format-Specific Notes

The file format to import is determined by the filename extension (not case sensitive).

OBJ

.mtl files will be used to load materials (if available). If the .mtl file is not available, texture files that match the material name will be loaded if found (with .ibc, then .jpg, then .png extension).

3DS

Textures will attempt to load using the default file extension and type. If the texture is not found, the model importer will look for the equivalent .ibc file in the same location.

 

Loading Assets

Each asset type, Textures, Geometry etc.. has it’s own static functions for loading assets, each with custom properties, but they all have the one property in common, AssetName.

AssetName is essentially, the filename of the asset to load, but the file can be embedded, a local file or a URL.

Below is an example of how to specify the different ways, using a Texture asset.

To load a texture from a local file:

Texture lensflare = Texture.Load(Mipmapping.Nearest, false,
                              "planets/sunflare.ibc");

To load a texture from a URL:

Texture lensflare = Texture.Load(Mipmapping.Nearest, false,
         "http://www.mywebsite.com.sg/planets/sunflare.ibc");

NOTE: The web server will need to be configured to allow downloading of the requisite file extensions, in this case, .ibc.

To load the texture from an embedded resource:

Texture lensflare = Texture.Load(Mipmapping.Nearest, false,
                                    "embed://sunflare.ibc");

NOTE: The web server will need to be configured to allow downloading of the requisite file extensions, in this case, .ibc.

Loading Textures

Creation

Texture lensflare = Texture.Load(Mipmapping.Nearest, false,
                                   "Planets/sunflare.ibc");

This code loads the texture in, in the same thread, with Nearest mipmapping, and not repeating (the “false” value).
To load the texture dynamically, use:

Texture lensflare = Texture.DynamicLoad(Mipmapping.Nearest, false,
                                  "Planets/sunflare.ibc", true);

This creates the Texture class for reference, but then schedules the texture for background loading, and loads the texture in a background thread. If the underlying OS does not support background loading (MacOSX or iOS for example)
the texture is loaded immediately. You may use any of the above variations, embed:// or http:// for dynamic loading as well.

Disposal

To dispose of the texture, either add it to the Scene that it is valid for, and the Texture will be disposed automatically on scene exit, or call the texture.Dispose() method. All currently loaded Textures are automatically disposed on applicaiton exit, but you may wish to dispose of them earlier to save memory.