CommonExampleInterface.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef COMMON_EXAMPLE_INTERFACE_H
  2. #define COMMON_EXAMPLE_INTERFACE_H
  3. struct CommonExampleOptions
  4. {
  5. struct GUIHelperInterface* m_guiHelper;
  6. //Those are optional, some examples will use them others don't. Each example should work with them being 0.
  7. int m_option;
  8. const char* m_fileName;
  9. class SharedMemoryInterface* m_sharedMem;
  10. CommonExampleOptions(struct GUIHelperInterface* helper, int option=0)
  11. :m_guiHelper(helper),
  12. m_option(option),
  13. m_fileName(0),
  14. m_sharedMem(0)
  15. {
  16. }
  17. };
  18. class CommonExampleInterface
  19. {
  20. public:
  21. typedef class CommonExampleInterface* (CreateFunc)(CommonExampleOptions& options);
  22. virtual ~CommonExampleInterface()
  23. {
  24. }
  25. virtual void initPhysics()=0;
  26. virtual void exitPhysics()=0;
  27. virtual void stepSimulation(float deltaTime)=0;
  28. virtual void renderScene()=0;
  29. virtual void physicsDebugDraw(int debugFlags)=0;//for now we reuse the flags in Bullet/src/LinearMath/btIDebugDraw.h
  30. //reset camera is only called when switching demo. this way you can restart (initPhysics) and watch in a specific location easier
  31. virtual void resetCamera(){};
  32. virtual bool mouseMoveCallback(float x,float y)=0;
  33. virtual bool mouseButtonCallback(int button, int state, float x, float y)=0;
  34. virtual bool keyboardCallback(int key, int state)=0;
  35. virtual void vrControllerMoveCallback(int controllerId, float pos[4], float orientation[4], float analogAxis) {}
  36. virtual void vrControllerButtonCallback(int controllerId, int button, int state, float pos[4], float orientation[4]){}
  37. virtual void processCommandLineArgs(int argc, char* argv[]){};
  38. };
  39. class ExampleEntries
  40. {
  41. public:
  42. virtual ~ExampleEntries() {}
  43. virtual void initExampleEntries()=0;
  44. virtual void initOpenCLExampleEntries()=0;
  45. virtual int getNumRegisteredExamples()=0;
  46. virtual CommonExampleInterface::CreateFunc* getExampleCreateFunc(int index)=0;
  47. virtual const char* getExampleName(int index)=0;
  48. virtual const char* getExampleDescription(int index)=0;
  49. virtual int getExampleOption(int index)=0;
  50. };
  51. CommonExampleInterface* StandaloneExampleCreateFunc(CommonExampleOptions& options);
  52. #ifdef B3_USE_STANDALONE_EXAMPLE
  53. #define B3_STANDALONE_EXAMPLE(ExampleFunc) CommonExampleInterface* StandaloneExampleCreateFunc(CommonExampleOptions& options)\
  54. {\
  55. return ExampleFunc(options);\
  56. }
  57. #else//B3_USE_STANDALONE_EXAMPLE
  58. #define B3_STANDALONE_EXAMPLE(ExampleFunc)
  59. #endif //B3_USE_STANDALONE_EXAMPLE
  60. #endif //COMMON_EXAMPLE_INTERFACE_H