PageRenderTime 24ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/xbmc/xbmc
C++ | 101 lines | 68 code | 11 blank | 22 comment | 6 complexity | 7a7b676f5acbb3f4a1d13bc9ef680330 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
 25#include <resources.hh>
 26#include <skyrocket.hh>
 27#include <spinner.hh>
 28#include <star.hh>
 29#include <vector.hh>
 30
 31void Spinner::update() {
 32	_remaining -= Common::elapsedTime;
 33
 34	if (_remaining <= 0.0f || _pos.y() < 0.0f) {
 35		_depth = DEAD_DEPTH;
 36		++Hack::numDead;
 37		return;
 38	}
 39
 40	float life = _remaining / _lifetime;
 41	_brightness = life * life;
 42	float temp = _lifetime - _remaining;
 43	if (temp < 0.5f)
 44		_brightness *= temp * 2.0f;
 45
 46	_vel.y() -= Common::elapsedTime * 32.0f;
 47	_pos += _vel * Common::elapsedTime;
 48	_pos.x() +=
 49		(0.1f - 0.00175f * _pos.y() + 0.0000011f * _pos.y() * _pos.y()) *
 50		Hack::wind * Common::elapsedTime;
 51
 52	Vector crossVector(Vector::cross(Vector(1.0f, 0.0f, 0.0f), _spinAxis));
 53	crossVector.normalize();
 54	crossVector *= 400.0f;
 55
 56	float dr = _radialVelocity * Common::elapsedTime;
 57	_starTimer += Common::elapsedTime * _brightness *
 58		(Common::randomFloat(10.0f) + 90.0f);
 59	unsigned int stars = (unsigned int)(_starTimer);
 60	_starTimer -= float(stars);
 61	for (unsigned int i = 0; i < stars; ++i) {
 62		Hack::pending.push_back(new Star(_pos, _vel - RotationMatrix(
 63			UnitQuat(
 64				_radialPosition + Common::randomFloat(dr),
 65				_spinAxis
 66			)
 67		).transform(crossVector) + Vector(
 68			Common::randomFloat(20.0f) - 10.0f,
 69			Common::randomFloat(20.0f) - 10.0f,
 70			Common::randomFloat(20.0f) - 10.0f
 71		), 0.612f, Common::randomFloat(0.5f) + 1.5f, _RGB, 15.0f));
 72	}
 73	_radialPosition += dr;
 74	if (_radialPosition > M_PI * 2)
 75		_radialPosition -= M_PI * 2;
 76
 77	Vector diff(Hack::cameraPos - _pos);
 78	_depth = diff.x() * Hack::cameraMat.get(8) +
 79		diff.y() * Hack::cameraMat.get(9) +
 80		diff.z() * Hack::cameraMat.get(10);
 81}
 82
 83void Spinner::updateCameraOnly() {
 84	Vector diff(Hack::cameraPos - _pos);
 85	_depth = diff.x() * Hack::cameraMat.get(8) +
 86		diff.y() * Hack::cameraMat.get(9) +
 87		diff.z() * Hack::cameraMat.get(10);
 88}
 89
 90void Spinner::draw() const {
 91	if (_depth < 0.0f)
 92		return;
 93
 94	glPushMatrix();
 95		glTranslatef(_pos.x(), _pos.y(), _pos.z());
 96		glScalef(20.0f, 20.0f, 20.0f);
 97		glMultMatrixf(Hack::cameraMat.get());
 98		glColor4f(_RGB.r(), _RGB.g(), _RGB.b(), _brightness);
 99		glCallList(Resources::DisplayLists::flares);
100	glPopMatrix();
101}