]> git.localhorst.tv Git - gong.git/blob - src/physics/State.hpp
half-{complete,assed} sphere collision detection
[gong.git] / src / physics / State.hpp
1 #ifndef GONG_PHYSICS_STATE_HPP_
2 #define GONG_PHYSICS_STATE_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         /// position of center of mass
14         glm::vec3 pos;
15         /// linear momentum
16         glm::vec3 lin;
17         /// orientation
18         glm::quat orient;
19         /// angular momentum
20         glm::vec3 ang;
21         /// angular velocity as quat
22         glm::quat Spin() const noexcept {
23                 return 0.5f * glm::quat(0.0f, ang * inverse_inertia) * orient;
24         }
25         float mass;
26         /// 1/mass
27         float inverse_mass;
28         /// rotational inertia
29         float inertia;
30         /// 1/inertia
31         float inverse_inertia;
32
33         /// calculate velocity at given point
34         /// (same coordinate system as used by pos)
35         glm::vec3 VelAt(const glm::vec3 &p) const noexcept {
36                 return (lin * inverse_mass) + glm::cross((ang * inverse_inertia), p - pos);
37         }
38 };
39
40 }
41 }
42
43 #endif