public void DrawGizmos(Color color) { SphericalCoordinates sphereCoordinates = SphereCoordinatesRef; if (sphereCoordinates != null) { if (sphereCoordinates.radius > 0f) { float cos = Mathf.Cos(RadiansTreshold); float sin = Mathf.Sin(RadiansTreshold); float posMagnitude = transform.position.magnitude; Vector3 posNormalized = transform.position / posMagnitude; Handles.color = color; Handles.DrawWireDisc(posNormalized * posMagnitude * cos, posNormalized, posMagnitude * sin); Handles.DrawWireArc(Vector3.zero, transform.right, posNormalized, angularTreshold, posMagnitude); Handles.DrawWireArc(Vector3.zero, -transform.right, posNormalized, angularTreshold, posMagnitude); Handles.DrawWireArc(Vector3.zero, transform.forward, posNormalized, angularTreshold, posMagnitude); Handles.DrawWireArc(Vector3.zero, -transform.forward, posNormalized, angularTreshold, posMagnitude); } else { Gizmos.color = color; Gizmos.DrawWireSphere(transform.position, sphereCoordinates.radius); } } }
public void Calculate_SetsSphericalCoordinates_FixedThetaCounterClockwise() { // Arrange IEnumerable <SphericalCoordinates> expected = CreateArrayOfThreeSphericalCoordinatesForFixedThetaCounterClockwise(); var coordinatesZeroZero = new SphericalCoordinates { Radius = 1.0, Phi = Angle.ForZeroDegrees, Theta = Angle.ForZeroDegrees }; var coordinatesZeroNintey = new SphericalCoordinates { Radius = 1.0, Phi = Angle.For90Degrees, Theta = Angle.ForZeroDegrees }; m_Sut.FromCoordinates = coordinatesZeroZero; m_Sut.ToCoordinates = coordinatesZeroNintey; m_Sut.TurnDirection = Constants.TurnDirection.Counterclockwise; m_Sut.Steps = 3; // Act m_Sut.Calculate(); // Assert SphericalCoordinatesHelper.AssertSphericalCoordinates(expected, m_Sut.SphericalCoordinates); }
public void DrawGizmos(Color color) { SphericalCoordinates sphereCoordinates = SphereCoordinatesRef; if (sphereCoordinates != null) { if (sphereCoordinates.radius > 0f) { int vertexCount = angularExtensionCurve.length * 4; List <float> angularExtensions = new List <float>(); for (int i = 0; i < vertexCount; i++) { angularExtensions.Add(angularExtensionCurve.Evaluate((float)i / vertexCount)); } /* * float cos = Mathf.Cos(RadiansTreshold); * float sin = Mathf.Sin(RadiansTreshold); * float posMagnitude = transform.position.magnitude; * Vector3 posNormalized = transform.position / posMagnitude; * Handles.color = color; * Handles.DrawWireDisc(posNormalized * posMagnitude * cos, posNormalized, posMagnitude * sin); * Handles.DrawWireArc(Vector3.zero, transform.right, posNormalized, angularTreshold, posMagnitude); * Handles.DrawWireArc(Vector3.zero, -transform.right, posNormalized, angularTreshold, posMagnitude); * Handles.DrawWireArc(Vector3.zero, transform.forward, posNormalized, angularTreshold, posMagnitude); * Handles.DrawWireArc(Vector3.zero, -transform.forward, posNormalized, angularTreshold, posMagnitude); */ } else { Gizmos.color = color; Gizmos.DrawWireSphere(transform.position, sphereCoordinates.radius); } } }
void Awake() { this._SphereCoords = new SphericalCoordinates(SphereRadius, Mathf.PI/2.0f, 0f, 0f, SphereRadius); Cursor = transform.Find("Cursor").gameObject; CursorMeshRenderer = Cursor.transform.GetComponentInChildren<MeshRenderer>(); CursorMeshRenderer.renderer.material.color = new Color(0.0f, 0.8f, 1.0f); }
public void Calculate_SetsVectorInCartesian_ForGivenValues( double radius, double phiInRadians, double polarThetaInRadians, double expectedX, double expectedY, double expectedZ) { // Arrange var sut = new SphericalToCartesianCalculator(); var expected = new CartesianCoordinates { X = expectedX, Y = expectedY, Z = expectedZ }; var sphericalCoordinates = new SphericalCoordinates { Radius = radius, Phi = Angle.FromRadians(phiInRadians), Theta = Angle.FromRadians(polarThetaInRadians) }; sut.SphericalCoordinates = sphericalCoordinates; // Act sut.Calculate(); // Assert CartesianCoordinatesHelper.AssertCartesianCoordinates(expected, sut.CartesianCoordinates); }
/// <summary> /// Converts a point from Cartesian coordinates (using positive Y as up) to /// Spherical and stores the results in the store var. (Radius, Azimuth, /// Polar) /// </summary> public static SphericalCoordinates CartesianToSpherical(Vector3 cartCoords) { SphericalCoordinates store = new SphericalCoordinates(); CartesianToSpherical(cartCoords, out store.radius, out store.polar, out store.elevation); return(store); }
void Start() { _camera = GetComponent <Camera>(); _sphericalCoordinate = new SphericalCoordinates(); Mov = new Vector2(); }
public static SphericalCoordinates CartesianToSpherical(Vector3 cartCoords) { SphericalCoordinates sphericalCoordinates = new SphericalCoordinates(); SphericalCoordinates.CartesianToSpherical(cartCoords, out sphericalCoordinates.radius, out sphericalCoordinates.polar, out sphericalCoordinates.elevation); return(sphericalCoordinates); }
public Vector3 ToCartesian() { Vector3 outCart = new Vector3(); SphericalCoordinates.SphericalToCartesian(this.radius, this.polar, this.elevation, out outCart); return(outCart); }
Vector3 GetVectorOut() { Vector3 o = Vector3.zero; SphericalCoordinates.SphericalToCartesian(_radius, _polar, _elevation, out o); return(o * _scale); }
private IEnumerable <SphericalCoordinates> CreateArrayOfThreeSphericalCoordinates() { var one = new SphericalCoordinates { Radius = 1.0, Phi = Angle.ForZeroDegrees, Theta = Angle.For180Degrees }; var two = new SphericalCoordinates { Radius = 1.0, Phi = Angle.For45Degrees, Theta = Angle.For225Degrees }; var three = new SphericalCoordinates { Radius = 1.0, Phi = Angle.For90Degrees, Theta = Angle.For270Degrees }; return(new[] { one, two, three }); }
/// <summary>Handle developer relative postiion adjustment</summary> /// <param name="preset"></param> /// <returns></returns> internal static bool OnSceneHandlePosition(Preset preset) { bool changed = false; // Visualize handler's if (Tools.current == Tool.Move) { Tools.hidden = true; Quaternion handlerQuat = (Tools.pivotRotation == PivotRotation.Global) ? Quaternion.identity : preset.transform.rotation; // Camera position handler float radius = preset.m_VirtualPosition.m_Camera.m_Coordinates.radius; Transform tran = preset.Instance.m_ChaseTargetOffsetHandler.transform; Vector3 org = tran.position.PointOnDistance((preset.Instance.m_PitchHandler.transform.forward * radius), radius), edit = Handles.PositionHandle(org, handlerQuat), ld1 = tran.InverseTransformPoint(org), ld2 = tran.InverseTransformPoint(edit); if (!edit.Equals(org)) { Undo.RecordObject(preset, "Change Camera coordinates" + preset.GetInstanceID()); SphericalCoordinates sc1 = SphericalCoordinates.RelativeToTarget(ld1, Vector3.zero), sc2 = SphericalCoordinates.RelativeToTarget(ld2, Vector3.zero); preset.Instance.YawDegree = preset.m_VirtualPosition.m_Camera.m_Coordinates.Yaw += sc1.Yaw - sc2.Yaw; preset.Instance.PitchDegree = preset.m_VirtualPosition.m_Camera.m_Coordinates.Pitch += sc1.Pitch - sc2.Pitch; preset.Instance.OrbitDistance = preset.m_VirtualPosition.m_Camera.m_Coordinates.radius = sc2.radius; preset.m_Editing = true; changed = true; } // ExtendLookAt handler if (preset.m_VirtualPosition.m_EnableLookTarget) { radius = preset.m_VirtualPosition.m_LookTarget.m_Coordinates.radius; tran = preset.Instance.m_PitchLookAtHandler.transform; org = tran.position.PointOnDistance((tran.forward * radius), radius); edit = Handles.PositionHandle(org, handlerQuat); ld1 = tran.InverseTransformPoint(org); ld2 = tran.InverseTransformPoint(edit); if (!edit.Equals(org)) { Undo.RecordObject(preset, "Change lookAt coordinates" + preset.GetInstanceID()); SphericalCoordinates sc1 = SphericalCoordinates.RelativeToTarget(ld1, Vector3.zero), sc2 = SphericalCoordinates.RelativeToTarget(ld2, Vector3.zero); preset.Instance.YawLookAtDegree = preset.m_VirtualPosition.m_LookTarget.m_Coordinates.Yaw += sc1.Yaw - sc2.Yaw; preset.Instance.PitchLookAtDegree = preset.m_VirtualPosition.m_LookTarget.m_Coordinates.Pitch += sc1.Pitch - sc2.Pitch; preset.Instance.OrbitLookAtDistance = preset.m_VirtualPosition.m_LookTarget.m_Coordinates.radius = sc2.radius; preset.m_Editing = true; changed = true; } } } return(changed); }
void Awake() { // Referenced from http://wiki.unity3d.com/index.php/SphericalCoordinates sphericalCoordinates = new SphericalCoordinates(1000f, (Mathf.PI / 2f), 0f, 0f, 20f, 0f, -(Mathf.PI * 2f), -(Mathf.PI / 3f), (Mathf.PI / 3f)); Cursor = transform.Find("Cursor").gameObject; CursorMeshRenderer = Cursor.transform.GetComponentInChildren <MeshRenderer>(); CursorMeshRenderer.GetComponent <Renderer>().material.color = new Color(0.0f, 0.8f, 1.0f); }
private void Start() { //スクリプトを初期化 sphericalCoordinates = new SphericalCoordinates(transform.position); //アタッチしたGameObjectのpositionを設定する transform.position = sphericalCoordinates.ToCartesian + pivot.position; }
private void Start() { //we use the function SphericalCoordinates. It does want I want it to but it isn't commented, so I just made it up // the final two values specify the min and max elevation relative to the pivot position sc = new SphericalCoordinates(transform.position, 3f, 10f, 0f, Mathf.PI * 2f, -1 * Mathf.PI / 4f, Mathf.PI / 4f); // Initialize position transform.position = sc.toCartesian + pivot.position; }
protected override void OnAwake() { Mode = ModeType.TX_THREAD; gpsLink = transform.parent; DeviceName = name; sphericalCoordinates = DeviceHelper.GetGlobalSphericalCoordinates(); }
public void BuildCircle() { // check if game object exists as child MeshRenderer meshRenderer; VolumetricLineStripBehavior volLineStrip; GameObject go; var childExists = transform.Find("Child Circle"); if (childExists == null) { // Create an empty game object go = new GameObject(); go.name = "Child Circle"; go.transform.parent = transform; go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = new Vector3(1, 1); // Add the MeshFilter component, VolumetricLineStripBehavior requires it go.AddComponent<MeshFilter>(); // Add a MeshRenderer, VolumetricLineStripBehavior requires it, and set the material meshRenderer = go.AddComponent<MeshRenderer>(); // Add the VolumetricLineStripBehavior and set parameters, like color and all the vertices of the line volLineStrip = go.AddComponent<VolumetricLineStripBehavior>(); } else { go = childExists.gameObject; meshRenderer = go.GetComponent<MeshRenderer>(); volLineStrip = go.GetComponent<VolumetricLineStripBehavior>(); } meshRenderer.material = m_volumetricLineStripMaterial; //volLineStrip.SetLineColorAtStart = true; volLineStrip.LineColor = m_color; volLineStrip.LineWidth = lineWidth; float dist = Mathf.Sqrt(900 - Mathf.Pow(radius, 2)) - m_offset; SphericalCoordinates sc = new SphericalCoordinates(dist, polar * Mathf.Deg2Rad, elevation * Mathf.Deg2Rad, 1, 30.3f, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); Vector3 position = sc.toCartesian; var lineVertices = new Vector3[m_numVertices]; for (int i = 0; i < m_numVertices; ++i) { float t = Mathf.Lerp(0f, 2 * Mathf.PI, (float)i / (float)(m_numVertices - 1)); float x = radius * Mathf.Cos(t); float y = radius * Mathf.Sin(t); lineVertices[i] = new Vector3(x, y, 0f); } volLineStrip.UpdateLineVertices(lineVertices); transform.position = position; }
public SphericalArcCalculator( [NotNull] ISphericalCoordinatesIntervallCalculator calculator, [NotNull] IRadiusPhiThetaToSphericalCoordinatesConverter converter) { m_Calculator = calculator; m_Converter = converter; Steps = 3; TurnDirection = Constants.TurnDirection.Clockwise; SphericalCoordinates = new SphericalCoordinates[0]; }
/*void Start() { sc = new SphericalCoordinates(radius, 0, 0, 1, maxRadius, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); }*/ // Update is called once per frame void Update() { if (sc == null) sc = new SphericalCoordinates(radius, 0, 0, 1, maxRadius, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); sc.SetRadius(radius); sc.SetRotation(polarAngle * Mathf.Deg2Rad, elevationAngle * Mathf.Deg2Rad); transform.position = sc.toCartesian; }
public void Setup() { m_Sut = new SphericalCoordinates { Radius = 1.0, PolarAngle = PolarAngle.FromRadians(Angle.For45Degrees.Radians), AzimuthalAngle = AzimuthAngle.FromRadians(Angle.For90Degrees.Radians), IsUnknown = true }; }
private void DeformMeshToCoverBoardSlot(BoardSlot slot, GameObject MeshGO) { if ((UnityEngine.Object)BaseMesh == (UnityEngine.Object)null) { BaseMesh = ShapeSpawner.GetComponent <MeshFilter>().mesh; BaseMeshVerts = BaseMesh.vertices; } int VisualX; int VisualY; int VisualZ; GetVisualPositionsForBoardSlot(slot, out VisualX, out VisualY, out VisualZ); int keyForY1 = GetKeyForY(VisualY, VisualZ); if (vertlists.ContainsKey(keyForY1)) { Mesh mesh = MeshGO.GetComponent <MeshFilter>().mesh; SphericalLayoutTest.VerticesInfo verticesInfo = vertlists[keyForY1]; mesh.vertices = verticesInfo.verts; mesh.normals = verticesInfo.normals; } else { float AzimuthToCenterDeg; float SlotAzimuthBreadthDeg; float ElevationToCenterDeg; float SlotElevationBreadthDeg; float SlotCenterRadius; GetSlotSphericalInfo(VisualX, VisualY, VisualZ, out AzimuthToCenterDeg, out SlotAzimuthBreadthDeg, out ElevationToCenterDeg, out SlotElevationBreadthDeg, out SlotCenterRadius); Mesh mesh = MeshGO.GetComponent <MeshFilter>().mesh; Vector3[] vector3Array = new Vector3[mesh.vertexCount]; Transform transform = MeshGO.transform; Vector3 localScale = transform.localScale; for (int index = 0; index < vector3Array.Length; ++index) { Vector3 vector3 = BaseMeshVerts[index]; float polar = (AzimuthToCenterDeg + vector3.x * SlotAzimuthBreadthDeg) * (float)(Math.PI / 180.0); float elevation = (ElevationToCenterDeg + vector3.y * SlotElevationBreadthDeg) * (float)(Math.PI / 180.0); Vector3 outCart; SphericalCoordinates.SphericalToCartesian(SlotCenterRadius - localScale.z * vector3.z, polar, elevation, out outCart); outCart = transform.InverseTransformPoint(outCart); vector3Array[index] = outCart; } mesh.vertices = vector3Array; mesh.RecalculateNormals(); int keyForY2 = GetKeyForY(VisualY, VisualZ); if (vertlists.ContainsKey(keyForY2)) { return; } vertlists[keyForY2] = new SphericalLayoutTest.VerticesInfo(); vertlists[keyForY2].verts = vector3Array; vertlists[keyForY2].normals = mesh.normals; } }
// Use this for initialization void Start() { copy = shotFreqeuncy; minPolar = minPolar *Mathf.Deg2Rad; maxPolar = maxPolar *Mathf.Deg2Rad; minElevation = minElevation * Mathf.Deg2Rad; maxElevation *= Mathf.Deg2Rad; curPos = new SphericalCoordinates(radius, 0, 0, 1, radius, minPolar, maxPolar, minElevation, maxElevation); sign = 1; }
// Formulae for converting back to cartesian coordinates from spherical, again adjusted for // the Unity world space coordinate frame private static Vector3 SphericalToCartesian(SphericalCoordinates spherical) { Vector3 cartesian = new Vector3(0, 0, 0) { x = spherical.Radius * Mathf.Cos(spherical.Elevation) * Mathf.Cos(spherical.Azimuth), y = spherical.Radius * Mathf.Sin(spherical.Elevation), z = spherical.Radius * Mathf.Cos(spherical.Elevation) * Mathf.Sin(spherical.Azimuth) }; return(cartesian); }
public static string ConvertToSTring( SphericalCoordinates coordinates) { var converter = new SphericalCoordinatesToStringConverter { Coordinates = coordinates }; converter.Convert(); return(converter.String); }
void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag("Slider")) { Slider s = collision.gameObject.GetComponent<Slider>(); if (s != null) { int tsign = s.getSign(); if (tsign == 0) { sign *= -1; } else { sign = tsign; direction = s.movementDimension; speed = s.angularSpeed; } } playSound(); } else if (collision.gameObject.CompareTag("Wedge")) { //Debug.Log("Hit Wedge"); WedgeBehavior wb = collision.gameObject.GetComponentInParent<WedgeBehavior>(); if (collision.collider.Equals(wb.bottom)) { sign *= wb.sign; direction = direction == 1 ? 0 : 1; //Debug.Log("Bottom"); } else { sign = -sign; //Debug.Log("side"); } playSound(); } else if (collision.gameObject.CompareTag("Barrier")) { sign *= -1; playSound(); } Vector3 startPos = gameObject.transform.position; SphericalCoordinates sc = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); sc.FromCartesian(startPos); elevationAngle = sc.elevation; polarAngle = sc.polar; activeAdjustment = true; }
// Use this for initialization void Start() { sphericalCoordinates = new SphericalCoordinates(transform.position); transform.position = sphericalCoordinates.toCartesian + pivot.position; Mesh mesh = pivot.gameObject.GetComponent<MeshFilter>().mesh; for (int i = 0; i < mesh.vertices.Length; i++) { if (triangleVertices.Count < 3) { triangleVertices.Add(mesh.vertices[i]); } } }
void Start() { string mapName = GlobalState().MapName(); map = new Map(mapName); Debug.Log("Game Mode: " + GlobalState().GameMode()); string mode = GlobalState().GameMode(); sc = new SphericalCoordinates(transform.localPosition, 0f, 10f, 0f, (Mathf.PI * 2f), -(Mathf.PI / 3f), (Mathf.PI / 3f)); transform.localPosition = sc.toCartesian; PutObjectAtStartPosition(); }
} // todo should not be negative, same with radius public void Calculate() { SphericalCoordinates fromSphericalCoordinates = ToSpherical(FromCoordinates); SphericalCoordinates toSphericalCoordinates = ToSpherical(ToCoordinates); m_SphericalArcCalculator.FromCoordinates = fromSphericalCoordinates; m_SphericalArcCalculator.ToCoordinates = toSphericalCoordinates; m_SphericalArcCalculator.TurnDirection = TurnDirection; m_SphericalArcCalculator.Steps = Steps; m_SphericalArcCalculator.Calculate(); CartesianCoordinates = ToCartesianCoordinates(m_SphericalArcCalculator.SphericalCoordinates); }
void Start() { RefreshControllers(); GameObject[] infoDisplays = GameObject.FindGameObjectsWithTag("InfoDisplay"); infoDisplay = infoDisplays[0]; SetInfoDisplayText(""); DisableInfoDisplay(); string mapName = GlobalState().MapName(); map = new Map(mapName); Debug.Log(this.name + ": In PlayerSphericalMovement.Start, mapName = " + mapName); Debug.Log(this.name + ": Game Mode: " + GlobalState().GameMode()); string mode = GlobalState().GameMode(); if (mode == "GameStart") { gameStartTime = Time.time; if (this.name == "Player") { if (GlobalState().AudioEnabled()) { audio.PlayOneShot(startSound); } humanControl = true; StartLevel(); } } else if (mode == "GameInProgress") { // new map started. StartLevel(); } else if (mode == "GameDemo") { humanControl = false; } sc = new SphericalCoordinates(transform.localPosition, 0f, 10f, 0f, (Mathf.PI * 2f), -(Mathf.PI / 3f), (Mathf.PI / 3f)); transform.localPosition = sc.toCartesian; PutPlayerAtStartPosition(); isDead = false; isScared = false; _size = new Vector2(1.0f / _uvTieX, 1.0f / _uvTieY); _myRenderer = renderer; _myRenderer.material.SetTextureScale("_MainTex", _size); }
void Start() { sc = new SphericalCoordinates(camera.transform.position, 3f, 10f, 0f, Mathf.PI * 2f, 0f, Mathf.PI / 2f); Debug.Log("Spherical coordinates created: " + sc); // Initialize position if (pivot == null) { Debug.Log("Pivot is null"); return; } Debug.Log("Using Pivot:", pivot); Debug.Log("Sc.toCartesian = " + sc.toCartesian); transform.position = sc.toCartesian + pivot.position; }
void Start() { GameObject[] states = GameObject.FindGameObjectsWithTag("PersistedState"); GameObject state = states[0]; string mapName = state.GetComponent <GlobalGameDetails>().MapName(); Map map = new Map(mapName); Debug.Log("In AddRegularPills.Start, mapName = " + mapName); int pillCount = 0; int powerPillCount = 0; for (int gridX = 0; gridX < GlobalGameDetails.mapColumns; gridX++) { for (int gridY = 0; gridY < GlobalGameDetails.mapRows; gridY++) { if (map.PillAtGridReference(gridX, gridY)) { float[] latLongRef = map.LatitudeLongitudeAtGridReference(gridX, gridY); float latitude = latLongRef [0]; float longitude = latLongRef [1]; // TODO: DRY this out - we should get GlobalGameDetails to return // a SphericalCoordinates instance for consistency SphericalCoordinates sc = new SphericalCoordinates( 0.5f, degreesToRadians(longitude), degreesToRadians(latitude), 0f, 10f, 0f, (Mathf.PI * 2f), -(Mathf.PI / 3f), (Mathf.PI / 3f) ); Vector3 newPillPosition = sc.toCartesian; GameObject pill; if (map.PowerPillAtGridReference(gridX, gridY)) { pill = Instantiate(powerPillObject) as GameObject; powerPillCount++; } else { pill = Instantiate(pillObject) as GameObject; } pillCount++; // powerPills are still pills pill.transform.parent = transform; pill.transform.localPosition = newPillPosition; } } } Debug.Log("Created " + pillCount + " pills, including " + powerPillCount + " power pills"); }
//----------- Locomotion Vector3 wander() { elevation += Random.Range(-delta, delta); // Increment elevation offset polar += Random.Range(-delta, delta); // Increment polar offset Vector3 sphericalProjection = new Vector3(); SphericalCoordinates.SphericalToCartesian(radius, polar, elevation, out sphericalProjection); // Calculate spherical coordinates Vector3 target = transform.position + transform.forward * projection + sphericalProjection; // Project target in front of object // debugWander(target, radius); return(seek(target, max_speed, max_force_mov)); }
// Use this for initialization void Start() { sphericalCoordinates = new SphericalCoordinates(transform.position); transform.position = sphericalCoordinates.toCartesian + pivot.position; Mesh mesh = pivot.gameObject.GetComponent <MeshFilter>().mesh; for (int i = 0; i < mesh.vertices.Length; i++) { if (triangleVertices.Count < 3) { triangleVertices.Add(mesh.vertices[i]); } } }
public Vector3 InitialiseCameraPos(float elevation, float azimuth) { // Set the initial elevation and azimuth of the camera. Start by converting its vector // position to spherical coordinates, moving it to the global origin for this SphericalCoordinates cameraSpherePos = CartesianToSpherical(CameraPosition - Origin); // Then add the elevation and azimuth angles (in radians) to the coordinates. cameraSpherePos.Elevation += elevation; cameraSpherePos.Azimuth += azimuth; // Finally, convert the spherical coordinates back to cartesian, move back to the correct // position with regards to the target and store the new position, also returning this vector. CameraPosition = Origin + SphericalToCartesian(cameraSpherePos); return(CameraPosition); }
public Vector3 ZoomCamera(float zoomSpeed, float zoomAmount) { // Again, convert cartesian vector to spherical coordinates with target on // global origin SphericalCoordinates cameraSpherePos = CartesianToSpherical(CameraPosition - Origin); // Add the zoom movement to the radius, again adjusting it using the zoom speed // and delta time cameraSpherePos.Radius += zoomAmount * Time.deltaTime * zoomSpeed; // Convert the coordinates back and associate with the true target origin once again. // Then, save and return the new vector position. CameraPosition = Origin + SphericalToCartesian(cameraSpherePos); return(CameraPosition); }
protected override void OnAwake() { gpsLink = transform.parent; deviceName = name; var coreObject = GameObject.Find("Core"); if (coreObject == null) { Debug.LogError("Failed to Find 'Core'!!!!"); } else { sphericalCoordinates = coreObject.GetComponent <SphericalCoordinates>(); } }
// Use this for initialization public void CreateLights() { for (int i=0; i<total; i++) { float polarAngle = Random.Range(-Mathf.PI, Mathf.PI); float elevationAngle = Random.Range (- Mathf.PI / 2, Mathf.PI / 2); float radius = sphereRadius - 0.6f + Random.Range(0, 0.4f); SphericalCoordinates sc = new SphericalCoordinates(radius, polarAngle, elevationAngle, 1, sphereRadius, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); //sc.SetRotation(polarAngle * Mathf.Deg2Rad, elevationAngle * Mathf.Deg2Rad); GameObject cur = new GameObject("The Light " + i); cur.transform.position = sc.toCartesian; cur.transform.parent = transform; Light lightComp = cur.AddComponent<Light>(); lightComp.type = LightType.Point; cur.isStatic = true; //GameObject cur = (GameObject) Instantiate(lightPrefab, sc.toCartesian, Quaternion.identity); } }
// Use this for initialization void Start() { curPos = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); curPos.loopPolar = true; Destroy(gameObject, lifetime); }
void Update() { if (activeAdjustment) { Vector3 currentPos = gameObject.transform.position; SphericalCoordinates sc = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); sc.loopPolar = true; sc.FromCartesian(currentPos); //sc.SetRadius(radius); float change = sign * speed * Time.deltaTime; if (direction == 0) { sc.RotatePolarAngle(change); gameObject.transform.position = sc.toCartesian; } else { sc.RotateElevationAngle(change); gameObject.transform.position = sc.toCartesian; } } if (Input.GetButton("R1")) { mainCam.SetActive(false); ballCam.SetActive(true); } else { mainCam.SetActive(true); ballCam.SetActive(false); } }
public void BuildWall() { SphericalCoordinates p1 = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); SphericalCoordinates p2 = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); SphericalCoordinates p3 = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); SphericalCoordinates p4 = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); int triBase; int numVertices = (segments) * 4 + 28; int numTriangles = (4 * segments) + 16; float polarDif = (polarSize * Mathf.Deg2Rad) / 2; float eleDif = (elevationSize * Mathf.Deg2Rad) / 2f; p1.SetRotation(-polarDif, eleDif); p2.SetRotation(-polarDif, -eleDif); p3.SetRotation(polarDif, eleDif); p4.SetRotation(polarDif, -eleDif); float polarStep = (polarSize * Mathf.Deg2Rad) / segments; float eleStep = 0;//(p1.elevation - p4.elevation) / segments; Vector3 p1Cart, p2Cart, p3Cart, p4Cart; p1Cart = p1.toCartesian; p2Cart = p2.toCartesian; p3Cart = p3.toCartesian; p4Cart = p4.toCartesian; //Vector3[] normals = new Vector3[numVertices]; Vector3[] vertices = new Vector3[numVertices]; int[] triangles = new int[3 * numTriangles]; Vector3 leftMid = (p1Cart + p3Cart) / 2; Vector3 rightMid = (p2Cart + p4Cart) / 2; Vector3 center = (leftMid + rightMid) / 2; //int v = 0; vertices[0] = p1Cart - center; vertices[1] = p2Cart - center; vertices[2] = p3Cart - center; vertices[3] = p4Cart - center; vertices[4] = leftMid - center; vertices[5] = rightMid - center; //Vector3 verticalNorm = -center.normalized; for (int i = 0; i < 6; i++) { //vertices[i + 6] = vertices[i] + height * norm; vertices[i + 6] = vertices[i+12] = vertices[i] - height * (vertices[i] + center).normalized; //normals[i + 6] = verticalNorm; } topLeft = vertices[6]; topRight = vertices[7]; bottomLeft = vertices[8]; bottomRight = vertices[9]; Vector3 farTopLeft = vertices[0]; Vector3 farTopRight = vertices[1]; Vector3 farBottomLeft = vertices[2]; Vector3 farBottomRight = vertices[3]; //front rectangle triangles[0] = 10; triangles[1] = 6; triangles[2] = 7; triangles[3] = 10; triangles[4] = 7; triangles[5] = 11; triangles[6] = 8; triangles[7] = 10; triangles[8] = 11; triangles[9] = 8; triangles[10] = 11; triangles[11] = 9; //left side rectangle triangles[12] = 16; triangles[13] = 4; triangles[14] = 12; triangles[15] = 12; triangles[16] = 4; triangles[17] = 0; triangles[18] = 2; triangles[19] = 4; triangles[20] = 16; triangles[21] = 14; triangles[22] = 2; triangles[23] = 16; //right side rectangle for (int i = 0; i < 12; i += 3) { triangles[i + 24] = triangles[i + 12] + 1; triangles[i + 25] = triangles[i + 14] + 1; triangles[i + 26] = triangles[i + 13] + 1; } vertices[18] = farTopLeft; vertices[19] = farTopRight; vertices[20] = farBottomLeft; vertices[21] = farBottomRight; vertices[22] = topLeft; vertices[23] = topRight; vertices[24] = bottomLeft; vertices[25] = bottomRight; //top rectangle triangles[36] = 23; triangles[37] = 22; triangles[38] = 19; triangles[39] = 19; triangles[40] = 22; triangles[41] = 18; //bottom rectangle triangles[42] = 24; triangles[43] = 25; triangles[44] = 20; triangles[45] = 20; triangles[46] = 25; triangles[47] = 21; vertices[26] = farTopLeft; vertices[27] = farTopRight; int roundleftIdx = 26; int roundrightIdx = 27; int flatLeftIdx = 0; int flatRightIdx = 1; for (int i = 1; i < segments; i++) { SphericalCoordinates newLeft = p1.Rotate(polarStep, eleStep); SphericalCoordinates newRight = p2.Rotate(polarStep, eleStep); //Debug.Log(newLeft.ToString()); //Debug.Log(newRight.ToString()); Vector3 nRCart = newRight.toCartesian - center; Vector3 nLCart = newLeft.toCartesian - center; int nLIdx = 4 * i + 26; int nRIdx = nLIdx+1; int bLIdx = nRIdx + 1; int bRIdx = bLIdx + 1; vertices[nLIdx] = vertices[bLIdx] = nLCart; vertices[nRIdx] = vertices [bRIdx] = nRCart; triBase = 12 * i + 36; triangles[triBase] = 4; triangles[triBase + 1] = bLIdx; triangles[triBase + 2] = flatLeftIdx; triangles[triBase + 3] = roundleftIdx; triangles[triBase + 4] = nLIdx; triangles[triBase + 5] = nRIdx; triangles[triBase + 6] = roundleftIdx; triangles[triBase + 7] = nRIdx; triangles[triBase + 8] = roundrightIdx; triangles[triBase + 9] = 5; triangles[triBase + 10] = flatRightIdx; triangles[triBase + 11] = bRIdx; roundleftIdx = nLIdx; roundrightIdx = nRIdx; flatLeftIdx = bLIdx; flatRightIdx = bRIdx; } vertices[flatRightIdx + 1] = farBottomLeft; vertices[flatRightIdx + 2] = farBottomRight; Debug.Log(flatRightIdx + 2); triBase = (3 * numTriangles) - 12; triangles[triBase] = 4; triangles[triBase + 1] = 2; triangles[triBase + 2] = flatLeftIdx; triangles[triBase + 3] = flatRightIdx + 2; triangles[triBase + 4] = roundleftIdx; triangles[triBase + 5] = flatRightIdx + 1; triangles[triBase + 6] = roundleftIdx; triangles[triBase + 7] = flatRightIdx + 2; triangles[triBase + 8] = roundrightIdx; triangles[triBase + 9] = 5; triangles[triBase + 10] = flatRightIdx; triangles[triBase + 11] = 3; //state = 'i'; Mesh mesh = new Mesh(); mesh.name = "Barrier"; mesh.vertices = vertices; mesh.triangles = triangles; mesh.RecalculateNormals(); //GameObject next = Instantiate(prefab, center, Quaternion.identity) as GameObject; p1.SetRotation(polarAngle * Mathf.Deg2Rad, elevationAngle * Mathf.Deg2Rad); p1.SetRadius(center.magnitude); transform.position = p1.toCartesian; GetComponent<MeshFilter>().sharedMesh = mesh; GetComponent<MeshCollider>().sharedMesh = mesh; CreateGlow(); }
/// <summary> /// Converts a point from Cartesian coordinates (using positive Y as up) to /// Spherical and stores the results in the store var. (Radius, Azimuth, /// Polar) /// </summary> public static SphericalCoordinates CartesianToSpherical(Vector3 cartCoords) { SphericalCoordinates store = new SphericalCoordinates(); CartesianToSpherical(cartCoords, out store.radius, out store.polar, out store.elevation); return store; }
void Start() { p1 = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); p2 = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); p3 = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); p4 = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); }
// Use this for initialization void Start() { startPosition = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, minPolar*Mathf.Deg2Rad, maxPolar * Mathf.Deg2Rad, minElevation * Mathf.Deg2Rad, maxElevation * Mathf.Deg2Rad); startPosition.loopPolar = false; startPosition.FromCartesian(transform.position); curPosition = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, minPolar * Mathf.Deg2Rad, maxPolar * Mathf.Deg2Rad, minElevation * Mathf.Deg2Rad, maxElevation * Mathf.Deg2Rad); curPosition.loopPolar = false; curPosition.FromCartesian(transform.position); sliders = GameObject.FindGameObjectsWithTag("Slider"); }