BulletSim: non-functional commenting and reorganization of material attribute specifications.
							parent
							
								
									7bb5613dc6
								
							
						
					
					
						commit
						6f1f7f0206
					
				|  | @ -50,10 +50,11 @@ public struct MaterialAttributes | |||
|         Avatar, | ||||
|         NumberOfTypes   // the count of types in the enum. | ||||
|     } | ||||
| 
 | ||||
|     // Names must be in the order of the above enum. | ||||
|     public static string[] MaterialNames = { "Stone", "Metal", "Glass", "Wood",  | ||||
|                                      "Flesh", "Plastic", "Rubber", "Light", "Avatar" }; | ||||
|     public static string[] MaterialAttribs = { "Density", "Friction", "Restitution"}; | ||||
|     // These names must coorespond to the lower case field names in the MaterialAttributes | ||||
|     //     structure as reflection is used to select the field to put the value in. | ||||
|     public static readonly string[] MaterialAttribs = { "Density", "Friction", "Restitution"}; | ||||
| 
 | ||||
|     public MaterialAttributes(string t, float d, float f, float r) | ||||
|     { | ||||
|  | @ -70,23 +71,37 @@ public struct MaterialAttributes | |||
| 
 | ||||
| public static class BSMaterials | ||||
| { | ||||
|     public static MaterialAttributes[] Attributes; | ||||
|     // Attributes for each material type | ||||
|     private static readonly MaterialAttributes[] Attributes; | ||||
| 
 | ||||
|     // Map of material name to material type code | ||||
|     public static readonly Dictionary<string, MaterialAttributes.Material> MaterialMap; | ||||
| 
 | ||||
|     static BSMaterials() | ||||
|     { | ||||
|         // Attribute sets for both the non-physical and physical instances of materials. | ||||
|         Attributes = new MaterialAttributes[(int)MaterialAttributes.Material.NumberOfTypes * 2]; | ||||
| 
 | ||||
|         // Map of name to type code. | ||||
|         MaterialMap = new Dictionary<string, MaterialAttributes.Material>(); | ||||
|         MaterialMap.Add("Stone", MaterialAttributes.Material.Stone); | ||||
|         MaterialMap.Add("Metal", MaterialAttributes.Material.Metal); | ||||
|         MaterialMap.Add("Glass", MaterialAttributes.Material.Glass); | ||||
|         MaterialMap.Add("Wood", MaterialAttributes.Material.Wood); | ||||
|         MaterialMap.Add("Flesh", MaterialAttributes.Material.Flesh); | ||||
|         MaterialMap.Add("Plastic", MaterialAttributes.Material.Plastic); | ||||
|         MaterialMap.Add("Rubber", MaterialAttributes.Material.Rubber); | ||||
|         MaterialMap.Add("Light", MaterialAttributes.Material.Light); | ||||
|         MaterialMap.Add("Avatar", MaterialAttributes.Material.Avatar); | ||||
|     } | ||||
| 
 | ||||
|     // This is where all the default material attributes are defined. | ||||
|     public static void InitializeFromDefaults(ConfigurationParameters parms) | ||||
|     { | ||||
|         // Values from http://wiki.secondlife.com/wiki/PRIM_MATERIAL | ||||
|         // public static string[] MaterialNames = { "Stone", "Metal", "Glass", "Wood",  | ||||
|       //                                "Flesh", "Plastic", "Rubber", "Light", "Avatar" }; | ||||
|         float dDensity = parms.defaultDensity; | ||||
|         float dFriction = parms.defaultFriction; | ||||
|         float dRestitution = parms.defaultRestitution; | ||||
|         float dDensity = parms.defaultDensity; | ||||
|         Attributes[(int)MaterialAttributes.Material.Stone] = | ||||
|                     new MaterialAttributes("stone",dDensity, 0.8f, 0.4f); | ||||
|         Attributes[(int)MaterialAttributes.Material.Metal] = | ||||
|  | @ -139,34 +154,34 @@ public static class BSMaterials | |||
|     //    the physical value. | ||||
|     public static void InitializefromParameters(IConfig pConfig) | ||||
|     { | ||||
|         int matType = 0; | ||||
|         foreach (string matName in MaterialAttributes.MaterialNames) | ||||
|         foreach (KeyValuePair<string, MaterialAttributes.Material> kvp in MaterialMap) | ||||
|         { | ||||
|             string matName = kvp.Key; | ||||
|             foreach (string attribName in MaterialAttributes.MaterialAttribs) | ||||
|             { | ||||
|                 string paramName = matName + attribName; | ||||
|                 if (pConfig.Contains(paramName)) | ||||
|                 { | ||||
|                     float paramValue = pConfig.GetFloat(paramName); | ||||
|                     SetAttributeValue(matType, attribName, paramValue); | ||||
|                     SetAttributeValue((int)kvp.Value, attribName, paramValue); | ||||
|                     // set the physical value also | ||||
|                     SetAttributeValue(matType + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue); | ||||
|                     SetAttributeValue((int)kvp.Value + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue); | ||||
|                 } | ||||
|                 paramName += "Physical"; | ||||
|                 if (pConfig.Contains(paramName)) | ||||
|                 { | ||||
|                     float paramValue = pConfig.GetFloat(paramName); | ||||
|                     SetAttributeValue(matType + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue); | ||||
|                     SetAttributeValue((int)kvp.Value + (int)MaterialAttributes.Material.NumberOfTypes, attribName, paramValue); | ||||
|                 } | ||||
|             } | ||||
|             matType++; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     // Use reflection to set the value in the attribute structure. | ||||
|     private static void SetAttributeValue(int matType, string attribName, float val) | ||||
|     { | ||||
|         MaterialAttributes thisAttrib = Attributes[matType]; | ||||
|         FieldInfo fieldInfo = thisAttrib.GetType().GetField(attribName); | ||||
|         FieldInfo fieldInfo = thisAttrib.GetType().GetField(attribName.ToLower()); | ||||
|         if (fieldInfo != null) | ||||
|         { | ||||
|             fieldInfo.SetValue(thisAttrib, val); | ||||
|  | @ -174,12 +189,12 @@ public static class BSMaterials | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     // Given a material type, return a structure of attributes. | ||||
|     public static MaterialAttributes GetAttributes(MaterialAttributes.Material type, bool isPhysical) | ||||
|     { | ||||
|         int ind = (int)type; | ||||
|         if (isPhysical) ind += (int)MaterialAttributes.Material.NumberOfTypes; | ||||
|         return Attributes[ind]; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| } | ||||
|  |  | |||
|  | @ -309,6 +309,7 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters | |||
|             BSMaterials.InitializeFromDefaults(Params); | ||||
|             if (pConfig != null) | ||||
|             { | ||||
|                 // Let the user add new and interesting material property values. | ||||
|                 BSMaterials.InitializefromParameters(pConfig); | ||||
|             } | ||||
|         } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 Robert Adams
						Robert Adams