Skip to content

Commit 10fadd9

Browse files
committed
Replaced scalar to float
1 parent b6ae5af commit 10fadd9

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

examples/shapes/shapes_double_pendulum.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@
3232
#define SIMULATION_STEPS 30
3333
#define G 9.81
3434

35-
#define scalar float
36-
3735
//----------------------------------------------------------------------------------
3836
// Module Functions Declaration
3937
//----------------------------------------------------------------------------------
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);
4240

4341
//------------------------------------------------------------------------------------
4442
// Program main entry point
@@ -52,18 +50,18 @@ int main(void)
5250

5351
// Simulation Paramters
5452
//--------------------------------------------------------------------------------------
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;
5957

6058
Vector2 previousPosition = CalculateDoublePendulumEndPoint(l1, theta1, l2, theta2);
6159
previousPosition.x += CENTER_X;
6260
previousPosition.y += CENTER_Y;
6361

6462
// Scale length
65-
scalar L1 = l1 * lengthScaler;
66-
scalar L2 = l2 * lengthScaler;
63+
float L1 = l1 * lengthScaler;
64+
float L2 = l2 * lengthScaler;
6765

6866
// Draw Parameters
6967
//--------------------------------------------------------------------------------------
@@ -82,25 +80,25 @@ int main(void)
8280
while (!WindowShouldClose()) // Detect window close button or ESC key
8381
{
8482
// 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;
8785

8886
// Update Physics - larger steps = better approximation
8987
//----------------------------------------------------------------------------------
9088
for (int i = 0; i < SIMULATION_STEPS; ++i)
9189
{
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;
9593

9694
// Calculate a1
97-
scalar a1 = (-G * (2 * m1 + m2) * sin(theta1)
95+
float a1 = (-G * (2 * m1 + m2) * sin(theta1)
9896
- m2 * G * sin(theta1 - 2 * theta2)
9997
- 2 * sinD * m2 * (ww2 * L2 + ww1 * L1 * cosD))
10098
/ (L1 * (2 * m1 + m2 - m2 * cos2D));
10199

102100
// Calculate a2
103-
scalar a2 = (2 * sinD * (ww1 * L1 * totalM
101+
float a2 = (2 * sinD * (ww1 * L1 * totalM
104102
+ G * totalM * cos(theta1)
105103
+ ww2 * L2 * m2 * cosD))
106104
/ (L2 * (2 * m1 + m2 - m2 * cos2D));
@@ -170,13 +168,13 @@ int main(void)
170168
}
171169

172170
// Calculate Pendulum End Point
173-
static Vector2 CalculatePendulumEndPoint(scalar l, scalar theta)
171+
static Vector2 CalculatePendulumEndPoint(float l, float theta)
174172
{
175173
return (Vector2){ 10 * l * sin(theta), 10 * l * cos(theta) };
176174
}
177175

178176
// 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)
180178
{
181179
Vector2 endpoint1 = CalculatePendulumEndPoint(l1, theta1);
182180
Vector2 endpoint2 = CalculatePendulumEndPoint(l2, theta2);

0 commit comments

Comments
 (0)