Skip to content

File CartesianCoordinateSystem.h

File List > Amplitude > Math > CartesianCoordinateSystem.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_CARTESIAN_COORDINATE_SYSTEM_H
#define _AM_MATH_CARTESIAN_COORDINATE_SYSTEM_H

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

namespace SparkyStudios::Audio::Amplitude
{
    class AM_API_PUBLIC CartesianCoordinateSystem
    {
    public:
        enum class Axis
        {
            PositiveX,

            PositiveY,

            PositiveZ,

            NegativeX,

            NegativeY,

            NegativeZ
        };

        class AM_API_PUBLIC Converter
        {
        public:
            Converter(const CartesianCoordinateSystem& from, const CartesianCoordinateSystem& to);

            [[nodiscard]] AmVector3 Forward(const AmVector3& vector) const;

            [[nodiscard]] AmQuaternion Forward(const AmQuaternion& quaternion) const;

            [[nodiscard]] AmReal32 Forward(const AmReal32& scalar) const;

            [[nodiscard]] AmVector3 Backward(const AmVector3& vector) const;

            [[nodiscard]] AmQuaternion Backward(const AmQuaternion& quaternion) const;

            [[nodiscard]] AmReal32 Backward(const AmReal32& scalar) const;

        private:
            AmMatrix3 _fromToMatrix;
            AmMatrix3 _toFromMatrix;

            AmReal32 _fromToScalar;
            AmReal32 _toFromScalar;

            AmReal32 _windingSwap;
        };

        static CartesianCoordinateSystem Default();

        static CartesianCoordinateSystem AmbiX();

        static CartesianCoordinateSystem RightHandedYUp();

        static CartesianCoordinateSystem LeftHandedYUp();

        static CartesianCoordinateSystem RightHandedZUp();

        static CartesianCoordinateSystem LeftHandedZUp();

        static AmVector3 Convert(const AmVector3& vector, const CartesianCoordinateSystem& from, const CartesianCoordinateSystem& to);

        static AmQuaternion Convert(
            const AmQuaternion& rotation, const CartesianCoordinateSystem& from, const CartesianCoordinateSystem& to);

        static AmReal32 Convert(AmReal32 scalar, const CartesianCoordinateSystem& from, const CartesianCoordinateSystem& to);

        static AmVector3 ConvertToDefault(const AmVector3& vector, const CartesianCoordinateSystem& from);

        static AmQuaternion ConvertToDefault(const AmQuaternion& rotation, const CartesianCoordinateSystem& from);

        static AmReal32 ConvertToDefault(AmReal32 scalar, const CartesianCoordinateSystem& from);

        [[nodiscard]] static AmVector3 GetVector(Axis axis);

        CartesianCoordinateSystem(Axis right, Axis forward, Axis up);

        [[nodiscard]] AM_INLINE AmVector3 GetRightVector() const
        {
            return GetVector(_rightAxis);
        }

        [[nodiscard]] AM_INLINE AmVector3 GetForwardVector() const
        {
            return GetVector(_forwardAxis);
        }

        [[nodiscard]] AM_INLINE AmVector3 GetUpVector() const
        {
            return GetVector(_upAxis);
        }

        [[nodiscard]] AmVector3 Convert(const AmVector3& vector, const CartesianCoordinateSystem& from) const;

        [[nodiscard]] AmQuaternion Convert(const AmQuaternion& quaternion, const CartesianCoordinateSystem& from) const;

        [[nodiscard]] AmReal32 Convert(const AmReal32& scalar, const CartesianCoordinateSystem& from) const;

    private:
        Axis _rightAxis;
        Axis _forwardAxis;
        Axis _upAxis;
    };
} // namespace SparkyStudios::Audio::Amplitude

#endif //_AM_MATH_CARTESIAN_COORDINATE_SYSTEM_H