32
32
#define SIMULATION_STEPS 30
33
33
#define G 9.81
34
34
35
- #define scalar float
36
-
37
35
//----------------------------------------------------------------------------------
38
36
// Module Functions Declaration
39
37
//----------------------------------------------------------------------------------
40
- static Vector2 CalculatePendulumEndPoint (scalar l , scalar theta );
41
- static Vector2 CalculateDoublePendulumEndPoint (scalar l1 , scalar theta1 , scalar l2 , scalar theta2 );
38
+ static Vector2 CalculatePendulumEndPoint (float l , float theta );
39
+ static Vector2 CalculateDoublePendulumEndPoint (float l1 , float theta1 , float l2 , float theta2 );
42
40
43
41
//------------------------------------------------------------------------------------
44
42
// Program main entry point
@@ -52,18 +50,18 @@ int main(void)
52
50
53
51
// Simulation Paramters
54
52
//--------------------------------------------------------------------------------------
55
- scalar l1 = 15 , m1 = 0.2 , theta1 = DEG2RAD * 170 , w1 = 0 ;
56
- scalar l2 = 15 , m2 = 0.1 , theta2 = DEG2RAD * 0 , w2 = 0 ;
57
- scalar lengthScaler = 0.1 ;
58
- scalar totalM = m1 + m2 ;
53
+ float l1 = 15 , m1 = 0.2 , theta1 = DEG2RAD * 170 , w1 = 0 ;
54
+ float l2 = 15 , m2 = 0.1 , theta2 = DEG2RAD * 0 , w2 = 0 ;
55
+ float lengthScaler = 0.1 ;
56
+ float totalM = m1 + m2 ;
59
57
60
58
Vector2 previousPosition = CalculateDoublePendulumEndPoint (l1 , theta1 , l2 , theta2 );
61
59
previousPosition .x += CENTER_X ;
62
60
previousPosition .y += CENTER_Y ;
63
61
64
62
// Scale length
65
- scalar L1 = l1 * lengthScaler ;
66
- scalar L2 = l2 * lengthScaler ;
63
+ float L1 = l1 * lengthScaler ;
64
+ float L2 = l2 * lengthScaler ;
67
65
68
66
// Draw Parameters
69
67
//--------------------------------------------------------------------------------------
@@ -82,25 +80,25 @@ int main(void)
82
80
while (!WindowShouldClose ()) // Detect window close button or ESC key
83
81
{
84
82
// Update
85
- scalar dt = GetFrameTime ();
86
- scalar step = dt / SIMULATION_STEPS , step2 = step * step ;
83
+ float dt = GetFrameTime ();
84
+ float step = dt / SIMULATION_STEPS , step2 = step * step ;
87
85
88
86
// Update Physics - larger steps = better approximation
89
87
//----------------------------------------------------------------------------------
90
88
for (int i = 0 ; i < SIMULATION_STEPS ; ++ i )
91
89
{
92
- scalar delta = theta1 - theta2 ;
93
- scalar sinD = sin (delta ), cosD = cos (delta ), cos2D = cos (2 * delta );
94
- scalar ww1 = w1 * w1 , ww2 = w2 * w2 ;
90
+ float delta = theta1 - theta2 ;
91
+ float sinD = sin (delta ), cosD = cos (delta ), cos2D = cos (2 * delta );
92
+ float ww1 = w1 * w1 , ww2 = w2 * w2 ;
95
93
96
94
// Calculate a1
97
- scalar a1 = (- G * (2 * m1 + m2 ) * sin (theta1 )
95
+ float a1 = (- G * (2 * m1 + m2 ) * sin (theta1 )
98
96
- m2 * G * sin (theta1 - 2 * theta2 )
99
97
- 2 * sinD * m2 * (ww2 * L2 + ww1 * L1 * cosD ))
100
98
/ (L1 * (2 * m1 + m2 - m2 * cos2D ));
101
99
102
100
// Calculate a2
103
- scalar a2 = (2 * sinD * (ww1 * L1 * totalM
101
+ float a2 = (2 * sinD * (ww1 * L1 * totalM
104
102
+ G * totalM * cos (theta1 )
105
103
+ ww2 * L2 * m2 * cosD ))
106
104
/ (L2 * (2 * m1 + m2 - m2 * cos2D ));
@@ -170,13 +168,13 @@ int main(void)
170
168
}
171
169
172
170
// Calculate Pendulum End Point
173
- static Vector2 CalculatePendulumEndPoint (scalar l , scalar theta )
171
+ static Vector2 CalculatePendulumEndPoint (float l , float theta )
174
172
{
175
173
return (Vector2 ){ 10 * l * sin (theta ), 10 * l * cos (theta ) };
176
174
}
177
175
178
176
// Calculate Double Pendulum End Point
179
- static Vector2 CalculateDoublePendulumEndPoint (scalar l1 , scalar theta1 , scalar l2 , scalar theta2 )
177
+ static Vector2 CalculateDoublePendulumEndPoint (float l1 , float theta1 , float l2 , float theta2 )
180
178
{
181
179
Vector2 endpoint1 = CalculatePendulumEndPoint (l1 , theta1 );
182
180
Vector2 endpoint2 = CalculatePendulumEndPoint (l2 , theta2 );
0 commit comments