00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef S5_INPUT_H_INCLUDED_
00019 #define S5_INPUT_H_INCLUDED_
00020
00021 #include <Inventor/nodes/SoSubNode.h>
00022 #include <Inventor/events/SoKeyboardEvent.h>
00023
00024 #ifdef USE_SO_GLUT
00025 #include "SoGlutRenderArea.h"
00026 #else
00027 #include <Inventor/Xt/SoXt.h>
00028 #include <Inventor/Xt/SoXtRenderArea.h>
00029 #endif
00030
00031 class SoLocation2Event;
00032
00033
00034
00035 class S5input : public SoNode
00036 {
00037
00038 SO_NODE_HEADER(S5input);
00039
00040 public:
00041
00042
00043 float getMouseX() { return mouseDX; };
00044 float getMouseY() { return mouseDY; };
00045
00046 void resetMousePosition();
00047 void resetMouse();
00048 float mouseSensitivityX;
00049 float mouseSensitivityY;
00050
00051
00052
00053 float getKbForward() { return kbForward.getState(1.f); };
00054 float getKbBackward() { return kbBackward.getState(1.f); };
00055 float getKbRight() { return kbRight.getState(1.f); };
00056 float getKbLeft() { return kbLeft.getState(1.f); };
00057 float getKbUp() { return kbUp.getState(1.f); };
00058 float getKbDown() { return kbDown.getState(1.f); };
00059 bool getKbFire() { return kbFire.getState(); };
00060
00061 bool getKbExit() { return kbExit.getState(); };
00062
00063 void resetKbPresses() { kbForward.pressReset(); kbBackward.pressReset();
00064 kbRight.pressReset(); kbLeft.pressReset(); kbUp.pressReset(); kbDown.pressReset();
00065 kbFire.pressReset(); kbExit.pressReset(); };
00066
00067
00068
00069 bool getActive() { return active; };
00070 void setActive(bool a);
00071
00072 void setRenderArea(SoXtRenderArea *renderArea);
00073 SoXtRenderArea *getRenderArea() { return renderArea; };
00074
00075
00076
00077 S5input();
00078 S5input(SoXtRenderArea *renderArea);
00079
00080 virtual void handleEvent(SoHandleEventAction * action);
00081
00082 static void initClass();
00083
00084 protected:
00085
00086 SoXtRenderArea *renderArea;
00087 bool active;
00088
00089 SbBool mouseMoveCB(const SoLocation2Event *event);
00090 SbBool kbPressCB(const SoKeyboardEvent *event);
00091
00092 virtual ~S5input();
00093
00094
00095 private:
00096
00097
00098 float mouseDX;
00099 float mouseDY;
00100
00101
00102
00103 typedef struct KbRecord {
00104 SoKeyboardEvent::Key key1;
00105 SoKeyboardEvent::Key key2;
00106 SoKeyboardEvent::Key key3;
00107 bool down;
00108 bool press;
00109
00110 KbRecord() : key1(SoKeyboardEvent::ANY), key2(SoKeyboardEvent::ANY), key3(SoKeyboardEvent::ANY), down(false), press(false) {};
00111
00112 bool getState() { return (down || press); };
00113 float getState(float sensitivity) { return getState() ? sensitivity : 0.f; };
00114
00115 bool handleKeyDown(SoKeyboardEvent::Key c) { if ((c == key1) || (c == key2) || (c == key3)) { down = true; press = true; return true; }; return false;};
00116 bool handleKeyUp(SoKeyboardEvent::Key c) { if ((c == key1) || (c == key2) || (c == key3)) { down = false; return true; }; return false; };
00117 void pressReset() { press = false; };
00118 } KbRecord;
00119
00120 KbRecord kbForward;
00121 KbRecord kbBackward;
00122 KbRecord kbRight;
00123 KbRecord kbLeft;
00124 KbRecord kbUp;
00125 KbRecord kbDown;
00126 KbRecord kbFire;
00127 KbRecord kbExit;
00128
00129 };
00130
00131
00132 #endif