// Use this for initialization
 void Start()
 {
     arcLength          = 0;
     measuredArc        = 0;
     transform.position = TelescopeUtils.TranslateAlongHelix(curvature, torsion, arcLength);
     transform.rotation = TelescopeUtils.RotateAlongHelix(curvature, torsion, arcLength);
 }
Exemple #2
0
        CylinderMesh GenerateInnerCylinder(TelescopeParameters nextParams, bool overhang, float arcOffset,
                                           int extraRings = 0)
        {
            TelescopeParameters ourParams = getParameters();
            CylinderMesh        innerCyl;

            // If there is a change in profile from this shell to the next...
            if (nextParams != null && (nextParams.curvature != curvature || nextParams.torsion != torsion ||
                                       nextParams.radius < radius - Constants.WALL_THICKNESS * 1.01f))
            {
                // Generate the outer profile of the child shell; this will become
                // the inner profile of this shell.
                TelescopeParameters innerParams = new TelescopeParameters(nextParams.length, nextParams.radius,
                                                                          nextParams.thickness, nextParams.curvature, nextParams.torsion, nextParams.twistFromParent);
                innerCyl = GenerateCylinder(innerParams,
                                            Constants.TAPER_SLOPE, innerGroove: true, overhang: overhang,
                                            extraRings: extraRings);

                // Move and rotate the inner profile so that the end circles align.
                Quaternion alignRotation    = TelescopeUtils.childBaseRotation(ourParams, nextParams);
                Vector3    alignTranslation = TelescopeUtils.childBasePosition(ourParams, nextParams);

                Quaternion backRotation = TelescopeUtils.RotateAlongHelix(nextParams.curvature,
                                                                          nextParams.torsion, arcOffset);
                Vector3 backTranslation = TelescopeUtils.TranslateAlongHelix(nextParams.curvature,
                                                                             nextParams.torsion, arcOffset);

                innerCyl.ApplyRotation(backRotation);
                innerCyl.ApplyTranslation(backTranslation);

                innerCyl.ApplyRotation(alignRotation);
                innerCyl.ApplyTranslation(alignTranslation);
            }

            else
            {
                TelescopeParameters innerParams = new TelescopeParameters(length, radius - thickness,
                                                                          thickness, curvature, torsion, 0);

                innerCyl = GenerateCylinder(innerParams,
                                            Constants.TAPER_SLOPE, innerGroove: (nextParams != null), overhang: overhang,
                                            extraRings: extraRings);

                if (nextParams != null)
                {
                    Quaternion backRotation = TelescopeUtils.RotateAlongHelix(nextParams.curvature,
                                                                              nextParams.torsion, arcOffset);
                    Vector3 backTranslation = TelescopeUtils.TranslateAlongHelix(nextParams.curvature,
                                                                                 nextParams.torsion, arcOffset);

                    innerCyl.ApplyRotation(backRotation);
                    innerCyl.ApplyTranslation(backTranslation);
                }
            }

            return(innerCyl);
        }
        Vector3 TransformedHelixPoint(CurveSegment cs, float arcLen)
        {
            // Get the helix point in local coordinates
            Vector3 helixPoint = TelescopeUtils.TranslateAlongHelix(cs.curvature, cs.torsion, arcLen);
            // Transform to world
            Quaternion rotateToWorld = Quaternion.LookRotation(cs.frame.T, cs.frame.N);
            Vector3    world         = rotateToWorld * helixPoint + cs.startPosition;

            return(world);
        }
        // Update is called once per frame
        void Update()
        {
            arcLength += Time.deltaTime;
            Vector3 pos  = TelescopeUtils.TranslateAlongHelix(curvature, torsion, arcLength);
            float   diff = Vector3.Distance(pos, transform.position);

            measuredArc       += diff;
            transform.position = pos;
            transform.rotation = TelescopeUtils.RotateAlongHelix(curvature, torsion, arcLength);

            velocity = diff / Time.deltaTime;
        }
Exemple #5
0
 Vector3 translationOfDistance(float arcLength, float curvature, float torsion)
 {
     return(TelescopeUtils.TranslateAlongHelix(curvature, torsion, arcLength));
 }