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) :
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 :
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
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