playing with camera
This commit is contained in:
		
							parent
							
								
									b8a70ebdee
								
							
						
					
					
						commit
						a0236fafe0
					
				
							
								
								
									
										
											BIN
										
									
								
								images/2k-stars-milky-way.bmp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								images/2k-stars-milky-way.bmp
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 6.0 MiB  | 
							
								
								
									
										47
									
								
								window.c
									
									
									
									
									
								
							
							
						
						
									
										47
									
								
								window.c
									
									
									
									
									
								
							@ -35,14 +35,19 @@ static surface_t * _sphere = NULL;
 | 
				
			|||||||
static int _use_tex = 1, _use_color = 0, _use_lighting = 1;
 | 
					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 */
 | 
					/*!\brief on peut bouger la caméra vers le haut et vers le bas avec cette variable */
 | 
				
			||||||
static float _ycam = 1.0f;
 | 
					static float _ycam = 0.0f;
 | 
				
			||||||
static float _xcam = 1.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. */
 | 
					/*!\brief paramètre l'application et lance la boucle infinie. */
 | 
				
			||||||
int main(int argc, char ** argv) {
 | 
					int main(int argc, char ** argv) {
 | 
				
			||||||
	/* tentative de création d'une fenêtre pour GL4Dummies */
 | 
						/* tentative de création d'une fenêtre pour GL4Dummies */
 | 
				
			||||||
	if(!gl4duwCreateWindow(argc, argv, /* args du programme */
 | 
						if(!gl4duwCreateWindow(argc, argv, /* args du programme */
 | 
				
			||||||
			 "Mon moteur de rendu <<Maison>>", /* titre */
 | 
									"Solar System", /* titre */
 | 
				
			||||||
				10, 10, 640, 480, /* x, y, largeur, heuteur */
 | 
									10, 10, 640, 480, /* x, y, largeur, heuteur */
 | 
				
			||||||
				GL4DW_SHOWN) /* état visible */) {
 | 
									GL4DW_SHOWN) /* état visible */) {
 | 
				
			||||||
		/* ici si échec de la création souvent lié à un problème d'absence
 | 
							/* 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 */
 | 
						/* on change les couleurs de surfaces */
 | 
				
			||||||
	_sphere->dcolor = g; 
 | 
						_sphere->dcolor = g; 
 | 
				
			||||||
	/* on leur rajoute la même texture */
 | 
						/* on leur rajoute la même texture */
 | 
				
			||||||
  id = getTexFromBMP("images/2k-jupiter.bmp");
 | 
						id = getTexFromBMP("images/2k-mars.bmp");
 | 
				
			||||||
	setTexId(_sphere, id);
 | 
						setTexId(_sphere, id);
 | 
				
			||||||
	/* si _use_tex != 0, on active l'utilisation de la texture pour les
 | 
						/* si _use_tex != 0, on active l'utilisation de la texture pour les
 | 
				
			||||||
	 * trois */
 | 
						 * trois */
 | 
				
			||||||
@ -106,7 +111,7 @@ void draw(void) {
 | 
				
			|||||||
	/* charger la matrice identité dans model-view */
 | 
						/* charger la matrice identité dans model-view */
 | 
				
			||||||
	MIDENTITY(mvMat);
 | 
						MIDENTITY(mvMat);
 | 
				
			||||||
	/* on place la caméra en arrière-haut, elle regarde le centre de la scène */
 | 
						/* 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 */
 | 
						/* la sphère est laissée au centre et tourne autour de son axe y */
 | 
				
			||||||
	memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
 | 
						memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
 | 
				
			||||||
	rotate(nmv, a, 0.0f, 1.0f, 0.0f);
 | 
						rotate(nmv, a, 0.0f, 1.0f, 0.0f);
 | 
				
			||||||
@ -122,16 +127,40 @@ void draw(void) {
 | 
				
			|||||||
void key(int keycode) {
 | 
					void key(int keycode) {
 | 
				
			||||||
	switch(keycode) {
 | 
						switch(keycode) {
 | 
				
			||||||
		case GL4DK_UP:
 | 
							case GL4DK_UP:
 | 
				
			||||||
    _ycam += 0.55f;
 | 
								_zcam -= 0.15f;
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case GL4DK_DOWN:
 | 
							case GL4DK_DOWN:
 | 
				
			||||||
    _ycam -= 0.55f;
 | 
								_zcam += 0.15f;
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case GL4DK_RIGHT:
 | 
							case GL4DK_RIGHT:
 | 
				
			||||||
	_xcam += 0.55f;
 | 
								_xcam += 0.15f;
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case GL4DK_LEFT:
 | 
							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;
 | 
								break;
 | 
				
			||||||
		case GL4DK_t: /* 't' la texture */
 | 
							case GL4DK_t: /* 't' la texture */
 | 
				
			||||||
			_use_tex = !_use_tex;
 | 
								_use_tex = !_use_tex;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user