[go: up one dir, main page]

Menu

[8286ad]: / body / Wheel.cpp  Maximize  Restore  History

Download this file

140 lines (121 with data), 4.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// 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 "Wheel.hpp"
#include "../geometry/Constants.hpp"
#include "../media/Ac3d.hpp"
using namespace Vamos_Body;
using namespace Vamos_Geometry;
Wheel::Wheel(double mass, Three_Vector position, double tire_offset, double restitution,
bool driven, Direction side, Tire* tire, Brake* brake)
: Particle(mass, position, Material(Material::RUBBER, 0.0, restitution)),
mp_tire(tire),
mp_brake(brake),
m_driven(driven),
m_side(side)
{}
void Wheel::contact(const Three_Vector& impulse, const Three_Vector& velocity, double distance,
const Three_Vector& normal, const Three_Vector& angular_velocity,
const Material& surface_material)
{
Particle::contact(impulse, rotate_in(velocity), distance, rotate_in(normal),
rotate_in(angular_velocity), surface_material);
m_normal = rotate_in(normal);
m_velocity = -rotate_in(velocity);
// Move the wheel in the suspension z-direction so the contact position is at the
// surface.
//!! For now assume distance was measured in the suspension z-direction.
m_displacement = distance;
translate(rotate_in(Three_Vector::Z * m_displacement));
//!! auto ground_velocity = m_velocity.project(m_normal) - m_velocity;
//!! mp_tire->input(ground_velocity, speed(),
//!! mp_suspension->force().project(m_normal),
//!! mp_suspension->current_camber(m_normal.unit().y),
//!! m_drive_torque + m_braking_torque, mp_brake->is_locked(),
//!! surface_material);
}
void Wheel::propagate(double time)
{
//!! m_rotational_speed
//!! = mp_brake->is_locked()
//!! ? 0.0
//!! : m_rotational_speed + (m_drive_torque - m_braking_torque) * time / m_inertia;
mp_tire->propagate(time);
m_force = mp_tire->force();
m_torque = mp_tire->torque();
m_rotation += m_rotational_speed * time;
}
void Wheel::drive_torque(double torque_in)
{
m_drive_torque = m_driven ? torque_in : 0.0;
}
void Wheel::brake(double factor)
{
//!! m_braking_torque = -mp_brake->torque(factor, mp_tire->rotational_speed());
}
Three_Vector Wheel::contact_position() const
{
return position() + mp_tire->contact_position();
}
void Wheel::reset()
{
Particle::reset();
mp_tire->reset();
}
GLuint Wheel::make_model(std::string file, double scale, const Three_Vector& translation,
const Three_Vector& rotation)
{
return Vamos_Media::Ac3d(file, scale, translation, rotation).build();
}
void Wheel::set_models(std::string slow_file, std::string fast_file, double transition_speed,
std::string stator_file, double stator_offset, double scale,
const Three_Vector& translation, const Three_Vector& rotation)
{
Three_Vector offset;
if (!stator_file.empty())
offset.y += m_side == RIGHT ? stator_offset : -stator_offset;
if (m_slow_wheel_list)
glDeleteLists(m_slow_wheel_list, 1);
m_slow_wheel_list = make_model(slow_file, scale, translation + offset, rotation);
if (m_fast_wheel_list)
glDeleteLists(m_fast_wheel_list, 1);
m_fast_wheel_list = make_model(fast_file, scale, translation + offset, rotation);
m_transition_speed = transition_speed;
if (stator_file.empty())
return;
if (m_stator_list)
glDeleteLists(m_stator_list, 1);
m_stator_list = make_model(stator_file, scale, translation, rotation);
}
void Wheel::transform()
{
glTranslatef(position().x, position().y, position().z);
auto [axis, angle] = axis_angle();
glRotatef(angle, axis.x, axis.y, axis.z);
}
void Wheel::draw()
{
glPushMatrix();
transform();
glCallList(m_stator_list);
if (speed() < m_transition_speed)
{
glRotatef(rad_to_deg(m_rotation), 0.0, 1.0, 0.0);
glCallList(m_slow_wheel_list);
}
else
glCallList(m_fast_wheel_list);
glPopMatrix();
//!! mp_suspension->draw();
}