PageRenderTime 30ms CodeModel.GetById 16ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/newview/llphysicsshapebuilderutil.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 138 lines | 78 code | 31 blank | 29 comment | 14 complexity | 7413b03bd72ee84eecf227e90e9d8f6d MD5 | raw file
  1/** 
  2 * @file llphysicsshapebuilder.h
  3 * @brief Generic system to convert LL(Physics)VolumeParams to physics shapes
  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_PHYSICS_SHAPE_BUILDER_H
 28#define LL_PHYSICS_SHAPE_BUILDER_H
 29
 30#include "indra_constants.h"
 31#include "llvolume.h"
 32
 33#define USE_SHAPE_QUANTIZATION 0
 34
 35#define SHAPE_BUILDER_DEFAULT_VOLUME_DETAIL 1
 36
 37#define SHAPE_BUILDER_IMPLICIT_THRESHOLD_HOLLOW 0.10f
 38#define SHAPE_BUILDER_IMPLICIT_THRESHOLD_HOLLOW_SPHERES 0.90f
 39#define SHAPE_BUILDER_IMPLICIT_THRESHOLD_PATH_CUT 0.05f
 40#define SHAPE_BUILDER_IMPLICIT_THRESHOLD_TAPER 0.05f
 41#define SHAPE_BUILDER_IMPLICIT_THRESHOLD_TWIST 0.09f
 42#define SHAPE_BUILDER_IMPLICIT_THRESHOLD_SHEAR 0.05f
 43
 44const F32 SHAPE_BUILDER_ENTRY_SNAP_SCALE_BIN_SIZE = 0.15f;
 45const F32 SHAPE_BUILDER_ENTRY_SNAP_PARAMETER_BIN_SIZE = 0.010f;
 46const F32 SHAPE_BUILDER_CONVEXIFICATION_SIZE = 2.f * COLLISION_TOLERANCE;
 47const F32 SHAPE_BUILDER_MIN_GEOMETRY_SIZE = 0.5f * COLLISION_TOLERANCE;
 48
 49class LLPhysicsVolumeParams : public LLVolumeParams
 50{
 51public:
 52
 53	LLPhysicsVolumeParams( const LLVolumeParams& params, bool forceConvex ) : 
 54		LLVolumeParams( params ),
 55		mForceConvex(forceConvex) {}
 56
 57	bool operator==(const LLPhysicsVolumeParams &params) const
 58	{
 59		return ( LLVolumeParams::operator==(params) && (mForceConvex == params.mForceConvex) );
 60	}
 61
 62	bool operator!=(const LLPhysicsVolumeParams &params) const
 63	{
 64		return !operator==(params);
 65	}
 66
 67	bool operator<(const LLPhysicsVolumeParams &params) const
 68	{
 69		if ( LLVolumeParams::operator!=(params) )
 70		{
 71			return LLVolumeParams::operator<(params);
 72		}
 73		return (params.mForceConvex == false) && (mForceConvex == true);	
 74	}
 75
 76	bool shouldForceConvex() const { return mForceConvex; }
 77
 78private:
 79	bool mForceConvex;
 80};
 81
 82
 83class LLPhysicsShapeBuilderUtil
 84{
 85public:
 86
 87	class PhysicsShapeSpecification
 88	{
 89	public:
 90		enum ShapeType
 91		{
 92			// Primitive types
 93			BOX,
 94			SPHERE,
 95			CYLINDER,
 96
 97			USER_CONVEX,	// User specified they wanted the convex hull of the volume
 98
 99			PRIM_CONVEX,	// Either a volume that is inherently convex but not a primitive type, or a shape
100							// with dimensions such that will convexify it anyway.
101
102 			SCULPT,			// Special case for traditional sculpts--they are the convex hull of a single particular set of volume params
103
104			USER_MESH,		// A user mesh. May or may not contain a convex decomposition.
105
106			PRIM_MESH,		// A non-convex volume which we have to represent accurately
107
108			INVALID
109		};
110
111		PhysicsShapeSpecification() : 
112		mType( INVALID ),
113		mScale( 0.f, 0.f, 0.f ),
114		mCenter( 0.f, 0.f, 0.f ) {}
115		
116		bool isConvex() { return (mType != USER_MESH && mType != PRIM_MESH && mType != INVALID); }
117		bool isMesh() { return (mType == USER_MESH) || (mType == PRIM_MESH); }
118
119		ShapeType getType() { return mType; }
120		const LLVector3& getScale() { return mScale; }
121		const LLVector3& getCenter() { return mCenter; }
122
123	private:
124		friend class LLPhysicsShapeBuilderUtil;
125
126		ShapeType	mType;
127
128		// Dimensions of an AABB around the shape
129		LLVector3	mScale;
130
131		// Offset of shape from origin of primitive's reference frame
132		LLVector3	mCenter;
133	};
134
135	static void determinePhysicsShape( const LLPhysicsVolumeParams& volume_params, const LLVector3& scale, PhysicsShapeSpecification& specOut );
136};
137
138#endif //LL_PHYSICS_SHAPE_BUILDER_H