MHydrax code example        

This code example shows how you can use the Managed Hydrax Wrapper under Mogre 1.7.

The code was written by user Jo0oker for his game engine Tehadon.

help For questions use this forum topic.

Overview

  • THydraxItem.cs
    ... TODO ...
  • ITHydraxItem.cs
    ... TODO ...
  • THydraxManager.cs
    ... TODO ...



TODO:

  • Add a short description for the classes
  • Attach code files as zip archive to wiki page




THydraxItem.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MHydrax;
using Mogre;

namespace Tehadon.Gfx.THydrax
{
    public class THydraxItem : ITHydraxItem
    {
        #region Private Members

        //Manager
        private THydraxManager myTHydraxManager;

        //Hydrax
        private MNoise myNoise;
        private MProjectedGrid.MOptions myOptions;
        private MModule myModule;
        private MHydrax.MHydrax myHydrax;

        private string myConfigFile;
        private Plane myPlane;
        private bool myDoUpdate;
        #endregion

        #region Constructor
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="THydraxManager"></param>
        public THydraxItem(THydraxManager THydraxManager)
        {
            myTHydraxManager = THydraxManager;
            myDoUpdate = true;
        }
        #endregion

        #region Update
        /// <summary>
        /// Update
        /// </summary>
        /// <param name="evt"></param>
        /// <returns></returns>
        public bool Update(FrameEvent evt)
        {
            if (!myDoUpdate)
            {
                return true;
            }

            if (myHydrax != null)
            {
                myHydrax.Update(evt.timeSinceLastFrame);
            }
            return true;
        }
        #endregion

        #region Create Grid
        /// <summary>
        /// Create the Projectiongrid
        /// </summary>
        public void CreateProjectedGrid()
        {
            myOptions = new MProjectedGrid.MOptions();
        }
        #endregion

        #region Create Plane
        /// <summary>
        /// Create the Ogre-Plaine
        /// </summary>
        public void CreatePlane()
        {
            myPlane = new Plane(new Vector3(0, 1, 0), new Vector3(0, 0, 0));
        }
        #endregion

        #region Create Noise
        /// <summary>
        /// Create Noise
        /// </summary>
        public void CreateNoise()
        {
            myNoise = new MPerlin();
        }
        #endregion

        #region Create Module
        /// <summary>
        /// Create the Main-Modul for Hydrax
        /// </summary>
        public void CreateModule()
        {
            myModule = new MProjectedGrid(myHydrax, myNoise, myPlane, MMaterialManager.MNormalMode.NM_VERTEX, 
                myOptions);
        }
        #endregion

        #region Create
        /// <summary>
        /// Create MHyydrax
        /// </summary>
        public void Create()
        {
            // create Hydrax instance
            myHydrax = new MHydrax.MHydrax(myTHydraxManager.GfxManager.TOgreManager.Singelton.SceneManager, 
                myTHydraxManager.GfxManager.TOgreManager.Singelton.Camera, 
                myTHydraxManager.GfxManager.TOgreManager.Singelton.Viewport);

            CreateModule();

            // set module and load settings
            myHydrax.SetModule(myModule);
            myHydrax.LoadCfg(myConfigFile);

            // create water
            myHydrax.Create();
        }
        #endregion

        #region Public Members
        public MHydrax.MHydrax Hydrax
        {
            get { return myHydrax; }
            set { myHydrax = value; }
        }

        public MNoise Noise
        {
            get { return myNoise; }
            set { myNoise = value; }
        }

        public MProjectedGrid.MOptions Options
        {
            get { return myOptions; }
            set { myOptions = value; }
        }

        public MModule Module
        {
            get { return myModule; }
            set { myModule = value; }
        }

        public string ConfigFile
        {
            get { return myConfigFile; }
            set { myConfigFile = value; }
        }

        public Plane Plane
        {
            get { return myPlane; }
            set { myPlane = value; }
        }
        #endregion
    }
}



ITHydraxItem.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mogre;
using MHydrax;

namespace Tehadon.Gfx.THydrax
{
    public interface ITHydraxItem
    {
        #region Update
        /// <summary>
        /// Update
        /// </summary>
        /// <param name="evt"></param>
        /// <returns></returns>
        bool Update(FrameEvent evt);
        #endregion

        #region Create Grid
        /// <summary>
        /// Create the Projectiongrid
        /// </summary>
        void CreateProjectedGrid();
        #endregion

        #region Create Plane
        /// <summary>
        /// Create the Ogre-Plaine
        /// </summary>
        void CreatePlane();
        #endregion

        #region Create Noise
        /// <summary>
        /// Create Noise
        /// </summary>
        void CreateNoise();
        #endregion

        #region Create Module
        /// <summary>
        /// Create the Main-Modul for Hydrax
        /// </summary>
        void CreateModule();
        #endregion

        #region Create
        /// <summary>
        /// Create MHyydrax
        /// </summary>
        void Create();
        #endregion

        #region Public Members
        MNoise Noise
        {
            get;
            set;
        }

        MProjectedGrid.MOptions Options
        {
            get;
            set;
        }

        MModule Module
        {
            get;
            set;
        }

        string ConfigFile
        {
            get;
            set;
        }

        Plane Plane
        {
            get;
            set;
        }

        MHydrax.MHydrax Hydrax
        {
            get;
            set;
        }
        #endregion
    }
}



THydraxManager.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Tehadon.Gfx.THydrax
{
    public class THydraxManager
    {
        #region Private Members
        private GfxManager myGfxManager;
        #endregion

        #region Constructor
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="GfxManager"></param>
        public THydraxManager(GfxManager GfxManager)
        {
            myGfxManager = GfxManager;
        }
        #endregion

        #region GetNew
        public ITHydraxItem GetNew()
        {
            return new THydraxItem(this);
        }
        #endregion

        #region Public Members
        public GfxManager GfxManager
        {
            get { return myGfxManager; }
            set { myGfxManager = value; }
        }
        #endregion
    }
}
Call to undefined function mb_split()Call to undefined function mb_split()Call to undefined function mb_split()Call to undefined function mb_split()