File: position.hpp

package info (click to toggle)
openmw 0.49.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,992 kB
  • sloc: cpp: 372,479; xml: 2,149; sh: 1,403; python: 797; makefile: 26
file content (47 lines) | stat: -rw-r--r-- 1,457 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef OPENMW_ESM3_POSITION_H
#define OPENMW_ESM3_POSITION_H

#include <components/misc/concepts.hpp>
#include <osg/Vec3f>
#include <tuple>

namespace ESM
{
    // Position and rotation
    struct Position
    {
        float pos[3]{};

        // In radians
        float rot[3]{};

        osg::Vec3f asVec3() const { return osg::Vec3f(pos[0], pos[1], pos[2]); }

        osg::Vec3f asRotationVec3() const { return osg::Vec3f(rot[0], rot[1], rot[2]); }

        friend inline bool operator<(const Position& l, const Position& r)
        {
            const auto tuple = [](const Position& v) { return std::tuple(v.asVec3(), v.asRotationVec3()); };
            return tuple(l) < tuple(r);
        }
    };

    bool inline operator==(const Position& left, const Position& right) noexcept
    {
        return left.pos[0] == right.pos[0] && left.pos[1] == right.pos[1] && left.pos[2] == right.pos[2]
            && left.rot[0] == right.rot[0] && left.rot[1] == right.rot[1] && left.rot[2] == right.rot[2];
    }

    bool inline operator!=(const Position& left, const Position& right) noexcept
    {
        return left.pos[0] != right.pos[0] || left.pos[1] != right.pos[1] || left.pos[2] != right.pos[2]
            || left.rot[0] != right.rot[0] || left.rot[1] != right.rot[1] || left.rot[2] != right.rot[2];
    }

    template <Misc::SameAsWithoutCvref<Position> T>
    void decompose(T&& v, const auto& f)
    {
        f(v.pos, v.rot);
    }
}
#endif