Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
phys_planetes
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
boris.stefanov
phys_planetes
Commits
95920e2e
Commit
95920e2e
authored
3 years ago
by
BobLeHibou
Browse files
Options
Downloads
Patches
Plain Diff
ADD: EPPUR SI MUOVE !
parent
814a2ed6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
main.c
+1
-2
1 addition, 2 deletions
main.c
planet/constants.h
+4
-0
4 additions, 0 deletions
planet/constants.h
planet/planet.c
+11
-6
11 additions, 6 deletions
planet/planet.c
planet/planet.h
+1
-2
1 addition, 2 deletions
planet/planet.h
with
17 additions
and
10 deletions
main.c
+
1
−
2
View file @
95920e2e
...
...
@@ -11,7 +11,7 @@
#define SUN_RADIUS 50
#define DELTA_T
36
00.0
#define DELTA_T
80
00.0
int
main
()
{
srand
(
time
(
NULL
));
...
...
@@ -32,7 +32,6 @@ int main() {
// end : draw state of system
// begin : update your system
update_system
(
&
sys
,
DELTA_T
);
usleep
(
100000
);
// end : update system
if
(
gfx_keypressed
()
==
SDLK_ESCAPE
)
{
break
;
}
}
...
...
This diff is collapsed.
Click to expand it.
planet/constants.h
+
4
−
0
View file @
95920e2e
...
...
@@ -2,6 +2,10 @@
#define PLANET_CONSTANTS_H
// display
#define DISPLAY_RADIUS_DIV 1.0e23
#define G 6.67e-11
#define M_SOLEIL 1.989e30
...
...
This diff is collapsed.
Click to expand it.
planet/planet.c
+
11
−
6
View file @
95920e2e
...
...
@@ -20,22 +20,22 @@ system_t create_system(double delta_t) {
system
.
star
=
create_planet
(
M_SOLEIL
,
vec2_create_zero
());
system
.
nb_planets
=
4
;
system
.
planets
=
malloc
(
system
.
nb_planets
*
sizeof
(
planet_t
));
double
masses
[
NB_PLANETS
]
=
{
double
masses
[]
=
{
M_MERCURE
,
M_VENUS
,
M_TERRE
,
M_MARS
};
vec2
positions
[
NB_PLANETS
]
=
{
vec2
positions
[]
=
{
vec2_create
(
PER_MERCURE
,
0
.
0
),
vec2_create
(
PER_VENUS
,
0
.
0
),
vec2_create
(
PER_TERRE
,
0
.
0
),
vec2_create
(
PER_MARS
,
0
.
0
)};
double
eccentricities
[
NB_PLANETS
]
=
{
double
eccentricities
[]
=
{
E_MERCURE
,
E_VENUS
,
E_TERRE
,
E_MARS
};
double
axis_major
[
NB_PLANETS
]
=
{
double
axis_major
[]
=
{
A_MERCURE
,
A_VENUS
,
A_TERRE
,
...
...
@@ -55,9 +55,12 @@ system_t create_system(double delta_t) {
}
void
show_system
(
struct
gfx_context_t
*
ctxt
,
system_t
*
system
,
const
uint32_t
width
,
const
uint32_t
height
)
{
void
show_system
(
struct
gfx_context_t
*
ctxt
,
system_t
*
system
)
{
// draw sun
const
coordinates
xy_sun
=
vec2_to_coordinates_centered
(
vec2_normalize
(
system
->
star
.
pos
),
width
,
height
);
const
coordinates
xy_sun
=
vec2_to_coordinates_centered
(
vec2_normalize
(
system
->
star
.
pos
),
ctxt
->
width
,
ctxt
->
height
);
draw_full_circle
(
ctxt
,
xy_sun
.
column
,
xy_sun
.
row
,
50
,
COLOR_YELLOW
);
// draw planets
for
(
uint32_t
i
=
0
;
i
<
system
->
nb_planets
;
++
i
)
{
...
...
@@ -85,12 +88,14 @@ void update_system(system_t* system, double delta_t) {
const
vec2
a_k
=
vec2_mul
(
a_norm
,
u
);
a
=
vec2_add
(
a
,
a_k
);
}
a
=
vec2_mul
(
-
1
.
0
,
a
);
// correct sign: towards center
// update position
vec2
next_pos
=
vec2_mul
(
2
.
0
,
system
->
planets
[
i
].
pos
);
next_pos
=
vec2_sub
(
next_pos
,
system
->
planets
[
i
].
prec_pos
);
next_pos
=
vec2_add
(
next_pos
,
vec2_mul
(
delta_t
*
delta_t
,
a
));
system
->
planets
[
i
].
prec_pos
=
system
->
planets
[
i
].
pos
;
system
->
planets
[
i
].
pos
=
next_pos
;
printf
(
"%lf %lf %lf
\n
"
,
system
->
planets
[
i
].
pos
.
x
,
system
->
planets
[
i
].
pos
.
y
,
vec2_norm
(
a
));
}
}
...
...
This diff is collapsed.
Click to expand it.
planet/planet.h
+
1
−
2
View file @
95920e2e
...
...
@@ -22,8 +22,7 @@ planet_t create_planet(double mass, vec2 pos);
system_t
create_system
(
double
delta_t
);
//void show_system(struct gfx_context_t *ctxt, system_t *system);
void
show_system
(
struct
gfx_context_t
*
ctxt
,
system_t
*
system
,
const
uint32_t
width
,
const
uint32_t
height
);
void
show_system
(
struct
gfx_context_t
*
ctxt
,
system_t
*
system
);
void
update_system
(
system_t
*
system
,
double
delta_t
);
...
...
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