f@0: /* f@0: XYPad - a haptic xy-pad that uses the jHapticGUI library f@0: f@0: Copyright (C) 2015 Queen Mary University of London (http://depic.eecs.qmul.ac.uk/) f@0: f@0: This program is free software: you can redistribute it and/or modify f@0: it under the terms of the GNU General Public License as published by f@0: the Free Software Foundation, either version 3 of the License, or f@0: (at your option) any later version. f@0: f@0: This program is distributed in the hope that it will be useful, f@0: but WITHOUT ANY WARRANTY; without even the implied warranty of f@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the f@0: GNU General Public License for more details. f@0: f@0: You should have received a copy of the GNU General Public License f@0: along with this program. If not, see . f@0: */ f@0: #pragma once f@0: f@0: f@0: #include "Message.h" f@0: f@0: f@0: namespace jhapticgui { f@0: f@0: class HapticScene { f@0: f@0: int mWidth; f@0: int mHeight; f@0: f@0: protected: f@0: void (*send) (const Message &m); f@0: f@0: public: f@0: f@0: /** f@0: * Returns the width of the openGL window where the scene is displayed f@0: */ f@0: inline int getWidth() { f@0: return mWidth; f@0: } f@0: f@0: /** f@0: * Returns the height of the openGL window where the scene is displayed f@0: */ f@0: inline int getHeight() { f@0: return mHeight; f@0: } f@0: f@0: /** f@0: * The constructor takes as argument a pointer to a function that must f@0: * be invoked to send a message to the Java thread from the this haptic f@0: * scene. f@0: */ f@0: HapticScene(void (*messageCallback) (const Message & m) ) : send(messageCallback) {} f@0: f@0: virtual ~HapticScene(void){} f@0: f@0: /** f@0: * Sets the size of the openGL window where the scene is displayed f@0: */ f@0: inline virtual void setSize(int w, int h){ f@0: mWidth = w; f@0: mHeight = h; f@0: } f@0: f@0: /** Try and initializes the haptic device, return false if the initialization fails */ f@0: virtual bool initHaptics(void) = 0; f@0: f@0: /** Initializes the openGL windows after the haptics has been successfully initialized */ f@0: virtual void initGL(void) = 0; f@0: f@0: /** handles an incoming message from the Java thread. f@0: * f@0: * Returns an update code if the message changes the f@0: * scene. The code is passed to drawScene() for updating f@0: * the scene accordingly. f@0: */ f@0: virtual unsigned int processMessage(const Message & m) = 0; f@0: f@0: /** called at the beginning of each frame */ f@0: virtual void beginFrame(void) = 0; f@0: f@0: /** called at the end of each frame */ f@0: virtual void endFrame(void) = 0; f@0: f@0: /** draws the haptic cursor, namely the haptic device proxy */ f@0: virtual void drawCursor(void) = 0; f@0: f@0: /** f@0: * Draws one frame both graphic and haptic. f@0: * f@0: * messageUpdate and callbacksUpdate are integer codes specifying what f@0: * needs to be updated in the haptic and graphic scenes. messageUpdate f@0: * is the value returned by processMessage and flags that a message from the f@0: * Java thread affects the scene which must therefore be updated. f@0: * f@0: * callbacksUpdate is the value returned by checkCallbacks f@0: * and flags that a haptic event happened that affects the scene, f@0: * which must therefore be updated. f@0: */ f@0: virtual void drawScene(unsigned int messageUpdate, unsigned int callbacksUpdate) = 0; f@0: f@0: /** Checks for haptic callbacks, namely functions that are called when f@0: * a haptic events occurs. Typical haptic events are proxy touching an f@0: * object, proxy moving, button pressed etc. f@0: * f@0: * Returns an update code if any event changes the f@0: * scene. The code is passed in the next frame to drawScene(), f@0: * for updating the scene accordingly. f@0: * f@0: */ f@0: virtual unsigned int checkCallbacks(void) = 0; f@0: f@0: }; f@0: f@0: }