// Copyright (C) 2001-2019 Sam Varner
//
// This file is part of Vamos Automotive Simulator.
//
// Vamos is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Vamos is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Vamos. If not, see <http://www.gnu.org/licenses/>.
#include "Material.hpp"
#include "Constants.hpp"
using namespace Vamos_Geometry;
Material::Material(Material_Type type, double friction, double restitution, double rolling,
double drag, const Two_Vector &bump_amplitude, double bump_wavelength,
std::string texture_file_name, bool smooth, bool mip_map, double width,
double height)
: m_type(type),
m_friction_factor(friction),
m_restitution_factor(restitution),
m_rolling_resistance_factor(rolling),
m_drag_factor(drag),
m_bump_amplitude(bump_amplitude),
m_bump_wavelength(bump_wavelength),
m_texture_file_name(texture_file_name),
m_smooth(smooth),
m_mip_map(mip_map),
m_width(width),
m_height(height)
{
}
Material::Material(Material_Type type, double friction, double restitution)
: Material(type, friction, restitution, 0.0, 0.0, Two_Vector(),
1.0, "", false, false, 1.0, 1.0)
{
}
inline double bump_function(double x, double y)
{
double phase = two_pi * (x + y);
return 0.25 * (sin(phase) + sin(root_2 * phase));
}
Three_Vector Material::bump(double x, double y) const
{
if (m_bump_wavelength == 0.0)
return Three_Vector();
// To avoid interfering with the initial placement of the car, don't return a positive
// number.
double bump = bump_function(x / m_bump_wavelength, y / m_bump_wavelength);
double side = m_bump_amplitude.y * bump;
double up = m_bump_amplitude.x * (bump - 0.5);
return Three_Vector(side, side, up);
}