Widget CreateContentPane(IUIStyle style) { var g = new Grid(style); g.ColumnConstraints.Add(LengthConstraint.Percentage(100)); g.RowConstraints.Add(LengthConstraint.Auto); g.RowConstraints.Add(LengthConstraint.Relative(1)); g.Add(CreateStyleSelector(style), new Point(0, 0)); g.Add(WidgetDemo.CreateRootPanel(style), new Point(0, 1)); return(g); }
public void Auto_Relative_Mixed() { var g = new Grid(LayoutTestStyle.Create()); g.ColumnConstraints.Add(LengthConstraint.Auto); g.ColumnConstraints.Add(LengthConstraint.Relative(1)); g.ColumnConstraints.Add(LengthConstraint.Relative(1)); g.AddChildAt(LayoutTestWidget.FixedSize(100, 10), 0, 0); g.AddChildAt(LayoutTestWidget.FixedSize(200, 10), 1, 0); g.AddChildAt(LayoutTestWidget.FixedSize(10, 10), 2, 0); g.Arrange(new Rectangle(10, 20, 400, 20)); g.DesiredSize.Should().Be(new Size(400, 10)); g.LayoutRect.Should().Be(new Rectangle(10, 20, 400, 10)); g[0].LayoutRect.Should().Be(new Rectangle(10, 20, 100, 10)); g[1].LayoutRect.Should().Be(new Rectangle(110, 20, 150, 10)); g[2].LayoutRect.Should().Be(new Rectangle(260, 20, 150, 10)); }
/// <summary> /// Get metadata for deploying a package to the given resource group /// </summary> /// <param name='parameters'> /// Required. Parameters for operation /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public async Task <GetDeploymentTemplateMetadataResponse> GetMetadataAsync(GetDeploymentMetadataRequest parameters, CancellationToken cancellationToken) { // Validate if (parameters == null) { throw new ArgumentNullException("parameters"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("parameters", parameters); TracingAdapter.Enter(invocationId, this, "GetMetadataAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/subscriptions/"; if (this.Client.Credentials.SubscriptionId != null) { url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId); } url = url + "/providers/Microsoft.AppService/deploymenttemplates/"; if (parameters.MicroserviceId != null) { url = url + Uri.EscapeDataString(parameters.MicroserviceId); } url = url + "/listmetadata"; List <string> queryParameters = new List <string>(); queryParameters.Add("api-version=2015-03-01-preview"); if (queryParameters.Count > 0) { url = url + "?" + string.Join("&", queryParameters); } string baseUrl = this.Client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Post; httpRequest.RequestUri = new Uri(url); // Set Headers // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { TracingAdapter.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { TracingAdapter.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } // Create Result GetDeploymentTemplateMetadataResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new GetDeploymentTemplateMetadataResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { DeploymentTemplateMetadata metadataInstance = new DeploymentTemplateMetadata(); result.Metadata = metadataInstance; JToken valueValue = responseDoc["value"]; if (valueValue != null && valueValue.Type != JTokenType.Null) { JToken microserviceIdValue = valueValue["microserviceId"]; if (microserviceIdValue != null && microserviceIdValue.Type != JTokenType.Null) { string microserviceIdInstance = ((string)microserviceIdValue); metadataInstance.MicroserviceId = microserviceIdInstance; } JToken displayNameValue = valueValue["displayName"]; if (displayNameValue != null && displayNameValue.Type != JTokenType.Null) { string displayNameInstance = ((string)displayNameValue); metadataInstance.DisplayName = displayNameInstance; } JToken appSettingsArray = valueValue["appSettings"]; if (appSettingsArray != null && appSettingsArray.Type != JTokenType.Null) { foreach (JToken appSettingsValue in ((JArray)appSettingsArray)) { ParameterMetadata parameterMetadataInstance = new ParameterMetadata(); metadataInstance.Parameters.Add(parameterMetadataInstance); JToken nameValue = appSettingsValue["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); parameterMetadataInstance.Name = nameInstance; } JToken typeValue = appSettingsValue["type"]; if (typeValue != null && typeValue.Type != JTokenType.Null) { string typeInstance = ((string)typeValue); parameterMetadataInstance.Type = typeInstance; } JToken displayNameValue2 = appSettingsValue["displayName"]; if (displayNameValue2 != null && displayNameValue2.Type != JTokenType.Null) { string displayNameInstance2 = ((string)displayNameValue2); parameterMetadataInstance.DisplayName = displayNameInstance2; } JToken descriptionValue = appSettingsValue["description"]; if (descriptionValue != null && descriptionValue.Type != JTokenType.Null) { string descriptionInstance = ((string)descriptionValue); parameterMetadataInstance.Description = descriptionInstance; } JToken tooltipValue = appSettingsValue["tooltip"]; if (tooltipValue != null && tooltipValue.Type != JTokenType.Null) { string tooltipInstance = ((string)tooltipValue); parameterMetadataInstance.Tooltip = tooltipInstance; } JToken uiHintValue = appSettingsValue["uiHint"]; if (uiHintValue != null && uiHintValue.Type != JTokenType.Null) { string uiHintInstance = ((string)uiHintValue); parameterMetadataInstance.UIHint = uiHintInstance; } JToken defaultValueValue = appSettingsValue["defaultValue"]; if (defaultValueValue != null && defaultValueValue.Type != JTokenType.Null) { string defaultValueInstance = ((string)defaultValueValue); parameterMetadataInstance.DefaultValue = defaultValueInstance; } JToken constraintsValue = appSettingsValue["constraints"]; if (constraintsValue != null && constraintsValue.Type != JTokenType.Null) { ParameterConstraints constraintsInstance = new ParameterConstraints(); parameterMetadataInstance.Constraints = constraintsInstance; JToken requiredValue = constraintsValue["required"]; if (requiredValue != null && requiredValue.Type != JTokenType.Null) { bool requiredInstance = ((bool)requiredValue); constraintsInstance.Required = requiredInstance; } JToken hiddenValue = constraintsValue["hidden"]; if (hiddenValue != null && hiddenValue.Type != JTokenType.Null) { bool hiddenInstance = ((bool)hiddenValue); constraintsInstance.Hidden = hiddenInstance; } JToken allowedValuesArray = constraintsValue["allowedValues"]; if (allowedValuesArray != null && allowedValuesArray.Type != JTokenType.Null) { foreach (JToken allowedValuesValue in ((JArray)allowedValuesArray)) { constraintsInstance.AllowedValues.Add(((string)allowedValuesValue)); } } JToken rangeValue = constraintsValue["range"]; if (rangeValue != null && rangeValue.Type != JTokenType.Null) { RangeConstraint rangeInstance = new RangeConstraint(); constraintsInstance.Range = rangeInstance; JToken lowerBoundValue = rangeValue["lowerBound"]; if (lowerBoundValue != null && lowerBoundValue.Type != JTokenType.Null) { int lowerBoundInstance = ((int)lowerBoundValue); rangeInstance.LowerBound = lowerBoundInstance; } JToken upperBoundValue = rangeValue["upperBound"]; if (upperBoundValue != null && upperBoundValue.Type != JTokenType.Null) { int upperBoundInstance = ((int)upperBoundValue); rangeInstance.UpperBound = upperBoundInstance; } } JToken lengthValue = constraintsValue["length"]; if (lengthValue != null && lengthValue.Type != JTokenType.Null) { LengthConstraint lengthInstance = new LengthConstraint(); constraintsInstance.Length = lengthInstance; JToken minValue = lengthValue["min"]; if (minValue != null && minValue.Type != JTokenType.Null) { int minInstance = ((int)minValue); lengthInstance.Min = minInstance; } JToken maxValue = lengthValue["max"]; if (maxValue != null && maxValue.Type != JTokenType.Null) { int maxInstance = ((int)maxValue); lengthInstance.Max = maxInstance; } } JToken containsCharactersValue = constraintsValue["containsCharacters"]; if (containsCharactersValue != null && containsCharactersValue.Type != JTokenType.Null) { string containsCharactersInstance = ((string)containsCharactersValue); constraintsInstance.ContainsCharacters = containsCharactersInstance; } JToken notContainsCharactersValue = constraintsValue["notContainsCharacters"]; if (notContainsCharactersValue != null && notContainsCharactersValue.Type != JTokenType.Null) { string notContainsCharactersInstance = ((string)notContainsCharactersValue); constraintsInstance.NotContainsCharacters = notContainsCharactersInstance; } JToken hasDigitValue = constraintsValue["hasDigit"]; if (hasDigitValue != null && hasDigitValue.Type != JTokenType.Null) { bool hasDigitInstance = ((bool)hasDigitValue); constraintsInstance.HasDigit = hasDigitInstance; } JToken hasLetterValue = constraintsValue["hasLetter"]; if (hasLetterValue != null && hasLetterValue.Type != JTokenType.Null) { bool hasLetterInstance = ((bool)hasLetterValue); constraintsInstance.HasLetter = hasLetterInstance; } JToken hasPunctuationValue = constraintsValue["hasPunctuation"]; if (hasPunctuationValue != null && hasPunctuationValue.Type != JTokenType.Null) { bool hasPunctuationInstance = ((bool)hasPunctuationValue); constraintsInstance.HasPunctuation = hasPunctuationInstance; } JToken numericValue = constraintsValue["numeric"]; if (numericValue != null && numericValue.Type != JTokenType.Null) { bool numericInstance = ((bool)numericValue); constraintsInstance.Numeric = numericInstance; } } } } JToken dependsOnArray = valueValue["dependsOn"]; if (dependsOnArray != null && dependsOnArray.Type != JTokenType.Null) { foreach (JToken dependsOnValue in ((JArray)dependsOnArray)) { MicroserviceMetadata microserviceMetadataInstance = new MicroserviceMetadata(); metadataInstance.DependsOn.Add(microserviceMetadataInstance); JToken microserviceIdValue2 = dependsOnValue["microserviceId"]; if (microserviceIdValue2 != null && microserviceIdValue2.Type != JTokenType.Null) { string microserviceIdInstance2 = ((string)microserviceIdValue2); microserviceMetadataInstance.MicroserviceId = microserviceIdInstance2; } JToken displayNameValue3 = dependsOnValue["displayName"]; if (displayNameValue3 != null && displayNameValue3.Type != JTokenType.Null) { string displayNameInstance3 = ((string)displayNameValue3); microserviceMetadataInstance.DisplayName = displayNameInstance3; } JToken appSettingsArray2 = dependsOnValue["appSettings"]; if (appSettingsArray2 != null && appSettingsArray2.Type != JTokenType.Null) { foreach (JToken appSettingsValue2 in ((JArray)appSettingsArray2)) { ParameterMetadata parameterMetadataInstance2 = new ParameterMetadata(); microserviceMetadataInstance.Parameters.Add(parameterMetadataInstance2); JToken nameValue2 = appSettingsValue2["name"]; if (nameValue2 != null && nameValue2.Type != JTokenType.Null) { string nameInstance2 = ((string)nameValue2); parameterMetadataInstance2.Name = nameInstance2; } JToken typeValue2 = appSettingsValue2["type"]; if (typeValue2 != null && typeValue2.Type != JTokenType.Null) { string typeInstance2 = ((string)typeValue2); parameterMetadataInstance2.Type = typeInstance2; } JToken displayNameValue4 = appSettingsValue2["displayName"]; if (displayNameValue4 != null && displayNameValue4.Type != JTokenType.Null) { string displayNameInstance4 = ((string)displayNameValue4); parameterMetadataInstance2.DisplayName = displayNameInstance4; } JToken descriptionValue2 = appSettingsValue2["description"]; if (descriptionValue2 != null && descriptionValue2.Type != JTokenType.Null) { string descriptionInstance2 = ((string)descriptionValue2); parameterMetadataInstance2.Description = descriptionInstance2; } JToken tooltipValue2 = appSettingsValue2["tooltip"]; if (tooltipValue2 != null && tooltipValue2.Type != JTokenType.Null) { string tooltipInstance2 = ((string)tooltipValue2); parameterMetadataInstance2.Tooltip = tooltipInstance2; } JToken uiHintValue2 = appSettingsValue2["uiHint"]; if (uiHintValue2 != null && uiHintValue2.Type != JTokenType.Null) { string uiHintInstance2 = ((string)uiHintValue2); parameterMetadataInstance2.UIHint = uiHintInstance2; } JToken defaultValueValue2 = appSettingsValue2["defaultValue"]; if (defaultValueValue2 != null && defaultValueValue2.Type != JTokenType.Null) { string defaultValueInstance2 = ((string)defaultValueValue2); parameterMetadataInstance2.DefaultValue = defaultValueInstance2; } JToken constraintsValue2 = appSettingsValue2["constraints"]; if (constraintsValue2 != null && constraintsValue2.Type != JTokenType.Null) { ParameterConstraints constraintsInstance2 = new ParameterConstraints(); parameterMetadataInstance2.Constraints = constraintsInstance2; JToken requiredValue2 = constraintsValue2["required"]; if (requiredValue2 != null && requiredValue2.Type != JTokenType.Null) { bool requiredInstance2 = ((bool)requiredValue2); constraintsInstance2.Required = requiredInstance2; } JToken hiddenValue2 = constraintsValue2["hidden"]; if (hiddenValue2 != null && hiddenValue2.Type != JTokenType.Null) { bool hiddenInstance2 = ((bool)hiddenValue2); constraintsInstance2.Hidden = hiddenInstance2; } JToken allowedValuesArray2 = constraintsValue2["allowedValues"]; if (allowedValuesArray2 != null && allowedValuesArray2.Type != JTokenType.Null) { foreach (JToken allowedValuesValue2 in ((JArray)allowedValuesArray2)) { constraintsInstance2.AllowedValues.Add(((string)allowedValuesValue2)); } } JToken rangeValue2 = constraintsValue2["range"]; if (rangeValue2 != null && rangeValue2.Type != JTokenType.Null) { RangeConstraint rangeInstance2 = new RangeConstraint(); constraintsInstance2.Range = rangeInstance2; JToken lowerBoundValue2 = rangeValue2["lowerBound"]; if (lowerBoundValue2 != null && lowerBoundValue2.Type != JTokenType.Null) { int lowerBoundInstance2 = ((int)lowerBoundValue2); rangeInstance2.LowerBound = lowerBoundInstance2; } JToken upperBoundValue2 = rangeValue2["upperBound"]; if (upperBoundValue2 != null && upperBoundValue2.Type != JTokenType.Null) { int upperBoundInstance2 = ((int)upperBoundValue2); rangeInstance2.UpperBound = upperBoundInstance2; } } JToken lengthValue2 = constraintsValue2["length"]; if (lengthValue2 != null && lengthValue2.Type != JTokenType.Null) { LengthConstraint lengthInstance2 = new LengthConstraint(); constraintsInstance2.Length = lengthInstance2; JToken minValue2 = lengthValue2["min"]; if (minValue2 != null && minValue2.Type != JTokenType.Null) { int minInstance2 = ((int)minValue2); lengthInstance2.Min = minInstance2; } JToken maxValue2 = lengthValue2["max"]; if (maxValue2 != null && maxValue2.Type != JTokenType.Null) { int maxInstance2 = ((int)maxValue2); lengthInstance2.Max = maxInstance2; } } JToken containsCharactersValue2 = constraintsValue2["containsCharacters"]; if (containsCharactersValue2 != null && containsCharactersValue2.Type != JTokenType.Null) { string containsCharactersInstance2 = ((string)containsCharactersValue2); constraintsInstance2.ContainsCharacters = containsCharactersInstance2; } JToken notContainsCharactersValue2 = constraintsValue2["notContainsCharacters"]; if (notContainsCharactersValue2 != null && notContainsCharactersValue2.Type != JTokenType.Null) { string notContainsCharactersInstance2 = ((string)notContainsCharactersValue2); constraintsInstance2.NotContainsCharacters = notContainsCharactersInstance2; } JToken hasDigitValue2 = constraintsValue2["hasDigit"]; if (hasDigitValue2 != null && hasDigitValue2.Type != JTokenType.Null) { bool hasDigitInstance2 = ((bool)hasDigitValue2); constraintsInstance2.HasDigit = hasDigitInstance2; } JToken hasLetterValue2 = constraintsValue2["hasLetter"]; if (hasLetterValue2 != null && hasLetterValue2.Type != JTokenType.Null) { bool hasLetterInstance2 = ((bool)hasLetterValue2); constraintsInstance2.HasLetter = hasLetterInstance2; } JToken hasPunctuationValue2 = constraintsValue2["hasPunctuation"]; if (hasPunctuationValue2 != null && hasPunctuationValue2.Type != JTokenType.Null) { bool hasPunctuationInstance2 = ((bool)hasPunctuationValue2); constraintsInstance2.HasPunctuation = hasPunctuationInstance2; } JToken numericValue2 = constraintsValue2["numeric"]; if (numericValue2 != null && numericValue2.Type != JTokenType.Null) { bool numericInstance2 = ((bool)numericValue2); constraintsInstance2.Numeric = numericInstance2; } } } } } } } } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { TracingAdapter.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }
void InitFromShape(MegaShape shape) { float len = shape.splines[0].length; // adjust by and pre stretch //Debug.Log("Length " + len + "m"); float volume = len * 2.0f * Mathf.PI * radius; //Debug.Log("Volume " + volume + "m3"); float totalmass = Density * volume; // Option for fill or set count, or count per unit len *= 0.75f; int nummasses = (int)(len / radius) + 1; //Debug.Log("Num Masses " + nummasses); float m = totalmass / (float)nummasses; if (DampingRatio > 1.0f) { DampingRatio = 1.0f; } damp = (DampingRatio * 0.45f) * (2.0f * Mathf.Sqrt(m * spring)); // The Max spring rate is based on m //float dmpratio = damp / (2.0f * Mathf.Sqrt(m * spring)); //Debug.Log("Current Damp Ratio " + dmpratio); //float dmp = DampingRatio * (2.0f * Mathf.Sqrt(m * spring)); //Debug.Log("TotalMass " + totalmass + "kg element mass " + m + "kg damp " + damp); // Mmm or should me move along iters by radius * 2 RopeLength = 0.0f; if (masses == null) { masses = new List <MegaRopeMass>(); } transform.position = Vector3.zero; masses.Clear(); //float ms = Mass / (float)(points + 1); float rlen = 0.0f; Vector3 lastpos = Vector3.zero; for (int i = 0; i <= nummasses; i++) { float alpha = (float)i / (float)nummasses; //points; //Vector3 pos = shape.transform.localToWorldMatrix.MultiplyPoint(shape.InterpCurve3D(0, alpha, true)); Vector3 pos = shape.transform.TransformPoint(shape.InterpCurve3D(0, alpha, true)); if (i != 0) { rlen += Vector3.Distance(lastpos, pos); lastpos = pos; } MegaRopeMass rm = new MegaRopeMass(m, pos); masses.Add(rm); } if (springs == null) { springs = new List <MegaRopeSpring>(); } springs.Clear(); if (constraints == null) { constraints = new List <MegaRopeConstraint>(); } constraints.Clear(); for (int i = 0; i < masses.Count - 1; i++) { MegaRopeSpring spr = new MegaRopeSpring(i, i + 1, spring, damp, this); springs.Add(spr); //spr.restlen = (rlen / masses.Count); // * 1.1f; RopeLength += spr.restlen; LengthConstraint lcon = new LengthConstraint(i, i + 1, spr.restlen); constraints.Add(lcon); } if (stiffsprings) { int gap = 2; for (int i = 0; i < masses.Count - gap; i++) { float alpha = (float)i / (float)masses.Count; // BUG: For a curve shape, len for stuff springs should be sum of springs we span MegaRopeSpring spr = new MegaRopeSpring(i, i + gap, stiffspring * stiffnessCrv.Evaluate(alpha), stiffdamp * stiffnessCrv.Evaluate(alpha), this); //spr.restlen = (springs[i].restlen + springs[i + 1].restlen); // * 1.1f; //spr.restlen = (RopeLength / masses.Count) * 2.0f; //(springs[i].restlen + springs[i + gap].restlen) * 1.0f; // TODO: Add these for rope, not needed for chain springs.Add(spr); LengthConstraint lcon = new LengthConstraint(i, i + gap, spr.restlen); //(RopeLength / masses.Count) * 2.0f); //spr.restlen); constraints.Add(lcon); } } if (top) { top.position = masses[0].pos; float ln = (masses[0].pos - masses[1].pos).magnitude; NewPointConstraint pconn = new NewPointConstraint(0, 1, ln, top.transform); //PointConstraint pconn = new PointConstraint(0, top.transform); constraints.Add(pconn); } if (bottom) { bottom.position = masses[masses.Count - 1].pos; float ln = (masses[masses.Count - 1].pos - masses[masses.Count - 2].pos).magnitude; NewPointConstraint pconn = new NewPointConstraint(masses.Count - 1, masses.Count - 2, ln, bottom.transform); //PointConstraint pconn = new PointConstraint(masses.Count - 1, bottom.transform); constraints.Add(pconn); } // Apply fixed end constraints //PointConstraint pcon = new PointConstraint(0, top.transform); //constraints.Add(pcon); //pcon = new PointConstraint(masses.Count - 1, bottom.transform); //constraints.Add(pcon); //float ln = (masses[0].pos - masses[1].pos).magnitude; //NewPointConstraint pconn = new NewPointConstraint(0, 1, ln, top.transform); //constraints.Add(pconn); //ln = (masses[masses.Count - 1].pos - masses[masses.Count - 2].pos).magnitude; //pconn = new NewPointConstraint(masses.Count - 1, masses.Count - 2, ln, bottom.transform); //constraints.Add(pconn); //ln = (masses[masses.Count - 1].pos - masses[masses.Count - 2].pos).magnitude; //NewPointConstraint pc = new NewPointConstraint(masses.Count / 2, (masses.Count / 2) + 1, ln, middle.transform); //constraints.Add(pc); if (top) { PointConstraint1 pcon1 = new PointConstraint1(); pcon1.p1 = 1; pcon1.off = new Vector3(0.0f, springs[0].restlen, 0.0f); pcon1.obj = top.transform; //.position; //constraints.Add(pcon1); //endcon = pcon1; } masspos = new Vector3[masses.Count + 2]; for (int i = 0; i < masses.Count; i++) { masspos[i + 1] = masses[i].pos; } masspos[0] = masspos[1]; masspos[masspos.Length - 1] = masspos[masspos.Length - 2]; }
public void Init() { if (startShape != null) { InitFromShape(startShape); } else { if (top == null || bottom == null) { return; } Vector3 p1 = top.position; Vector3 p2 = bottom.position; RopeLength = (p1 - p2).magnitude; if (masses == null) { masses = new List <MegaRopeMass>(); } transform.position = Vector3.zero; masses.Clear(); float ms = Mass / (float)(points + 1); for (int i = 0; i <= points; i++) { float alpha = (float)i / (float)points; MegaRopeMass rm = new MegaRopeMass(ms, Vector3.Lerp(p1, p2, alpha)); masses.Add(rm); } if (springs == null) { springs = new List <MegaRopeSpring>(); } springs.Clear(); if (constraints == null) { constraints = new List <MegaRopeConstraint>(); } constraints.Clear(); for (int i = 0; i < masses.Count - 1; i++) { MegaRopeSpring spr = new MegaRopeSpring(i, i + 1, spring, damp, this); springs.Add(spr); LengthConstraint lcon = new LengthConstraint(i, i + 1, spr.restlen); constraints.Add(lcon); } int gap = 2; for (int i = 0; i < masses.Count - gap; i++) { float alpha = (float)i / (float)masses.Count; MegaRopeSpring spr = new MegaRopeSpring(i, i + gap, stiffspring * stiffnessCrv.Evaluate(alpha), stiffdamp * stiffnessCrv.Evaluate(alpha), this); springs.Add(spr); LengthConstraint lcon = new LengthConstraint(i, i + gap, spr.restlen); constraints.Add(lcon); } // Apply fixed end constraints PointConstraint pcon = new PointConstraint(0, top.transform); constraints.Add(pcon); pcon = new PointConstraint(masses.Count - 1, bottom.transform); constraints.Add(pcon); PointConstraint1 pcon1 = new PointConstraint1(); pcon1.p1 = 1; pcon1.off = new Vector3(0.0f, springs[0].restlen, 0.0f); pcon1.obj = top.transform; //.position; constraints.Add(pcon1); endcon = pcon1; masspos = new Vector3[masses.Count + 2]; for (int i = 0; i < masses.Count; i++) { masspos[i + 1] = masses[i].pos; } masspos[0] = masspos[1]; masspos[masspos.Length - 1] = masspos[masspos.Length - 2]; } }
void InitFromShape(MegaShape shape) { float len = shape.splines[0].length; // adjust by and pre stretch //Debug.Log("Length " + len + "m"); float volume = len * 2.0f * Mathf.PI * radius; //Debug.Log("Volume " + volume + "m3"); float totalmass = Density * volume; // Option for fill or set count, or count per unit len *= 0.75f; int nummasses = (int)(len / radius) + 1; //Debug.Log("Num Masses " + nummasses); float m = totalmass / (float)nummasses; if ( DampingRatio > 1.0f ) DampingRatio = 1.0f; damp = (DampingRatio * 0.45f) * (2.0f * Mathf.Sqrt(m * spring)); // The Max spring rate is based on m //float dmpratio = damp / (2.0f * Mathf.Sqrt(m * spring)); //Debug.Log("Current Damp Ratio " + dmpratio); //float dmp = DampingRatio * (2.0f * Mathf.Sqrt(m * spring)); //Debug.Log("TotalMass " + totalmass + "kg element mass " + m + "kg damp " + damp); // Mmm or should me move along iters by radius * 2 RopeLength = 0.0f; if ( masses == null ) masses = new List<MegaRopeMass>(); transform.position = Vector3.zero; masses.Clear(); //float ms = Mass / (float)(points + 1); float rlen = 0.0f; Vector3 lastpos = Vector3.zero; for ( int i = 0; i <= nummasses; i++ ) { float alpha = (float)i / (float)nummasses; //points; //Vector3 pos = shape.transform.localToWorldMatrix.MultiplyPoint(shape.InterpCurve3D(0, alpha, true)); Vector3 pos = shape.transform.TransformPoint(shape.InterpCurve3D(0, alpha, true)); if ( i != 0 ) { rlen += Vector3.Distance(lastpos, pos); lastpos = pos; } MegaRopeMass rm = new MegaRopeMass(m, pos); masses.Add(rm); } if ( springs == null ) springs = new List<MegaRopeSpring>(); springs.Clear(); if ( constraints == null ) constraints = new List<MegaRopeConstraint>(); constraints.Clear(); for ( int i = 0; i < masses.Count - 1; i++ ) { MegaRopeSpring spr = new MegaRopeSpring(i, i + 1, spring, damp, this); springs.Add(spr); //spr.restlen = (rlen / masses.Count); // * 1.1f; RopeLength += spr.restlen; LengthConstraint lcon = new LengthConstraint(i, i + 1, spr.restlen); constraints.Add(lcon); } if ( stiffsprings ) { int gap = 2; for ( int i = 0; i < masses.Count - gap; i++ ) { float alpha = (float)i / (float)masses.Count; // BUG: For a curve shape, len for stuff springs should be sum of springs we span MegaRopeSpring spr = new MegaRopeSpring(i, i + gap, stiffspring * stiffnessCrv.Evaluate(alpha), stiffdamp * stiffnessCrv.Evaluate(alpha), this); //spr.restlen = (springs[i].restlen + springs[i + 1].restlen); // * 1.1f; //spr.restlen = (RopeLength / masses.Count) * 2.0f; //(springs[i].restlen + springs[i + gap].restlen) * 1.0f; // TODO: Add these for rope, not needed for chain springs.Add(spr); LengthConstraint lcon = new LengthConstraint(i, i + gap, spr.restlen); //(RopeLength / masses.Count) * 2.0f); //spr.restlen); constraints.Add(lcon); } } if ( top ) { top.position = masses[0].pos; float ln = (masses[0].pos - masses[1].pos).magnitude; NewPointConstraint pconn = new NewPointConstraint(0, 1, ln, top.transform); //PointConstraint pconn = new PointConstraint(0, top.transform); constraints.Add(pconn); } if ( bottom ) { bottom.position = masses[masses.Count - 1].pos; float ln = (masses[masses.Count - 1].pos - masses[masses.Count - 2].pos).magnitude; NewPointConstraint pconn = new NewPointConstraint(masses.Count - 1, masses.Count - 2, ln, bottom.transform); //PointConstraint pconn = new PointConstraint(masses.Count - 1, bottom.transform); constraints.Add(pconn); } // Apply fixed end constraints //PointConstraint pcon = new PointConstraint(0, top.transform); //constraints.Add(pcon); //pcon = new PointConstraint(masses.Count - 1, bottom.transform); //constraints.Add(pcon); //float ln = (masses[0].pos - masses[1].pos).magnitude; //NewPointConstraint pconn = new NewPointConstraint(0, 1, ln, top.transform); //constraints.Add(pconn); //ln = (masses[masses.Count - 1].pos - masses[masses.Count - 2].pos).magnitude; //pconn = new NewPointConstraint(masses.Count - 1, masses.Count - 2, ln, bottom.transform); //constraints.Add(pconn); //ln = (masses[masses.Count - 1].pos - masses[masses.Count - 2].pos).magnitude; //NewPointConstraint pc = new NewPointConstraint(masses.Count / 2, (masses.Count / 2) + 1, ln, middle.transform); //constraints.Add(pc); if ( top ) { PointConstraint1 pcon1 = new PointConstraint1(); pcon1.p1 = 1; pcon1.off = new Vector3(0.0f, springs[0].restlen, 0.0f); pcon1.obj = top.transform; //.position; //constraints.Add(pcon1); //endcon = pcon1; } masspos = new Vector3[masses.Count + 2]; for ( int i = 0; i < masses.Count; i++ ) masspos[i + 1] = masses[i].pos; masspos[0] = masspos[1]; masspos[masspos.Length - 1] = masspos[masspos.Length - 2]; }
public void Init() { if ( startShape != null ) InitFromShape(startShape); else { if ( top == null || bottom == null ) return; Vector3 p1 = top.position; Vector3 p2 = bottom.position; RopeLength = (p1 - p2).magnitude; if ( masses == null ) masses = new List<MegaRopeMass>(); transform.position = Vector3.zero; masses.Clear(); float ms = Mass / (float)(points + 1); for ( int i = 0; i <= points; i++ ) { float alpha = (float)i / (float)points; MegaRopeMass rm = new MegaRopeMass(ms, Vector3.Lerp(p1, p2, alpha)); masses.Add(rm); } if ( springs == null ) springs = new List<MegaRopeSpring>(); springs.Clear(); if ( constraints == null ) constraints = new List<MegaRopeConstraint>(); constraints.Clear(); for ( int i = 0; i < masses.Count - 1; i++ ) { MegaRopeSpring spr = new MegaRopeSpring(i, i + 1, spring, damp, this); springs.Add(spr); LengthConstraint lcon = new LengthConstraint(i, i + 1, spr.restlen); constraints.Add(lcon); } int gap = 2; for ( int i = 0; i < masses.Count - gap; i++ ) { float alpha = (float)i / (float)masses.Count; MegaRopeSpring spr = new MegaRopeSpring(i, i + gap, stiffspring * stiffnessCrv.Evaluate(alpha), stiffdamp * stiffnessCrv.Evaluate(alpha), this); springs.Add(spr); LengthConstraint lcon = new LengthConstraint(i, i + gap, spr.restlen); constraints.Add(lcon); } // Apply fixed end constraints PointConstraint pcon = new PointConstraint(0, top.transform); constraints.Add(pcon); pcon = new PointConstraint(masses.Count - 1, bottom.transform); constraints.Add(pcon); PointConstraint1 pcon1 = new PointConstraint1(); pcon1.p1 = 1; pcon1.off = new Vector3(0.0f, springs[0].restlen, 0.0f); pcon1.obj = top.transform; //.position; constraints.Add(pcon1); endcon = pcon1; masspos = new Vector3[masses.Count + 2]; for ( int i = 0; i < masses.Count; i++ ) masspos[i + 1] = masses[i].pos; masspos[0] = masspos[1]; masspos[masspos.Length - 1] = masspos[masspos.Length - 2]; } }
public BasicDemoPane(IUIStyle style) : base(style) { model = new BasicDemoModel(); Content = new Grid(UIStyle) { Spacing = 5, Columns = new[] { LengthConstraint.Auto, LengthConstraint.Relative(1), LengthConstraint.Relative(1) }, Children = new[] { new[] { new Label(UIStyle, "PasswordBox"), CreatePasswordBox() }, new[] { new Label(UIStyle, "Text-Box"), CreateTextBox() }, new[] { new Label(UIStyle, "DropDown-Box"), CreateDropBox() }, new[] { new Label(UIStyle, "RadioButtonSet"), CreateRadioButtonSet() }, new[] { new Label(UIStyle, "Slider"), CreateSlider() }, new[] { new Label(UIStyle, "Button"), CreateButton() }, new[] { new Label(UIStyle, "Checkbox"), CreateCheckBox() }, new[] { new Label(UIStyle, "Keybox"), CreateKeyBox() }, new[] { new Label(UIStyle, "Spinner"), CreateSpinner() }, new[] { new Label(UIStyle, "Progressbar"), CreateProgressBar() }, new[] { new Label(UIStyle, "ListBox"), CreateListView() } } }; }
public LengthConstraintGenerator(BaseFieldGenerator field, LengthConstraint rule) { _field = field; _rule = rule; }