SuperDex Physics C++ API
Loading...
Searching...
No Matches
sphere.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19// PLEASE DO NOT ADD OTHER INCLUDES HERE. This header is included in the mochi_physics public API.
26
27#include <type_traits>
28
29namespace superdex {
30
31/**************************************************************************************************
32 Sphere
33*/
34
35class Sphere final {
36 public:
37 Real3 center{}; ///< Center of the sphere [m].
38 real radius{}; ///< Radius of the sphere [m].
39
43 MOCHI_FORCE_INLINE Sphere(Vec4r packedCenterAndRadius)
44 : center(ToReal3(packedCenterAndRadius)), radius(Get<3>(packedCenterAndRadius)) {}
45
46 [[nodiscard]] MOCHI_FORCE_INLINE Real3 GetCenter() const {
47 return center;
48 }
49
50 [[nodiscard]] MOCHI_FORCE_INLINE real GetRadius() const {
51 return radius;
52 }
53
54 [[nodiscard]] MOCHI_FORCE_INLINE Vec4r VGetPacked() const {
55 return ToSimd(center, radius);
56 }
57
58 [[nodiscard]] MOCHI_FORCE_INLINE Vec4r VGetCenter() const {
59 return ToSimd(center, 1_r);
60 }
61
62#if MOCHI_LANGUAGE_CPP20
63 bool operator==(Sphere const& other) const = default;
64 bool operator!=(Sphere const& other) const = default;
65#endif
66
71};
72
73namespace details {
74template <>
75inline constexpr bool IsPrimitiveShapeDef<Sphere> = true;
76} // namespace details
77
78} // namespace superdex
Real3 GetCenter() const
Definition sphere.h:46
Real3 center
Center of the sphere [m].
Definition sphere.h:37
bool operator==(Sphere const &other) const =default
bool operator!=(Sphere const &other) const =default
Sphere(Real3 const &center, real radius)
Definition sphere.h:42
real radius
Radius of the sphere [m].
Definition sphere.h:38
Vec4r VGetCenter() const
Definition sphere.h:58
Sphere()=default
Sphere(Vec4r packedCenterAndRadius)
Definition sphere.h:43
real GetRadius() const
Definition sphere.h:50
Vec4r VGetPacked() const
Definition sphere.h:54
Sphere(Vec4r center, real radius)
Definition sphere.h:41
#define MOCHI_FORCE_INLINE
Simd< T, 4 > ToSimd(NdArray< T, 2 > const &v, T z=T(0), T w=T(0))
Definition vmatrix.h:413
Real3 ToReal3(Simd< T, 4 > v)
Definition vmatrix.h:354
Simd< real, 4 > Vec4r
Definition simd.h:206
T Get(Simd< T, N > v)
Definition simd_inl.h:300
NdArray< real, 3 > Real3
Definition nd_array.h:106
#define MOCHI_STRUCT_END()
Definition reflection.h:279
#define MOCHI_FIELD(name)
Definition reflection.h:293
#define MOCHI_STRUCT_BEGIN(name)
Definition reflection.h:278
#define MOCHI_ATTRIBUTE(...)
Definition reflection.h:298