00001 #pragma once
00002 #ifndef BL7_P2_CONTACT_H
00003 #define BL7_P2_CONTACT_H
00004
00005 #include "../core.h"
00006
00007 #include <MathLabs/Vector2.h>
00008
00009
00010
00011 namespace bl7 {
00012 namespace particles2 {
00013
00014
00015
00016 class Particle;
00017 class ContactGenerator;
00018 class ContactRegistry;
00019 class ContactResolver;
00020
00021
00022
00026 class BODYLABS_API Contact
00027 {
00028
00029
00030
00031
00032 public:
00034 ~Contact(void)
00035 { }
00036
00038 Contact(const Contact& rhs)
00039 : _particle1( rhs._particle1 ), _particle2( rhs._particle2 )
00040 , _normal( rhs._normal ), _penetration( rhs._penetration ), _restitution( rhs._restitution )
00041 , _movement1( rhs._movement1 ), _movement2( rhs._movement2 )
00042 {
00043 }
00044
00046 Contact& operator = (const Contact& rhs)
00047 {
00048 _particle1 = rhs._particle1;
00049 _particle2 = rhs._particle2;
00050 _normal = rhs._normal;
00051 _penetration = rhs._penetration;
00052 _restitution = rhs._restitution;
00053 _movement1 = rhs._movement1;
00054 _movement2 = rhs._movement2;
00055 return *this;
00056 }
00057
00063 Contact(Particle* particle, const ml7::Vector2& normal, const float penetration, const float restitution)
00064 : _particle1( particle ), _particle2( NULL )
00065 , _normal( normal ), _penetration( penetration ), _restitution( restitution )
00066 , _movement1(), _movement2()
00067 { assert( particle ); }
00068
00074 Contact(Particle* particle1, Particle* particle2, const ml7::Vector2& normal, const float penetration, const float restitution)
00075 : _particle1( particle1 ), _particle2( particle2 )
00076 , _normal( normal ), _penetration( penetration), _restitution( restitution )
00077 , _movement1(), _movement2()
00078 { assert( particle1 ); }
00079
00080 private:
00082 Contact(void)
00083 { }
00084
00085
00086
00087
00088
00089
00090 private:
00095 Particle* _particle1;
00096
00101 Particle* _particle2;
00102
00106 ml7::Vector2 _normal;
00107
00111 float _penetration;
00112
00116 float _restitution;
00117
00122 ml7::Vector2 _movement1;
00123
00128 ml7::Vector2 _movement2;
00129
00130
00131
00132
00133
00134
00135 public:
00141 void resolve(const float time);
00142
00147 void resolve_velocity(const float time);
00148
00153 void resolve_position(const float time);
00154
00158 float calculate_penetrating_speed() const;
00159
00160 private:
00164 float remove_acceleration_factor(const float speed, const float time) const;
00165
00166
00167
00168 friend ContactGenerator;
00169 friend ContactRegistry;
00170 friend ContactResolver;
00171
00172 };
00173
00174
00175
00176 }
00177 }
00178
00179 #endif // BL7_P2_CONTACT_H