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

/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
25#include <meteor.hh>
26#include <resources.hh>
27#include <skyrocket.hh>
28#include <star.hh>
29#include <vector.hh>
30
31void Meteor::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	_vel.y() -= Common::elapsedTime * 32.0f;
41	_pos += _vel * Common::elapsedTime;
42	_pos.x() +=
43		(0.1f - 0.00175f * _pos.y() + 0.0000011f * _pos.y() * _pos.y()) *
44		Hack::wind * Common::elapsedTime;
45
46	float temp = (_lifetime - _remaining) / _lifetime;
47	_brightness = 1.0f - temp * temp * temp * temp;
48
49	Vector step(_pos - _sparkPos);
50	float distance = step.normalize();
51
52	if (distance > 10.0f) {
53		unsigned int n = (unsigned int)(distance / 10.0f);
54		step *= 10.0f;
55		for (unsigned int i = 0; i < n; ++i) {
56			Hack::pending.push_back(new Star(_sparkPos,
57				_vel + Vector(
58					Common::randomFloat(40.0f) - 20.0f,
59					Common::randomFloat(40.0f) - 20.0f,
60					Common::randomFloat(40.0f) - 20.0f
61				), 2.0f, Common::randomFloat(0.5f) + 1.5f, _RGB, 10.0f
62			));
63			_sparkPos += step;
64		}
65	}
66
67	Vector diff(Hack::cameraPos - _pos);
68	_depth = diff.x() * Hack::cameraMat.get(8) +
69		diff.y() * Hack::cameraMat.get(9) +
70		diff.z() * Hack::cameraMat.get(10);
71}
72
73void Meteor::updateCameraOnly() {
74	Vector diff(Hack::cameraPos - _pos);
75	_depth = diff.x() * Hack::cameraMat.get(8) +
76		diff.y() * Hack::cameraMat.get(9) +
77		diff.z() * Hack::cameraMat.get(10);
78}
79
80void Meteor::draw() const {
81	if (_depth < 0.0f)
82		return;
83
84	glPushMatrix();
85		glTranslatef(_pos.x(), _pos.y(), _pos.z());
86		glScalef(_size, _size, _size);
87		glMultMatrixf(Hack::cameraMat.get());
88		glColor4f(_RGB.r(), _RGB.g(), _RGB.b(), _brightness);
89		glCallList(Resources::DisplayLists::flares);
90	glPopMatrix();
91}