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
51201730
Commit
51201730
authored
3 years ago
by
BobLeHibou
Browse files
Options
Downloads
Patches
Plain Diff
ADD: create_system
parent
e506aa6d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
planet/planet.c
+40
-7
40 additions, 7 deletions
planet/planet.c
with
40 additions
and
7 deletions
planet/planet.c
+
40
−
7
View file @
51201730
...
...
@@ -26,8 +26,8 @@ typedef struct _system
planet_t
create_planet
(
double
mass
,
vec2
pos
)
{
planet_t
p
;
p
.
mass
=
mass
;
p
.
prec_pos
=
pos
;
p
.
pos
=
pos
;
p
.
prec_pos
=
pos
;
// must be changed
return
p
;
}
...
...
@@ -37,17 +37,48 @@ 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
[
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
()};
if
(
NULL
==
system
.
planets
)
return
NULL
;
double
masses
[
system
.
nb_planets
]
=
{
M_MERCURE
,
M_VENUS
,
M_TERRE
,
M_MARS
};
vec2
positions
[
system
.
nb_planets
]
=
{
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
[
system
.
nb_planets
]
=
{
E_MERCURE
,
E_VENUS
,
E_TERRE
,
E_MARS
};
double
axis_major
[
system
.
nb_planets
]
=
{
A_MERCURE
,
A_VENUS
,
A_TERRE
,
A_MARS
};
for
(
uint32_t
i
=
0
;
i
<
system
.
nb_planets
;
++
i
)
{
system
.
planets
[
i
].
mass
=
masses
[
i
];
system
.
planets
[
i
].
pos
=
positions
[
i
];
double
vel
=
G
*
system
.
star
.
mass
*
(
1
.
0
+
eccentricities
[
i
]);
vel
/=
axis_major
[
i
]
*
(
1
.
0
-
eccentricities
[
i
]);
vel
=
sqrt
(
vel
);
const
vec2
ru
=
vec2_normalize
(
vec2_sub
(
system
.
planets
[
i
].
pos
,
system
.
star
.
pos
));
const
vec2
rp
=
vec2_create
(
-
ru
.
y
,
ru
.
x
);
const
vec2
v
=
vec2_mul
(
vel
,
r
);
system
.
planets
[
i
].
prec_pos
=
vec2_sub
(
system
.
planets
[
i
].
pos
,
vec2_mul
(
delta_t
,
v
));
}
return
system
;
}
void
show_system
(
struct
gfx_context_t
*
ctxt
,
system_t
*
system
);
void
show_system
(
struct
gfx_context_t
*
ctxt
,
system_t
*
system
)
{
//TODO
}
void
update_system
(
system_t
*
system
,
double
delta_t
)
{
void
update_system
(
system_t
*
system
,
double
delta_t
)
{
for
(
uint32_t
i
=
0
;
i
<
system
->
nb_planets
;
++
i
)
{
// apply the effects of the sun
vec2
a
=
vec2_mul
((
G
*
system
->
star
.
mass
)
/
r_star_2
,
vec2_normalize
(
system
->
planets
[
i
].
pos
));
...
...
@@ -71,4 +102,6 @@ void update_system(system_t *system, double delta_t) {
}
void
free_system
(
system_t
*
system
);
void
free_system
(
system_t
*
system
)
{
free
(
system
->
planets
);
}
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