proper scale, 1min == 1day, accel/deccel time, object scale x12, orbit movement
This commit is contained in:
parent
456a3e0a76
commit
bd43f5bc79
@ -102,7 +102,7 @@ surface_t * mkCube(void) {
|
||||
/*!\brief fabrique et renvoie une surface représentant une sphère
|
||||
* centrée en zéro et de rayon 1. Elle est découpée en \a longitudes
|
||||
* longitudes et \a latitudes latitudes. */
|
||||
surface_t * mkSphere(int longitudes, int latitudes, double s) {
|
||||
surface_t * mkSphere(int longitudes, int latitudes) {
|
||||
triangle_t * t;
|
||||
vertex_t * data;
|
||||
double phi, theta, r, y;
|
||||
@ -118,8 +118,8 @@ surface_t * mkSphere(int longitudes, int latitudes, double s) {
|
||||
assert(t);
|
||||
for(z = 0, k = 0; z <= latitudes; ++z) {
|
||||
theta = -M_PI_2 + z * cMPI_Lat;
|
||||
y = sin(theta) * s;
|
||||
r = cos(theta) * s;
|
||||
y = sin(theta);
|
||||
r = cos(theta);
|
||||
for(x = 0; x <= longitudes; ++x, ++k) {
|
||||
phi = x * c2MPI_Long;
|
||||
data[k].position.x = r * cos(phi);
|
||||
|
16
moteur.h
16
moteur.h
@ -1,11 +1,11 @@
|
||||
/*!\file moteur.h
|
||||
/*!\file moteur.h
|
||||
*
|
||||
* \brief structures de données et protos de fonctions externes
|
||||
* (primitives.c transformations.c et scene.c (pas encore créé)) pour
|
||||
* réaliser un moteur de rendu par rastérisation.
|
||||
*
|
||||
* \author Farès BELHADJ, amsi@up8.edu
|
||||
* \date November 25, 2020.
|
||||
* \date November 25, 2020.
|
||||
*/
|
||||
|
||||
#ifndef MOTEUR_H_SEEN
|
||||
@ -20,7 +20,7 @@
|
||||
# ifdef __cplusplus
|
||||
extern "C" {
|
||||
# endif
|
||||
|
||||
|
||||
typedef enum pstate_t pstate_t;
|
||||
typedef enum soptions_t soptions_t;
|
||||
typedef struct vec4 vec4;
|
||||
@ -105,7 +105,7 @@ extern "C" {
|
||||
/*!\brief le triangle */
|
||||
struct triangle_t {
|
||||
vertex_t v[3];
|
||||
vec3 normal;
|
||||
vec3 normal;
|
||||
enum pstate_t state;
|
||||
};
|
||||
|
||||
@ -123,7 +123,7 @@ extern "C" {
|
||||
void (*interpolatefunc)(vertex_t *, vertex_t *, vertex_t *, float, float);
|
||||
void (*shadingfunc)(surface_t *, GLuint *, vertex_t *);
|
||||
};
|
||||
|
||||
|
||||
/* dans primitives.c */
|
||||
extern void transform_n_raster(surface_t * s, float * mvMat, float * projMat);
|
||||
extern void clearDepth(void);
|
||||
@ -139,7 +139,7 @@ extern "C" {
|
||||
extern void rotate(float * m, float angle, float x, float y, float z);
|
||||
extern void scale(float * m, float sx, float sy, float sz);
|
||||
extern void lookAt(float * m, float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ);
|
||||
|
||||
|
||||
/* dans scene.c */
|
||||
extern void tnormal(triangle_t * t);
|
||||
extern void snormals(surface_t * s);
|
||||
@ -153,9 +153,9 @@ extern "C" {
|
||||
extern GLuint getTexFromBMP(const char * filename);
|
||||
|
||||
/* dans geometry.c */
|
||||
extern surface_t * mkQuad(void);
|
||||
extern surface_t * mkQuad(void);
|
||||
extern surface_t * mkCube(void);
|
||||
extern surface_t * mkSphere(int longitudes, int latitudes, double s);
|
||||
extern surface_t * mkSphere(int longitudes, int latitudes);
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
# endif
|
||||
|
37
window.c
37
window.c
@ -54,6 +54,7 @@ static int _wW = 1200, _wH = 1000;
|
||||
static int _xm = 400, _ym = 300;
|
||||
|
||||
static int _pause = 0;
|
||||
static float _s = 1.0f;
|
||||
|
||||
/*!\brief paramètre l'application et lance la boucle infinie. */
|
||||
int main(int argc, char ** argv) {
|
||||
@ -91,12 +92,12 @@ void init(void) {
|
||||
uint sun_id, mercury_id, venus_id, earth_id;
|
||||
/*vec4 g = {0, 1, 0, 1};*/
|
||||
/* on créé nos trois type de surfaces */
|
||||
_sun = mkSphere(12, 12, 1); /*ça fait 12x12x2 trianles !*/
|
||||
_sun = mkSphere(12, 12); /*ça fait 12x12x2 trianles !*/
|
||||
/* on change les couleurs de surfaces */
|
||||
/*_sun->dcolor = g; */
|
||||
_planet[0] = mkSphere(12, 12, (1/227.0f) * 12.0f);
|
||||
_planet[1] = mkSphere(12, 12, (1/113.0f) * 12.0f);
|
||||
_planet[2] = mkSphere(12, 12, (1/108.0f) * 12.0f);
|
||||
_planet[0] = mkSphere(12, 12);
|
||||
_planet[1] = mkSphere(12, 12);
|
||||
_planet[2] = mkSphere(12, 12);
|
||||
|
||||
sun_id = getTexFromBMP("images/2k-sun.bmp");
|
||||
mercury_id = getTexFromBMP("images/2k-mercury.bmp");
|
||||
@ -154,28 +155,34 @@ void draw(void) {
|
||||
/*_cam.y = 1.0 - (_ym - (_wH >> 1)) / 300.0f;*/
|
||||
lookAt(mvMat, _cam.x, _cam.y, _cam.z, _cam.x - sin(_cam.theta), 1.0 - (_ym - (_wH >> 1)) / 300.0f, _cam.z - cos(_cam.theta), 0.0, 1.0, 0.0);
|
||||
|
||||
// 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 */
|
||||
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
|
||||
rotate(nmv, a, 0.0f, 1.0f, 0.0f);
|
||||
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);
|
||||
|
||||
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
|
||||
rotate(nmv, a, 0.0f, 1.0f, 0.0f); // orbit mouvement
|
||||
rotate(nmv, (a / 88.0f), 0.0f, 1.0f, 0.0f); // orbit mouvement
|
||||
translate(nmv, 10.0f, 1.0f, 0.0f);
|
||||
rotate(nmv, a, 0.0f, 1.0f, 0.0f); // rotation
|
||||
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
|
||||
transform_n_raster(_planet[0], nmv, projMat);
|
||||
|
||||
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
|
||||
rotate(nmv, a - 10, 0.0f, 1.0f, 0.0f); // orbit mouvement
|
||||
rotate(nmv, (a / 224.7f), 0.0f, 1.0f, 0.0f); // orbit mouvement
|
||||
translate(nmv, 20.0f, 1.0f, 0.0f);
|
||||
rotate(nmv, a, 0.0f, -1.0f, 0.0f); // rotation anti-clockwise
|
||||
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
|
||||
transform_n_raster(_planet[1], nmv, projMat);
|
||||
|
||||
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
|
||||
rotate(nmv, a - 20, 0.0f, 1.0f, 0.0f); // orbit mouvement
|
||||
rotate(nmv, (a / 365.2425f), 0.0f, 1.0f, 0.0f);
|
||||
translate(nmv, 30.0f, 1.0f, 0.0f);
|
||||
rotate(nmv, a, 0.0f, 1.0f, 0.0f); // rotation
|
||||
scale(nmv, (1/108.0f) * 12.0f, (1/108.0f) * 12.0f, (1/108.0f) * 12.0f);
|
||||
rotate(nmv, a, 0.0f, 1.0f, 0.0f);
|
||||
transform_n_raster(_planet[2], nmv, projMat);
|
||||
|
||||
/* déclarer qu'on a changé (en bas niveau) des pixels du screen */
|
||||
@ -183,7 +190,7 @@ void draw(void) {
|
||||
/* fonction permettant de raffraîchir l'ensemble de la fenêtre*/
|
||||
gl4dpUpdateScreen(NULL);
|
||||
if (_pause != 1)
|
||||
a += 360 * dt;
|
||||
a += (dt * 60) * _s; // 1 minute == 1 day
|
||||
}
|
||||
|
||||
/*!\brief intercepte l'événement clavier pour modifier les options. */
|
||||
@ -195,8 +202,10 @@ void key(int keycode) {
|
||||
case GL4DK_DOWN:
|
||||
break;
|
||||
case GL4DK_RIGHT:
|
||||
_s += 30.0f;
|
||||
break;
|
||||
case GL4DK_LEFT:
|
||||
_s -= 30.0f;
|
||||
break;
|
||||
case GL4DK_w:
|
||||
_cam.x += -_v * step * sin(_cam.theta);
|
||||
@ -230,6 +239,10 @@ void key(int keycode) {
|
||||
_v = 0.5f;
|
||||
}
|
||||
break;
|
||||
case GL4DK_f:
|
||||
break;
|
||||
case GL4DK_z:
|
||||
break;
|
||||
case GL4DK_t: /* 't' la texture */
|
||||
_use_tex = !_use_tex;
|
||||
if(_use_tex) {
|
||||
|
Loading…
Reference in New Issue
Block a user