f@0
|
1 /*
|
f@0
|
2 XYPad - a haptic xy-pad that uses the jHapticGUI library
|
f@0
|
3
|
f@0
|
4 Copyright (C) 2015 Queen Mary University of London (http://depic.eecs.qmul.ac.uk/)
|
f@0
|
5
|
f@0
|
6 This program is free software: you can redistribute it and/or modify
|
f@0
|
7 it under the terms of the GNU General Public License as published by
|
f@0
|
8 the Free Software Foundation, either version 3 of the License, or
|
f@0
|
9 (at your option) any later version.
|
f@0
|
10
|
f@0
|
11 This program is distributed in the hope that it will be useful,
|
f@0
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
f@0
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
f@0
|
14 GNU General Public License for more details.
|
f@0
|
15
|
f@0
|
16 You should have received a copy of the GNU General Public License
|
f@0
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
f@0
|
18 */
|
f@0
|
19 #pragma once
|
f@0
|
20
|
f@0
|
21
|
f@0
|
22 #include "Message.h"
|
f@0
|
23
|
f@0
|
24
|
f@0
|
25 namespace jhapticgui {
|
f@0
|
26
|
f@0
|
27 class HapticScene {
|
f@0
|
28
|
f@0
|
29 int mWidth;
|
f@0
|
30 int mHeight;
|
f@0
|
31
|
f@0
|
32 protected:
|
f@0
|
33 void (*send) (const Message &m);
|
f@0
|
34
|
f@0
|
35 public:
|
f@0
|
36
|
f@0
|
37 /**
|
f@0
|
38 * Returns the width of the openGL window where the scene is displayed
|
f@0
|
39 */
|
f@0
|
40 inline int getWidth() {
|
f@0
|
41 return mWidth;
|
f@0
|
42 }
|
f@0
|
43
|
f@0
|
44 /**
|
f@0
|
45 * Returns the height of the openGL window where the scene is displayed
|
f@0
|
46 */
|
f@0
|
47 inline int getHeight() {
|
f@0
|
48 return mHeight;
|
f@0
|
49 }
|
f@0
|
50
|
f@0
|
51 /**
|
f@0
|
52 * The constructor takes as argument a pointer to a function that must
|
f@0
|
53 * be invoked to send a message to the Java thread from the this haptic
|
f@0
|
54 * scene.
|
f@0
|
55 */
|
f@0
|
56 HapticScene(void (*messageCallback) (const Message & m) ) : send(messageCallback) {}
|
f@0
|
57
|
f@0
|
58 virtual ~HapticScene(void){}
|
f@0
|
59
|
f@0
|
60 /**
|
f@0
|
61 * Sets the size of the openGL window where the scene is displayed
|
f@0
|
62 */
|
f@0
|
63 inline virtual void setSize(int w, int h){
|
f@0
|
64 mWidth = w;
|
f@0
|
65 mHeight = h;
|
f@0
|
66 }
|
f@0
|
67
|
f@0
|
68 /** Try and initializes the haptic device, return false if the initialization fails */
|
f@0
|
69 virtual bool initHaptics(void) = 0;
|
f@0
|
70
|
f@0
|
71 /** Initializes the openGL windows after the haptics has been successfully initialized */
|
f@0
|
72 virtual void initGL(void) = 0;
|
f@0
|
73
|
f@0
|
74 /** handles an incoming message from the Java thread.
|
f@0
|
75 *
|
f@0
|
76 * Returns an update code if the message changes the
|
f@0
|
77 * scene. The code is passed to drawScene() for updating
|
f@0
|
78 * the scene accordingly.
|
f@0
|
79 */
|
f@0
|
80 virtual unsigned int processMessage(const Message & m) = 0;
|
f@0
|
81
|
f@0
|
82 /** called at the beginning of each frame */
|
f@0
|
83 virtual void beginFrame(void) = 0;
|
f@0
|
84
|
f@0
|
85 /** called at the end of each frame */
|
f@0
|
86 virtual void endFrame(void) = 0;
|
f@0
|
87
|
f@0
|
88 /** draws the haptic cursor, namely the haptic device proxy */
|
f@0
|
89 virtual void drawCursor(void) = 0;
|
f@0
|
90
|
f@0
|
91 /**
|
f@0
|
92 * Draws one frame both graphic and haptic.
|
f@0
|
93 *
|
f@0
|
94 * messageUpdate and callbacksUpdate are integer codes specifying what
|
f@0
|
95 * needs to be updated in the haptic and graphic scenes. messageUpdate
|
f@0
|
96 * is the value returned by processMessage and flags that a message from the
|
f@0
|
97 * Java thread affects the scene which must therefore be updated.
|
f@0
|
98 *
|
f@0
|
99 * callbacksUpdate is the value returned by checkCallbacks
|
f@0
|
100 * and flags that a haptic event happened that affects the scene,
|
f@0
|
101 * which must therefore be updated.
|
f@0
|
102 */
|
f@0
|
103 virtual void drawScene(unsigned int messageUpdate, unsigned int callbacksUpdate) = 0;
|
f@0
|
104
|
f@0
|
105 /** Checks for haptic callbacks, namely functions that are called when
|
f@0
|
106 * a haptic events occurs. Typical haptic events are proxy touching an
|
f@0
|
107 * object, proxy moving, button pressed etc.
|
f@0
|
108 *
|
f@0
|
109 * Returns an update code if any event changes the
|
f@0
|
110 * scene. The code is passed in the next frame to drawScene(),
|
f@0
|
111 * for updating the scene accordingly.
|
f@0
|
112 *
|
f@0
|
113 */
|
f@0
|
114 virtual unsigned int checkCallbacks(void) = 0;
|
f@0
|
115
|
f@0
|
116 };
|
f@0
|
117
|
f@0
|
118 }
|