CK_MACK
19-01-2007 05:06:20
Once I hit tutorial #5, there is the problem of not using Ogre's input system.
The problem is handled by asking the "user" to just go find one and implement it. This is not easy for me since, well, I am just trying to learn HOW to use Mogre and I am not familiar enough with it.
Since Tutorial 4 has a working mesh with a camera that moves, I wanted to put Microsoft.DirectX.DirectInput into Tutorial #4 as a kind of proof of concept.
I was looking at a tutorial located here: http://www.riemers.net/eng/Tutorials/Di ... 1/tut9.php
(please take a quick look at that link)
The part where I seem to be running into difficulty is this line:
our_directx_form.InitializeKeyboard();
My question is:
What is the equivalent of "our_directx_form" in Mogre?
An example the code I "flung" together for Tutorial 4 and a DirectInput Tutorial is below:
I apologize in advance for asking stupid noob questions, but I don't know where else to ask these questions.
Marc.
The problem is handled by asking the "user" to just go find one and implement it. This is not easy for me since, well, I am just trying to learn HOW to use Mogre and I am not familiar enough with it.
Since Tutorial 4 has a working mesh with a camera that moves, I wanted to put Microsoft.DirectX.DirectInput into Tutorial #4 as a kind of proof of concept.
I was looking at a tutorial located here: http://www.riemers.net/eng/Tutorials/Di ... 1/tut9.php
(please take a quick look at that link)
The part where I seem to be running into difficulty is this line:
our_directx_form.InitializeKeyboard();
My question is:
What is the equivalent of "our_directx_form" in Mogre?
An example the code I "flung" together for Tutorial 4 and a DirectInput Tutorial is below:
// Tutorial 4 + DirectInput: Frame Listeners but substitute in DirectInput for the Keyboard
// Try to use J and K, to move the camera left and right.
// requires the following References: Microsoft.DirectX.DirectInput, Mogre, MogreFramework, System, System.Data,
// System.Deployment, System.Drawing, System.Windows.Forms, System.Xml
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using MogreFramework;
using Mogre;
using System.Drawing;
using Microsoft.DirectX.DirectInput;
namespace Tutorial04
{
static class Program
{
[STAThread]
static void Main()
{
try
{
MyOgreWindow win = new MyOgreWindow();
new SceneCreator(win);
// Initialize the keyboard
win.Go();
}
catch (System.Runtime.InteropServices.SEHException)
{
if (OgreException.IsThrown)
MessageBox.Show(OgreException.LastException.FullDescription, "An Ogre exception has occurred!");
else
throw;
}
}
}
class MyOgreWindow : OgreWindow
{
const float TRANSLATE = 400; // 200 for slower camera motion
const float ROTATE = 0.2f;
bool mRotating = false;
Vector3 mTranslation = Vector3.ZERO;
Radian mYaw = 0.0f;
Point mLastPosition;
private Microsoft.DirectX.DirectInput.Device keyb;
protected override void CreateInputHandler() // Allows us to overide the inputhandler
{
keyb = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);
keyb.SetCooperativeLevel(this, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
keyb.Acquire();
// Here's the line where I don't know what to use for our form name...
win.InitializeKeyboard(); // obviously its not our_directX_form, but what is it? How can I get that info and bring it here?
this.Root.FrameStarted += new FrameListener.FrameStartedHandler(FrameStarted);
this.KeyDown += new KeyEventHandler(ReadKeyboard);
}
void ReadKeyboard(object sender, KeyEventArgs e)
{
KeyboardState keys = keyb.GetCurrentKeyboardState();
if (keys[Key.J])
{ mTranslation.x = -TRANSLATE; }
if (keys[Key.K])
{ mTranslation.x = TRANSLATE; }
}
bool FrameStarted(FrameEvent evt)
{
Camera.Position += Camera.Orientation * mTranslation * evt.timeSinceLastFrame;
return true;
}
}
class SceneCreator
{
public SceneCreator(OgreWindow win)
{
win.SceneCreating += new OgreWindow.SceneEventHandler(SceneCreating);
}
void SceneCreating(OgreWindow win)
{
win.SceneManager.AmbientLight = new ColourValue(0.25f, 0.25f, 0.25f);
Entity ent = win.SceneManager.CreateEntity("Ninja", "ninja.mesh");
win.SceneManager.RootSceneNode.CreateChildSceneNode().AttachObject(ent);
Light light = win.SceneManager.CreateLight("Light");
light.Type = Light.LightTypes.LT_POINT;
light.Position = new Vector3(250, 150, 250);
light.DiffuseColour = ColourValue.White;
light.SpecularColour = ColourValue.White;
win.Camera.Position = new Vector3(0, 200, 400);
win.Camera.LookAt(ent.BoundingBox.Center);
}
}
}
I apologize in advance for asking stupid noob questions, but I don't know where else to ask these questions.
Marc.