playing with camera

This commit is contained in:
Volodymyr Patuta 2020-12-13 12:04:32 +01:00
parent b8a70ebdee
commit a0236fafe0
2 changed files with 144 additions and 115 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 MiB

View File

@ -35,14 +35,19 @@ static surface_t * _sphere = NULL;
static int _use_tex = 1, _use_color = 0, _use_lighting = 1;
/*!\brief on peut bouger la caméra vers le haut et vers le bas avec cette variable */
static float _ycam = 1.0f;
static float _xcam = 1.0f;
static float _ycam = 0.0f;
static float _xcam = 0.0f;
static float _zcam = 10.0f;
static float _y = 0.0f;
static float _x = 0.0f;
static float _z = 0.0f;
/*!\brief paramètre l'application et lance la boucle infinie. */
int main(int argc, char ** argv) {
/* tentative de création d'une fenêtre pour GL4Dummies */
if(!gl4duwCreateWindow(argc, argv, /* args du programme */
"Mon moteur de rendu <<Maison>>", /* titre */
"Solar System", /* titre */
10, 10, 640, 480, /* x, y, largeur, heuteur */
GL4DW_SHOWN) /* état visible */) {
/* ici si échec de la création souvent lié à un problème d'absence
@ -76,7 +81,7 @@ void init(void) {
/* on change les couleurs de surfaces */
_sphere->dcolor = g;
/* on leur rajoute la même texture */
id = getTexFromBMP("images/2k-jupiter.bmp");
id = getTexFromBMP("images/2k-mars.bmp");
setTexId(_sphere, id);
/* si _use_tex != 0, on active l'utilisation de la texture pour les
* trois */
@ -106,7 +111,7 @@ void draw(void) {
/* charger la matrice identité dans model-view */
MIDENTITY(mvMat);
/* on place la caméra en arrière-haut, elle regarde le centre de la scène */
lookAt(mvMat, _xcam, _ycam, 10, 0, 0, 0, 0, 1, 0);
lookAt(mvMat, _xcam, _ycam, _zcam, _x, _y, _z, 0, 1, 0);
/* 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);
@ -122,16 +127,40 @@ void draw(void) {
void key(int keycode) {
switch(keycode) {
case GL4DK_UP:
_ycam += 0.55f;
_zcam -= 0.15f;
break;
case GL4DK_DOWN:
_ycam -= 0.55f;
_zcam += 0.15f;
break;
case GL4DK_RIGHT:
_xcam += 0.55f;
_xcam += 0.15f;
break;
case GL4DK_LEFT:
_xcam -= 0.55f;
_xcam -= 0.15f;
break;
case GL4DK_w:
if (_y > 10.0f) {
_y = -_y;
}
_y += 0.15f;
break;
case GL4DK_a:
if (_x < -10.0f) {
_x = -_x;
}
_x -= 0.15f;
break;
case GL4DK_s:
if (_y < -10.0f) {
_y = -_y;
}
_y -= 0.15f;
break;
case GL4DK_d:
if (_x > 10.0f) {
_x = -_x;
}
_x += 0.15f;
break;
case GL4DK_t: /* 't' la texture */
_use_tex = !_use_tex;