src/vamos/geometry/Material.cc

Go to the documentation of this file.
00001 //      Vamos Automotive Simulator
00002 //  Copyright (C) 2001--2002 Sam Varner
00003 //
00004 //  This program is free software; you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation; either version 2 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program; if not, write to the Free Software
00016 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 #include <vamos/geometry/Material.h>
00019 #include <vamos/geometry/Conversions.h>
00020 #include <vamos/geometry/Constants.h>
00021 
00022 #include <cassert>
00023 
00024 Vamos_Geometry::Material::
00025 Material (Material_Type type, double friction, double restitution,
00026                   double rolling, double drag, 
00027                   double bump_amplitude, double bump_wavelength, 
00028                   Gl_Texture_Image* image)
00029   : m_type (type),
00030         m_friction_factor (friction),
00031         m_restitution_factor (restitution),
00032         m_rolling_resistance_factor (rolling),
00033         m_drag_factor (drag),
00034         m_bump_amplitude (bump_amplitude),
00035         m_bump_wavelength (bump_wavelength),
00036         mp_texture_image (image)
00037 {
00038 }
00039 
00040 Vamos_Geometry::Material::
00041 Material () :
00042   m_type (UNKNOWN),
00043   m_friction_factor (1.0),
00044   m_restitution_factor (1.0),
00045   m_rolling_resistance_factor (1.0),
00046   m_drag_factor (0.0),
00047   m_bump_amplitude (0.0),
00048   m_bump_wavelength (0.0),
00049   mp_texture_image (0)
00050 {
00051 }
00052 
00053 Vamos_Geometry::Material::
00054 Material (const Material& material)
00055 {
00056   m_type = material.m_type;
00057   m_friction_factor = material.m_friction_factor;
00058   m_restitution_factor = material.m_restitution_factor;
00059   m_rolling_resistance_factor = material.m_rolling_resistance_factor;
00060   m_drag_factor = material.m_drag_factor;
00061   m_bump_amplitude = material.m_bump_amplitude;
00062   m_bump_wavelength = material.m_bump_wavelength;
00063 
00064   if (material.mp_texture_image != 0)
00065         {
00066           mp_texture_image = new Gl_Texture_Image (*(material.mp_texture_image));
00067         }
00068   else
00069         {
00070           mp_texture_image = 0;
00071         }
00072 }
00073 
00074 Vamos_Geometry::Material::
00075 ~Material ()
00076 {
00077   delete mp_texture_image;
00078 }
00079 
00080 const Vamos_Geometry::Material& Vamos_Geometry::Material::
00081 operator = (const Material& material)
00082 {
00083   if (&material != this)
00084         {
00085           m_type = material.m_type;
00086           m_friction_factor = material.m_friction_factor;
00087           m_restitution_factor = material.m_restitution_factor;
00088           m_rolling_resistance_factor = material.m_rolling_resistance_factor;
00089           m_drag_factor = material.m_drag_factor;
00090           m_bump_amplitude = material.m_bump_amplitude;
00091           m_bump_wavelength = material.m_bump_wavelength;
00092           
00093           if (material.mp_texture_image != 0)
00094                 {
00095                   delete mp_texture_image;
00096                   mp_texture_image 
00097                         = new Gl_Texture_Image (*(material.mp_texture_image));
00098                 }
00099           else
00100                 {
00101                   mp_texture_image = 0; 
00102                 }
00103         }
00104 
00105   return *this;
00106 }
00107 
00108 double Vamos_Geometry::Material::
00109 bump (double distance) const
00110 {
00111   if ((m_bump_amplitude == 0.0) || (m_bump_wavelength == 0.0)) return 0.0;
00112 
00113   // To avoid interfering with the initial placement of the car, don't
00114   // return a positive number.
00115   const double phase = two_pi * distance / m_bump_wavelength; 
00116   const double shift = 2.0 * sin (phase * root_2);
00117   const double amplitude = 0.25 * m_bump_amplitude;
00118   return amplitude * (sin (phase + shift) + sin (root_2 * phase) - 2.0);
00119 }

Generated on Thu Oct 19 04:05:55 2006 by  doxygen 1.4.6