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
f7a1c800
Commit
f7a1c800
authored
3 years ago
by
Florian Burgener
Browse files
Options
Downloads
Patches
Plain Diff
Zoom + frame of reference
parent
06e8f994
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
PlanetarySystem.c
+5
-5
5 additions, 5 deletions
PlanetarySystem.c
PlanetarySystem.h
+2
-0
2 additions, 0 deletions
PlanetarySystem.h
main.c
+38
-4
38 additions, 4 deletions
main.c
with
45 additions
and
9 deletions
PlanetarySystem.c
+
5
−
5
View file @
f7a1c800
...
...
@@ -36,6 +36,8 @@ PlanetarySystem *planetary_system_create(double interval) {
planetary_system
->
objects_length
=
6
;
planetary_system
->
objects
=
(
CelestialObject
**
)
malloc
(
sizeof
(
PlanetarySystem
*
)
*
planetary_system
->
objects_length
);
planetary_system
->
interval
=
interval
;
planetary_system
->
zoom_factor
=
1
;
planetary_system
->
reference_frame_object_index
=
0
;
planetary_system
->
objects
[
0
]
=
celestial_object_create
(
SUN_MASS
,
0
,
0
,
50
,
0x00FFFFFF
);
planetary_system
->
objects
[
1
]
=
celestial_object_create
(
MERCURY_MASS
,
MERCURY_SEMI_MAJOR_AXIS
,
MERCURY_ECCENTRICITY
,
10
,
0x00DBCECA
);
...
...
@@ -88,13 +90,11 @@ void planetary_system_update(PlanetarySystem *planetary_system) {
Vector2
r
=
vector2_normalize
(
vector2_create
(
current_position
.
y
,
-
current_position
.
x
));
Vector2
periapsis_velocity
=
vector2_multiply
(
r
,
periapsis_velocity_scalar
);
vector2_print
(
periapsis_velocity
);
new_position
=
vector2_add
(
current_position
,
vector2_multiply
(
periapsis_velocity
,
planetary_system
->
interval
));
Vector2
a
=
calculate_gravitational_acceleration
(
planetary_system
,
i
);
new_position
=
vector2_add
(
new_position
,
vector2_multiply
(
a
,
0
.
5
*
pow
(
planetary_system
->
interval
,
2
)));
}
else
{
// continue;
new_position
=
vector2_substract
(
vector2_multiply
(
current_position
,
2
),
object
->
previous_position
);
Vector2
a
=
calculate_gravitational_acceleration
(
planetary_system
,
i
);
new_position
=
vector2_add
(
new_position
,
vector2_multiply
(
a
,
pow
(
planetary_system
->
interval
,
2
)));
...
...
@@ -116,9 +116,9 @@ void planetary_system_draw(PlanetarySystem *planetary_system, struct gfx_context
for
(
uint32_t
i
=
0
;
i
<
planetary_system
->
objects_length
;
i
+=
1
)
{
CelestialObject
*
object
=
planetary_system
->
objects
[
i
];
//
Vector2 tmp = vector2_substract(object->current_position, planetary_system->objects[
3
]->current_position);
//
tmp = vector2_multiply(tmp,
1
);
Vector2
scaled_position
=
scale_position
(
object
->
current_position
);
Vector2
tmp
=
vector2_substract
(
object
->
current_position
,
planetary_system
->
objects
[
planetary_system
->
reference_frame_object_index
]
->
current_position
);
tmp
=
vector2_multiply
(
tmp
,
planetary_system
->
zoom_factor
);
Vector2
scaled_position
=
scale_position
(
tmp
);
draw_full_circle
(
context
,
scaled_position
.
x
,
scaled_position
.
y
,
object
->
drawing_disc_radius
,
object
->
drawing_color
);
}
...
...
This diff is collapsed.
Click to expand it.
PlanetarySystem.h
+
2
−
0
View file @
f7a1c800
...
...
@@ -13,6 +13,8 @@ typedef struct {
uint32_t
objects_length
;
CelestialObject
**
objects
;
double
interval
;
double
zoom_factor
;
uint32_t
reference_frame_object_index
;
}
PlanetarySystem
;
PlanetarySystem
*
planetary_system_create
(
double
interval
);
...
...
This diff is collapsed.
Click to expand it.
main.c
+
38
−
4
View file @
f7a1c800
...
...
@@ -18,8 +18,8 @@ int main() {
return
EXIT_FAILURE
;
}
int32_t
time_elapsing_per_second
=
3600
*
24
*
10
;
int32_t
refresh_rate
=
4
8
0
;
int32_t
time_elapsing_per_second
=
3600
*
24
*
5
;
int32_t
refresh_rate
=
2
40
;
int32_t
elapsed_time
=
0
;
double
sleep_duration
=
1
.
0
/
refresh_rate
*
1E9
;
printf
(
"%lf
\n
"
,
(
double
)
time_elapsing_per_second
/
refresh_rate
);
...
...
@@ -39,8 +39,42 @@ int main() {
SDL_SetWindowTitle
(
context
->
window
,
title
);
}
if
(
gfx_keypressed
()
==
SDLK_ESCAPE
)
break
;
SDL_Event
event
;
if
(
SDL_PollEvent
(
&
event
))
{
if
(
event
.
type
==
SDL_MOUSEWHEEL
)
{
if
(
event
.
wheel
.
y
>
0
)
{
planetary_system
->
zoom_factor
*=
1
.
1
;
}
else
if
(
event
.
wheel
.
y
<
0
)
{
planetary_system
->
zoom_factor
/=
1
.
1
;
if
(
planetary_system
->
zoom_factor
<
1
)
{
planetary_system
->
zoom_factor
=
1
;
}
}
}
if
(
event
.
type
==
SDL_KEYDOWN
)
{
if
(
event
.
key
.
keysym
.
sym
==
SDLK_ESCAPE
)
{
break
;
}
if
(
event
.
key
.
keysym
.
sym
==
SDLK_LEFT
)
{
planetary_system
->
reference_frame_object_index
-=
1
;
planetary_system
->
reference_frame_object_index
%=
planetary_system
->
objects_length
;
}
if
(
event
.
key
.
keysym
.
sym
==
SDLK_RIGHT
)
{
planetary_system
->
reference_frame_object_index
+=
1
;
planetary_system
->
reference_frame_object_index
%=
planetary_system
->
objects_length
;
}
}
}
// if (gfx_keypressed() == SDLK_ESCAPE)
// break;
// if (gfx_keypressed() == SDL_MOUSEBUTTONDOWN) {
// printf("A");
// }
struct
timespec
t
=
{.
tv_sec
=
0
,
.
tv_nsec
=
sleep_duration
};
nanosleep
(
&
t
,
NULL
);
elapsed_time
+=
1
;
...
...
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