Mogre Framework... where?

DarkHorizon

26-04-2009 17:40:52

Hello,

Just getting started with Mogre 1.6.2, and following the tutorial <a href=http://www.ogre3d.org/wiki/index.php/Mogre_Basic_Tutorial_0">here</a>... where is MogreFramework.dll? The site that hosts it (idleengineer.net) is down.

If some kind soul could please email me with a download location for 1.6.x-compatible source for the framework, it'd be much appreciated...

Thanks!

raygeee

26-04-2009 19:28:40

It's only three classes, so here's the code. It's from reflector, that's the reason for the layout.
You can compile yourself with your Mogre.dll, System and System.Windows.Forms as references.

public class DefaultInputHandler
{
// Fields
private const int INTERVAL = 0x11;
private bool mLastFocus;
private Point mLastLocation;
protected float mRot = -0.2f;
private bool mRotating;
private Timer mTimer = new Timer();
protected float mTrans = 10f;
protected Vector3 mTranslate = Vector3.ZERO;
protected OgreWindow mWindow;

// Methods
public DefaultInputHandler(OgreWindow win)
{
this.mWindow = win;
win.KeyDown += new KeyEventHandler(this.HandleKeyDown);
win.KeyUp += new KeyEventHandler(this.HandleKeyUp);
win.MouseDown += new MouseEventHandler(this.HandleMouseDown);
win.MouseUp += new MouseEventHandler(this.HandleMouseUp);
win.Disposed += new EventHandler(this.win_Disposed);
win.LostFocus += new EventHandler(this.win_LostFocus);
win.GotFocus += new EventHandler(this.win_GotFocus);
this.mTimer.Interval = 0x11;
this.mTimer.Enabled = true;
this.mTimer.Tick += new EventHandler(this.Timer_Tick);
}

protected virtual void HandleKeyDown(object sender, KeyEventArgs e)
{
float mTrans = this.mTrans;
switch (e.KeyCode)
{
case Keys.Q:
case Keys.Prior:
this.mTranslate.y = mTrans;
return;

case Keys.R:
case Keys.End:
case Keys.Home:
case Keys.B:
case Keys.C:
break;

case Keys.S:
case Keys.Down:
this.mTranslate.z = mTrans;
return;

case Keys.W:
case Keys.Up:
this.mTranslate.z = -mTrans;
return;

case Keys.Next:
case Keys.E:
this.mTranslate.y = -mTrans;
break;

case Keys.Left:
case Keys.A:
this.mTranslate.x = -mTrans;
return;

case Keys.Right:
case Keys.D:
this.mTranslate.x = mTrans;
return;

default:
return;
}
}

protected virtual void HandleKeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Q:
case Keys.Prior:
case Keys.Next:
case Keys.E:
this.mTranslate.y = 0f;
break;

case Keys.R:
case Keys.End:
case Keys.Home:
case Keys.B:
case Keys.C:
break;

case Keys.S:
case Keys.W:
case Keys.Up:
case Keys.Down:
this.mTranslate.z = 0f;
return;

case Keys.Left:
case Keys.Right:
case Keys.A:
case Keys.D:
this.mTranslate.x = 0f;
return;

default:
return;
}
}

protected virtual void HandleMouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
Cursor.Hide();
this.mRotating = true;
}
}

private void HandleMouseMove(Point delta)
{
if (this.mRotating)
{
this.mWindow.Camera.Yaw(new Degree(delta.X * this.mRot));
this.mWindow.Camera.Pitch(new Degree(delta.Y * this.mRot));
}
}

protected virtual void HandleMouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
Cursor.Show();
this.mRotating = false;
}
}

private void Timer_Tick(object sender, EventArgs e)
{
if (this.mLastFocus)
{
Point position = Cursor.Position;
position.X -= this.mLastLocation.X;
position.Y -= this.mLastLocation.Y;
this.HandleMouseMove(position);
}
this.mLastLocation = Cursor.Position;
this.mLastFocus = this.mWindow.Focused;
if (this.mLastFocus)
{
Camera camera = this.mWindow.Camera;
camera.Position += this.mWindow.Camera.Orientation * this.mTranslate;
}
}

private void win_Disposed(object sender, EventArgs e)
{
this.mTimer.Enabled = false;
}

private void win_GotFocus(object sender, EventArgs e)
{
this.mTimer.Enabled = true;
}

private void win_LostFocus(object sender, EventArgs e)
{
this.mTimer.Enabled = false;
this.mTranslate = Vector3.ZERO;
}
}

public class OgreWindow : Form
{
// Fields
private IContainer components;
private Camera mCamera;
private Root mRoot;
private SceneManager mSceneMgr;
private Viewport mViewport;
private RenderWindow mWindow;

// Events
public event SceneEventHandler SceneCreating;

// Methods
public OgreWindow()
{
this.InitializeComponent();
base.Icon = Resources.OgreHead;
}

protected virtual void CreateCamera()
{
this.mCamera = this.mSceneMgr.CreateCamera("MainCamera");
this.mCamera.NearClipDistance = 1f;
this.mCamera.Position = new Vector3(0f, 0f, 300f);
this.mCamera.LookAt(Vector3.ZERO);
}

protected virtual void CreateInputHandler()
{
new DefaultInputHandler(this);
}

protected virtual void CreateRenderWindow(IntPtr handle)
{
this.mRoot.Initialise(false, "Main Ogre Window");
NameValuePairList miscParams = new NameValuePairList();
if (handle != IntPtr.Zero)
{
miscParams["externalWindowHandle"] = handle.ToString();
this.mWindow = this.mRoot.CreateRenderWindow("Autumn main RenderWindow", 800, 600, false, miscParams);
}
else
{
this.mWindow = this.mRoot.CreateRenderWindow("Autumn main RenderWindow", 800, 600, false);
}
}

protected virtual void CreateSceneManager()
{
this.mSceneMgr = this.mRoot.CreateSceneManager(SceneType.ST_GENERIC, "Main SceneManager");
}

protected virtual void CreateViewport()
{
this.mViewport = this.mWindow.AddViewport(this.mCamera);
this.mViewport.BackgroundColour = new ColourValue(0f, 0f, 0f, 1f);
}

protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}

public void Go()
{
if (this.mRoot == null)
{
this.InitializeOgre();
}
base.Show();
bool flag = true;
while (flag && (this.mRoot != null))
{
flag = this.mRoot.RenderOneFrame();
Application.DoEvents();
}
}

private void InitializeComponent()
{
base.SuspendLayout();
base.AutoScaleDimensions = new SizeF(6f, 13f);
base.AutoScaleMode = AutoScaleMode.Font;
base.ClientSize = new Size(0x318, 0x23d);
base.FormBorderStyle = FormBorderStyle.Fixed3D;
base.MaximizeBox = false;
base.Name = "OgreWindow";
base.StartPosition = FormStartPosition.CenterScreen;
this.Text = "Mogre Render Window";
base.ResumeLayout(false);
}

public void InitializeOgre()
{
if (this.mRoot != null)
{
throw new Exception("Ogre is already initialized!");
}
Splash splash = new Splash();
splash.Show();
try
{
splash.Increment("Creating the root object...");
this.mRoot = new Root();
splash.Increment("Loading resources...");
this.InitResources();
splash.Increment("Setting up DirectX...");
this.SetupDirectX();
splash.Increment("Creating the window...");
this.CreateRenderWindow(base.Handle);
splash.Increment("Initializing resources...");
ResourceGroupManager.Singleton.InitialiseAllResourceGroups();
splash.Increment("Creating Ogre objects...");
this.CreateSceneManager();
this.CreateCamera();
this.CreateViewport();
splash.Increment("Creating input handler...");
this.CreateInputHandler();
splash.Increment("Creating scene...");
base.Disposed += new EventHandler(this.OgreWindow_Disposed);
this.OnSceneCreating();
}
finally
{
splash.Close();
splash.Dispose();
}
}

protected virtual void InitResources()
{
ConfigFile file = new ConfigFile();
file.Load("resources.cfg", "\t:=", true);
ConfigFile.SectionIterator sectionIterator = file.GetSectionIterator();
while (sectionIterator.MoveNext())
{
string currentKey = sectionIterator.CurrentKey;
foreach (KeyValuePair<string, string> pair in sectionIterator.Current)
{
string key = pair.Key;
string name = pair.Value;
ResourceGroupManager.Singleton.AddResourceLocation(name, key, currentKey);
}
}
}

private void OgreWindow_Disposed(object sender, EventArgs e)
{
this.mRoot.Dispose();
this.mRoot = null;
this.mWindow = null;
this.mCamera = null;
this.mViewport = null;
this.mSceneMgr = null;
}

protected virtual void OnSceneCreating()
{
if (this.SceneCreating != null)
{
this.SceneCreating(this);
}
}

private void SetupDirectX()
{
RenderSystem renderSystemByName = this.mRoot.GetRenderSystemByName("Direct3D9 Rendering Subsystem");
this.mRoot.RenderSystem = renderSystemByName;
renderSystemByName.SetConfigOption("Full Screen", "No");
renderSystemByName.SetConfigOption("Video Mode", "800 x 600 @ 32-bit colour");
}

// Properties
public Camera Camera
{
get
{
return this.mCamera;
}
protected set
{
this.mCamera = value;
}
}

public RenderWindow RenderWindow
{
get
{
return this.mWindow;
}
protected set
{
this.mWindow = value;
}
}

public Root Root
{
get
{
return this.mRoot;
}
}

public SceneManager SceneManager
{
get
{
return this.mSceneMgr;
}
protected set
{
this.mSceneMgr = value;
}
}

public Viewport Viewport
{
get
{
return this.mViewport;
}
protected set
{
this.mViewport = value;
}
}

// Nested Types
public delegate void SceneEventHandler(OgreWindow win);
}


internal class Splash : Form
{
// Fields
private IContainer components;
private Label LoadingText;
private ProgressBar Progress;

// Methods
public Splash()
{
this.InitializeComponent();
}

protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}

public void Increment(string text)
{
this.Progress.Increment(1);
this.LoadingText.Text = text;
base.Update();
Application.DoEvents();
}

private void InitializeComponent()
{
this.LoadingText = new Label();
this.Progress = new ProgressBar();
base.SuspendLayout();
this.LoadingText.AutoEllipsis = true;
this.LoadingText.BackColor = Color.Transparent;
this.LoadingText.ForeColor = Color.White;
this.LoadingText.Location = new Point(9, 0x9f);
this.LoadingText.Name = "LoadingText";
this.LoadingText.Size = new Size(0x178, 13);
this.LoadingText.TabIndex = 0;
this.LoadingText.Text = "Loading...";
this.LoadingText.UseWaitCursor = true;
this.Progress.Location = new Point(12, 0xaf);
this.Progress.Maximum = 8;
this.Progress.Name = "Progress";
this.Progress.Size = new Size(0x175, 14);
this.Progress.Step = 1;
this.Progress.TabIndex = 1;
this.Progress.UseWaitCursor = true;
base.AutoScaleDimensions = new SizeF(6f, 13f);
base.AutoScaleMode = AutoScaleMode.Font;
this.BackgroundImage = Resources.Splash;
this.BackgroundImageLayout = ImageLayout.Stretch;
base.ClientSize = new Size(400, 200);
base.ControlBox = false;
base.Controls.Add(this.Progress);
base.Controls.Add(this.LoadingText);
base.FormBorderStyle = FormBorderStyle.None;
base.Name = "Splash";
base.ShowIcon = false;
base.StartPosition = FormStartPosition.CenterScreen;
this.Text = "Loading...";
base.UseWaitCursor = true;
base.ResumeLayout(false);
}

public void Show()
{
base.Show();
Application.DoEvents();
}
}

Pyritie

08-02-2010 22:23:32

I did this and then got these errors:

"The type or namespace name 'Point' could not be found (are you missing a using directive or an assembly reference?)"
"The type or namespace name 'IContainer' could not be found (are you missing a using directive or an assembly reference?)"

smiley80

08-02-2010 22:32:40

'Point' is in System.Drawing (System.Drawing.dll)
'IContainer' is in System.ComponentModel (System.dll)

Pyritie

09-02-2010 00:28:20

Thanks I got it working