00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _RIGID_BODY_H_
00022 #define _RIGID_BODY_H_
00023
00024 #include <vamos/geometry/Three_Vector.h>
00025 #include <vamos/geometry/Three_Matrix.h>
00026 #include <vamos/geometry/Material.h>
00027 #include <vamos/geometry/Inertia_Tensor.h>
00028 #include <vamos/body/Frame.h>
00029 #include <vamos/body/Contact_Point.h>
00030
00031 #include <vector>
00032
00033 namespace Vamos_Body
00034 {
00035 struct Contact_Parameters
00036 {
00037 Contact_Parameters ();
00038
00039 Particle* mp_contact_point;
00040 double m_distance;
00041 Vamos_Geometry::Three_Vector m_normal;
00042 Vamos_Geometry::Material_Handle m_material;
00043 };
00044
00045
00046 class Rigid_Body : public Frame
00047 {
00048
00049 Vamos_Geometry::Three_Vector m_initial_position;
00050
00051 Vamos_Geometry::Three_Vector m_last_position;
00052
00053
00054 Vamos_Geometry::Three_Vector m_cm_velocity;
00055
00056 Vamos_Geometry::Three_Vector m_last_cm_velocity;
00057
00058 Vamos_Geometry::Three_Vector m_last_velocity;
00059
00060 Vamos_Geometry::Three_Matrix m_last_orientation;
00061
00062 Vamos_Geometry::Three_Vector m_last_ang_velocity;
00063
00064
00065
00066
00067 Vamos_Geometry::Three_Vector m_gravity;
00068
00069
00070 double m_delta_time;
00071
00072
00073 double m_mass;
00074
00075
00076 void private_reset ();
00077
00078 Contact_Parameters m_contact_parameters;
00079
00080 bool valid;
00081
00082 protected:
00083
00084 Vamos_Geometry::Inertia_Tensor m_inertia;
00085
00086
00087
00088 std::vector <Particle*> m_particles;
00089
00090
00091
00092 Vamos_Geometry::Three_Vector m_body_cm;
00093
00094 Vamos_Geometry::Three_Vector m_last_body_cm;
00095
00096 public:
00097
00098
00099
00100 Rigid_Body (const Vamos_Geometry::Three_Vector& pos,
00101 const Vamos_Geometry::Three_Matrix& orient);
00102
00103
00104 Rigid_Body (const Vamos_Geometry::Three_Vector& pos);
00105
00106
00107 Rigid_Body ();
00108
00109
00110 virtual ~Rigid_Body ();
00111
00112
00113 Vamos_Geometry::Three_Vector center_of_mass () const { return m_body_cm; }
00114
00115
00116
00117 Vamos_Geometry::Three_Vector cm_position ();
00118
00119
00120
00121 Vamos_Geometry::Three_Vector position () const
00122 { return Frame::position (); }
00123
00124 bool IsValid() {return valid;}
00125
00126
00127
00128 Vamos_Geometry::Three_Vector contact_position (Particle* contact_point);
00129 Vamos_Geometry::Three_Vector last_contact_position (Particle* contact_point);
00130
00131
00132 double lowest_contact_position () const;
00133
00134
00135 void add_particle (Particle* const comp)
00136 { m_particles.push_back (comp); }
00137
00138
00139
00140 void update_center_of_mass ();
00141
00142
00143 std::vector <Particle*>& particles () { return m_particles; }
00144
00145 void find_forces ();
00146
00147
00148 void propagate (double time);
00149
00150 void propagate_contact ();
00151
00152
00153 void rewind ();
00154
00155
00156 void end_timestep ();
00157
00158
00159
00160 void gravity (const Vamos_Geometry::Three_Vector& grav)
00161 { m_gravity = grav; }
00162
00163
00164
00165
00166 Vamos_Geometry::Three_Vector velocity (Particle* particle);
00167
00168
00169 Vamos_Geometry::Three_Vector cm_velocity () const { return m_cm_velocity; }
00170 Vamos_Geometry::Three_Vector cm_last_velocity () const { return m_last_cm_velocity; }
00171
00172
00173 void cm_velocity (Vamos_Geometry::Three_Vector vel)
00174 { m_cm_velocity = vel;}
00175
00176
00177 void contact (Particle* contact_point,
00178 double distance,
00179 const Vamos_Geometry::Three_Vector& normal,
00180 Vamos_Geometry::Material_Handle material);
00181
00182
00183
00184 void wind (Particle* aero_device,
00185 const Vamos_Geometry::Three_Vector& wind_vector,
00186 double density);
00187
00188
00189 double mass () const { return m_mass; }
00190
00191
00192
00193 virtual void draw () {};
00194
00195
00196 virtual void reset ();
00197
00198
00199
00200 virtual void reset (const Vamos_Geometry::Three_Vector& position,
00201 const Vamos_Geometry::Three_Matrix& orientation);
00202
00203 void set_position(Vamos_Geometry::Three_Vector np) {place(np);m_last_position = np;}
00204 void set_orientation(Vamos_Geometry::Three_Matrix no) {orient(no);m_last_orientation = no;}
00205 void set_angvel(Vamos_Geometry::Three_Vector nav) {set_ang_velocity(nav); m_last_ang_velocity = nav;}
00206 void set_velocity(Vamos_Geometry::Three_Vector vel) {m_cm_velocity = vel; m_velocity = vel; m_last_velocity = vel; m_last_cm_velocity = vel;}
00207
00208
00209 void roll_back();
00210
00211
00212 void kill_vel();
00213
00214
00215 void single_point_contact(Vamos_Geometry::Three_Vector worldposition,
00216 double distance,
00217 Vamos_Geometry::Three_Vector normal,
00218 Vamos_Geometry::Material_Handle material, double time);
00219 };
00220 }
00221
00222 #endif // !_BODY_H_