Skip to content

File SphericalPosition.h

File List > Amplitude > Math > SphericalPosition.h

Go to the documentation of this file

// Copyright (c) 2024-present Sparky Studios. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#ifndef _AM_MATH_SPHERICAL_POSITION_H
#define _AM_MATH_SPHERICAL_POSITION_H

#include <SparkyStudios/Audio/Amplitude/Core/Common.h>
#include <SparkyStudios/Audio/Amplitude/Math/LinearAlgebra.h>

namespace SparkyStudios::Audio::Amplitude
{
    struct AM_API_PUBLIC SphericalPosition
    {
        static SphericalPosition FromWorldSpace(const AmVector3& position);

        static SphericalPosition ForHRTF(const AmVector3& position);

        static SphericalPosition FromDegrees(AmReal32 azimuthDegrees, AmReal32 elevationDegrees, AmReal32 radius = 1.0f);

        SphericalPosition() = default;

        SphericalPosition(AmReal32 azimuth, AmReal32 elevation, AmReal32 radius = 1.0f);

        [[nodiscard]] SphericalPosition FlipAzimuth() const;

        [[nodiscard]] SphericalPosition Rotate(AmQuaternion rotation) const;

        [[nodiscard]] AmVector3 ToCartesian() const;

        [[nodiscard]] AM_INLINE AmReal32 GetAzimuth() const
        {
            return _azimuth;
        }

        [[nodiscard]] AM_INLINE AmReal32 GetElevation() const
        {
            return _elevation;
        }

        [[nodiscard]] AM_INLINE AmReal32 GetRadius() const
        {
            return _radius;
        }

        AM_INLINE void SetAzimuth(AmReal32 azimuth)
        {
            _azimuth = azimuth;
        }

        AM_INLINE void SetElevation(AmReal32 elevation)
        {
            _elevation = elevation;
        }

        AM_INLINE void SetRadius(AmReal32 radius)
        {
            _radius = radius;
        }

        bool operator==(const SphericalPosition& other) const;

        bool operator!=(const SphericalPosition& other) const;

    private:
        AmReal32 _azimuth = 0.0f;
        AmReal32 _elevation = 0.0f;
        AmReal32 _radius = 1.0f;
    };
} // namespace SparkyStudios::Audio::Amplitude

#endif // _AM_MATH_SPHERICAL_POSITION_H