Source

KODE / include / kode / joints / Hinge.hpp

Full commit
/*
  This file is part of the KODE.

    KODE Physics Library
    Copyright (C) 2013-2014  Daniel Kohler Osmari

    KODE is free software: you can redistribute it and/or modify it
    under the terms of EITHER:

        * the GNU Lesser General Public License as published by the
          Free Software Foundation, either version 3 of the License,
          or (at your option) any later version.

        * the Apache License, Version 2.0.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU Lesser General Public License and the Apache License for more
    details.

    You should have received a copy of the GNU Lesser General Public
    License along with this program.  If not, see
    <http://www.gnu.org/licenses/>.

    You may obtain a copy of the Apache License at
       http://www.apache.org/licenses/LICENSE-2.0
*/

#ifndef KODE_HINGE_JOINT_H
#define KODE_HINGE_JOINT_H

#include <kode/Quaternion.hpp>
#include <kode/joints/BallSocket.hpp>

#include <kode/joints/AngularMotor.hpp>

namespace kode {

    class Hinge : public BallSocket {
    protected:
        Vector3 localAxis1 = {1,0,0};
        Vector3 localAxis2 = {1,0,0};

        Radian offsetAngle = Radian{0};
        Quaternion offsetRot = Quaternion::Identity();

        AngularMotor motor;

    public:
        Hinge() noexcept = default;

        Hinge(Body* b1, Body* b2, const Vector3& anchor, const Vector3& axis);
        Hinge(Body& b, const Vector3& anchor, const Vector3& axis);
        Hinge(Body& b1, Body& b2, const Vector3& anchor, const Vector3& axis);

        void setAxis(const Vector3& axis);
        void setAxis(Real ax, Real ay, Real az); // convenience
        void setAxis1(const Vector3& axis);
        void setAxis2(const Vector3& axis);

        Vector3 getAxis1() const noexcept;
        Vector3 getAxis2() const noexcept;

        inline
        const Vector3& getLocalAxis1() const noexcept;
        inline
        const Vector3& getLocalAxis2() const noexcept;

        /// Returns how much the first body has rotate w.r.t. the second body
        void resetAngle(Radian ra) noexcept;
        Radian getAngle() const noexcept;


        void updateConstraints(World& world) noexcept override;

        inline
        const AngularMotor& getMotor() const noexcept;

        inline
        AngularMotor& getMotor() noexcept;

    };

    // inline definitions
    inline
    const AngularMotor&
    Hinge::getMotor() const noexcept
    {
        return motor;
    }


    inline
    AngularMotor&
    Hinge::getMotor() noexcept
    {
        return motor;
    }


    inline
    const Vector3&
    Hinge::getLocalAxis1() const noexcept
    {
        return localAxis1;
    }


    inline
    const Vector3&
    Hinge::getLocalAxis2() const noexcept
    {
        return localAxis2;
    }

}

#endif