-
Notifications
You must be signed in to change notification settings - Fork 3
/
boat.c
98 lines (78 loc) · 2.13 KB
/
boat.c
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
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "boat.h"
#include "physics.h"
Boat *sailing_boat_init(const char *name) {
Boat *boat = calloc(1, sizeof(Boat));
boat->name = strdup(name);
sailing_boat_reset(boat);
return boat;
}
void sailing_boat_reset(Boat *boat) {
boat->x = 0;
boat->y = 0;
boat->angle = M_PI_4;
boat->sail_angle = 0;
boat->rudder_angle = 0;
boat->sail_is_free = 0;
boat->v = 5;
boat->sheet_length = 1;
boat->rotational_velocity = 0.0;
boat->inertia = 10000.0;
boat->drift_coefficient = 0.05;
boat->rudder_distance = 4.0;
boat->angular_friction = 8000;
boat->mass = 300.0;
boat->tangential_friction = 0.1;
boat->mast_distance = 1;
boat->rudder_lift = 8000.0;
boat->sail_center_of_effort = 1.0;
boat->sail_lift = 1000.0;
}
void sailing_boat_free(Boat *boat) {
free(boat->name);
free(boat);
}
char *sailing_boat_get_name(const Boat *boat) {
return boat->name;
}
double sailing_boat_get_latitude(const Boat *boat) {
return boat->y;
}
void sailing_boat_set_latitude(Boat *boat, double latitude) {
boat->y = latitude;
}
double sailing_boat_get_longitude(const Boat *boat) {
return boat->x;
}
void sailing_boat_set_longitude(Boat *boat, double longitude) {
boat->x = longitude;
}
double sailing_boat_get_sail_angle(const Boat *boat) {
return boat->sail_angle;
}
void sailing_boat_set_sail_angle(Boat *boat, double sail_angle) {
boat->sail_angle = sail_angle;
}
double sailing_boat_get_angle(const Boat *boat) {
return boat->angle;
}
void sailing_boat_set_angle(Boat *boat, double angle) {
boat->angle = angle;
}
double sailing_boat_get_rudder_angle(const Boat *boat) {
return boat->rudder_angle;
}
void sailing_boat_set_rudder_angle(Boat *boat, double rudder_angle) {
boat->rudder_angle = rudder_angle;
}
double sailing_boat_get_velocity(const Boat *boat) {
return boat->v;
}
void sailing_boat_set_sheet_length(Boat *boat, double sheet_length) {
boat->sheet_length = sheet_length;
}
double sailing_boat_get_sheet_length(const Boat *boat) {
return boat->sheet_length;
}