public void Set(ObiCurveSection section) { normal = section.normal; tangent = section.tangent; binormal = Vector3.Cross(normal, tangent); position = section.positionAndRadius; }
public override void TransportFrame(ObiCurveFrame frame, ObiCurveSection section, float sectionTwist) { if (frame != null) { frame.Set(section); } }
public void Transport(ObiCurveSection section, float twist) { // Calculate delta rotation: Quaternion rotQ = Quaternion.FromToRotation(tangent, section.tangent); Quaternion twistQ = Quaternion.AngleAxis(twist, section.tangent); Quaternion finalQ = twistQ * rotQ; // Rotate previous frame axes to obtain the new ones: normal = finalQ * normal; binormal = finalQ * binormal; tangent = section.tangent; position = section.positionAndRadius; }
/** * Generate a list of smooth curves using particles as control points. Will take into account cuts in the rope, * generating one curve for each continuous piece of rope. */ public void SmoothCurvesFromParticles() { curves.Clear(); curveSections = 0; curveLength = 0; // count amount of segments in each rope chunk: CountContinuousSegments(); Matrix4x4 w2l = transform.worldToLocalMatrix; Quaternion matrixRotation = Quaternion.LookRotation( w2l.GetColumn(2), w2l.GetColumn(1)); int firstSegment = 0; // generate curve for each rope chunk: for (int i = 0; i < rawCurves.Count; ++i) { int segments = rawCurves[i].Count - 1; // allocate memory for the curve: ObiList <ObiCurveSection> controlPoints = rawCurves[i]; // get control points position: int lastParticle = -1; int particle1 = -1, particle2 = -1; for (int m = 0; m < segments; ++m) { if (GetStructuralConstraintParticles(firstSegment + m, ref particle1, ref particle2)) { if (m == 0) { lastParticle = particle1; } // Find next and previous vectors: Vector3 nextV = GetParticlePosition(particle2) - GetParticlePosition(particle1); Vector3 prevV = GetParticlePosition(particle1) - GetParticlePosition(lastParticle); Vector3 pos = w2l.MultiplyPoint3x4(GetParticlePosition(particle1)); Quaternion orient = matrixRotation * Quaternion.SlerpUnclamped(GetParticleOrientation(lastParticle), GetParticleOrientation(particle1), 0.5f); Vector3 tangent = w2l.MultiplyVector(prevV + nextV).normalized; Color color = (this.colors != null && particle1 < this.colors.Length) ? this.colors[particle1] : Color.white; controlPoints[m] = new ObiCurveSection(new Vector4(pos.x, pos.y, pos.z, principalRadii[particle1][0]), tangent, orient * Vector3.up, color); lastParticle = particle1; } } // last segment adds its second particle too: if (segments > 0) { Vector3 pos = w2l.MultiplyPoint3x4(GetParticlePosition(particle2)); Quaternion orient = matrixRotation * GetParticleOrientation(particle1); Vector3 tangent = w2l.MultiplyVector(GetParticlePosition(particle2) - GetParticlePosition(particle1)).normalized; Color color = (this.colors != null && particle2 < this.colors.Length) ? this.colors[particle2] : Color.white; controlPoints[segments] = new ObiCurveSection(new Vector4(pos.x, pos.y, pos.z, principalRadii[particle2][0]), tangent, orient * Vector3.up, color); } firstSegment += segments; // get smooth curve points: ObiCurveFrame.Chaikin(controlPoints, curves[i], smoothing); // count total curve sections and total curve length: curveSections += curves[i].Count - 1; curveLength += CalculateCurveLength(curves[i]); } }
public abstract void TransportFrame(ObiCurveFrame frame, ObiCurveSection section, float sectionTwist);