-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathphysics_init.cpp
More file actions
121 lines (94 loc) · 3.24 KB
/
physics_init.cpp
File metadata and controls
121 lines (94 loc) · 3.24 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
#include "eol_settings.h"
#include "physics_init.h"
static motorst Motorst1;
static motorst Motorst2;
motorst* Motor1 = &Motorst1;
motorst* Motor2 = &Motorst2;
// Perpendicular velocity required to detach wheel from ground.
double GroundEscapeVelocity;
// Amount by which the wheel is sunk into the ground
double WheelDeformationLength;
double Gravity;
// Minimum distance between two vertices to be considered separate points
double TwoPointDiscriminationDistance;
double VoltDelay;
double LevelEndDelay;
double SpringTensionCoefficient;
double SpringResistanceCoefficient;
double HeadRadius;
double ObjectRadius = 0.4;
// Render size of the wheel when not turning, in meters, to avoid the wheel appearing to be inside
// the ground
double WheelBackgroundRenderRadius = 0.395;
double LeftWheelDX;
double LeftWheelDY;
double RightWheelDX;
double RightWheelDY;
double BodyDY;
double MetersToPixels;
double PixelsToMeters;
int MinimapScaleFactor = 10;
double MetersToMinimapPixels;
void init_motor(motorst* motor) {
motor->flipped_bike = 0;
motor->flipped_camera = 0;
motor->gravity_direction = MotorGravity::Down;
motor->prev_brake = false;
motor->bike.rotation = 0.0;
motor->bike.angular_velocity = 0.0;
motor->bike.radius = 0.3;
motor->bike.mass = 200;
// inertia = mass * radius * radius
// although radius = 0.55 is used instead of 0.3, as set above.
motor->bike.inertia = 200.0 * 0.55 * 0.55;
motor->bike.r = vect2(2.75, 3.6);
motor->bike.v = vect2(0, 0);
motor->left_wheel.rotation = 0.0;
motor->left_wheel.angular_velocity = 0.0;
motor->left_wheel.radius = 0.4;
motor->left_wheel.mass = 10;
motor->left_wheel.inertia = 0.32;
motor->left_wheel.r = vect2(1.9, 3.0);
motor->left_wheel.v = vect2(0, 0);
motor->right_wheel.rotation = 0.0;
motor->right_wheel.angular_velocity = 0.0;
motor->right_wheel.radius = 0.4;
motor->right_wheel.mass = 10;
motor->right_wheel.inertia = 0.32;
motor->right_wheel.r = vect2(3.6, 3.0);
motor->right_wheel.v = vect2(0, 0);
motor->body_r = vect2(2.75, 4.04);
motor->body_v = vect2(0.0, 0.0);
}
void set_zoom_factor() {
double zoom_factor = 0.48 * EolSettings->zoom();
MetersToPixels = 100.0 * zoom_factor;
PixelsToMeters = 1.0 / MetersToPixels;
set_minimap_zoom_factor();
}
void set_minimap_zoom_factor() {
MinimapScaleFactor = (int)(0.42 * MetersToPixels * 0.5 / EolSettings->minimap_zoom());
MetersToMinimapPixels = MetersToPixels / MinimapScaleFactor;
}
void init_physics_data(void) {
init_motor(Motor1);
init_motor(Motor2);
set_zoom_factor();
GroundEscapeVelocity = 0.01; // m/s
WheelDeformationLength = 0.005; // m
Gravity = 10.0; // m/s^2
TwoPointDiscriminationDistance = 0.1; // m
VoltDelay = 0.4;
LevelEndDelay = 1.0;
SpringTensionCoefficient = 10000.0; // N/m
SpringResistanceCoefficient = 1000.0; // N/(m/s)
HeadRadius = 0.238; // m
// Relative positions
vect2 vtmp = Motor1->left_wheel.r - Motor1->bike.r;
LeftWheelDX = vtmp.x;
LeftWheelDY = vtmp.y;
vtmp = Motor1->right_wheel.r - Motor1->bike.r;
RightWheelDX = vtmp.x;
RightWheelDY = vtmp.y;
BodyDY = Motor1->body_r.y - Motor1->bike.r.y;
}