I wanted to have my game panel run inside a splitter with a collapsible properties panel. This was quite easy to achieve, merely needing the changing of the handle that directX was pointing at. i.e. changing this:
to this:
But-it-broke-my-game.
How? The OnKeyDown event doesn't percolate to parents. That truly sucks. Oddly the only key that does percolate is ALT+key which windows needed to get menu key-presses (ALT-F,X) -- ain't that just too hacky. The mechanism is there, but disabled to frustrate us.
I didn't really want my players to have to play while holding ALT ;) so I went and figured out how to use DirectInput, with the aid of Riemer's tutorial. And it just works. Quickly.
I'm polling the input from my main loop now, and compared to the handling of the OnKeyDown event I'm getting squagillions more keypresses. Needless to say ints became floats (Vector3s actually) rather quickly to handle the smaller iterations.
Other changes include having to have to input de-bounce. I do this by copying the previous state's keys and passing them into the next input parse.
And in the main loop:
The debouncer was necessary to do 'edge detection' on the squagillion keypresses that I was getting, e.g. to toggle the property pane once only. The extra call to OnResetDevice is to handle the change in FoV which is done based on the current size of the panel.
End of dev iteration.
d3dDevice = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, this, flags, d3dpp);
to this:
d3dDevice = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, this.panel1, flags, d3dpp);
But-it-broke-my-game.
How? The OnKeyDown event doesn't percolate to parents. That truly sucks. Oddly the only key that does percolate is ALT+key which windows needed to get menu key-presses (ALT-F,X) -- ain't that just too hacky. The mechanism is there, but disabled to frustrate us.
I didn't really want my players to have to play while holding ALT ;) so I went and figured out how to use DirectInput, with the aid of Riemer's tutorial. And it just works. Quickly.
I'm polling the input from my main loop now, and compared to the handling of the OnKeyDown event I'm getting squagillions more keypresses. Needless to say ints became floats (Vector3s actually) rather quickly to handle the smaller iterations.
Other changes include having to have to input de-bounce. I do this by copying the previous state's keys and passing them into the next input parse.
private List Input(List laststate)
{
List seen = new List();
Vector3 rotationInput = new Vector3(0, 0, 0);
KeyboardState keys = keyb.GetCurrentKeyboardState();
if (keys[Key.Escape]) this.Dispose();
if (keys[Key.W]) rotationInput.Y++;
...
if (keys[Key.P] && !laststate.Contains(Key.P))
{
PropertyGridVisible = !PropertyGridVisible;
splitContainer1.Panel2Collapsed = !PropertyGridVisible;
OnResetDevice(d3dDevice, null);
}
...
return seen;
}
And in the main loop:
static void Main()
{ ...
using (Game grav = new Game())
{ ...
List laststate = new List();
while (grav.Created) { ...
laststate = grav.Input(laststate);
... }}}
The debouncer was necessary to do 'edge detection' on the squagillion keypresses that I was getting, e.g. to toggle the property pane once only. The extra call to OnResetDevice is to handle the change in FoV which is done based on the current size of the panel.
End of dev iteration.