Problems with MOIS and WinForm

paddy3k

25-07-2008 09:44:45

Hi there :)

I'm developing a 3D player for simulation protocols. The GUI frontend is built using windows.forms and the rendering is done in a splitcontainer panel.

First what I want :

1. The user should have control over the Forms GUI by default.
2. If the user presses the right mouse button, the program switches to
"Scene-Control" (user can move the camera with mouse and keyboard).

I tried a couple of things now, but doesn't came up with a nice solution.

I'm using the following code (from example framework I think) :


public class InputHandler
{
protected MOIS.InputManager inputManager;
protected MOIS.Keyboard inputKeyboard;
protected MOIS.Mouse inputMouse;

private Camera camera;

private float camSpeed = 10f;
private Degree rotateSpeed = 0.2f;
bool moving;

#region InputHandler Member

public InputHandler()
{
inputManager = null;
inputKeyboard = null;
inputMouse = null;

moving = false;
}

public bool Init(IntPtr WindowHandle, IView view)
{
// Hook up the InputManager to the Application Window
inputManager = MOIS.InputManager.CreateInputSystem((uint)WindowHandle);

if (inputManager != null)
{
// Create all devices
inputKeyboard = (MOIS.Keyboard)inputManager.CreateInputObject(MOIS.Type.OISKeyboard, false);
inputMouse = (MOIS.Mouse)inputManager.CreateInputObject(MOIS.Type.OISMouse, false);
}

if (inputKeyboard != null && inputMouse != null)
{
this.camera = view.Camera;

view.Root.FrameStarted += new FrameListener.FrameStartedHandler(FrameStarted);

return true;
}

return false;
}

private bool FrameStarted(FrameEvent evt)
{
// Move about 100 units per second,
float moveScale = camSpeed * evt.timeSinceLastFrame;
// Take about 10 seconds for full rotation
Degree scaleRotate = rotateSpeed * evt.timeSinceLastFrame;
Vector3 camVelocity = Vector3.ZERO;
Vector3 translateVector = Vector3.ZERO;

Capture();

if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_A))
{
translateVector.x = -moveScale;
}

if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_D))
{
translateVector.x = moveScale;
}

if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_W))
{
translateVector.z = -moveScale;
}

if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_S))
{
translateVector.z = moveScale;
}

if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_LEFT))
{
camera.Yaw(scaleRotate);
}

if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_RIGHT))
{
camera.Yaw(-scaleRotate);
}

if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_UP))
{
camera.Pitch(scaleRotate);
}

if (inputKeyboard.IsKeyDown(MOIS.KeyCode.KC_DOWN))
{
camera.Pitch(-scaleRotate);
}

MOIS.MouseState_NativePtr mouseState = inputMouse.MouseState;

if (mouseState.ButtonDown(MOIS.MouseButtonID.MB_Right))
{
Cursor.Hide();

Degree cameraYaw = -mouseState.X.rel * .13f;
Degree cameraPitch = -mouseState.Y.rel * .13f;

camera.Yaw(cameraYaw);
camera.Pitch(cameraPitch);
}
else
{
Cursor.Show(); // translateVector.x += mouseState.X.rel * 0.13f;
}

// move the camera based on the accumulated movement vector
camera.MoveRelative(translateVector);

return true;
}

private void Capture()
{
inputKeyboard.Capture();
inputMouse.Capture();
}

#endregion
}


this works as it should except the following :

If right mouse button isn't pressed, i see a "wait" mouse cursor and don't have control over the forms gui.

My main render loop looks like this :


while (view.Root != null)
{
view.RenderOneFrame();

Application.DoEvents();
}


so I don't know how to solve that :-/

I also already tried to use buffered mode with event handlers, but in this case no event was ever fired (is it so, because I'm rendering in a panel instead using the whole window for that ?!?)... I'm very new to Ogre, sorry for this noobish questions :-)

greets
paddy

Makaze

25-07-2008 20:04:08

Stick WindowEventUtilities.MessagePump(); that in right before you do RenderOneFrame.

paddy3k

25-07-2008 23:56:12

hm shouldn't do that Application.DoEvents() ?! If not, what else it is doing then ? thanks :-)

greets!

Makaze

26-07-2008 06:28:10

Honestly I don't know what all goes on it WindowsEventHandler.MessagePump. Heck it may very well call Application.DoEvents itself. But I do know that the only way I've gotten things to work right in the past is to call it.

paddy3k

26-07-2008 09:02:05

Hi,

I tried it now this way :


while (view.Root != null)
{
WindowEventUtilities.MessagePump();

view.RenderOneFrame();

Application.DoEvents();
}


but it doesn't work :-( .... still got the "busy" mouse cursor and cannot interact with the gui.

Other suggestions ?

feanor91

26-07-2008 11:26:18

Hello

see this :

http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=7697

My last post about MOIS and Direct Input....

paddy3k

28-07-2008 19:02:50

just for the others, who has the same problem. I just solved it, combining MOIS with MouseDown / MouseUp events of the Main Form :

Source can be found here :

http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=7697

greets