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

/indra/llmath/llbbox.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 101 lines | 46 code | 22 blank | 33 comment | 0 complexity | 11e0965d6f4c128dd7d94097a771d2a6 MD5 | raw file
  1/** 
  2 * @file llbbox.h
  3 * @brief General purpose bounding box class
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_BBOX_H
 28#define LL_BBOX_H
 29
 30#include "v3math.h"
 31#include "llquaternion.h"
 32
 33// Note: "local space" for an LLBBox is defined relative to agent space in terms of
 34// a translation followed by a rotation.  There is no scale term since the LLBBox's min and 
 35// max are not necessarily symetrical and define their own extents.
 36
 37class LLBBox
 38{
 39public:
 40	LLBBox() {mEmpty = TRUE;}
 41	LLBBox( const LLVector3& pos_agent,
 42		const LLQuaternion& rot,
 43		const LLVector3& min_local,
 44		const LLVector3& max_local )
 45		:
 46		mMinLocal( min_local ), mMaxLocal( max_local ), mPosAgent(pos_agent), mRotation( rot), mEmpty( TRUE )
 47		{}
 48
 49	// Default copy constructor is OK.
 50
 51	const LLVector3&	getPositionAgent() const			{ return mPosAgent; }
 52	const LLQuaternion&	getRotation() const					{ return mRotation; }
 53
 54	LLVector3           getMinAgent() const;
 55	const LLVector3&	getMinLocal() const					{ return mMinLocal; }
 56	void				setMinLocal( const LLVector3& min )	{ mMinLocal = min; }
 57
 58	LLVector3           getMaxAgent() const;
 59	const LLVector3&	getMaxLocal() const					{ return mMaxLocal; }
 60	void				setMaxLocal( const LLVector3& max )	{ mMaxLocal = max; }
 61
 62	LLVector3			getCenterLocal() const				{ return (mMaxLocal - mMinLocal) * 0.5f + mMinLocal; }
 63	LLVector3			getCenterAgent() const				{ return localToAgent( getCenterLocal() ); }
 64
 65	LLVector3			getExtentLocal() const				{ return mMaxLocal - mMinLocal; }
 66
 67	BOOL				containsPointLocal(const LLVector3& p) const;
 68	BOOL				containsPointAgent(const LLVector3& p) const;
 69
 70	void				addPointAgent(LLVector3 p);
 71	void				addBBoxAgent(const LLBBox& b);
 72	
 73	void				addPointLocal(const LLVector3& p);
 74	void				addBBoxLocal(const LLBBox& b) {	addPointLocal( b.mMinLocal ); addPointLocal( b.mMaxLocal ); }
 75
 76	void				expand( F32 delta );
 77
 78	LLVector3			localToAgent( const LLVector3& v ) const;
 79	LLVector3			agentToLocal( const LLVector3& v ) const;
 80
 81	// Changes rotation but not position
 82	LLVector3			localToAgentBasis(const LLVector3& v) const;
 83	LLVector3			agentToLocalBasis(const LLVector3& v) const;
 84
 85	// Get the smallest possible axis aligned bbox that contains this bbox
 86	LLBBox              getAxisAligned() const;
 87
 88//	friend LLBBox operator*(const LLBBox& a, const LLMatrix4& b);
 89
 90private:
 91	LLVector3			mMinLocal;
 92	LLVector3			mMaxLocal;
 93	LLVector3			mPosAgent;  // Position relative to Agent's Region
 94	LLQuaternion		mRotation;
 95	BOOL				mEmpty;		// Nothing has been added to this bbox yet
 96};
 97
 98//LLBBox operator*(const LLBBox &a, const LLMatrix4 &b);
 99
100
101#endif  // LL_BBOX_H