Marine systems simulation
CollisionManager.h
1#pragma once
2#include <Eigen/StdVector>
3#include "ConstraintSet.h"
4#include "DataStructures.h"
5
6namespace CoRiBoDynamics{
7
37{
38public:
39 CollisionManager(ConstraintSolver* solver, double timeConstant);
41
42 int AddCapsule(double radius, double height, double contactStiffness, double contactDamping, double frictionCoefficient, int index);
43 int AddSphere(double radius, double contactStiffness, double contactDamping, double frictionCoefficient, int index);
44 int AddTorus(double majorRadius, double minorRadius, double contactStiffness, double contactDamping, double frictionCoefficient, int index);
45 int AddChamfer(double majorRadius, double minorRadius, double contactStiffness, double contactDamping, double frictionCoefficient, int index);
46 int AddPlate(double lengthX, double lengthY, double thickness, double contactStiffness, double contactDamping, double frictionCoefficient, int index);
47
48 int addExternalSphere(double radius, const double* Position, const double* Velocity, const double* Orientation, const double* AngularVelocity, double contactStiffness, double contactDamping, double frictionCoefficient);
49 int addExternalCapsule(double length, double radius, const double* Position, const double* Velocity, const double* Orientation, const double* AngularVelocity, double contactStiffness, double contactDamping, double frictionCoefficient);
50 int addExternalToroid(double majorRadius, double minorRadius, const double* Position, const double* Velocity, const double* Orientation, const double* AngularVelocity, double contactStiffness, double contactDamping, double frictionCoefficient);
51 int addExternalChamfer(double majorRadius, double minorRadius, const double* Position, const double* Velocity, const double* Orientation, const double* AngularVelocity, double contactStiffness, double contactDamping, double frictionCoefficient);
52 int addExternalPlate(double lengthX, double lengthY, double thickness, const double* Position, const double* Velocity, const double* Orientation, const double* AngularVelocity, double contactStiffness, double contactDamping, double frictionCoefficient);
53
54 enum ShapeType {SPHERE=0, CAPSULE=1, CHAMFER=2, BOX=3, TOROID=4, PLATE=5};
55
57 double contactDamping;
60 MaterialCharacteristic(double K, double D, double F){
61 contactStiffness = K; contactDamping = D; frictionCoefficient = F;
62 }
64 contactStiffness = std::numeric_limits<double>::quiet_NaN(); contactDamping = std::numeric_limits<double>::quiet_NaN(); frictionCoefficient = std::numeric_limits<double>::quiet_NaN();
65 }
66 };
67
68 /*
69 Singly linked list. Contains the index of the element involved in the collition, and the response matrix of the contact.
70 */
72 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
73 mat6 constraint_matrix;
74 int element_ix;
76 };
77
79 public:
80 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
81
82 GeometricObject(){m_contact_matrix = nullptr;};
83 virtual ~GeometricObject(){}
84
85 void SetAsSphere(double radius, const MaterialCharacteristic& material);
86 void SetAsCapsule(double radius, double length, const MaterialCharacteristic& material);
87 void SetAsChamfer(double minor_radius, double major_radius, const MaterialCharacteristic& material);
88 void SetAsTorus(double minor_radius, double major_radius, const MaterialCharacteristic& material);
89 void SetAsPlate(double radius, double lx, double ly, const MaterialCharacteristic& material);
90
91 GeometryTools::Sphere* GetSphere() {return (GeometryTools::Sphere*)(&m_buffer);}
92 GeometryTools::Capsule* GetCapsule(){return (GeometryTools::Capsule*)(&m_buffer);}
93 GeometryTools::Chamfer* GetChamfer(){return (GeometryTools::Chamfer*)(&m_buffer);}
94 GeometryTools::Torus* GetTorus() {return (GeometryTools::Torus*)(&m_buffer);}
95 GeometryTools::Plate* GetPlate() {return (GeometryTools::Plate*)(&m_buffer);}
96
97 GeometryTools::Point* GetPoint() {return &(GetSphere()->point);}
98 GeometryTools::Segment* GetSegment(){return &(GetCapsule()->segment);}
99 GeometryTools::Disk* GetDisk() {return &(GetChamfer()->disk);}
100 GeometryTools::Ring* GetRing() {return &(GetTorus()->ring);}
101 GeometryTools::Plane* GetPlane() {return &(GetPlate()->plane);}
102
103 void Update();
104
105 virtual vec3 P()=0;
106 virtual vec3 V()=0;
107 virtual Quat Q()=0;
108 virtual vec3 W()=0;
109
110 double m_bounding_sphere_radius;
111 vec3 m_OBB;
112
113 double m_radius;
114 ShapeType m_shape_type;
115 char m_buffer[sizeof(GeometryTools::Plate)];
116 GeometryTools::AABB m_aabb;
117 MaterialCharacteristic m_material;
118 vec6 m_contact_forces;
119 contact_matrix_index_pair* m_contact_matrix;
120 };
121
123 public:
124 explicit InternalObject(RigidElement* element){m_element = element;}
125 RigidElement* m_element;
126 vec3 P();
127 vec3 V();
128 Quat Q();
129 vec3 W();
130 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
131 };
132
133
134
136 public:
137 explicit ExternalObject(){
138 UpdateStates(nullptr,nullptr,nullptr,nullptr);
139 //contact = nullptr;
140 }
141
142 ExternalObject(const double* P, const double* Q, const double* V, const double* W){
143 UpdateStates(P, Q, V, W);
144 //contact = nullptr;
145 }
146
147 void UpdateStates(const double* P, const double* Q, const double* V, const double* W){
148 m_P = P; m_Q = Q; m_V = V, m_W = W;
149 }
150 const double* m_P;
151 const double* m_Q;
152 const double* m_V;
153 const double* m_W;
154
155 vec3 P();
156 vec3 V();
157 Quat Q();
158 vec3 W();
159
160 //contact_matrix_index_pair* contact;
161
162 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
163 };
164
165 void updateExternalElement(int index, const double* Position, const double* Velocity, const double* Orientation, const double* AngularVelocity);
166 vec6 getExternalObjectReactionForce(int index);
167 vec6 getExternalObjectReactionForce(ExternalObject& external_object);
168
169 vec6 getInternalObjectReactionForce(InternalObject& internal_object);
170
171 virtual void ComputeConstraints(const double T, const double * const X);
172
173 void setSpacePartitionOrigo(double x, double y, double z);
174 void setSpacePartitionBlockSize(double length);
175
176protected:
177
178 std::vector<ExternalObject, Eigen::aligned_allocator<ExternalObject> > m_ExternalObjects;
179 std::vector<InternalObject, Eigen::aligned_allocator<InternalObject> > m_InternalObjects;
180
181 void CollisionTest( InternalObject* objectA, InternalObject* objectB , const double * const X);
182
183 void CollisionTest( ExternalObject* ExtObj, InternalObject* IntObj , const double * const X);
184
185 double ObjectDistance(GeometricObject* shapeA, GeometricObject* shapeB, GeometryTools::MinDistanceInfo& result);
186
187 bool BoundingSphereRejectionTest(GeometricObject* sphereA, GeometricObject* sphereB);
188
189 bool OBB_BoundingSphereRejectionTest(GeometricObject* box, GeometricObject* sphere);
190
191 DataStructures::SpacePartitioner m_CollisionPartition;
193
194 double m_timeConstant;
195};
196
197}
Definition: CollisionManager.h:135
ExternalObject()
Rigid bodies that are controlled externally.
Definition: CollisionManager.h:137
const double * m_W
velocity of the object
Definition: CollisionManager.h:153
const double * m_V
orientation quaternion of the object. order {w,x,y,z}
Definition: CollisionManager.h:152
vec3 P()
angular velocity 'omega' of the object
const double * m_Q
position of the object
Definition: CollisionManager.h:151
Definition: CollisionManager.h:78
double m_radius
half dimensions of the oriented bounding box
Definition: CollisionManager.h:113
Definition: CollisionManager.h:122
InternalObject(RigidElement *element)
Rigid bodies that are under direct control by the constraint solver.
Definition: CollisionManager.h:124
Definition: CollisionManager.h:37
virtual void ComputeConstraints(const double T, const double *const X)
void CollisionTest(InternalObject *objectA, InternalObject *objectB, const double *const X)
list of all internal objects in this collision manager
std::vector< InternalObject, Eigen::aligned_allocator< InternalObject > > m_InternalObjects
list of all external objects in this collision manager
Definition: CollisionManager.h:179
Definition: ConstraintSet.h:24
Definition: ConstraintSolver.h:31
Definition: DataStructures.h:107
Definition: ObjectFactoryStack.h:22
Definition: RigidElement.h:15
Definition: CollisionManager.h:6
enum of different shape types
Definition: CollisionManager.h:56
MaterialCharacteristic(double K, double D, double F)
contact friction coefficient
Definition: CollisionManager.h:60
double contactStiffness
relative damping coefficient of contact forces. relates to alpha as: alpha = beta*contactDamping
Definition: CollisionManager.h:58
double frictionCoefficient
determines contact force stiffness together with the timeConstant.
Definition: CollisionManager.h:59
Definition: GeometryTools.h:88
Definition: GeometryTools.h:60
every point inside 'radius' from 'ring'
Definition: GeometryTools.h:63
Definition: GeometryTools.h:52
Definition: GeometryTools.h:38
every point inside 'radius' from 'disk'
Definition: GeometryTools.h:64
Definition: GeometryTools.h:28
Definition: GeometryTools.h:45
Definition: GeometryTools.h:32
every point inside 'radius' from 'segment'
Definition: GeometryTools.h:61
every point inside 'radius' from 'point'
Definition: GeometryTools.h:62