1 //	Contact_Point.cc - a particle that responds to collisions.
2 //
3 //  Copyright (C) 2002 Sam Varner
4 //
5 //  This file is part of Vamos Automotive Simulator.
6 //
7 //  This program is free software; you can redistribute it and/or modify
8 //  it under the terms of the GNU General Public License as published by
9 //  the Free Software Foundation; either version 2 of the License, or
10 //  (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 
21 #include "Contact_Point.h"
22 
23 using namespace Vamos_Geometry;
24 using namespace Vamos_Body;
25 
26 //* Constructors
27 
Contact_Point(double mass,const Three_Vector & position,const Three_Matrix & orientation,Material::Material_Type type,double friction,double restitution,const Frame * parent)28 Contact_Point::Contact_Point (double mass,
29                               const Three_Vector& position,
30                               const Three_Matrix& orientation,
31                               Material::Material_Type type,
32                               double friction,
33                               double restitution,
34                               const Frame* parent)
35   : Particle (mass, position, orientation, parent),
36 	m_contact (false)
37 {
38   set_material (Material (type, friction, restitution));
39 }
40 
41 // Take the parent's orientation.
Contact_Point(double mass,const Three_Vector & position,Material::Material_Type type,double friction,double restitution,const Frame * parent)42 Contact_Point::Contact_Point (double mass,
43                const Three_Vector& position,
44 			   Material::Material_Type type,
45 			   double friction,
46                double restitution,
47                const Frame* parent)
48   : Particle (mass, position, parent),
49 	m_contact (false)
50 {
51   set_material (Material (type, friction, restitution));
52 }
53 
Contact_Point(const Particle & particle,const Material & material)54 Contact_Point::Contact_Point (const Particle& particle,
55                               const Material& material)
56   : Particle (particle),
57 	m_contact (false)
58 {
59   set_material (material);
60 }
61 
62 
63 // Handle collisions.  The return value is how much the particle has
64 // moved as a result of the contact.  For a Particle, this is always
65 // 0.  But, for derived classes that model moving parts, a non-zero
66 // value may be returned.
67 double
contact(const Three_Vector & impulse,const Three_Vector & velocity,double distance,const Three_Vector & normal,const Three_Vector & angular_velocity,const Material & material)68 Contact_Point::contact (const Three_Vector& impulse,
69                         const Three_Vector& velocity,
70                         double distance,
71                         const Three_Vector& normal,
72                         const Three_Vector& angular_velocity,
73                         const Material& material)
74 {
75   set_impulse (rotate_from_parent (impulse));
76   m_contact = true;
77   return 0.0;
78 }
79 
80 
81 // Find and store the forces and torques for the current
82 // configuration.
83 void
find_forces()84 Contact_Point::find_forces ()
85 {
86   if (!m_contact)
87     reset ();
88 }
89 
90 // Do any neccary cleanup at the end of a time step.
91 void
end_timestep()92 Contact_Point::end_timestep ()
93 {
94   m_contact = false;
95 }
96