00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00114
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 }