/xbmc/screensavers/rsxs-0.9/src/skyrocket/meteor.cc

http://github.com/xbmc/xbmc · C++ · 91 lines · 58 code · 11 blank · 22 comment · 5 complexity · a7a00cc8715d16ca41ef9f342046f125 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. #include <common.hh>
  24. #include <meteor.hh>
  25. #include <resources.hh>
  26. #include <skyrocket.hh>
  27. #include <star.hh>
  28. #include <vector.hh>
  29. void Meteor::update() {
  30. _remaining -= Common::elapsedTime;
  31. if (_remaining <= 0.0f || _pos.y() <= 0.0f) {
  32. _depth = DEAD_DEPTH;
  33. ++Hack::numDead;
  34. return;
  35. }
  36. _vel.y() -= Common::elapsedTime * 32.0f;
  37. _pos += _vel * Common::elapsedTime;
  38. _pos.x() +=
  39. (0.1f - 0.00175f * _pos.y() + 0.0000011f * _pos.y() * _pos.y()) *
  40. Hack::wind * Common::elapsedTime;
  41. float temp = (_lifetime - _remaining) / _lifetime;
  42. _brightness = 1.0f - temp * temp * temp * temp;
  43. Vector step(_pos - _sparkPos);
  44. float distance = step.normalize();
  45. if (distance > 10.0f) {
  46. unsigned int n = (unsigned int)(distance / 10.0f);
  47. step *= 10.0f;
  48. for (unsigned int i = 0; i < n; ++i) {
  49. Hack::pending.push_back(new Star(_sparkPos,
  50. _vel + Vector(
  51. Common::randomFloat(40.0f) - 20.0f,
  52. Common::randomFloat(40.0f) - 20.0f,
  53. Common::randomFloat(40.0f) - 20.0f
  54. ), 2.0f, Common::randomFloat(0.5f) + 1.5f, _RGB, 10.0f
  55. ));
  56. _sparkPos += step;
  57. }
  58. }
  59. Vector diff(Hack::cameraPos - _pos);
  60. _depth = diff.x() * Hack::cameraMat.get(8) +
  61. diff.y() * Hack::cameraMat.get(9) +
  62. diff.z() * Hack::cameraMat.get(10);
  63. }
  64. void Meteor::updateCameraOnly() {
  65. Vector diff(Hack::cameraPos - _pos);
  66. _depth = diff.x() * Hack::cameraMat.get(8) +
  67. diff.y() * Hack::cameraMat.get(9) +
  68. diff.z() * Hack::cameraMat.get(10);
  69. }
  70. void Meteor::draw() const {
  71. if (_depth < 0.0f)
  72. return;
  73. glPushMatrix();
  74. glTranslatef(_pos.x(), _pos.y(), _pos.z());
  75. glScalef(_size, _size, _size);
  76. glMultMatrixf(Hack::cameraMat.get());
  77. glColor4f(_RGB.r(), _RGB.g(), _RGB.b(), _brightness);
  78. glCallList(Resources::DisplayLists::flares);
  79. glPopMatrix();
  80. }