Esempio n. 1
0
        public void PrependShell()
        {
            Vector3    loc = shells[0].getLocalLocationAlongPath(-1);
            Quaternion rot = shells[0].getLocalRotationAlongPath(-1);

            TelescopeParameters p = new TelescopeParameters(shells[0].getParameters());

            p.radius += p.thickness;

            // Create the new shell object
            GameObject     newShell = new GameObject();
            TelescopeShell shell    = newShell.AddComponent <TelescopeShell>();

            shell.GenerateGeometry(p, null);
            shell.setMaterial(material);

            Vector3    shellLoc = shells[0].transform.position;
            Quaternion shellRot = shells[0].transform.rotation;

            // Move the new shell to be in position to receive the old one
            shell.transform.parent   = shells[0].transform.parent;
            shell.transform.position = shellLoc + shellRot * loc;
            shell.transform.rotation = shellRot * rot;

            // Reparent the old starting shell so it becomes the child of the new one
            shells[0].baseTranslation  = Vector3.zero;
            shells[0].baseRotation     = Quaternion.identity;
            shells[0].transform.parent = shell.transform;
            shell.extensionRatio       = shells[0].extensionRatio;
            shells.Insert(0, shell);
        }
Esempio n. 2
0
        public TelescopeShell addChildShell(TelescopeShell parent,
                                            TelescopeParameters parentParams, TelescopeParameters childParams,
                                            TelescopeParameters nextParams, bool isNotLast)
        {
            int i = shells.Count;
            // Make the new shell, and set the previous shell as its parent
            GameObject shellObj = new GameObject();

            shellObj.transform.parent = parent.transform;
            shellObj.name             = name + "-shell" + i;

            // Make the geometry, etc.
            TelescopeShell newShell = shellObj.AddComponent <TelescopeShell>();

            newShell.GenerateGeometry(childParams, nextParams, doOverhang: true);
            newShell.setMaterial(material);

            // Set the shell's rest transformation relative to its parent.
            // When the shell's current extension ratio is 0, this is where
            // it is located relative to its parent.
            // newShell.baseRadians = newShell.radiansOfLength(wallThickness);
            newShell.baseTranslation = TelescopeUtils.childBasePosition(parentParams, childParams);
            newShell.baseRotation    = TelescopeUtils.childBaseRotation(parentParams, childParams);
            shells.Add(newShell);

            shellObj.layer = 8;

            newShell.containingSegment = this;

            return(newShell);
        }
Esempio n. 3
0
        public void MakeAllShells(List <TelescopeParameters> paramList, bool reversed = false)
        {
            DeleteTelescope();

            // Create an object for the first shell
            GameObject rootShellObj = new GameObject();

            rootShellObj.name                    = name + "-shell0";
            rootShellObj.transform.parent        = this.transform;
            rootShellObj.transform.localPosition = Vector3.zero;

            telescopeRootShell = rootShellObj;

            // Make the shell geometry
            TelescopeShell shell = rootShellObj.AddComponent <TelescopeShell>();
            // Get the twist impulse of the shell after, since we need to cut the
            // grooves in this shell to enable it
            TelescopeParameters params1 = (paramList.Count > 1) ? paramList[1] : null;

            shell.GenerateGeometry(paramList[0], params1, outerGroove: false);
            shell.setMaterial(material);

            // Shells don't know anything about their position/rotation,
            // so we set that here.
            Quaternion initialFacing = Quaternion.LookRotation(initialDirection, initialUp);

            rootShellObj.transform.rotation = initialFacing;
            rootShellObj.layer = 8;

            shell.containingSegment = this;

            // shell.baseRadians = 0;
            shell.baseTranslation = Vector3.zero;
            shell.baseRotation    = Quaternion.identity;

            shells.Add(shell);
            shell.isRoot = true;

            // Make all of the child shells here.
            TelescopeShell      prevShell      = shell;
            TelescopeParameters previousParams = paramList[0];
            TelescopeParameters currentParams  = paramList[0];

            float accumulatedTaper = shell.getTaperLoss();

            for (int i = 1; i < paramList.Count; i++)
            {
                // Get the computed parameters for this and the previous shell.
                currentParams  = paramList[i];
                previousParams = paramList[i - 1];

                // Shrink the radius by the accumulated taper so far.
                currentParams.radius -= accumulatedTaper;

                // Get the twist impulse for the next shell, so that we can cut the grooves.
                TelescopeParameters nextParams = (i < paramList.Count - 1) ? paramList[i + 1] : null;

                TelescopeParameters taperedParams = (nextParams != null) ? new TelescopeParameters(nextParams) : null;
                if (taperedParams != null)
                {
                    taperedParams.radius -= accumulatedTaper;
                }

                // Add it.
                bool isNotLast = (i < paramList.Count - 1);
                prevShell         = addChildShell(prevShell, previousParams, currentParams, taperedParams, isNotLast);
                accumulatedTaper += prevShell.getTaperLoss();
            }


            if (fountainPrefab)
            {
                GameObject fountain = Instantiate <GameObject>(fountainPrefab);
                fountain.transform.parent = prevShell.transform;
            }
        }