Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
JoltConversions.hpp
Go to the documentation of this file.
1/**************************************************************************
2 * EngineSquared v0.1.1
3 *
4 * EngineSquared is a software package, part of the Engine² organization.
5 *
6 * This file is part of the EngineSquared project that is under MIT License.
7 * Copyright © 2025-present by @EngineSquared, All rights reserved.
8 *
9 * EngineSquared is a free software: you can redistribute it and/or modify
10 * it under the terms of the MIT License. See the project's LICENSE file for
11 * the full license text and details.
12 *
13 * @file JoltConversions.hpp
14 * @brief Conversion utilities between GLM and Jolt Physics types
15 *
16 * This file provides conversion functions between GLM types (vec3, quat) and
17 * Jolt Physics types (Vec3, Quat). These inline functions ensure zero-cost
18 * conversions for efficient interoperability.
19 *
20 * @author @EngineSquared
21 * @version 0.1.1
22 * @date 2025-10-30
23 **************************************************************************/
24
25#pragma once
26
27#include <glm/glm.hpp>
28#include <glm/gtc/quaternion.hpp>
29
30namespace Physics::Utils {
31
32//=============================================================================
33// GLM → Jolt conversions
34//=============================================================================
35
39inline JPH::Vec3 ToJoltVec3(const glm::vec3 &v) { return JPH::Vec3(v.x, v.y, v.z); }
40
46inline JPH::RVec3 ToJoltRVec3(const glm::vec3 &v) { return JPH::RVec3(v.x, v.y, v.z); }
47
51inline JPH::Quat ToJoltQuat(const glm::quat &q) { return JPH::Quat(q.x, q.y, q.z, q.w); }
52
53//=============================================================================
54// Jolt → GLM conversions
55//=============================================================================
56
60inline glm::vec3 FromJoltVec3(const JPH::Vec3 &v) { return glm::vec3(v.GetX(), v.GetY(), v.GetZ()); }
61
68inline glm::vec3 FromJoltRVec3(const JPH::RVec3 &v)
69{
70 return glm::vec3(static_cast<float>(v.GetX()), static_cast<float>(v.GetY()), static_cast<float>(v.GetZ()));
71}
72
76inline glm::quat FromJoltQuat(const JPH::Quat &q) { return glm::quat(q.GetW(), q.GetX(), q.GetY(), q.GetZ()); }
77
78} // namespace Physics::Utils
Definition BiMap.hpp:7
JPH::RVec3 ToJoltRVec3(const glm::vec3 &v)
Convert glm::vec3 to JPH::RVec3 (real vector, double precision).
Definition JoltConversions.hpp:46
glm::quat FromJoltQuat(const JPH::Quat &q)
Convert JPH::Quat to glm::quat.
Definition JoltConversions.hpp:76
glm::vec3 FromJoltRVec3(const JPH::RVec3 &v)
Convert JPH::RVec3 (real vector, double precision) to glm::vec3.
Definition JoltConversions.hpp:68
JPH::Vec3 ToJoltVec3(const glm::vec3 &v)
Convert glm::vec3 to JPH::Vec3.
Definition JoltConversions.hpp:39
glm::vec3 FromJoltVec3(const JPH::Vec3 &v)
Convert JPH::Vec3 to glm::vec3.
Definition JoltConversions.hpp:60
JPH::Quat ToJoltQuat(const glm::quat &q)
Convert glm::quat to JPH::Quat.
Definition JoltConversions.hpp:51