PageRenderTime 36ms CodeModel.GetById 25ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llprimitive/llmaterialtable.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 188 lines | 112 code | 32 blank | 44 comment | 0 complexity | 873b7d47cf028896ac25539ef9e0c2f4 MD5 | raw file
  1/** 
  2 * @file llmaterialtable.h
  3 * @brief Table of material information for the viewer UI
  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_LLMATERIALTABLE_H
 28#define LL_LLMATERIALTABLE_H
 29
 30#include "lluuid.h"
 31#include "llstring.h"
 32
 33#include <list>
 34
 35class LLMaterialInfo;
 36
 37const U32 LLMATERIAL_INFO_NAME_LENGTH = 256;
 38
 39// We've moved toward more reasonable mass values for the Havok4 engine.
 40// The LEGACY_DEFAULT_OBJECT_DENSITY is used to maintain support for
 41// legacy scripts code (llGetMass()) and script energy consumption.
 42const F32 DEFAULT_OBJECT_DENSITY = 1000.0f;			// per m^3
 43const F32 LEGACY_DEFAULT_OBJECT_DENSITY = 10.0f;
 44
 45// Avatars density depends on the collision shape used.  The approximate
 46// legacy volumes of avatars are:
 47// Body_Length Body_Width Body_Fat Leg_Length  Volume(m^3)
 48// -------------------------------------------------------
 49//    min     |   min    |  min   |    min    |   0.123   |
 50//    max     |   max    |  max   |    max    |   0.208   |
 51//
 52// Either the avatar shape must be tweaked to match those volumes
 53// or the DEFAULT_AVATAR_DENSITY must be adjusted to achieve the 
 54// legacy mass.
 55//
 56// The current density appears to be low because the mass and
 57// inertia are computed as if the avatar were a cylinder which
 58// has more volume than the actual collision shape of the avatar.
 59// See the physics engine mass properties code for more info.
 60const F32 DEFAULT_AVATAR_DENSITY = 445.3f;		// was 444.24f;
 61
 62
 63class LLMaterialTable
 64{
 65public:
 66	static const F32 FRICTION_MIN;
 67	static const F32 FRICTION_GLASS;
 68	static const F32 FRICTION_LIGHT;
 69	static const F32 FRICTION_METAL;
 70	static const F32 FRICTION_PLASTIC;
 71	static const F32 FRICTION_WOOD;
 72	static const F32 FRICTION_LAND;
 73	static const F32 FRICTION_STONE;
 74	static const F32 FRICTION_FLESH;
 75	static const F32 FRICTION_RUBBER;
 76	static const F32 FRICTION_MAX;
 77
 78	static const F32 RESTITUTION_MIN;
 79	static const F32 RESTITUTION_LAND;
 80	static const F32 RESTITUTION_FLESH;
 81	static const F32 RESTITUTION_STONE;
 82	static const F32 RESTITUTION_METAL;
 83	static const F32 RESTITUTION_WOOD;
 84	static const F32 RESTITUTION_GLASS;
 85	static const F32 RESTITUTION_PLASTIC;
 86	static const F32 RESTITUTION_LIGHT;
 87	static const F32 RESTITUTION_RUBBER;
 88	static const F32 RESTITUTION_MAX;
 89
 90	typedef std::list<LLMaterialInfo*> info_list_t;
 91	info_list_t mMaterialInfoList;
 92
 93	LLUUID *mCollisionSoundMatrix;
 94	LLUUID *mSlidingSoundMatrix;
 95	LLUUID *mRollingSoundMatrix;
 96
 97	static const F32 DEFAULT_FRICTION;
 98	static const F32 DEFAULT_RESTITUTION;
 99
100public:
101	LLMaterialTable();
102	LLMaterialTable(U8);  // cheat with an overloaded constructor to build our basic table
103	~LLMaterialTable();
104
105	void initBasicTable();
106
107	void initTableTransNames(std::map<std::string, std::string> namemap);
108	
109	BOOL add(U8 mcode, const std::string& name, const LLUUID &uuid);	                 
110	BOOL addCollisionSound(U8 mcode, U8 mcode2, const LLUUID &uuid);
111	BOOL addSlidingSound(U8 mcode, U8 mcode2, const LLUUID &uuid);
112	BOOL addRollingSound(U8 mcode, U8 mcode2, const LLUUID &uuid);
113	BOOL addShatterSound(U8 mcode, const LLUUID &uuid);
114	BOOL addDensity(U8 mcode, const F32 &density);
115	BOOL addFriction(U8 mcode, const F32 &friction);
116	BOOL addRestitution(U8 mcode, const F32 &restitution);
117	BOOL addDamageAndEnergy(U8 mcode, const F32 &hp_mod, const F32 &damage_mod, const F32 &ep_mod);
118
119	LLUUID getDefaultTextureID(const std::string& name);					// LLUUID::null if not found
120	LLUUID getDefaultTextureID(U8 mcode);					// LLUUID::null if not found
121	U8     getMCode(const std::string& name);						// 0 if not found
122	std::string getName(U8 mcode);
123
124	F32 getDensity(U8 mcode);						        // kg/m^3, 0 if not found
125	F32 getFriction(U8 mcode);						        // physics values
126	F32 getRestitution(U8 mcode);						    // physics values
127	F32 getHPMod(U8 mcode);
128	F32 getDamageMod(U8 mcode);
129	F32 getEPMod(U8 mcode);
130
131	LLUUID getCollisionSoundUUID(U8 mcode, U8 mcode2); 
132	LLUUID getSlidingSoundUUID(U8 mcode, U8 mcode2); 
133	LLUUID getRollingSoundUUID(U8 mcode, U8 mcode2); 
134	LLUUID getShatterSoundUUID(U8 mcode);					// LLUUID::null if not found
135
136	LLUUID getGroundCollisionSoundUUID(U8 mcode);
137	LLUUID getGroundSlidingSoundUUID(U8 mcode);
138	LLUUID getGroundRollingSoundUUID(U8 mcode);
139	LLUUID getCollisionParticleUUID(U8 mcode, U8 mcode2);
140	LLUUID getGroundCollisionParticleUUID(U8 mcode);
141
142	static LLMaterialTable basic;
143};
144
145
146class LLMaterialInfo
147{
148public:
149	U8		    mMCode;
150	std::string	mName;
151	LLUUID		mDefaultTextureID;
152	LLUUID		mShatterSoundID;
153	F32         mDensity;           // kg/m^3
154	F32         mFriction;
155	F32         mRestitution;
156
157	// damage and energy constants
158	F32			mHPModifier;		// modifier on mass based HP total
159	F32			mDamageModifier;	// modifier on KE based damage
160	F32			mEPModifier;		// modifier on mass based EP total
161
162	LLMaterialInfo(U8 mcode, const std::string& name, const LLUUID &uuid)
163	{
164		init(mcode,name,uuid);
165	};
166
167	void init(U8 mcode, const std::string& name, const LLUUID &uuid)
168	{
169		mDensity = 1000.f;             // default to 1000.0 (water)
170		mFriction = LLMaterialTable::DEFAULT_FRICTION;
171		mRestitution = LLMaterialTable::DEFAULT_RESTITUTION;
172		mHPModifier = 1.f;
173		mDamageModifier = 1.f;
174		mEPModifier = 1.f;
175
176		mMCode = mcode;
177		mName = name;
178		mDefaultTextureID = uuid;		
179	};
180
181	~LLMaterialInfo()
182	{
183	};
184
185};
186
187#endif
188