// Start is called before the first frame update void Start() { // Get Vertex count MeshFilter MF = GetComponent <MeshFilter>(); ModelSpaceVertices = MF.mesh.vertices; CurrentPosition = new Vectors(transform.position.x, transform.position.y, transform.position.z); // So we can see current position of mesh (as matrix moves verices) x = CurrentPosition.x; y = CurrentPosition.y; z = CurrentPosition.z; // Fills our orbit path data orbit = GetComponent <OrbitPath>(); // Find time TimeM = FindObjectOfType <TimeModifier>(); // Set ellipses origin if (Parent != null) { RotationOrigin = new Vectors(Parent.x, Parent.y, Parent.z); } else { RotationOrigin = new Vectors(0, 0, 0); } // Set our orbit setOrbit(); }
/* should be called immediately after instantiation */ public void InitSatellite(CelestialBody primary, OrbitPath path, float rad1, float rad2) { this._path = path; _path.Initialize(primary, rad1, rad2); this.transform.position = _path.GetWorldPointByIndex(0); this.transform.rotation = Quaternion.identity; //offset = transform.position - Primary.transform.position; this.IncrementPathPoint(); if (debugMode) { Debug.Log("first point is " + _nextPathPoint + " at index " + _pointIndex); } markers = new GameObject[4]; CalculateOrbitRegion(); }
/* adds a satellite in orbit around an existing body */ public void AddSatellite(CelestialType type) { /* * TODO: * 1) get larger radius of primary's furthest orbital path * 2) min valid orbit rad = furthestOrbit.region.upperLimit + minDist (for now) * 3) add satellite at some radius s.t. not overlapping with former furthest */ if (!_sceneIsEditable) { return; } CelestialBody primary; if (!user || !user.isActiveAndEnabled) { if (debugMode && debugSelectedObject) { primary = debugSelectedObject; } else { primary = initialStar; } } else if ((primary = user.selectedObject.GetComponent <CelestialBody> ()) == null) { return; } float furthestRegionLimit; if (primary.NumSatellites <= 0) { furthestRegionLimit = primary.naturalMaxSize / 2; } else { furthestRegionLimit = primary.FurthestSatellite.Region.Max; } float orbitRadius = furthestRegionLimit + CelestialBody.MinimumSeparatingDistance + templates[type].naturalMaxSize / 2; OrbitPath path = Instantiate(orbitPathTemplate); Debug.Log("orbit radius is " + orbitRadius); /* * TODO: spawn satellite at path's north position * set satellite's path * add satellite to SM's list of CBs */ OrbitingBody satellite = Instantiate(templates[type]); satellite.InitSatellite(primary, path, orbitRadius, orbitRadius); bodies.Add(satellite); primary.AddOrbitingBody(satellite); if (debugMode) { UpdateDisplayInfo(); } }