コード例 #1
0
    public Vector3 ToCartesian()
    {
        Vector3 outCart = new Vector3();

        SphericalCoordinates.SphericalToCartesian(this.radius, this.polar, this.elevation, out outCart);
        return(outCart);
    }
コード例 #2
0
        Vector3 GetVectorOut()
        {
            Vector3 o = Vector3.zero;

            SphericalCoordinates.SphericalToCartesian(_radius, _polar, _elevation, out o);
            return(o * _scale);
        }
コード例 #3
0
    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;
        }
    }
コード例 #4
0
    //----------- 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));
    }
コード例 #5
0
    private void GetPositionAndNormalForSlotXAndY(int VisSlotX, int VisSlotY, int VisSlotZ, out Vector3 pos, out Vector3 norm)
    {
        float AzimuthToCenterDeg;
        float SlotAzimuthBreadthDeg;
        float ElevationToCenterDeg;
        float SlotElevationBreadthDeg;
        float SlotCenterRadius;

        GetSlotSphericalInfo(VisSlotX, VisSlotY, VisSlotZ, out AzimuthToCenterDeg, out SlotAzimuthBreadthDeg, out ElevationToCenterDeg, out SlotElevationBreadthDeg, out SlotCenterRadius);
        float polar     = AzimuthToCenterDeg * (float)(Math.PI / 180.0);
        float elevation = ElevationToCenterDeg * (float)(Math.PI / 180.0);

        SphericalCoordinates.SphericalToCartesian(SlotCenterRadius, polar, elevation, out pos);
        Vector3 zero = Vector3.zero;

        norm = (pos - zero).normalized;
    }
コード例 #6
0
    void FillCoords()
    {
        points       = new Vector3[37, 19];
        pointsSphere = new Vector3[37, 19];
        pointsReal   = new Vector3[37, 19];


        for (int x = 0; x < 361; x += 10)
        {
            for (int y = 0; y < 181; y += 10)
            {
                var pos = new Vector2(x - 180, y - 90);
                points[x / 10, y / 10]       = pos;
                pointsSphere[x / 10, y / 10] = SphericalCoordinates.SphericalToCartesian(Radius, pos.x,
                                                                                         pos.y);
            }
        }
    }
コード例 #7
0
    private void OnDrawGizmos()
    {
        if (NoDrawGizmos)
        {
            return;
        }
        float radius = InitialRadius;

        Gizmos.DrawSphere(Vector3.zero, 0.25f);
        Gizmos.DrawWireSphere(Vector3.zero, radius);
        float num1 = WidthRadiusDeg / (float)SlotsWidth;
        float num2 = HeightRadiusDeg / (float)SlotsWidth;
        float num3 = num1 * 0.5f;
        float num4 = num2 * 0.5f;
        float num5 = WidthRadiusDeg;

        if (CenterWidth)
        {
            num5 = (float)(180.0 - (180.0 - (double)WidthRadiusDeg) * 0.5);
        }
        for (int index1 = 0; index1 < SlotsHeight; ++index1)
        {
            float elevation = (HeightRadiusDeg / 2f - num4 - (float)index1 * num2) * (float)(Math.PI / 180.0);
            for (int index2 = 0; index2 < SlotsWidth; ++index2)
            {
                float   polar = (-num5 + num3 + (float)index2 * num1) * (float)(Math.PI / 180.0);
                Vector3 outCart;
                SphericalCoordinates.SphericalToCartesian(radius, polar, elevation, out outCart);
                Vector3 vector3 = outCart - Vector3.zero;
                vector3.Normalize();
                Gizmos.color = Color.red;
                Gizmos.DrawRay(outCart, vector3 * 2f);
                Gizmos.color = Color.white;
                Gizmos.DrawWireCube(outCart, Vector3.one);
            }
        }
    }
コード例 #8
0
 public Vector3 AsSpherical(float radius, Vector3 offset)
 {
     return(SphericalCoordinates.SphericalToCartesian(radius, Longitude, Latitude) + offset);
 }