neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
rigid_body.hpp
Go to the documentation of this file.
1
// rigid_body.hpp
2
/*
3
neogfx C++ App/Game Engine
4
Copyright (c) 2018, 2020 Leigh Johnston. All Rights Reserved.
5
6
This program is free software: you can redistribute it and / or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
10
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
15
16
You should have received a copy of the GNU General Public License
17
along with this program. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#pragma once
21
22
#include <
neogfx/neogfx.hpp
>
23
#include <
neolib/core/uuid.hpp
>
24
#include <
neolib/core/string.hpp
>
25
#include <
neogfx/game/i_component_data.hpp
>
26
27
namespace
neogfx::game
28
{
29
struct
rigid_body
30
{
31
vec3
position
;
32
scalar
mass
;
33
vec3
velocity
;
34
vec3
acceleration
;
35
vec3
angle
;
36
vec3
spin
;
37
vec3
centerOfMass
;
38
scalar
drag
;
39
40
struct
meta
:
i_component_data::meta
41
{
42
static
const
neolib::uuid
&
id
()
43
{
44
static
const
neolib::uuid
sId = { 0xf0481779, 0xc203, 0x4c7c, 0x9d8d, { 0x9d, 0x3d, 0xaf, 0x34, 0x71, 0x58 } };
45
return
sId;
46
}
47
static
const
i_string
&
name
()
48
{
49
static
const
string
sName =
"Rigid Body"
;
50
return
sName;
51
}
52
static
uint32_t
field_count
()
53
{
54
return
8;
55
}
56
static
component_data_field_type
field_type
(uint32_t aFieldIndex)
57
{
58
switch
(aFieldIndex)
59
{
60
case
0:
61
return
component_data_field_type::Vec3;
62
case
1:
63
return
component_data_field_type::Scalar;
64
case
2:
65
case
3:
66
case
4:
67
case
5:
68
case
6:
69
return
component_data_field_type::Vec3;
70
case
7:
71
return
component_data_field_type::Scalar;
72
default
:
73
throw
invalid_field_index
();
74
}
75
}
76
static
const
i_string
&
field_name
(uint32_t aFieldIndex)
77
{
78
static
const
string
sFieldNames[] =
79
{
80
"Position"
,
81
"Mass"
,
82
"Velocity"
,
83
"Acceleration"
,
84
"Angle"
,
85
"Spin"
,
86
"Center Of Mass"
,
87
"Drag"
88
};
89
return
sFieldNames[aFieldIndex];
90
}
91
};
92
};
93
94
inline
mat44
to_transformation_matrix
(
const
game::rigid_body
& aRigidBody,
bool
aIncludeTranslation =
true
)
95
{
96
scalar
az = aRigidBody.
angle
.
z
;
97
// todo: following rotation is 2D, make it 3D...
98
return
aIncludeTranslation ?
99
mat44
100
{
101
{ std::cos(az), std::sin(az), 0.0, 0.0 },
102
{ -std::sin(az), std::cos(az), 0.0, 0.0 },
103
{ 0.0, 0.0, 1.0, 0.0 },
104
{ aRigidBody.
position
.
x
, aRigidBody.
position
.
y
, aRigidBody.
position
.
z
, 1.0 }
105
} :
106
mat44
107
{
108
{ std::cos(az), std::sin(az), 0.0, 0.0 },
109
{ -std::sin(az), std::cos(az), 0.0, 0.0 },
110
{ 0.0, 0.0, 1.0, 0.0 },
111
{ 0.0, 0.0, 0.0, 1.0 }
112
};
113
}
114
}
neolib::i_string
Definition
i_string.hpp:49
neolib::math::basic_matrix
Definition
numerical.hpp:903
neolib::math::basic_vector
Definition
numerical.hpp:112
neolib::math::basic_vector::x
value_type x
Definition
numerical.hpp:226
neolib::math::basic_vector::y
value_type y
Definition
numerical.hpp:227
neolib::math::basic_vector::z
value_type z
Definition
numerical.hpp:228
neogfx::game
Definition
aabb_octree.hpp:31
neogfx::game::to_transformation_matrix
mat44 const & to_transformation_matrix(animation_filter const &aAnimationFilter)
Definition
animation_filter.hpp:113
neolib::ecs::component_data_field_type
component_data_field_type
Definition
i_component_data.hpp:52
neolib::math::scalar
double scalar
Definition
numerical.hpp:63
i_component_data.hpp
neogfx.hpp
string.hpp
neogfx::game::rigid_body::meta
Definition
rigid_body.hpp:41
neogfx::game::rigid_body::meta::field_count
static uint32_t field_count()
Definition
rigid_body.hpp:52
neogfx::game::rigid_body::meta::id
static const neolib::uuid & id()
Definition
rigid_body.hpp:42
neogfx::game::rigid_body::meta::field_type
static component_data_field_type field_type(uint32_t aFieldIndex)
Definition
rigid_body.hpp:56
neogfx::game::rigid_body::meta::field_name
static const i_string & field_name(uint32_t aFieldIndex)
Definition
rigid_body.hpp:76
neogfx::game::rigid_body::meta::name
static const i_string & name()
Definition
rigid_body.hpp:47
neogfx::game::rigid_body
Definition
rigid_body.hpp:30
neogfx::game::rigid_body::angle
vec3 angle
Definition
rigid_body.hpp:35
neogfx::game::rigid_body::mass
scalar mass
Definition
rigid_body.hpp:32
neogfx::game::rigid_body::centerOfMass
vec3 centerOfMass
Definition
rigid_body.hpp:37
neogfx::game::rigid_body::acceleration
vec3 acceleration
Definition
rigid_body.hpp:34
neogfx::game::rigid_body::position
vec3 position
Definition
rigid_body.hpp:31
neogfx::game::rigid_body::drag
scalar drag
Definition
rigid_body.hpp:38
neogfx::game::rigid_body::velocity
vec3 velocity
Definition
rigid_body.hpp:33
neogfx::game::rigid_body::spin
vec3 spin
Definition
rigid_body.hpp:36
neolib::ecs::i_component_data::meta::invalid_field_index
Definition
i_component_data.hpp:134
neolib::ecs::i_component_data::meta
Definition
i_component_data.hpp:133
neolib::uuid
Definition
uuid.hpp:51
uuid.hpp
include
neogfx
game
rigid_body.hpp
Generated by
1.9.8