/xbmc/screensavers/rsxs-0.9/src/implicit.hh

http://github.com/xbmc/xbmc · C++ Header · 128 lines · 89 code · 17 blank · 22 comment · 2 complexity · c5ae245b8011e42e187a66caba55dca1 MD5 · raw file

  1. /*
  2. * Really Slick XScreenSavers
  3. * Copyright (C) 2002-2006 Michael Chapman
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. *****************************************************************************
  19. *
  20. * This is a Linux port of the Really Slick Screensavers,
  21. * Copyright (C) 2002 Terence M. Welsh, available from www.reallyslick.com
  22. */
  23. #ifndef _IMPLICIT_HH
  24. #define _IMPLICIT_HH
  25. #include <common.hh>
  26. #include <color.hh>
  27. #include <memory>
  28. #include <vector.hh>
  29. typedef float (*ImplicitField)(const Vector&);
  30. typedef std::list<Vector> CrawlPointVector;
  31. template <typename T> class LazyVector {
  32. private:
  33. T* _data;
  34. unsigned int _used, _capacity;
  35. public:
  36. LazyVector() : _data(new T[1000]), _used(0), _capacity(1000) {}
  37. LazyVector(const LazyVector& lv) : _data(new T[lv._capacity]),
  38. _used(lv._used), _capacity(lv._capacity) {
  39. std::copy(lv._data, lv._data + _used, _data);
  40. }
  41. ~LazyVector() { delete[] _data; }
  42. void reset() { _used = 0; }
  43. unsigned int size() const { return _used; }
  44. typedef const T* const_iterator;
  45. const T* begin() const { return _data; }
  46. const T* end() const { return _data + _used; }
  47. void push_back(const T& v) {
  48. if (_used == _capacity) {
  49. _capacity += 1000;
  50. T* temp = new T[_capacity];
  51. std::uninitialized_copy(_data, _data + _used, temp);
  52. delete[] _data;
  53. _data = temp;
  54. }
  55. _data[_used++] = v;
  56. }
  57. };
  58. enum Axis {
  59. X_AXIS,
  60. Y_AXIS,
  61. Z_AXIS
  62. };
  63. class Implicit : public ResourceManager::Resource<void> {
  64. private:
  65. static unsigned int _width, _height, _length;
  66. static unsigned int _width1, _height1, _length1;
  67. static Vector _lbf;
  68. static float _cw;
  69. static unsigned int _cubeTable[256][17];
  70. static bool _crawlTable[256][6];
  71. public:
  72. static void init(unsigned int, unsigned int, unsigned int, float);
  73. void operator()() const {}
  74. private:
  75. struct Info {
  76. struct Cube {
  77. unsigned int serial;
  78. unsigned char mask;
  79. } cube;
  80. struct Corner {
  81. unsigned int serial;
  82. float value;
  83. Vector XYZ;
  84. } corner;
  85. struct Edge {
  86. unsigned int serial;
  87. unsigned int index;
  88. } edge[3];
  89. };
  90. std::vector<Info> _info;
  91. struct VertexData {
  92. float nx, ny, nz;
  93. float x, y, z;
  94. };
  95. unsigned int _serial;
  96. ImplicitField _field;
  97. float _threshold;
  98. LazyVector<VertexData> _vertices;
  99. LazyVector<unsigned int> _indices;
  100. LazyVector<unsigned int> _lengths;
  101. inline unsigned char calculateCube(unsigned int);
  102. inline void crawl(unsigned int, unsigned int, unsigned int);
  103. inline void polygonize(unsigned int);
  104. inline void addVertex(Axis, unsigned int);
  105. public:
  106. Implicit(ImplicitField);
  107. void update(float, const CrawlPointVector&);
  108. void update(float);
  109. void draw(GLenum = GL_TRIANGLE_STRIP) const;
  110. };
  111. #endif // _IMPLICIT_HH