Cursor.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "Cursor.h"
  2. #include <GL/freeglut.h>
  3. #include <cmath>
  4. #include "CrystalPoint.h"
  5. Cursor* Cursor::instance = NULL;
  6. Cursor::Cursor()
  7. {
  8. enabled = false;
  9. }
  10. Cursor::~Cursor()
  11. {
  12. }
  13. Cursor* Cursor::getInstance(void)
  14. {
  15. if (instance == nullptr)
  16. instance = new Cursor();
  17. return instance;
  18. }
  19. void Cursor::enable(bool enable)
  20. {
  21. enabled = enable;
  22. }
  23. bool Cursor::isEnabled(void)
  24. {
  25. return enabled;
  26. }
  27. void Cursor::draw(void)
  28. {
  29. //Draw Cursor
  30. glMatrixMode(GL_PROJECTION);
  31. glLoadIdentity();
  32. glOrtho(0, CrystalPoint::width, CrystalPoint::height, 0, -10, 10);
  33. glMatrixMode(GL_MODELVIEW);
  34. glLoadIdentity();
  35. glDisable(GL_LIGHTING);
  36. glDisable(GL_DEPTH_TEST);
  37. glColor4f(1, cos(glutGet(GLUT_ELAPSED_TIME) / 1000.0f), sin(glutGet(GLUT_ELAPSED_TIME) / 1000.0f), 1);
  38. glBegin(GL_TRIANGLES);
  39. glVertex2f(mousePosition.x, mousePosition.y);
  40. glVertex2f(mousePosition.x + 15, mousePosition.y + 15);
  41. glVertex2f(mousePosition.x + 5, mousePosition.y + 20);
  42. glEnd();
  43. }
  44. void Cursor::update(Vec2f newPosition)
  45. {
  46. mousePosition = newPosition;
  47. }