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>
26
27namespace neogfx::game
28{
30 {
39
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}
mat44 const & to_transformation_matrix(animation_filter const &aAnimationFilter)
double scalar
Definition numerical.hpp:63
static uint32_t field_count()
static const neolib::uuid & id()
static component_data_field_type field_type(uint32_t aFieldIndex)
static const i_string & field_name(uint32_t aFieldIndex)
static const i_string & name()