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

/indra/llmath/llsphere.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 77 lines | 29 code | 15 blank | 33 comment | 0 complexity | 3fa6442a08a5253c43d2b6b3966e51a7 MD5 | raw file
 1// llsphere.h
 2/**
 3 * @file llsphere.cpp
 4 * @author Andrew Meadows
 5 * @brief Simple sphere implementation for basic geometric operations
 6 *
 7 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
 8 * Second Life Viewer Source Code
 9 * Copyright (C) 2010, Linden Research, Inc.
10 * 
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation;
14 * version 2.1 of the License only.
15 * 
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 * Lesser General Public License for more details.
20 * 
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24 * 
25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
26 * $/LicenseInfo$
27 */
28
29#ifndef LL_SPHERE_H
30#define LL_SPHERE_H
31
32#include "stdtypes.h"
33#include "v3math.h"
34#include <iostream>
35#include <vector>
36
37class LLSphere
38{
39public:
40	LLSphere();
41	LLSphere( const LLVector3& center, F32 radius );
42
43	void set( const LLVector3& center, F32 radius );
44	void setCenter( const LLVector3& center );
45	void setRadius( F32 radius );
46
47	const LLVector3& getCenter() const;
48	F32 getRadius() const;
49
50	// returns TRUE if this sphere completely contains other_sphere
51	BOOL contains(const LLSphere& other_sphere) const;
52
53	// returns TRUE if this sphere overlaps other_sphere
54	BOOL overlaps(const LLSphere& other_sphere) const;
55
56	// returns overlap distance
57	// negative overlap is closest approach
58	F32 getOverlap(const LLSphere& other_sphere) const;
59
60	// removes any spheres that are contained in others
61	static void collapse(std::vector<LLSphere>& sphere_list);
62
63	// returns minimum sphere bounding sphere for a set of spheres
64	static LLSphere getBoundingSphere(const LLSphere& first_sphere, const LLSphere& second_sphere);
65	static LLSphere getBoundingSphere(const std::vector<LLSphere>& sphere_list);
66
67	bool operator==(const LLSphere& rhs) const;
68
69	friend std::ostream& operator<<( std::ostream& output_stream, const LLSphere& line );
70
71protected:
72	LLVector3 mCenter;
73	F32 mRadius;
74};
75
76
77#endif