JPL Spatial
Sound spatialization and propagation library
Loading...
Searching...
No Matches
Position.h
Go to the documentation of this file.
1//
2// ██╗██████╗ ██╗ ██╗██████╗ ███████╗
3// ██║██╔══██╗ ██║ ██║██╔══██╗██╔════╝ ** JPLSpatial **
4// ██║██████╔╝ ██║ ██║██████╔╝███████╗
5// ██ ██║██╔═══╝ ██║ ██║██╔══██╗╚════██║ https://github.com/Jaytheway/JPLSpatial
6// ╚█████╔╝██║ ███████╗██║██████╔╝███████║
7// ╚════╝ ╚═╝ ╚══════╝╚═╝╚═════╝ ╚══════╝
8//
9// Copyright 2024 Jaroslav Pevno, JPLSpatial is offered under the terms of the ISC license:
10//
11// Permission to use, copy, modify, and/or distribute this software for any purpose with or
12// without fee is hereby granted, provided that the above copyright notice and this permission
13// notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
14// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
16// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17// WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20#pragma once
21
22#include "JPLSpatial/Core.h"
26
27namespace JPL
28{
30 template<CVec3 Vec3Type>
32 {
33 // Note: we may just switch to Basis to store all three axes at some point,
34 // unless we want to keep this Orientation as customization point
35 // for the different axes semantics in different engies.
36
37 Vec3Type Up;
38 Vec3Type Forward;
39
41 {
42 return { .Up = Vec3Type(0, 1, 0), .Forward = Vec3Type(0, 0, 1) };
43 }
44
47 {
48 return { .Up = Vec3Type(0, 1, 0), .Forward = Vec3Type(0, 0, -1) };
49 }
50
52 {
54 return Math::MakeBasis(-Forward, Up);
55 }
56
57 // Use this if Up and Forward are guaranteed to be orthogonal
59 {
61 const Vec3Type forward = -Forward;
63 return Basis<Vec3Type>{
64 .X = CrossProduct(Up, forward),
65 .Y = Up,
66 .Z = forward
67 };
68 }
69
71 {
73 return Math::QuatFromUpAndForward(Up, -Forward);
74 }
75 };
76
78 template<CVec3 Vec3Type>
84
85 template<CVec3 Vec3Type>
87 {
88 return lhs.Up== rhs.Up && lhs.Forward == rhs.Forward;
89 }
90
91 template<CVec3 Vec3Type>
93 {
94 return lhs.Location == rhs.Location && lhs.Orientation == rhs.Orientation;
95 }
96} // namespace JPL
#define JPL_ASSERT(inExpression,...)
Main assert macro, usage: JPL_ASSERT(condition, message) or JPL_ASSERT(condition)
Definition ErrorReporting.h:76
JPL_INLINE constexpr bool IsNearlyZero(T value, T errorTolerance=JPL_FLOAT_EPS_V< T >) noexcept
Definition Math.h:146
Definition AcousticMaterial.h:36
JPL_INLINE constexpr bool operator==(const Vec2 &A, const Vec2 &B) noexcept
Definition MinimalVec2.h:59
JPL_INLINE simd min(const simd &a, const simd &b) noexcept
Element-wise min.
Definition SIMD.h:1813
Orthonormal basis (column-major)
Definition MinimalBasis.h:35
Vec3 X
Definition MinimalBasis.h:38
Minimum data required to do our orientation math.
Definition Position.h:32
static JPL_INLINE OrientationData< Vec3Type > Identity() noexcept
Definition Position.h:40
static JPL_INLINE OrientationData< Vec3Type > IdentityForward() noexcept
Identity facing forward as per right-handed rotation.
Definition Position.h:46
Vec3Type Up
Definition Position.h:37
JPL_INLINE Basis< Vec3Type > ToBasis() const noexcept
Definition Position.h:51
JPL_INLINE Basis< Vec3Type > ToBasisUnsafe() const
Definition Position.h:58
JPL_INLINE Quat< Vec3Type > ToQuat() const noexcept
Definition Position.h:70
Vec3Type Forward
Definition Position.h:38
Location and orientation in one place.
Definition Position.h:80
OrientationData< Vec3Type > Orientation
Definition Position.h:82
Vec3Type Location
Definition Position.h:81
Minimal quaternion (w + xi + yj + zk)
Definition MinimalQuat.h:38