//private Vector3 lastPos; //private void Start() //{ // lastPos = transform.position; //} private void Update() { // 1 var pos = transform.position; var s = SphereUtility.CartesianToSpherical(pos); target.r = s.x; target.lat = s.y; target.lon = s.z; // 2 //var pos = transform.position; // NOTE: spherical positions can't be subtracted like this //var s = SphereUtility.CartesianToSpherical(pos) - SphereUtility.CartesianToSpherical(lastPos); //lastPos = pos; //target.r += s.x; //target.lat += s.y; //target.lon += s.z; // 3 //var pos = transform.position; //var s = SphereUtility.CartesianToSpherical(pos) - SphereUtility.CartesianToSpherical(lastPos); //target.r += s.x; ////target.lat += s.y; ////target.lon += s.z; //var quat = Quaternion.FromToRotation(lastPos, pos); ////Debug.Log(quat.eulerAngles); //target.transform.rotation = quat * target.transform.rotation; //lastPos = pos; }
public void FallingUpdate(CharacterMotor self) { SphereUtility.Accelerate(ref self.phi, ref self.theta, ref self.vertical_velocity, ref self.horizontal_velocity, 0.03f, -self.input.x / 10, Time.fixedDeltaTime); self.current_position = SphereUtility.SphereToCartesian(new Vector2(self.phi, self.theta)); self.transform.rotation = Quaternion.LookRotation(self.current_position, self.North); }
private void Update() { transform.eulerAngles = new Vector3(0, lon, -lat); if (translated) { translated.position = SphereUtility.SphericalToCartesian(new Vector3(r, lat, lon)); } }
public void StartRecord() { mytrail.Clear(); startPos = transform.position; startSph = new Spherical3(); SphereUtility.CartesianToSpherical(startPos - origin.transform.position, out startSph); mytrail.Push(startSph); StartCoroutine("Recording"); }
public override IEnumerator ComputeStarData() { SendProgress(0); // Create 1 large texture, then render smaller tiles into it. Texture2D tex = new Texture2D((int)imageSize, (int)imageSize, TextureFormat.RGBA32, false); // Random points on sphere surface to position stars. int tileSize = (int)imageSize; List <StarPoint> starPoints = GenerateRandomStarsPoints(density, tileSize, tileSize); SendProgress(0); // Fill in the image. for (int yIndex = 0; yIndex < tileSize; yIndex++) { float yPercent = (float)yIndex / (float)(tileSize - 1); float yPosition = SphereUtility.PercentToHeight(yPercent); for (int xIndex = 0; xIndex < tileSize; xIndex++) { float anglePercent = (float)xIndex / (float)(tileSize - 1); float angle = SphereUtility.PercentToRadAngle(anglePercent); Vector3 currentSpot = SphereUtility.SphericalToPoint(yPosition, angle); // Closest star to current spot. StarPoint star = NearestStarPoint(currentSpot, starPoints); UnityEngine.Color c = new UnityEngine.Color( PointAxisToPercent(star.position.x), PointAxisToPercent(star.position.y), PointAxisToPercent(star.position.z), star.noise); // Noise value used to randomize each star. tex.SetPixel(xIndex, yIndex, c); } // Update the GUI progress bar. float totalProgress = (float)((yIndex + 1) * tileSize) / (float)(tileSize * tileSize); SendProgress(totalProgress); yield return(null); } tex.Apply(false); SendCompletion(tex, true); yield break; }
void UpdateMoonData(List <MaterialProperty> allProps) { MaterialProperty heightProp = GetPropertyWithName(allProps, "_MoonHeight"); if (heightProp == null) { Debug.LogError("Missing moon height property"); return; } MaterialProperty angleProp = GetPropertyWithName(allProps, "_MoonAngle"); if (angleProp == null) { Debug.LogError("Missing moon angle property"); return; } // Convert our percent properties to spherical point. float moonYPosition = SphereUtility.PercentToHeight(heightProp.floatValue); float moonAngle = SphereUtility.PercentToRadAngle(angleProp.floatValue); Vector3 moonPoint = SphereUtility.SphericalToPoint(moonYPosition, moonAngle); float xRotation = 0; float yRotation = 0; SphereUtility.CalculateStarRotation(moonPoint, out xRotation, out yRotation); MaterialProperty moonPositionProp = GetPropertyWithName(allProps, "_MoonComputedPositionData"); if (moonPositionProp == null) { Debug.LogError("Can't update precomputed moon position without property"); return; } moonPositionProp.vectorValue = new Vector4(moonPoint.x, moonPoint.y, moonPoint.z, 0); MaterialProperty moonRotationProp = GetPropertyWithName(allProps, "_MoonComputedRotationData"); if (moonRotationProp == null) { Debug.LogError("Can't update precomputed moon rotation without property"); return; } moonRotationProp.vectorValue = new Vector4(xRotation, yRotation, 0, 0); }
// Update is called once per frame void Update() { Spherical3 sc = new Spherical3(); Vector3 where = toTrack.transform.position - origin.transform.position; SphereUtility.CartesianToSpherical(where, out sc); // reflecting sc.p *= -1; Vector3 nwhere = new Vector3(); SphereUtility.SphericalToCartesian(sc, out nwhere); transform.position = startPos + nwhere; }
public void Move(Vector2 input) { if (between_levels) //FEATURE: enable movement (grounded and aerial) in between_levels { connection.data.Move(Input.GetAxis("Vertical"), this); } else if (grounded) //FIXME: this entire block if it is JANK //spelling -_-' { if (input.sqrMagnitude > 1) { input.Normalize(); } Transform camera_transform = GameObject.Find("MainCamera").transform; //FIXME: JANK Vector3 input3D = new Vector3(input.x, input.y, 0f); //FIXME: JANK if (input3D.sqrMagnitude > 1) { input3D.Normalize(); } float left_product = Vector3.Dot(camera_transform.rotation * input3D, left); float right_product = Vector3.Dot(camera_transform.rotation * input3D, right); float product = -Mathf.Abs(left_product); if (right_product > left_product) { product = +Mathf.Abs(right_product); } if (right_product < 0 && left_product < 0) { product = 0; } angle += product / height / 64; //FIXME: slight math error here-ish current_position = ArcOfSphere.Evaluate(ground.data, radius); transform.rotation = Quaternion.LookRotation(current_position, arc.EvaluateNormal(angle, radius)); } else { SphereUtility.Accelerate(ref phi, ref theta, ref vertical_velocity, ref horizontal_velocity, 0.03f, -input.x / 10, Time.fixedDeltaTime); current_position = SphereUtility.SphereToCartesian(new Vector2(phi, theta)); transform.rotation = Quaternion.LookRotation(current_position, North); } }
public void UpdateMoonData() { // Convert our percent properties to spherical point. float moonYPosition = SphereUtility.PercentToHeight(verticalPosition); float moonAngle = SphereUtility.PercentToRadAngle(horizontalPosition); Vector3 moonPoint = SphereUtility.SphericalToPoint(moonYPosition, moonAngle); float xRotation = 0; float yRotation = 0; SphereUtility.CalculateStarRotation(moonPoint, out xRotation, out yRotation); Vector4 moonPositionData = new Vector4(moonPoint.x, moonPoint.y, moonPoint.z, 0); Vector4 moonRotationData = new Vector4(xRotation, yRotation, 0, 0); moonMaterial.SetVector("_MoonComputedPositionData", moonPositionData); moonMaterial.SetVector("_MoonComputedRotationData", moonRotationData); }
public override optional <float> Distance(Vector3 to, Vector3 from, float radius) //distance is Euclidean but is (guaranteed?) to be sorted correctly with the current assertions about speed vs player_radius { optional <Vector3> point = SphereUtility.Intersection(from, to, Center(radius), AngularRadius(radius)); optional <float> intersection = new optional <float>(); if (point.exists) { intersection = CartesianToRadial(point.data); } if (intersection.exists) { float angle = intersection.data; Vector3 new_position = Evaluate(angle, radius); return((from - new_position).sqrMagnitude); //CONSIDER: does Cartesian distance matter? } return(new optional <float>()); }
IEnumerator Recording() { while (true) { Vector3 where = transform.position - origin.transform.position; if (randomize) { where.x += Random.Range(-0.5f, 0.5f); where.y += Random.Range(-0.5f, 0.5f); where.z += Random.Range(-0.5f, 0.5f); } SphereUtility.CartesianToSpherical(where, out sc); mytrail.Push(sc); Debug.Log(mytrail.Count); yield return(new WaitForSeconds(0.1f)); } }
public override void Move(float delta, CharacterMotor motor) { interpolation_distance += delta * direction * Time.deltaTime; float exponent = Mathf.Clamp01(interpolation_distance / 10); motor.radius = Mathf.Pow(start_size, 1 - exponent) * Mathf.Pow(end_size, exponent); Vector2 phi_theta = new Vector2(motor.radius, 0f); motor.current_position = SphereUtility.SphereToCartesian(phi_theta, up, up, forward); if (interpolation_distance < 0) { ExitNexus(motor); } else if (interpolation_distance > 10f) { RoomLoader.Instance.UnloadRoom(near_id); RoomLoader.Instance.LoadRoom(far_id); ExitNexus(motor); } }
public override Vector3 EvaluateRight(float angle, float radius) //TODO: optimize { return(SphereUtility.SphereToCartesian(new Vector2(Mathf.PI / 2 - AngularRadius(radius), angle), arc_left_normal, -arc_left, path_normal)); }
/** Find the point of collision with an arc. */ public optional <Vector3> Intersect(Vector3 to, Vector3 from, float radius) { optional <Vector3> result = SphereUtility.Intersection(from, to, Pole(), AngularRadius(radius)); return(result); }
/** return the position of the player based on the circular path * */ public override Vector3 Evaluate(float angle, float radius) { return(SphereUtility.SphereToCartesian(new Vector2(AngularRadius(radius), angle), arc_left, arc_left_normal, path_normal)); }
protected override Vector3 Center(float radius) { return(SphereUtility.SphereToCartesian(new Vector2(radius / Mathf.Cos(arc_angle / 2), arc_angle / 2), arc_left, arc_left_normal, path_normal)); //wow, I can't believe it was really cos(angle/2) }
// Update is called once per frame void Update() { //foreach (string s in new string[]{ "Idling", "Magic", "Victory", "Open", "Wheelbarrow", "Strong"}) //{ // if (model.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName(s)) // { // messages.GetComponent<TextMeshPro>().text = motion + ":" + s; // } //} if (motion && model.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("Idling")) { motion = false; leftsource.GetComponent <TrailRecorder>().StopRecord(); leftmatch.GetComponent <TrailRecorder>().StopRecord(); rightsource.GetComponent <TrailRecorder>().StopRecord(); rightmatch.GetComponent <TrailRecorder>().StopRecord(); TrailRecorder str = rightsource.GetComponent <TrailRecorder>(); Spherical3[] sourceTrail = str.mytrail.ToArray(); TrailRecorder mtr = leftmatch.GetComponent <TrailRecorder>(); Spherical3[] matchTrail = mtr.mytrail.ToArray(); Debug.Log("Comparing left trails"); float d = SphereUtility.Divergence(sourceTrail, matchTrail); str = leftsource.GetComponent <TrailRecorder>(); sourceTrail = str.mytrail.ToArray(); mtr = rightmatch.GetComponent <TrailRecorder>(); matchTrail = mtr.mytrail.ToArray(); Debug.Log("Comparing right trails"); d += SphereUtility.Divergence(sourceTrail, matchTrail); d /= 2; Debug.Log("Divergence = " + d); messages.GetComponent <TextMeshPro>().text = "Score: " + (1 - Mathf.Min(d, 1)); Vector3[] sourceCarts = SphereUtility.SphericaToCartesianMirror(sourceTrail); go.GetComponent <LineRenderer>().positionCount = sourceCarts.Length; go.GetComponent <LineRenderer>().SetPositions(sourceCarts); Vector3[] matchCarts = SphereUtility.SphericaToCartesian(matchTrail); go2.GetComponent <LineRenderer>().positionCount = matchCarts.Length; go2.GetComponent <LineRenderer>().SetPositions(matchCarts); } else if (OVRInput.GetDown(OVRInput.Button.Any)) { Debug.Log("Advancing to Next Animation"); if (OVRInput.GetDown(OVRInput.Button.One)) { model.GetComponent <Animator>().SetTrigger("victory"); StartCoroutine(StartMotion()); messages.GetComponent <TextMeshPro>().text = "Victory.."; } else if (OVRInput.GetDown(OVRInput.Button.Two)) { model.GetComponent <Animator>().SetTrigger("wheelbarrow"); StartCoroutine(StartMotion()); messages.GetComponent <TextMeshPro>().text = "Wheelbarrow.."; } else if (OVRInput.GetDown(OVRInput.Button.Three)) { model.GetComponent <Animator>().SetTrigger("strong"); StartCoroutine(StartMotion()); messages.GetComponent <TextMeshPro>().text = "Strong.."; } else if (OVRInput.GetDown(OVRInput.Button.Four)) { model.GetComponent <Animator>().SetTrigger("lift"); StartCoroutine(StartMotion()); messages.GetComponent <TextMeshPro>().text = "Lift.."; } } }