Example #1
0
        public void GetSectorIdAt(Vector3 localPosition, out MyPlanetSectorId id)
        {
            id = new MyPlanetSectorId();

            Vector3D local = localPosition;

            MyCubemapHelpers.ProjectToNearestFace(ref local, out localPosition);
            MyCubemapHelpers.GetCubeFaceDirection(ref localPosition, out id.Direction);
            id.Direction = -id.Direction;

            localPosition = (localPosition + 1f) * .5f;

            id.Position = new Vector3S(localPosition.X * m_numSectors, localPosition.Y * m_numSectors, localPosition.Z * m_numSectors);
            if (id.Position.X == m_numSectors)
            {
                id.Position.X = (short)(m_numSectors - 1);
            }
            if (id.Position.Y == m_numSectors)
            {
                id.Position.Y = (short)(m_numSectors - 1);
            }
            if (id.Position.Z == m_numSectors)
            {
                id.Position.Z = (short)(m_numSectors - 1);
            }
        }
Example #2
0
        // Compute the position in the sector cube from planet space coordinates.
        private void LocalPositionToSectorCube(Vector3D localCoords, out Vector3 sectorCoords)
        {
            Vector3 textcoord;

            MyCubemapHelpers.ProjectToNearestFace(ref localCoords, out textcoord);

            // bring textcoords into 0-1 space.
            textcoord = (textcoord + 1f) * .5f;

            sectorCoords = new Vector3(textcoord.X * m_numSectors, textcoord.Y * m_numSectors, textcoord.Z * m_numSectors);

            if (sectorCoords.X == m_numSectors)
            {
                sectorCoords.X = (m_numSectors - 1);
            }
            if (sectorCoords.Y == m_numSectors)
            {
                sectorCoords.Y = (m_numSectors - 1);
            }
            if (sectorCoords.Z == m_numSectors)
            {
                sectorCoords.Z = (m_numSectors - 1);
            }
        }