00001
00002
00003
00004
00005
00006 namespace NewGamePhysics.Physics
00007 {
00008 using System;
00009 using System.Collections.Generic;
00010 using System.Text;
00011
00015 public enum RotationalFrictionType
00016 {
00020 None,
00021
00025 Linear,
00026
00030 Stribeck
00031 }
00032
00038 public class RotationalFrictionModel
00039 {
00043 private RotationalFrictionType frictionType;
00044
00048 private double linearFrictionCoefficient;
00049
00053 private double stribeckStaticFriction;
00054
00055
00059 private double stribeckFrictionScale;
00060
00065 public double LinearFrictionCoefficient
00066 {
00067 get { return linearFrictionCoefficient; }
00068 }
00069
00074 public double StribeckStaticFriction
00075 {
00076 get { return stribeckStaticFriction; }
00077 }
00078
00083 public double StribeckFrictionScale
00084 {
00085 get { return stribeckFrictionScale; }
00086 }
00087
00092 public RotationalFrictionModel()
00093 {
00094 this.frictionType = RotationalFrictionType.None;
00095 }
00096
00101 public RotationalFrictionModel(RotationalFrictionType f)
00102 {
00103 this.frictionType = f;
00104 switch (f)
00105 {
00106 case RotationalFrictionType.Linear:
00107 this.linearFrictionCoefficient = 0.0005;
00108 break;
00109 case RotationalFrictionType.Stribeck:
00110 this.stribeckStaticFriction = 0.0001;
00111 this.stribeckFrictionScale = 0.0002;
00112 break;
00113 }
00114 }
00115
00119 public void SetNone()
00120 {
00121 this.frictionType = RotationalFrictionType.None;
00122 }
00123
00127 public void SetLinear(double linearFrictionCoefficient)
00128 {
00129 this.frictionType = RotationalFrictionType.Linear;
00130 this.linearFrictionCoefficient = linearFrictionCoefficient;
00131 }
00132
00138 public void SetStribeck(double stribeckStaticFriction, double stribeckFrictionScale)
00139 {
00140 this.frictionType = RotationalFrictionType.Stribeck;
00141 this.stribeckStaticFriction = stribeckStaticFriction;
00142 this.stribeckFrictionScale = stribeckFrictionScale;
00143 }
00144
00150 public double ApplyFriction(double omega)
00151 {
00152
00153 double deltaOmega = 0.0;
00154 double o = Math.Abs(omega);
00155
00156
00157 switch (this.frictionType)
00158 {
00159 case RotationalFrictionType.None:
00160
00161 deltaOmega = 0.0;
00162 break;
00163 case RotationalFrictionType.Linear:
00164
00165 deltaOmega = linearFrictionCoefficient * o;
00166 break;
00167 case RotationalFrictionType.Stribeck:
00168
00169 if (o < stribeckStaticFriction)
00170 {
00171
00172 return 0.0;
00173 }
00174 else
00175 {
00176
00177 deltaOmega = stribeckFrictionScale * (o - Math.Exp(-Math.Pow((o / 0.025), 0.3)) + Math.Pow(2.0 * o, (1 - 0.3)));
00178 }
00179 break;
00180 }
00181
00182
00183 if (omega > 0.0)
00184 {
00185 omega -= deltaOmega;
00186 if (omega < 0.0)
00187 {
00188 omega = 0.0;
00189 }
00190 }
00191 else
00192 {
00193 omega += deltaOmega;
00194 if (omega > 0.0)
00195 {
00196 omega = 0.0;
00197 }
00198 }
00199
00200 return omega;
00201 }
00202 }
00203 }