private void AddWidgetInfo(Widget widget) { int num = Enum.GetNames(typeof(SpringType)).Length; LiveSpringPanel.WidgetInfo widgetInfo = new LiveSpringPanel.WidgetInfo { originalPivot = widget.PivotType, weight = 200f, springConstants = new float[num], dampingConstants = new float[num], springLimitations = new float[num], velocities = new float[num], displacements = new float[num], useSpecifiedValues = new bool[num], prevDisplacements = new float[num] }; this.widgetInfos.Add(widget, widgetInfo); foreach (SpringType type in Enum.GetValues(typeof(SpringType))) { this.SetSpringConstant(widget, type, this.defaultSpringConstant); this.SetDampingConstant(widget, type, this.defaultDampingConstant); } widget.PivotType = PivotType.MiddleCenter; widgetInfo.originalPos = widget.Transform3D.ColumnW.Xyz; widgetInfo.prevTransform3D = widget.Transform3D; widget.PivotType = widgetInfo.originalPivot; }
private void UpdateWidgetsPosition(Widget widget, float elapsedTime) { LiveSpringPanel.WidgetInfo widgetInfo = this.widgetInfos[widget]; widgetInfo.originalPivot = widget.PivotType; widget.PivotType = PivotType.MiddleCenter; if (widgetInfo.prevTransform3D != widget.Transform3D) { widgetInfo.originalPos = (Matrix4.Translation(-widgetInfo.prevDisplacements[3], -widgetInfo.prevDisplacements[4], -widgetInfo.prevDisplacements[5]) * widget.Transform3D * Matrix4.RotationXyz(-widgetInfo.prevDisplacements[0], -widgetInfo.prevDisplacements[1], -widgetInfo.prevDisplacements[2])).ColumnW.Xyz; } foreach (SpringType springType in Enum.GetValues(typeof(SpringType))) { if (widgetInfo.useSpecifiedValues[(int)springType]) { widgetInfo.useSpecifiedValues[(int)springType] = false; } else { float num = this.CalculateExternalAcceleration(widgetInfo, springType); float num2 = (-widgetInfo.springConstants[(int)springType] * widgetInfo.displacements[(int)springType] + widgetInfo.dampingConstants[(int)springType] * widgetInfo.velocities[(int)springType]) / widgetInfo.weight + num; widgetInfo.velocities[(int)springType] += num2 * elapsedTime; widgetInfo.displacements[(int)springType] += widgetInfo.velocities[(int)springType]; widgetInfo.displacements[(int)springType] *= widgetInfo.springLimitations[(int)springType]; } widgetInfo.prevDisplacements[(int)springType] = widgetInfo.displacements[(int)springType]; } float num3 = widgetInfo.displacements[3]; float num4 = widgetInfo.displacements[4]; float num5 = widgetInfo.displacements[5]; float num6 = widgetInfo.displacements[0]; float num7 = widgetInfo.displacements[1]; float num8 = widgetInfo.displacements[2]; widget.Transform3D = Matrix4.Translation(num3, num4, num5) * Matrix4.Translation(widgetInfo.originalPos) * Matrix4.RotationXyz(num6, num7, num8); widgetInfo.prevTransform3D = widget.Transform3D; widget.PivotType = widgetInfo.originalPivot; }
private float CalculateExternalAcceleration(LiveSpringPanel.WidgetInfo info, SpringType type) { float acceleration = 0f; switch (type) { case SpringType.AngleAxisX: case SpringType.PositionY: acceleration = this.sensorAcceleration.Y + this.moveAcceleration.Y + this.userAcceleration.Y; break; case SpringType.AngleAxisY: acceleration = -(this.sensorAcceleration.X + this.moveAcceleration.X + this.userAcceleration.X); break; case SpringType.AngleAxisZ: { bool flag = false; bool[] useSpecifiedValues = info.useSpecifiedValues; for (int i = 0; i < useSpecifiedValues.Length; i++) { bool flag2 = useSpecifiedValues[i]; flag |= flag2; } if (!flag) { float num = info.displacements[3]; float num2 = info.displacements[4]; float num3 = FMath.Abs(num); float num4 = FMath.Abs(num2); bool flag3; if (num * num2 > 0f) { flag3 = (num3 > num4); } else { flag3 = (num3 < num4); } float num5 = FMath.Min(FMath.Abs(num3 - num4), FMath.Min(num3, num4)) / 200f; float num6 = flag3 ? num5 : (-num5); float num7 = info.displacements[0]; float num8 = info.displacements[1]; float num9 = FMath.Abs(num7); float num10 = FMath.Abs(num8); if (-num7 * num8 > 0f) { flag3 = (num9 < num10); } else { flag3 = (num9 > num10); } num5 = FMath.Min(FMath.Abs(num9 - num10), FMath.Min(num9, num10)) / 20f; float num11 = flag3 ? num5 : (-num5); acceleration = num6 + num11; } break; } case SpringType.PositionX: acceleration = this.sensorAcceleration.X + this.moveAcceleration.X + this.userAcceleration.X; break; case SpringType.PositionZ: acceleration = this.sensorAcceleration.Z + this.moveAcceleration.Z + this.userAcceleration.Z; break; } if (type == SpringType.PositionX || type == SpringType.PositionY || type == SpringType.PositionZ) { return(this.ClipAcceleration(acceleration)); } return(this.ClipAcceleration(acceleration) * 0.0125663709f); }