Created
March 24, 2016 20:19
-
-
Save andykorth/b6abf59895c8f6a67964 to your computer and use it in GitHub Desktop.
Pencil.gaming callbacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static GlfwMouseButtonFun mouseCallback; | |
public static GlfwKeyFun keyCallback; | |
protected virtual void Setup(){ | |
// Setup mouse callbacks: | |
mouseCallback += HandleMouseClick; | |
Glfw.SetMouseButtonCallback(mouseCallback); | |
keyCallback += HandleKeyDown; | |
Glfw.SetKeyCallback (keyCallback); | |
// this is my window resizing code | |
Glfw.SetWindowSizeCallback ((int width, int height) => { | |
Screen.viewSize = new Size (width, height); | |
needsResizing = true; | |
}); | |
} | |
public void HandleKeyDown(Key key, Keystate state){ | |
if (state == Keystate.Press && key == (Key) 'Z') { | |
UpdateTestState (testState - 1); | |
} | |
if (state == Keystate.Press && key == (Key) 'X') { | |
UpdateTestState (testState + 1); | |
} | |
if (state == Keystate.Press && key == (Key) 'K') { | |
UpdateSkyboxState (skyboxState - 1); | |
} | |
if (state == Keystate.Press && key == (Key) 'L') { | |
UpdateSkyboxState (skyboxState + 1); | |
} | |
if (state == Keystate.Press && key == (Key) 'J') { | |
UpdateSkyboxState (0); | |
} | |
} | |
public void HandleMouseClick(MouseButton mouseButton, Keystate state){//,int mouseButton, int buttonDown){ | |
int x = 0; | |
int y = 0; | |
Glfw.GetMousePos(out x, out y); | |
// screenSpace = new Vector4(x, y, 0, 1); | |
//My math to flip the Y | |
Vector3 worldSpace = UnProject(new Vector3(x,Screen.viewSize.Height - y,0), renderQueue.modelview, renderQueue.projection, new float[]{0, 0, Screen.x, Screen.y}); | |
Vector3 uiSpace = UnProject(new Vector3(x,Screen.viewSize.Height - y,0), uiRenderQueue.modelview, uiRenderQueue.projection, new float[]{0, 0, Screen.x, Screen.y}); | |
if(state == Keystate.Release){ | |
// Debug.Log ("button: " + mouseButton + " up at " + screenSpace.ToString() + " -> " + worldSpace.ToString()); | |
// call your own helper functions if you want | |
MouseUpHelper (uiSpace.Xy, worldSpace, mouseButton); | |
}else{ | |
// Debug.Log ("button: " + mouseButton + " down at " + screenSpace.ToString() + " -> " + worldSpace.ToString()); | |
MouseDownHelper (uiSpace.Xy, worldSpace, mouseButton); | |
previousMouseDown = GetMousePos (); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment