added all planets

This commit is contained in:
Volodymyr Patuta 2020-12-22 15:31:33 +01:00
parent bd43f5bc79
commit 0d8b70f77f
2 changed files with 76 additions and 23 deletions

BIN
images/pluto.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 759 KiB

View File

@ -89,43 +89,44 @@ int main(int argc, char ** argv) {
/*!\brief init de nos données, spécialement les trois surfaces
* utilisées dans ce code */
void init(void) {
uint sun_id, mercury_id, venus_id, earth_id;
uint id[9], sun_id, i;
/*vec4 g = {0, 1, 0, 1};*/
/* on créé nos trois type de surfaces */
_sun = mkSphere(12, 12); /*ça fait 12x12x2 trianles !*/
/* on change les couleurs de surfaces */
/*_sun->dcolor = g; */
_planet[0] = mkSphere(12, 12);
_planet[1] = mkSphere(12, 12);
_planet[2] = mkSphere(12, 12);
for(i = 0; i < 9; ++i) {
_planet[i] = mkSphere(12, 12);
}
sun_id = getTexFromBMP("images/2k-sun.bmp");
mercury_id = getTexFromBMP("images/2k-mercury.bmp");
venus_id = getTexFromBMP("images/2k-venus-surface.bmp");
earth_id = getTexFromBMP("images/2k-earth-daymap.bmp");
id[0] = getTexFromBMP("images/2k-mercury.bmp");
id[1] = getTexFromBMP("images/2k-venus-surface.bmp");
id[2] = getTexFromBMP("images/2k-earth-daymap.bmp");
id[3] = getTexFromBMP("images/2k-mars.bmp");
id[4] = getTexFromBMP("images/2k-jupiter.bmp");
id[5] = getTexFromBMP("images/2k-saturn.bmp");
id[6] = getTexFromBMP("images/2k-uranus.bmp");
id[7] = getTexFromBMP("images/2k-neptune.bmp");
id[8] = getTexFromBMP("images/pluto.bmp");
setTexId(_sun, sun_id);
setTexId(_planet[0], mercury_id);
setTexId(_planet[1], venus_id);
setTexId(_planet[2], earth_id);
for(i = 0; i < 9; ++i)
setTexId(_planet[i], id[i]);
/* si _use_tex != 0, on active l'utilisation de la texture pour les
* trois */
if(_use_tex) {
enableSurfaceOption(_sun, SO_USE_TEXTURE);
enableSurfaceOption(_planet[0], SO_USE_TEXTURE);
enableSurfaceOption(_planet[1], SO_USE_TEXTURE);
enableSurfaceOption(_planet[2], SO_USE_TEXTURE);
for(i = 0; i < 9; ++i)
enableSurfaceOption(_planet[i], SO_USE_TEXTURE);
}
/* si _use_lighting != 0, on active l'ombrage */
if(_use_lighting) {
enableSurfaceOption(_sun, SO_USE_LIGHTING);
enableSurfaceOption(_planet[0], SO_USE_LIGHTING);
enableSurfaceOption(_planet[1], SO_USE_LIGHTING);
enableSurfaceOption(_planet[2], SO_USE_LIGHTING);
for(i = 0; i < 9; ++i)
enableSurfaceOption(_planet[i], SO_USE_LIGHTING);
}
disableSurfaceOption(_sun, SO_USE_COLOR);
disableSurfaceOption(_planet[0], SO_USE_COLOR);
disableSurfaceOption(_planet[1], SO_USE_COLOR);
disableSurfaceOption(_planet[2], SO_USE_COLOR);
for(i = 0; i < 9; ++i)
disableSurfaceOption(_planet[i], SO_USE_COLOR);
atexit(sortie);
}
@ -158,26 +159,30 @@ void draw(void) {
// scales https://www.jpl.nasa.gov/infographics/infographic.view.php?id=10749
/* la sphère est laissée au centre et tourne autour de son axe y */
// SUN
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, (a / 24.5f), 0.0f, 1.0f, 0.0f);
translate(nmv, 0.0f, 1.0f, 0.0f);
scale(nmv, 2,2,2);
transform_n_raster(_sun, nmv, projMat);
// MERCURY
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, (a / 88.0f), 0.0f, 1.0f, 0.0f); // orbit mouvement
rotate(nmv, (a / 87.97f), 0.0f, 1.0f, 0.0f); // orbit mouvement
translate(nmv, 10.0f, 1.0f, 0.0f);
scale(nmv, (1/227.0f) * 12.0f, (1/227.0f) * 12.0f, (1/227.0f) * 12.0f);
rotate(nmv, (a / 176.0f), 0.0f, 1.0f, 0.0f); // rotation
rotate(nmv, (a / 59.0f), 0.0f, 1.0f, 0.0f); // rotation
transform_n_raster(_planet[0], nmv, projMat);
// VENUS
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, (a / 224.7f), 0.0f, 1.0f, 0.0f); // orbit mouvement
translate(nmv, 20.0f, 1.0f, 0.0f);
scale(nmv, (1/113.0f) * 12.0f, (1/113.0f) * 12.0f, (1/113.0f) * 12.0f);
rotate(nmv, (a / 116.75f), 0.0f, -1.0f, 0.0f); // rotation anti-clockwise
rotate(nmv, (a / 243.75f), 0.0f, -1.0f, 0.0f); // rotation anti-clockwise
transform_n_raster(_planet[1], nmv, projMat);
// EARTH
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, (a / 365.2425f), 0.0f, 1.0f, 0.0f);
translate(nmv, 30.0f, 1.0f, 0.0f);
@ -185,6 +190,54 @@ void draw(void) {
rotate(nmv, a, 0.0f, 1.0f, 0.0f);
transform_n_raster(_planet[2], nmv, projMat);
// MARS
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, (a / 686.98f), 0.0f, 1.0f, 0.0f);
translate(nmv, 50.0f, 1.0f, 0.0f);
scale(nmv, (1/208.0f) * 12.0f, (1/208.0f) * 12.0f, (1/208.0f) * 12.0f);
rotate(nmv, 1.0416f * a, 0.0f, 1.0f, 0.0f);
transform_n_raster(_planet[3], nmv, projMat);
// JUPITER
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, a / (12 * 365.2425f), 0.0f, 1.0f, 0.0f);
translate(nmv, 70.0f, 1.0f, 0.0f);
scale(nmv, (1/9.7f) * 12.0f, (1/9.7f) * 12.0f, (1/9.7f) * 12.0f);
rotate(nmv, a / 0.416f, 0.0f, 1.0f, 0.0f);
transform_n_raster(_planet[4], nmv, projMat);
// SATURN
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, a / (30 * 365.2425f), 0.0f, 1.0f, 0.0f);
translate(nmv, 90.0f, 1.0f, 0.0f);
scale(nmv, (1/11.4f) * 12.0f, (1/11.4f) * 12.0f, (1/11.4f) * 12.0f);
rotate(nmv, a / 0.4583f, 0.0f, 1.0f, 0.0f);
transform_n_raster(_planet[5], nmv, projMat);
// URANUS
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, a / (84 * 365.2425f), 0.0f, 1.0f, 0.0f);
translate(nmv, 110.0f, 1.0f, 0.0f);
scale(nmv, (1/26.8f) * 12.0f, (1/26.8f) * 12.0f, (1/26.8f) * 12.0f);
rotate(nmv, a / 0.7083f, 0.0f, 1.0f, 0.0f);
transform_n_raster(_planet[6], nmv, projMat);
// NEPTUNE
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, a / (165 * 365.2425f), 0.0f, 1.0f, 0.0f);
translate(nmv, 130.0f, 1.0f, 0.0f);
scale(nmv, (1/27.7f) * 12.0f, (1/27.7f) * 12.0f, (1/27.7f) * 12.0f);
rotate(nmv, a / 0.6f, 0.0f, 1.0f, 0.0f);
transform_n_raster(_planet[7], nmv, projMat);
// PLUTO
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, a / (248 * 365.2425f), 0.0f, 1.0f, 0.0f);
translate(nmv, 150.0f, 1.0f, 0.0f);
scale(nmv, (1/500.0f) * 12.0f, (1/500.0f) * 12.0f, (1/500.0f) * 12.0f);
rotate(nmv, a / 6.4, 0.0f, 1.0f, 0.0f);
transform_n_raster(_planet[8], nmv, projMat);
/* déclarer qu'on a changé (en bas niveau) des pixels du screen */
gl4dpScreenHasChanged();
/* fonction permettant de raffraîchir l'ensemble de la fenêtre*/