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
GitLab 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
d840a2e7
Commit
d840a2e7
authored
3 years ago
by
Boris Stefanovic
Browse files
Options
Downloads
Patches
Plain Diff
ADD: some constants
parent
b2c8808c
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
main.c
+27
-28
27 additions, 28 deletions
main.c
planet/constants.h
+32
-0
32 additions, 0 deletions
planet/constants.h
planet/planet.c
+20
-6
20 additions, 6 deletions
planet/planet.c
planet/planet.h
+7
-7
7 additions, 7 deletions
planet/planet.h
with
87 additions
and
41 deletions
.gitignore
+
1
−
0
View file @
d840a2e7
.idea
*.o
*.o
main
main
tests
tests
This diff is collapsed.
Click to expand it.
main.c
+
27
−
28
View file @
d840a2e7
...
@@ -8,34 +8,33 @@
...
@@ -8,34 +8,33 @@
#define SCREEN_WIDTH 1000
#define SCREEN_WIDTH 1000
#define SCREEN_HEIGHT 1000
#define SCREEN_HEIGHT 1000
int
main
()
// arbitraire, en secondes ?
{
#define DELTA_T 0.125
int
main
()
{
srand
(
time
(
NULL
));
srand
(
time
(
NULL
));
struct
gfx_context_t
*
ctxt
=
struct
gfx_context_t
*
ctxt
=
gfx_create
(
"Planetary system"
,
SCREEN_WIDTH
,
SCREEN_HEIGHT
);
gfx_create
(
"Planetary system"
,
SCREEN_WIDTH
,
SCREEN_HEIGHT
);
if
(
!
ctxt
)
if
(
!
ctxt
)
{
{
fprintf
(
stderr
,
"Graphics initialization failed!
\n
"
);
fprintf
(
stderr
,
"Graphics initialization failed!
\n
"
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
// TODO : create your system
// TODO : create your system
system_t
sys
=
create_system
(
DELTA_T
);
// end : create system
// end : create system
while
(
true
)
while
(
true
)
{
{
gfx_present
(
ctxt
);
gfx_present
(
ctxt
);
gfx_clear
(
ctxt
,
COLOR_BLACK
);
// TODO : draw the current state of your system
// TODO : draw the current state of your system
// end : draw state of system
// end : draw state of system
// TODO : update your system
// TODO : update your system
// end : update system
// end : update system
gfx_clear
(
ctxt
,
COLOR_BLACK
);
if
(
gfx_keypressed
()
==
SDLK_ESCAPE
)
{
break
;
}
if
(
gfx_keypressed
()
==
SDLK_ESCAPE
)
{
break
;
}
}
}
// TODO : Free your system
// TODO : Free your system
free_system
(
sys
);
// end : free system
// end : free system
gfx_destroy
(
ctxt
);
gfx_destroy
(
ctxt
);
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
...
...
This diff is collapsed.
Click to expand it.
planet/constants.h
0 → 100644
+
32
−
0
View file @
d840a2e7
#ifndef PLANET_CONSTANTS_H
#define PLANET_CONSTANTS_H
#define G 6.67e-11
#define M_SOLEIL 1.989e30
// source: CRM
#define M_TERRE 5.9742e24
// source: wiki
#define M_MERCURE 3.3011e23
#define M_VENUS 4.8675e24
#define M_MARS 6.4171e23
#define A_MERCURE 5.7909e10
#define A_VENUS 1.0821e11
#define A_TERRE 1.4960e11
#define A_MARS 2.2794e11
#define E_MERCURE 0.205630
#define E_VENUS 0.006772
#define E_TERRE 0.0167086
#define E_MARS 0.0934
//TODO: perihelion
#define PER_MERCURE
#define PER_VENUS
#define PER_TERRE
#define PER_MARS
#endif //PLANET_CONSTANTS_H
This diff is collapsed.
Click to expand it.
planet/planet.c
+
20
−
6
View file @
d840a2e7
#include
"planet.h"
#include
"planet.h"
#include
<stdlib.h>
#include
<stdlib.h>
#define G 6.67e-11
#include
"constants.h"
#define M_SOLEIL 1.989e30
/*
/*
...
@@ -24,10 +23,25 @@ typedef struct _system
...
@@ -24,10 +23,25 @@ typedef struct _system
// TODO : complete all implementations
// TODO : complete all implementations
planet_t
create_planet
(
double
mass
,
vec2
pos
);
planet_t
create_planet
(
double
mass
,
vec2
pos
)
{
planet_t
p
;
p
.
mass
=
mass
;
system_t
create_system
(
double
delta_t
);
p
.
prec_pos
=
pos
;
p
.
pos
=
pos
;
return
p
;
}
system_t
create_system
(
double
delta_t
)
{
system_t
system
;
system
.
star
=
create_planet
(
M_SOLEIL
,
vec2_create_zero
());
system
.
nb_planets
=
4
;
system
.
planets
=
malloc
(
system
.
nb_planets
*
sizeof
(
planet_t
));
double
masses
[
system
.
nb_planets
]
=
{
M_MERCURE
,
M_VENUS
,
M_TERRE
,
M_MARS
};
//TODO
vec2
positions
[
system
.
nb_planets
]
=
{
vec2_create
(),
vec2_create
(),
vec2_create
(),
vec2_create
()};
return
system
;
}
void
show_system
(
struct
gfx_context_t
*
ctxt
,
system_t
*
system
);
void
show_system
(
struct
gfx_context_t
*
ctxt
,
system_t
*
system
);
...
...
This diff is collapsed.
Click to expand it.
planet/planet.h
+
7
−
7
View file @
d840a2e7
...
@@ -18,7 +18,7 @@ typedef struct _system
...
@@ -18,7 +18,7 @@ typedef struct _system
planet_t
*
planets
;
// An array of orbiting planets
planet_t
*
planets
;
// An array of orbiting planets
}
system_t
;
}
system_t
;
// Th
o
se function are not mandatory to implement,
// Th
e
se function
s
are not mandatory to implement,
// it's rather a hint of what you should have.
// it's rather a hint of what you should have.
planet_t
create_planet
(
double
mass
,
vec2
pos
);
planet_t
create_planet
(
double
mass
,
vec2
pos
);
system_t
create_system
(
double
delta_t
);
system_t
create_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