-
Notifications
You must be signed in to change notification settings - Fork 41
/
GetContacts.hh
108 lines (95 loc) · 3.45 KB
/
GetContacts.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* Copyright (C) 2019 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GZ_PHYSICS_GETCONTACTS_HH_
#define GZ_PHYSICS_GETCONTACTS_HH_
#include <vector>
#include <gz/physics/FeatureList.hh>
#include <gz/physics/ForwardStep.hh>
#include <gz/physics/Geometry.hh>
#include <gz/physics/SpecifyData.hh>
namespace gz
{
namespace physics
{
/// \brief GetContactsFromLastStepFeature is a feature for retrieving the list
/// of contacts generated in the previous simulation step.
class GZ_PHYSICS_VISIBLE GetContactsFromLastStepFeature
: public virtual FeatureWithRequirements<ForwardStep>
{
public: template <typename PolicyT>
struct ExtraContactDataT
{
using Scalar = typename PolicyT::Scalar;
using VectorType = typename FromPolicy<PolicyT>::template Use<Vector>;
/// \brief The contact force acting on the first body expressed
/// in the world frame
VectorType force;
/// \brief The normal of the force acting on the first body expressed
/// in the world frame
VectorType normal;
/// \brief The penetration depth
Scalar depth;
};
public: template <typename PolicyT, typename FeaturesT>
class World : public virtual Feature::World<PolicyT, FeaturesT>
{
public: using Scalar = typename PolicyT::Scalar;
public: using ShapePtrType = ShapePtr<PolicyT, FeaturesT>;
public: using VectorType =
typename FromPolicy<PolicyT>::template Use<Vector>;
public: using ExtraContactData = ExtraContactDataT<PolicyT>;
public: struct ContactPoint
{
/// \brief Collision shape of the first body
ShapePtrType collision1;
/// \brief Collision shape of the second body
ShapePtrType collision2;
/// \brief The point of contact expressed in the world frame
VectorType point;
};
public: using Contact = SpecifyData<
RequireData<ContactPoint>,
ExpectData<ExtraContactData> >;
/// \brief Get contacts generated in the previous simulation step
public: std::vector<Contact> GetContactsFromLastStep() const;
};
public: template <typename PolicyT>
class Implementation : public virtual Feature::Implementation<PolicyT>
{
public: using Scalar = typename PolicyT::Scalar;
public: using VectorType =
typename FromPolicy<PolicyT>::template Use<Vector>;
public: using ExtraContactData = ExtraContactDataT<PolicyT>;
public: struct ContactInternal
{
/// \brief Identity of the first body
Identity collision1;
/// \brief Identity of the second body
Identity collision2;
/// \brief The point of contact expressed in the world frame
VectorType point;
/// \brief Extra data related to contact.
CompositeData extraData;
};
public: virtual std::vector<ContactInternal> GetContactsFromLastStep(
const Identity &_worldID) const = 0;
};
};
}
}
#include "gz/physics/detail/GetContacts.hh"
#endif /* end of include guard: GZ_PHYSICS_GETCONTACTS_HH_ */