public void Init(StarData data, Camera mainCamera) { int orbitCount = Random.Range(data.MinCount, data.MaxCount + 1); List <Vector2> sizes = new List <Vector2>(); if (data.IsOverlappingAllowed) { sizes = ComputeOverlappingSizes(orbitCount, data); } else { sizes = ComputeNonOverlappingSizes(orbitCount, data); } for (int i = 0; i < sizes.Count; i++) { Orbiter orbit = Instantiate(orbitPrefab, transform); float width = sizes[i].x; float height = sizes[i].y; float period = Random.Range(data.MinPeriod, data.MaxPeriod); bool isClockwise = data.IsClockwiseOnly ? true : Random.value < 0.5f; orbit.Init(width, height, period, isClockwise, mainCamera); orbits.Add(orbit); } }
private void OnTriggerEnter(Collider other) { { Orbiter orbit = other.GetComponent <Orbiter>(); if (!orbit.isActiveAndEnabled) { orbitList.Add(other.gameObject); orbit.enabled = true; if (level == 1) { if (orbitList.Count == 1) { orbit.orbitDegreesPerSec = 45; // orbit.axis = new Vector3(0f, 1f, 0f); } if (orbitList.Count == 2) { orbit.enabled = true; orbit.orbitDegreesPerSec = 180; // orbit.axis = new Vector3(1f, 0f, 0f); } } } } }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Player") { PlayerController player = collision.gameObject.GetComponent <PlayerController>(); if (cameraObject != null) { iTween.ShakePosition(cameraObject, new Vector3(0.75f, 0.75f, 0.5f), 0.5f); iTween.ValueTo(gameObject, iTween.Hash("from", 1.75f, "to", 0f, "onUpdate", "UpdateChroma", "time", 1f)); } player.die(); destroySelf(); } else if (collision.gameObject.tag == "Bullet") { Orbiter myOrbit = GetComponent <Orbiter>(); Orbiter otherOrbit = collision.gameObject.GetComponent <Orbiter>(); if (cameraObject != null) { iTween.PunchPosition(cameraObject, new Vector3(Random.Range(-0.2f, 0.2f), Random.Range(-0.2f, 0.2f), 0), 0.2f); } if (myOrbit.moveClockwise != otherOrbit.moveClockwise) { destroySelf(); } } }
void shoot() { if (Mathf.Abs(orbiter.targetRadius - orbiter.radius) > 0.05f) { return; } if (ammoScript.currentAmmo > 0) { FindObjectOfType <AudioManager>().Play("ShootingBullet", this.gameObject); GameObject bullet = Instantiate(bulletPrefab); bullet.transform.position = transform.position; var angle = Mathf.Atan2(transform.position.y, transform.position.x) * Mathf.Rad2Deg; bullet.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); Orbiter bulletOrbiter = bullet.GetComponent <Orbiter>(); bulletOrbiter.radius = orbiter.radius; bulletOrbiter.targetRadius = orbiter.radius; bulletOrbiter.speed = orbiter.speed * 2; bulletOrbiter.moveClockwise = orbiter.moveClockwise; bulletOrbiter.orbit(50); ammoScript.consumeAmmo(); } }
GameObject GeneratePlanet(Transform center, float minD, float maxD, float minR, float maxR, float minST, float maxST) { GameObject planet = Instantiate(planetPrefab, center); maxR = (maxD - minD) / 2; if (maxR < minR) { Debug.LogWarning("Minimum radius will produce planet larger than distance range"); maxR = minR; } float radius = (float)(rand.NextDouble() * (maxR - minR) + minR); Vector3 localScale = planet.transform.localScale; localScale.x *= radius * 2; localScale.y *= radius * 2; planet.transform.localScale = localScale; maxD -= radius; minD += radius; Orbiter orbiter = planet.GetComponent <Orbiter> (); orbiter.center = center; orbiter.ccw = rand.Next() % 2 == 0; orbiter.distance = (float)(rand.NextDouble() * (maxD - minD) + minD); orbiter.period = orbitalPeriodConstant * orbiter.distance; orbiter.spinPeriod = (float)((rand.Next() % 2 == 0 ? -1 : 1) * (rand.NextDouble() * (maxST - minST) + minST)); orbiter.offset = (float)rand.NextDouble(); return(planet); }
void Start() { finalBatchCount = 0; orbiters = new Orbiter[4000]; matrices = new Matrix4x4[orbiters.Length / instancesPerBatch + 1][]; matrices[0] = new Matrix4x4[instancesPerBatch]; colors = new Vector4[matrices.Length][]; colors[0] = new Vector4[instancesPerBatch]; int batch = 0; for (int i = 0; i < orbiters.Length; i++) { orbiters[i] = new Orbiter(Random.insideUnitSphere * 50f); finalBatchCount++; if (finalBatchCount == instancesPerBatch) { batch++; finalBatchCount = 0; matrices[batch] = new Matrix4x4[instancesPerBatch]; colors[batch] = new Vector4[instancesPerBatch]; } } matProps = new MaterialPropertyBlock[colors.Length]; for (int i = 0; i <= batch; i++) { matProps[i] = new MaterialPropertyBlock(); matProps[i].SetVectorArray("_Color", new Vector4[instancesPerBatch]); } }
private void OnDrawGizmosSelected() { if (orbiter == null) { orbiter = GetComponent <Orbiter>(); } // Bail out if there is no object to orbit around if (!orbiter.orbitAround) { return; } // Recalculate the ellipse only when in the editor if (!Application.isPlaying) { if (orbiter.Ellipse() == null) { return; } orbiter.Ellipse().Update(orbiter.orbitAround.position, transform.position, orbiter.apsisDistance, orbiter.circularOrbit); } DrawEllipse(); DrawStartingPosition(); }
void Start() { myVars = GetComponent <Orbiter>(); healthMgr = GetComponent <EnemyHealthManager>(); powerupMgr = GetComponent <FodderPowerupMgr>(); deathEffect = myVars.DeathEffect; }
private void Awake() { ship = GetComponent <PlayerShip>(); navigation = GetComponent <Navigation>(); orbiter = GetComponent <Orbiter>(); engine = GetComponent <Engine>(); hold = GetComponent <Hold>(); }
public void AddOrbiter(Orbiter newOrbiter) { if (orbiters.Contains(newOrbiter)) { return; } newOrbiter.thingToOrbit = transform; orbiters.Add(newOrbiter); }
public List <TrajectorySegment> GetTrajectory(int lenght) { while (segments.Count < lenght) { segments.Add(Orbiter.CalculateTrajectorySegment(lastSegment.lastPosition, lastSegment.endVelocity)); } return(segments); }
// Update the state of the orbiter when its position along the ellipse changes // Note: Make sure the ellipse is up to date before updating the orbit state private void Update(float orbiterAngle, Orbiter orbiter, OrbitalEllipse ellipse) { this.orbiter = orbiter; this.ellipse = ellipse; this.normal = CalcNormal(orbiterAngle); this.tangent = CalcTangent(normal); this.position = ellipse.GetPosition(orbiterAngle, orbiter.orbitAround.position); this.velocity = CalcVelocity(orbiter.orbitSpeed * orbiter.GravityConstant(), position, orbiter.orbitAround.position); }
float3 FutureLocalPosition(Orbiter o, float t) { // TODO: Mass stubbed out here... should come from the body? const float MASS = 1; float period = Orbiter.Period(o, MASS, G); float radians = (o.Radians + (float)o.Direction * TWO_PI / period * t) % (TWO_PI); float3 futurePosition = o.Radius * UnitCircle(radians); return(futurePosition); }
public ResultView2(string stl_path) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); InitializeComponent(); orb = new Orbiter(); GL_Monitor.MouseDown += orb.Control_MouseDownEvent; GL_Monitor.MouseUp += orb.Control_MouseUpEvent; GL_Monitor.MouseWheel += orb.Control_MouseWheelEvent; GL_Monitor.KeyPress += orb.Control_KeyPress_Event; stlpath = stl_path; }
public AppMainForm() { /* dot/comma selection for floating point numbers */ Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); InitializeComponent(); orb = new Orbiter(); GL_Monitor.MouseDown += orb.Control_MouseDownEvent; GL_Monitor.MouseUp += orb.Control_MouseUpEvent; GL_Monitor.MouseWheel += orb.Control_MouseWheelEvent; GL_Monitor.KeyPress += orb.Control_KeyPress_Event; }
private void Awake() { float shellInnerRadius = sun.radius + baseHeight; for (int shellNumber = 0; shellNumber < numberOfShells; shellNumber++) { float shellThickness = Random.Range(minShellSize, maxShellSize); float circumference = 2 * Mathf.PI * shellInnerRadius; float shellSpeed = Random.Range(minSpeed, maxSpeed); float direction = Random.Range(0.0f, 1.0f) > 0.5 ? 1.0f : -1.0f; for (float lastOccupied = 0.0f; lastOccupied <= circumference;) { float maxDiameter = Mathf.Min(circumference - lastOccupied - minPlanetSpacing, shellThickness); if (maxDiameter < minPlanetDiameter) { break; } float planetDiameter = Random.Range(minPlanetDiameter, shellThickness); float spawnPosition = lastOccupied + planetDiameter / 2.0f + Random.Range(minPlanetSpacing, maxPlanetSpacing); lastOccupied = spawnPosition + planetDiameter / 2.0f; float heightInShell = Random.Range(planetDiameter / 2.0f, shellThickness - (planetDiameter / 2.0f)); float chance = shellNumber == 0 ? firstLayerSpawnChance : spawnChance; if (Random.Range(0.0f, 1.0f) > chance) { continue; } Orbiter newPlanet = Instantiate(planetPrefab.gameObject).GetComponent <Orbiter>(); newPlanet.transform.localScale = Vector3.one * planetDiameter; newPlanet.objectToOrbit = sun; newPlanet.angle = (spawnPosition / shellInnerRadius) * Mathf.Rad2Deg; newPlanet.orbitSpeed = shellSpeed * direction; newPlanet.orbitHeightAboveSurface = shellInnerRadius + heightInShell - sun.radius; newPlanet.GetComponentInChildren <Rotator>().spinRate = Random.onUnitSphere * Random.Range(-10.0f, 10.0f); if (Random.Range(0.0f, 1.0f) < wishProbability) { Orbiter newWish = Instantiate(wishPrefab.gameObject).GetComponent <Orbiter>(); newWish.objectToOrbit = newPlanet.GetComponent <OrbitBody>(); float wDir = Random.Range(0.0f, 1.0f) > 0.5 ? 1.0f : -1.0f; newWish.orbitSpeed = wishSpeed * wDir; newWish.orbitHeightAboveSurface = wishHeight; newWish.GetComponentInChildren <Rotator>().spinRate = Random.onUnitSphere * Random.Range(-10.0f, 10.0f); } } shellInnerRadius += shellThickness + minPlanetSpacing; } }
// Start is called before the first frame update void Start() { cameraObject = GameObject.Find("Main Camera"); orbiter = GetComponent <Orbiter>(); ammoScript = GetComponent <Ammo>(); changeRing(ringGenerator.numRings); orbiter.speed = LevelManager.Instance.getRoundType().playerSpeed; if (!orbiter.moveClockwise) { transform.Rotate(0, 0, 180); } }
public void Execute(int index, Orbiter orbiter, Transform transform) { LineRenderer lr = LineRenderers[index]; lr.positionCount = PathResolution + 1; for (int i = 0; i <= PathResolution; i++) { Vector3 localPosition = orbiter.Radius * UnitCircle(2 * PI * (float)i / PathResolution); Vector3 worldPosition = orbiter.transform.parent.TransformPoint(localPosition); lr.SetPosition(i, worldPosition); } }
private void placeWall() { Orbiter wallScript = wall.GetComponent <Orbiter>(); if (isClear() && resources >= wallScript.cost) { resources -= wallScript.cost; GameObject ring = ringMan.getRing(transform.position); GameObject newWall = Instantiate(wall, ring.transform); Orbiter newWallScript = newWall.GetComponent <Orbiter>(); newWallScript.setTheta(angle); newWallScript.setRho(radius); } }
public Logic() { InitializeComponent(); //panelOpenGl.InitializeContexts(); _currentIndexlayer = -1; _layers = new List <Layer>(); _triangles = new List <MyTriangle>(); orb = new Orbiter(); GL_Monitor1.MouseDown += orb.Control_MouseDownEvent; GL_Monitor1.MouseUp += orb.Control_MouseUpEvent; GL_Monitor1.MouseWheel += orb.Control_MouseWheelEvent; GL_Monitor1.KeyPress += orb.Control_KeyPress_Event; button2.Enabled = true; }
private void placeTurret() { Orbiter turretScript = turret.GetComponent <Orbiter>(); if (isClear() && resources >= turretScript.cost) { resources -= turretScript.cost; GameObject ring = ringMan.getRing(transform.position); GameObject newTurret = Instantiate(turret, ring.transform); Orbiter newTurretScript = newTurret.GetComponent <Orbiter>(); newTurretScript.setTheta(angle); newTurretScript.setRho(radius); newTurretScript.ring = ring; } }
///<summary> /// Calculates another step of trajectory ///</summary> public void Step() { // Robi to na zasadzie: // 1. Wzięcia elementu z początku listy // 2. Obliczenia dla niego nowych wartości (odświeżenia) // 3. Dodanie go na koniec listy TrajectorySegment segmentToRefresh = firstSegment; segmentToRefresh = Orbiter.CalculateTrajectorySegment(segments[segments.Count - 1].lastPosition, segments[segments.Count - 1].endVelocity); segments.RemoveAt(0); segments.Add(segmentToRefresh); }
void Start() { playerShip = GameObject.FindGameObjectWithTag("Player"); myVars = GetComponent <Orbiter>(); gameManager = GameObject.FindGameObjectWithTag("Game Manager").GetComponent <PlayerManager>(); bumpDamage = gameManager.GetComponent <WeaponManager>().FactorBeamTractorBumpDamage; bumpEffect = gameManager.BumpEffect; thrustForce = myVars.ThrustForce; maxSpeed = myVars.MaxSpeed; bumpForce = gameManager.BumpForce; bumpTime = gameManager.BumpTime; bumpTimer = gameObject.AddComponent <Timer>(); bumpTimer.Trigger += BumpOver; stunTimer = gameObject.AddComponent <Timer>(); stunTimer.Trigger += StunOff; }
List <Orbiter> OrbitersInOrder() { Orbiter[] allOrbiters = FindObjectsOfType <Orbiter>(); List <Orbiter> orbitersInOrder = new List <Orbiter>(); Orbiter newAddable = allOrbiters[0]; Orbiter notNewAddable = allOrbiters[0]; while (orbitersInOrder.Count < allOrbiters.Length) { newAddable = notNewAddable; for (int i = 0; i < allOrbiters.Length; i++) { if (orbitersInOrder.Count > 0) { for (int j = 0; j < orbitersInOrder.Count; j++) { if (allOrbiters[i] != orbitersInOrder[j]) { if (Vector3.Distance(allOrbiters[i].transform.GetChild(0).transform.position, transform.position) < Vector3.Distance(newAddable.transform.GetChild(0).transform.position, transform.position)) { newAddable = allOrbiters[i]; } } } } else { if (Vector3.Distance(allOrbiters[i].transform.GetChild(0).transform.position, transform.position) < Vector3.Distance(newAddable.transform.GetChild(0).transform.position, transform.position)) { newAddable = allOrbiters[i]; } else if (Vector3.Distance(allOrbiters[i].transform.GetChild(0).transform.position, transform.position) > Vector3.Distance(notNewAddable.transform.GetChild(0).transform.position, transform.position)) { notNewAddable = allOrbiters[i]; } } } if (newAddable != null) { orbitersInOrder.Add(newAddable); } } return(orbitersInOrder); }
private void RenderOrbiterPreview(Orbiter orbiter) { if (!SetPreviews(PreviewType.Default, orbiter)) { return; } if (orbiter == null) { return; } pbPreview.Resize += PreviewOnResize; var planetFactory = FactoryManager.GetFactory(orbiter.Name) as PlanetFactory; float padding, scale; ComputeScaleAndOffset(GetMaxRadius(orbiter.Moons), out scale, out padding); // Render all objects from left to right, starting with the sun. using (var g = System.Drawing.Graphics.FromImage(pbPreview.Image)) { g.SmoothingMode = SmoothingMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.HighQuality; using (var brush = new SolidBrush(System.Drawing.Color.White)) { if (planetFactory != null && planetFactory.Radius != null) { brush.Color = System.Drawing.Color.FromArgb(150, planetFactory.SurfaceTint.R, planetFactory.SurfaceTint.G, planetFactory.SurfaceTint.B); var diameter = scale * planetFactory.Radius.Low * 2; g.FillEllipse(brush, padding - diameter / 2f, pbPreview.Image.Height / 2f - diameter / 2f, diameter, diameter); diameter = scale * planetFactory.Radius.High * 2; g.FillEllipse(brush, padding - diameter / 2f, pbPreview.Image.Height / 2f - diameter / 2f, diameter, diameter); } RenderOrbit(orbiter.Moons, padding, scale, g, brush); } } }
// Update is called once per frame void Update() { if (GameProperties.props.state == GameState.Ready) { Debug.Log("creating from update"); this.CreateSun(); } else if (GameProperties.props.state == GameState.CreatePlanet) { if (planetPlaceholder.activeSelf == false) { planetPlaceholder.SetActive(true); } Vector3 loc = GetIntersectionLocation(); planetPlaceholder.transform.position = loc; if (Input.GetMouseButtonDown(0)) { Debug.Log("Create a planet here"); GameProperties.props.state = GameState.Playing; string planetName = ((GameObject)planetPrefabs[Random.Range(0, planetPrefabs.Count - 1)]).name; //GameObject newPlanet = Instantiate (planetPrefabs [0], loc, Quaternion.identity) as GameObject; GameObject newPlanet = PhotonNetwork.Instantiate(planetName, loc, Quaternion.identity, 0) as GameObject; Orbiter orbiter = newPlanet.GetComponent <Orbiter> (); orbiter.orbitCenter = GameProperties.props.selectedObject; orbiter.owner = GameProperties.props.playerName; orbiter.type = PlanetType.LifePlanet; orbiter.orbitSpeed = Random.Range(1.0f, 5.0f); } } else { if (planetPlaceholder.activeSelf == true) { planetPlaceholder.SetActive(false); } } }
void CreatePlanet(float radius, float variation, float seaLevel, Color planetColor, float atmosphereRadius, Color atmosphereColor, bool habitableAtmosphere, Orbit orbit) { PlanetVars planetVars = new PlanetVars(radius, variation, seaLevel, planetColor, atmosphereRadius, atmosphereColor, habitableAtmosphere, orbit); GameObject planet = new GameObject(); Icosphere.Create(planet, 6, planetVars.radius, Mathf.RoundToInt(Random.value * int.MaxValue), planetVars.variation, planetVars.variation); planet.AddComponent <MeshRenderer>(); planet.AddComponent <MeshCollider>(); planet.AddComponent <Orbiter>(); //Generate Material Material planetMaterial = new Material(triplanar); planetMaterial.SetTexture("_MainTex", ground); planetMaterial.SetTexture("_MainTex1", ground); planetMaterial.SetTexture("_MainTex2", ground); planet.GetComponent <MeshRenderer>().material = planetMaterial; //Generate Orbit planet.GetComponent <Orbiter>().orbit = planetVars.orbit; //Make ocean GameObject ocean = new GameObject(); Icosphere.Create(ocean, 6, planetVars.radius, Mathf.RoundToInt(Random.value * int.MaxValue), 0, 0); ocean.AddComponent <MeshRenderer>(); ocean.transform.parent = planet.transform; //Make ocean material Material oceanMaterial = new Material(triplanar); oceanMaterial.SetTexture("_MainTex", water); oceanMaterial.SetTexture("_MainTex1", water); oceanMaterial.SetTexture("_MainTex2", water); ocean.GetComponent <MeshRenderer>().material = oceanMaterial; //Set starting position planet.transform.localScale = new Vector3(radius, radius, radius); planet.transform.position = Orbiter.GetPointOnEclipse(90, planetVars.orbit); }
private void Update() { for (int i = 0; i < orbiters.Length; i++) { Orbiter orbiter = orbiters[i]; Vector3 scale = new Vector3(.1f, .01f, Mathf.Max(.1f, orbiter.velocity.magnitude * speedStretch)); Matrix4x4 matrix = Matrix4x4.TRS(orbiter.position, Quaternion.LookRotation(orbiter.velocity), scale); matrices[i / instancesPerBatch][i % instancesPerBatch] = matrix; colors[i / instancesPerBatch][i % instancesPerBatch] = orbiter.color; } for (int i = 0; i < matrices.Length; i++) { int count = instancesPerBatch; if (i == matrices.Length - 1) { count = finalBatchCount; } matProps[i].SetVectorArray("_Color", colors[i]); Graphics.DrawMeshInstanced(particleMesh, 0, particleMaterial, matrices[i], count, matProps[i]); } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { Vector2 inputMouse = Camera.main.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(inputMouse, Vector2.zero, Mathf.Infinity); if (hit.collider != null && hit.transform.tag == "Orbiter") { orbiter = hit.transform.GetComponent <Orbiter>(); orbiter.Select(); } } if (Input.GetMouseButton(0) && orbiter != null) { orbiter.Drag(); } if (Input.GetMouseButtonUp(0)) { orbiter = null; } }
public void EarthOrbit() { var world = new MockUniverse(); var universe = Universe.Builder.Build(world.Universe).Materialise(); var sol = universe.StarClusters .SelectMany(x => x.SolarSystems) .Single(x => x.Id == world.SolarSystem.ObjectId); var earth = sol.Satellites .Single(x => x.Id == world.Earth.ObjectId); var context = new TickContext(0) { ElapsedTicks = 60 * 60 * 5 }; var orbiter = new Orbiter(sol); var orbitRadius = earth.Position.LocalCoordinates.Magnitude; for (var i = 0; i < 12*21; i++) { orbiter.Orbit(context); Console.WriteLine("{0}: {1:n}", i, earth.Position.LocalCoordinates * 1e-5); earth.Position.LocalCoordinates.Magnitude.ShouldBe(orbitRadius, Units.Tolerance*100); } }
void OnTriggerEnter(Collider collider) { if (collider.tag == "Player") { disable.SetActive(false); enableOrbit.transform.SetParent(collider.gameObject.transform); enableOrbit.transform.rotation = Quaternion.identity; Orbit orb = enableOrbit.GetComponent <Orbit>(); Orbiter orbiter = collider.GetComponent <Orbiter>(); orb.SetStartPosition(orbiter.startingPoint); orb.centerOfGravity = orbiter.centerOfGravity; orb.speed = 1.0f; orb.orbitDirection = Vector3.up; //orb.transform.localScale = new Vector3(1, 1, 1); Destroy(gameObject); } }
// Use this for initialization void Start() { this.spectate = false; this.character = gameObject.transform.GetChild(1).gameObject; this.orb = null; if (isLocalPlayer) this.cam = gameObject.transform.GetChild(0); }
private void RpcSetOrbit() { if (!isLocalPlayer) return; if (this.orb != null) this.orb.clear(); this.orb = new Orbiter(this.character.transform.position, this.character.transform.rotation.eulerAngles); }
// Use this for initialization void Start() { _orbiter = GetComponent<Orbiter>(); _pedManager = PedestrianManager.Instance; LoadAmmo(); }