]> git.localhorst.tv Git - gong.git/blob - src/physics/Derivative.hpp
simple physics simulation
[gong.git] / src / physics / Derivative.hpp
1 #ifndef GONG_PHYSICS_DERIVATIVE_HPP_
2 #define GONG_PHYSICS_DERIVATIVE_HPP_
3
4 #include "../graphics/glm.hpp"
5
6 #include <glm/gtc/quaternion.hpp>
7
8
9 namespace gong {
10 namespace physics {
11
12 struct State;
13
14
15 struct Derivative {
16
17         glm::vec3 dpos;
18         glm::vec3 dlin;
19         glm::quat dorient;
20         glm::vec3 dang;
21
22         Derivative() noexcept;
23         Derivative(
24                 const glm::vec3 &,
25                 const glm::vec3 &,
26                 const glm::quat &,
27                 const glm::vec3 &
28         ) noexcept;
29
30 };
31
32
33 inline Derivative operator +(const Derivative &a, const Derivative &b) noexcept {
34         return Derivative(a.dpos + b.dpos, a.dlin + b.dlin, a.dorient * b.dorient, a.dang + b.dang);
35 }
36
37 inline Derivative operator *(float f, const Derivative &d) noexcept {
38         return Derivative(f * d.dpos, f * d.dlin, f * d.dorient, f * d.dang);
39 }
40 inline Derivative operator *(const Derivative &d, float f) noexcept {
41         return f * d;
42 }
43
44 State &operator +=(State &s, const Derivative &d) noexcept;
45
46 }
47 }
48
49 #endif