randomCoder
17-11-2006 03:11:39
Im new to mogre, and ive been using it for almost an hour now, and i like it so far ![Very Happy :D]({SMILIES_PATH}/icon_biggrin.gif)
I have followed the examples and read the forums, and I have been attempting to get keyDown/keyUp/mouseMove/etc. handlers working. the problem is ...they do... but in a weird way...
id like to preface this with the disclaimer that i could be functionally retarded, and not know it
anyhow, i created my own project and ripped apart the mogreForms example. I created a seperate class for handling ogre type activities, created some uinput handlers, and registered them on the mian form that
contains the panel i want ogre displayed in.
in my ogreWindowClass, all the handlers reside, and the class contains a pointer to the form on which mogre is rendered.
oddly, the handlers are called on mouse input/key presses, etc. (the movement ocde was taken from tutorial 4 i think?), but behave strangely-- nothing happens. i can trace the code and see that control is passed to those functions...if i debug and step through, it works...if i dont step through, i get tnothing. so i output some text to a debug label on the form itself...and if i access the label on the main form with something like:
it begins working. so i placed this in the frameStarted frame:
and i can see the camerapos changing. without the debug output in the keyDown handler...the camera position does not change. with the debug text, it does. makes no sense to me. theres more:
when i have debug text in all places and i can tell input is being passed to the handlers...lets say i want to mvoe the camera to the right (code from tutorial 4)... i can press the right key, and nothing happens, unless i alternate between the right key and some other random key...then the mogre panel updates.
the mouse functions do not work past hiding the cursor when the right mouse button is pressed. once again, i can trace through the code and output code in the functions, but the cmaera itself does not change.
heres a large chunk of ocde if it helps:
the form:
and segments of the mogre window class
InitMogre() is from the mogreForm example
i may have explained this poorly (im a bit burnt out from work all day), so if i did something weird, feel free to belittle me
thanks!
![Very Happy :D]({SMILIES_PATH}/icon_biggrin.gif)
I have followed the examples and read the forums, and I have been attempting to get keyDown/keyUp/mouseMove/etc. handlers working. the problem is ...they do... but in a weird way...
id like to preface this with the disclaimer that i could be functionally retarded, and not know it
![Razz :P]({SMILIES_PATH}/icon_razz.gif)
anyhow, i created my own project and ripped apart the mogreForms example. I created a seperate class for handling ogre type activities, created some uinput handlers, and registered them on the mian form that
contains the panel i want ogre displayed in.
in my ogreWindowClass, all the handlers reside, and the class contains a pointer to the form on which mogre is rendered.
oddly, the handlers are called on mouse input/key presses, etc. (the movement ocde was taken from tutorial 4 i think?), but behave strangely-- nothing happens. i can trace the code and see that control is passed to those functions...if i debug and step through, it works...if i dont step through, i get tnothing. so i output some text to a debug label on the form itself...and if i access the label on the main form with something like:
public void KeyDownHandler(object sender, KeyEventArgs e)
{
mParentForm.setDebugLabel("keypress: " + e.KeyCode+" CamPos: (" + camera.Position.x + "," + camera.Position.y + "," + camera.Position.z + ")");
switch (e.KeyCode)
it begins working. so i placed this in the frameStarted frame:
bool FrameStarted(FrameEvent evt)
{
camera.Position += camera.Orientation * mTranslation * evt.timeSinceLastFrame;
mParentForm.setDebugLabel("CamPos: (" + camera.Position.x + "," + camera.Position.y + "," + camera.Position.z + ")");
and i can see the camerapos changing. without the debug output in the keyDown handler...the camera position does not change. with the debug text, it does. makes no sense to me. theres more:
when i have debug text in all places and i can tell input is being passed to the handlers...lets say i want to mvoe the camera to the right (code from tutorial 4)... i can press the right key, and nothing happens, unless i alternate between the right key and some other random key...then the mogre panel updates.
the mouse functions do not work past hiding the cursor when the right mouse button is pressed. once again, i can trace through the code and output code in the functions, but the cmaera itself does not change.
heres a large chunk of ocde if it helps:
the form:
public partial class MogreForm : Form
{
protected OgreWindow mogreWin;
public MogreForm()
{
InitializeComponent();
this.Disposed += new EventHandler(MogreForm_Disposed);
mogreWin = new OgreWindow(new Point(100, 30), mogrePanel.Handle);
mogreWin.InitMogre();
mogreWin.setParentForm(this);
createHandlers();
}
public void createHandlers()
{
this.KeyDown += new KeyEventHandler(mogreWin.KeyDownHandler);
this.KeyUp += new KeyEventHandler(mogreWin.KeyUpHandler);
this.mogrePanel.MouseDown += new MouseEventHandler(mogreWin.MouseDownHandler);
this.mogrePanel.MouseUp += new MouseEventHandler(mogreWin.MouseUpHandler);
this.mogrePanel.MouseMove += new MouseEventHandler(mogreWin.MouseMoveHandler);
}
private void MogreForm_Paint(object sender, PaintEventArgs e)
{
mogreWin.Paint();
}
void MogreForm_Disposed(object sender, EventArgs e)
{
mogreWin.Dispose();
}
public void setDebugLabel(String text)
{
label1.Text = text;
}
}
and segments of the mogre window class
InitMogre() is from the mogreForm example
public class OgreWindow
{
public Root root;
public SceneManager sceneMgr;
protected Camera camera;
protected Viewport viewport;
protected RenderWindow window;
protected Point position;
protected IntPtr hWnd;
public MogreForm mParentForm;
//input stuffs
Vector3 mTranslation = Vector3.ZERO;
const float TRANSLATE = 10;
const float ROTATE = 0.2f;
bool mRotating = false;
Point mLastPosition;
public void setParentForm(MogreForm form)
{
mParentForm = form;
}
public OgreWindow(Point origin, IntPtr hWnd)
{
position = origin;
this.hWnd = hWnd;
}
public void initMogre(){...};
public void Paint()
{
root.RenderOneFrame();
}
public void Dispose()
{
if (root != null)
{
root.Dispose();
root = null;
}
}
public void KeyUpHandler(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Up:
case Keys.W:
case Keys.Down:
case Keys.S:
mTranslation.z = 0;
break;
case Keys.Left:
case Keys.A:
case Keys.Right:
case Keys.D:
mTranslation.x = 0;
break;
case Keys.PageUp:
case Keys.Q:
case Keys.PageDown:
case Keys.E:
mTranslation.y = 0;
break;
}
}
public void KeyDownHandler(object sender, KeyEventArgs e)
{
// mParentForm.setDebugLabel("keypress: " + e.KeyCode+" CamPos: (" + camera.Position.x + "," + camera.Position.y + "," + camera.Position.z + ")");
switch (e.KeyCode)
{
case Keys.Up:
case Keys.W:
mTranslation.z = -TRANSLATE;
break;
case Keys.Down:
case Keys.S:
mTranslation.z = TRANSLATE;
break;
case Keys.Left:
case Keys.A:
mTranslation.x = -TRANSLATE;
break;
case Keys.Right:
case Keys.D:
mTranslation.x = TRANSLATE;
break;
case Keys.PageUp:
case Keys.Q:
mTranslation.y = TRANSLATE;
break;
case Keys.PageDown:
case Keys.E:
mTranslation.y = -TRANSLATE;
break;
}
}
public void MouseMoveHandler(object sender, MouseEventArgs e)
{
if (mRotating)
{
float x = mLastPosition.X - Cursor.Position.X;
float y = mLastPosition.Y - Cursor.Position.Y;
camera.Yaw(new Degree(x * ROTATE));
camera.Pitch(new Degree(y * ROTATE));
mLastPosition = Cursor.Position;
}
}
public void MouseUpHandler(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
Cursor.Show();
mRotating = false;
}
}
public void MouseDownHandler(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
Cursor.Hide();
mRotating = true;
mLastPosition = Cursor.Position;
}
}
bool FrameStarted(FrameEvent evt)
{
camera.Position += camera.Orientation * mTranslation * evt.timeSinceLastFrame;
//mParentForm.setDebugLabel("CamPos: (" + camera.Position.x + "," + camera.Position.y + "," + camera.Position.z + ")");
//mParentForm.setDebugLabel("CamPos: (" + mTranslation.x + "," + mTranslation.y + "," + mTranslation.z + ")");
return true;
}
}
i may have explained this poorly (im a bit burnt out from work all day), so if i did something weird, feel free to belittle me
![Smile :)]({SMILIES_PATH}/icon_smile.gif)