History: MHydrax code example
Preview of version: 2
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.
For questions use this forum topic.
Overview
- THydraxItem.cs
... TODO ... - ITHydraxItem.cs
... TODO ... - THydraxManager.cs
... TODO ...
TODO:
- Add a short description for the classes
- Translate comments/regions to English
- Attach code files as zip archive to wiki page
THydraxItem.cs
{VERSIONS(nav="y",default="C#")}
Copy to clipboard
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 } }
-(VB.NET)-
Copy to clipboard
Imports System.Collections.Generic Imports System.Linq Imports System.Text Imports MHydrax Imports Mogre Namespace Tehadon.Gfx.THydrax Public Class THydraxItem Implements ITHydraxItem #Region "Private Members" 'Manager Private myTHydraxManager As THydraxManager 'Hydrax Private myNoise As MNoise Private myOptions As MProjectedGrid.MOptions Private myModule As MModule Private myHydrax As MHydrax.MHydrax Private myConfigFile As String Private myPlane As Plane Private myDoUpdate As Boolean #End Region #Region "Constructor" ''' <summary> ''' Constructor ''' </summary> ''' <param name="THydraxManager"></param> Public Sub New(THydraxManager As THydraxManager) myTHydraxManager = THydraxManager myDoUpdate = True End Sub #End Region #Region "Update" ''' <summary> ''' Update ''' </summary> ''' <param name="evt"></param> ''' <returns></returns> Public Function Update(evt As FrameEvent) As Boolean If Not myDoUpdate Then Return True End If If myHydrax IsNot Nothing Then myHydrax.Update(evt.timeSinceLastFrame) End If Return True End Function #End Region #Region "Create Grid" ''' <summary> ''' Create the Projectiongrid ''' </summary> Public Sub CreateProjectedGrid() myOptions = New MProjectedGrid.MOptions() End Sub #End Region #Region "Create Plane" ''' <summary> ''' Create the Ogre-Plaine ''' </summary> Public Sub CreatePlane() myPlane = New Plane(New Vector3(0, 1, 0), New Vector3(0, 0, 0)) End Sub #End Region #Region "Create Noise" ''' <summary> ''' Create Noise ''' </summary> Public Sub CreateNoise() myNoise = New MPerlin() End Sub #End Region #Region "Create Module" ''' <summary> ''' Create the Main-Modul for Hydrax ''' </summary> Public Sub CreateModule() myModule = New MProjectedGrid(myHydrax, myNoise, myPlane, MMaterialManager.MNormalMode.NM_VERTEX, myOptions) End Sub #End Region #Region "Create" ''' <summary> ''' Create MHyydrax ''' </summary> Public Sub 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() End Sub #End Region #Region "Public Members" Public Property Hydrax() As MHydrax.MHydrax Get Return myHydrax End Get Set myHydrax = value End Set End Property Public Property Noise() As MNoise Get Return myNoise End Get Set myNoise = value End Set End Property Public Property Options() As MProjectedGrid.MOptions Get Return myOptions End Get Set myOptions = value End Set End Property Public Property [Module]() As MModule Get Return myModule End Get Set myModule = value End Set End Property Public Property ConfigFile() As String Get Return myConfigFile End Get Set myConfigFile = value End Set End Property Public Property Plane() As Plane Get Return myPlane End Get Set myPlane = value End Set End Property #End Region End Class End Namespace
ITHydraxItem.cs
Copy to clipboard
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 } }
-(VB.NET)-
Copy to clipboard
Imports System.Collections.Generic Imports System.Linq Imports System.Text Imports Mogre Imports MHydrax Namespace Tehadon.Gfx.THydrax Public Interface ITHydraxItem #Region "Update" ''' <summary> ''' Update ''' </summary> ''' <param name="evt"></param> ''' <returns></returns> Function Update(evt As FrameEvent) As Boolean #End Region #Region "Create Grid" ''' <summary> ''' Create the Projectiongrid ''' </summary> Sub CreateProjectedGrid() #End Region #Region "Create Plane" ''' <summary> ''' Create the Ogre-Plaine ''' </summary> Sub CreatePlane() #End Region #Region "Create Noise" ''' <summary> ''' Create Noise ''' </summary> Sub CreateNoise() #End Region #Region "Create Module" ''' <summary> ''' Create the Main-Modul for Hydrax ''' </summary> Sub CreateModule() #End Region #Region "Create" ''' <summary> ''' Create MHyydrax ''' </summary> Sub Create() #End Region #Region "Public Members" Property Noise() As MNoise Property Options() As MProjectedGrid.MOptions Property [Module]() As MModule Property ConfigFile() As String Property Plane() As Plane Property Hydrax() As MHydrax.MHydrax #End Region End Interface End Namespace
THydraxManager.cs
Copy to clipboard
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 } }
-(VB.NET)-
Copy to clipboard
Imports System.Collections.Generic Imports System.Linq Imports System.Text Namespace Tehadon.Gfx.THydrax Public Class THydraxManager #Region "Private Members" Private myGfxManager As GfxManager #End Region #Region "Constructor" ''' <summary> ''' Constructor ''' </summary> ''' <param name="GfxManager"></param> Public Sub New(GfxManager As GfxManager) myGfxManager = GfxManager End Sub #End Region #Region "GetNew" Public Function GetNew() As ITHydraxItem Return New THydraxItem(Me) End Function #End Region #Region "Public Members" Public Property GfxManager() As GfxManager Get Return myGfxManager End Get Set myGfxManager = value End Set End Property #End Region End Class End Namespace