Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ISC_123 - Travail Pratique 001 - Simulation Système Planétaire
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
florian.burgener
ISC_123 - Travail Pratique 001 - Simulation Système Planétaire
Commits
32d0208e
Commit
32d0208e
authored
3 years ago
by
Florian Burgener
Browse files
Options
Downloads
Patches
Plain Diff
Move functions
parent
58922599
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CelestialObject.c
+25
-25
25 additions, 25 deletions
CelestialObject.c
CelestialObject.h
+2
-2
2 additions, 2 deletions
CelestialObject.h
with
27 additions
and
27 deletions
CelestialObject.c
+
25
−
25
View file @
32d0208e
...
...
@@ -8,7 +8,7 @@
#include
"drawing.h"
const
double
G
=
6
.
67430
*
1E-11
;
const
int32_t
PREVIOUS_POSITIONS_MAXIMUM_LENGTH
=
2
00
;
const
int32_t
PREVIOUS_POSITIONS_MAXIMUM_LENGTH
=
3
00
;
CelestialObject
*
celestial_object_create
(
char
*
name
,
double
mass
,
double
semi_major_axis
,
double
eccentricity
,
int32_t
drawing_disc_radius
,
int32_t
drawing_color
)
{
CelestialObject
*
object
=
(
CelestialObject
*
)
malloc
(
sizeof
(
CelestialObject
));
...
...
@@ -37,6 +37,30 @@ void celestial_object_destroy(CelestialObject *object) {
free
(
object
);
}
int32_t
get_zoomed_drawing_disc_radius
(
CelestialObject
*
object
,
double
zoom_factor
)
{
if
(
zoom_factor
<
1
)
{
return
object
->
drawing_disc_radius
*
zoom_factor
;
}
return
object
->
drawing_disc_radius
;
}
Vector2
calculate_gravitational_acceleration
(
int32_t
object_index
,
CelestialObject
**
objects
,
int32_t
objects_length
)
{
Vector2
a
=
vector2_create_zero
();
for
(
int32_t
i
=
0
;
i
<
objects_length
;
i
+=
1
)
{
if
(
i
==
object_index
)
{
continue
;
}
Vector2
r
=
vector2_substract
((
i
<
object_index
)
?
objects
[
i
]
->
previous_position
:
objects
[
i
]
->
position
,
objects
[
object_index
]
->
position
);
double
a_scalar
=
G
*
objects
[
i
]
->
mass
*
pow
(
pow
(
vector2_norm
(
r
),
2
),
-
1
);
a
=
vector2_add
(
a
,
vector2_multiply
(
vector2_normalize
(
r
),
a_scalar
));
}
return
a
;
}
void
celestial_object_first_update
(
int32_t
object_index
,
CelestialObject
**
objects
,
int32_t
objects_length
,
int32_t
main_object_index
)
{
CelestialObject
*
object
=
objects
[
object_index
];
CelestialObject
*
main_object
=
objects
[
main_object_index
];
...
...
@@ -71,22 +95,6 @@ void celestial_object_update(int32_t object_index, CelestialObject **objects, in
celestial_object_update_previous_positions
(
object
);
}
Vector2
calculate_gravitational_acceleration
(
int32_t
object_index
,
CelestialObject
**
objects
,
int32_t
objects_length
)
{
Vector2
a
=
vector2_create_zero
();
for
(
int32_t
i
=
0
;
i
<
objects_length
;
i
+=
1
)
{
if
(
i
==
object_index
)
{
continue
;
}
Vector2
r
=
vector2_substract
((
i
<
object_index
)
?
objects
[
i
]
->
previous_position
:
objects
[
i
]
->
position
,
objects
[
object_index
]
->
position
);
double
a_scalar
=
G
*
objects
[
i
]
->
mass
*
pow
(
pow
(
vector2_norm
(
r
),
2
),
-
1
);
a
=
vector2_add
(
a
,
vector2_multiply
(
vector2_normalize
(
r
),
a_scalar
));
}
return
a
;
}
void
celestial_object_update_previous_positions
(
CelestialObject
*
object
)
{
object
->
previous_positions
[
0
]
=
object
->
position
;
int32_t
length
=
object
->
previous_positions_length
;
...
...
@@ -118,14 +126,6 @@ void celestial_object_draw(CelestialObject *object, Vector2 reference_frame, dou
}
}
int32_t
get_zoomed_drawing_disc_radius
(
CelestialObject
*
object
,
double
zoom_factor
)
{
if
(
zoom_factor
<
1
)
{
return
object
->
drawing_disc_radius
*
zoom_factor
;
}
return
object
->
drawing_disc_radius
;
}
void
celestial_object_draw_name
(
CelestialObject
*
object
,
Vector2
reference_frame
,
double
zoom_factor
)
{
Vector2
scaled_position
=
scale_position
(
object
->
position
,
reference_frame
,
zoom_factor
);
...
...
This diff is collapsed.
Click to expand it.
CelestialObject.h
+
2
−
2
View file @
32d0208e
...
...
@@ -18,12 +18,12 @@ typedef struct CelestialObject {
CelestialObject
*
celestial_object_create
(
char
*
name
,
double
mass
,
double
semi_major_axis
,
double
eccentricity
,
int32_t
drawing_disc_radius
,
int32_t
drawing_color
);
void
celestial_object_destroy
(
CelestialObject
*
object
);
int32_t
get_zoomed_drawing_disc_radius
(
CelestialObject
*
object
,
double
zoom_factor
);
Vector2
calculate_gravitational_acceleration
(
int32_t
object_index
,
CelestialObject
**
objects
,
int32_t
objects_length
);
void
celestial_object_first_update
(
int32_t
object_index
,
CelestialObject
**
objects
,
int32_t
objects_length
,
int32_t
main_object_index
);
void
celestial_object_update
(
int32_t
object_index
,
CelestialObject
**
objects
,
int32_t
objects_length
,
double
interval
,
double
previous_interval
);
Vector2
calculate_gravitational_acceleration
(
int32_t
object_index
,
CelestialObject
**
objects
,
int32_t
objects_length
);
void
celestial_object_update_previous_positions
(
CelestialObject
*
object
);
void
celestial_object_draw
(
CelestialObject
*
object
,
Vector2
reference_frame
,
double
zoom_factor
);
int32_t
get_zoomed_drawing_disc_radius
(
CelestialObject
*
object
,
double
zoom_factor
);
void
celestial_object_draw_name
(
CelestialObject
*
object
,
Vector2
reference_frame
,
double
zoom_factor
);
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment