PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/xbmc/screensavers/rsxs-0.9/src/lattice/camera.hh

http://github.com/xbmc/xbmc
C++ Header | 60 lines | 27 code | 9 blank | 24 comment | 0 complexity | d5a2ee496369e0482b6bbe444f9e6a1c 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 _CAMERA_HH
24#define _CAMERA_HH
25
26#include <common.hh>
27
28#include <vector.hh>
29
30namespace Camera {
31	float _farPlane;
32	Vector _cullVec[4];	// vectors perpendicular to viewing volume planes
33
34	void set(const float* m, float farPlane) {
35		_farPlane = farPlane;
36
37		float temp;
38
39		// bottom and planes' vectors
40		temp = std::atan(1.0f / m[5]);
41		_cullVec[0].set(0.0f, std::cos(temp), -std::sin(temp));
42		_cullVec[1].set(0.0f, -std::cos(temp), -std::sin(temp));
43
44		// left and right planes' vectors
45		temp = std::atan(1.0f / m[0]);
46		_cullVec[2].set(std::cos(temp), 0.0f, -std::sin(temp));
47		_cullVec[3].set(-std::cos(temp), 0.0f,-std::sin(temp));
48	}
49
50	bool isVisible(const Vector& pos, float radius) {
51		return
52			pos.z() >= -(_farPlane + radius) &&
53			Vector::dot(pos, _cullVec[0]) >= -radius &&
54			Vector::dot(pos, _cullVec[1]) >= -radius &&
55			Vector::dot(pos, _cullVec[2]) >= -radius &&
56			Vector::dot(pos, _cullVec[3]) >= -radius;
57	}
58};
59
60#endif // _CAMERA_HH