Exemplo n.º 1
0
        public static TelescopeJuncture CreateJuncture(Vector3 position, float initialRadius)
        {
            // Create the actual object for the juncture
            GameObject junctureObj = new GameObject();

            junctureObj.name = "bulb" + (JunctureCount++);
            // Add the juncture component and initialize its fields
            TelescopeJuncture juncture = junctureObj.AddComponent <TelescopeJuncture>();

            juncture.transform.position = position;
            juncture.childSegments      = new List <TelescopeSegment>();

            juncture.Radius = initialRadius;

            return(juncture);
        }
Exemplo n.º 2
0
        public void TICToTelescope()
        {
            // Create a telescope structure empty object
            GameObject structureObj = new GameObject();

            structureObj.name = "TelescopingStructure";
            TelescopeStructure structure = structureObj.AddComponent <TelescopeStructure>();

            structure.transform.parent = transform;

            // Create dictionary to record created telescope junctures
            Dictionary <DCurveBulb, TelescopeJuncture> bulbDict = new Dictionary <DCurveBulb, TelescopeJuncture>();

            // Create all of the junctures, and hash the original abstract intersections to them
            foreach (DCurveBulb dcb in tiBulbs)
            {
                TelescopeJuncture junct = TelescopeJuncture.CreateJuncture(dcb.transform.position, dcb.radius * Mathf.Sqrt(2));
                bulbDict.Add(dcb, junct);
                structure.junctures.Add(junct);
                junct.transform.parent = structure.transform;
            }

            // Now we need to loop over all telescope segments,
            // create the telescopes, and attach them to the correct junctions.
            foreach (TorsionImpulseCurve tic in tiCurves)
            {
                // Set radius to match the radii at endpoints
                float startRadius = tic.NumSegments * Constants.WALL_THICKNESS + 0.2f
                                    + (tic.ArcLength * Constants.TAPER_SLOPE);

                TelescopeSegment seg;

                // Need to address four cases, corresponding to whether or not
                // the segment is connected to a juncture at the beginning and end.
                // In this step, we just create telescopes with the appropriate radii.
                if (tic.StartJuncture && tic.EndJuncture)
                {
                    if (tic.EndJuncture.radius > tic.StartJuncture.radius)
                    {
                        //startRadius = tic.EndJuncture.radius;
                        startRadius = FindStartRadius(tic.StartJuncture.radius, tic.ArcLength, tic.NumSegments);
                        seg         = tic.MakeTelescope(startRadius, reverse: true);
                    }
                    else
                    {
                        //startRadius = tic.StartJuncture.radius;
                        startRadius = FindStartRadius(tic.EndJuncture.radius, tic.ArcLength, tic.NumSegments);
                        seg         = tic.MakeTelescope(startRadius);
                    }
                }
                else if (tic.StartJuncture && !tic.EndJuncture)
                {
                    startRadius = tic.StartJuncture.radius;
                    seg         = tic.MakeTelescope(startRadius);
                }
                else if (!tic.StartJuncture && tic.EndJuncture)
                {
                    startRadius = tic.EndJuncture.radius;
                    seg         = tic.MakeTelescope(startRadius, reverse: true);
                }
                else
                {
                    seg = tic.MakeTelescope(startRadius);
                }

                seg.transform.parent = structure.transform;
                structure.segments.Add(seg);

                seg.ExtendImmediate(1);

                // Now we actually connect the telescopes.
                // We look up which instantiated telescope object
                // the current segment should be connected to.
                if (tic.StartJuncture)
                {
                    TelescopeJuncture bulb = bulbDict[tic.StartJuncture];
                    seg.keepLocalPositionOnStart = true;
                    seg.SetParent(bulb);

                    bulb.childSegments.Add(seg);
                }
                if (tic.EndJuncture)
                {
                    TelescopeJuncture bulb = bulbDict[tic.EndJuncture];
                    bulb.keepLocalPositionOnStart = true;
                    bulb.SetParentToSegmentEnd(seg);
                }

                // Turn off all of the old objects.
                foreach (DCurveBulb oldBulb in tiBulbs)
                {
                    oldBulb.gameObject.SetActive(false);
                }

                foreach (TorsionImpulseCurve oldTc in tiCurves)
                {
                    oldTc.gameObject.SetActive(false);
                }
            }

            ActiveStructure = structure;
            stage           = CanvasStage.Telescope;
        }
Exemplo n.º 3
0
 public void SetParent(TelescopeJuncture bulb)
 {
     parent = bulb;
     parentElementNumber = 0;
 }