2
0

WaterSample.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef WATERSAMPLE_H_
  2. #define WATERSAMPLE_H_
  3. #include "gameplay.h"
  4. #include "Sample.h"
  5. using namespace gameplay;
  6. /**
  7. * Sample creating a water effect.
  8. */
  9. class WaterSample : public Sample
  10. {
  11. public:
  12. WaterSample();
  13. void touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex);
  14. void keyEvent(Keyboard::KeyEvent evt, int key);
  15. bool mouseEvent(Mouse::MouseEvent evt, int x, int y, int wheelDelta);
  16. void gamepadEvent(Gamepad::GamepadEvent evt, Gamepad* gamepad);
  17. protected:
  18. void initialize();
  19. void finalize();
  20. void update(float elapsedTime);
  21. void render(float elapsedTime);
  22. private:
  23. enum CameraMovement
  24. {
  25. MOVE_FORWARD = (1 << 0),
  26. MOVE_BACKWARD = (1 << 1),
  27. MOVE_LEFT = (1 << 2),
  28. MOVE_RIGHT = (1 << 3)
  29. };
  30. Font* _font;
  31. Scene* _scene;
  32. Node* _cameraNode;
  33. Node* _reflectCameraNode;
  34. Vector3 _cameraAcceleration;
  35. float _waterHeight;
  36. unsigned _inputMask;
  37. int _prevX, _prevY;
  38. FrameBuffer* _refractBuffer;
  39. SpriteBatch* _refractBatch;
  40. FrameBuffer* _reflectBuffer;
  41. SpriteBatch* _reflectBatch;
  42. bool _showBuffers;
  43. Vector4 _clipPlane;
  44. const Vector4& getClipPlane() const
  45. {
  46. return _clipPlane;
  47. }
  48. Matrix m_worldViewProjectionReflection;
  49. const Matrix& getReflectionMatrix() const
  50. {
  51. return m_worldViewProjectionReflection;
  52. }
  53. float getTime() const
  54. {
  55. return Game::getGameTime() * 0.0001;
  56. }
  57. Gamepad* _gamepad;
  58. bool drawScene(Node* node, bool drawWater);
  59. };
  60. #endif