Exemplo n.º 1
0
void display(void)
{
	handle_keyboard(&cam, &lookAtPoint, &upVector, &movement_speed);

	// clear the screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	mat4 total, modelView, camMatrix;

	printError("pre display");

	glUseProgram(program);

	// Build matrix
	camMatrix = lookAtv(cam,lookAtPoint,upVector);

	modelView = IdentityMatrix();
	total = Mult(camMatrix, modelView);
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m);

	glBindTexture(GL_TEXTURE_2D, tex1);		// Bind Our Texture tex1
	DrawModel(tm, program, "inPosition", "inNormal", "inTexCoord");

	printError("display 2");

	glutSwapBuffers();
}
Exemplo n.º 2
0
/*
	handle_input() - Determine the input type assigned to the class
					 and execute the relavent routine to handle inputs.
 */
void player::handle_input()
{
#ifdef WIN32
	if( ( ( input_type * )input )->get_input_type() == INPUT_TYPE_GAMEPAD )
		handle_gamepad();
#endif
	if( ( ( input_type * )input )->get_input_type() == INPUT_TYPE_KEYBOARD )
		handle_keyboard();
}
Exemplo n.º 3
0
void AllegroShell::run(){
// run the loop
	unsigned num = 0;
	ALLEGRO_EVENT ev;
	al_start_timer(timer);

	unsigned keyboard_count = 0;
	unsigned mouse_count = 0;
	unsigned timer_count = 0;
	
	while( run_flag ){
		al_wait_for_event(queue,&ev);
		num++;
		printf("\r%d",num);

		if( ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE){
			run_flag = false;
		}else if( isKeyboardEvent(&ev)){
			// handle keyboard input
			++keyboard_count;
			al_get_keyboard_state(&(keyboard));
			handle_keyboard(&ev);
		}else if( isMouseEvent(&ev) ){
			// handle mouse input
			++mouse_count;
			mouse->update(&ev);
			handle_mouse(&ev);
		}else if( ev.type  == ALLEGRO_EVENT_TIMER){
			++timer_count;
			// Update the model only if we haven't drawn the scene
			if(draw_flag == false){
				if(step_once_flag){
					// always step once if the user requests it
					model->step();
					step_once_flag = false;
				}else if(step_flag) {
					model->step();
				}
			}
			draw_flag = true;
		}else if (ev.type == USER_VIEW_EVENT){
			// handling user events
			al_unref_user_event(&ev.user);
		}

		if( draw_flag && al_event_queue_is_empty(queue)){
			draw();
			draw_flag = false;
		}
	} // end while(run_flag)

	Textlog::get().log("\nkeyboard_count = %u\n",keyboard_count);
	Textlog::get().log("mouse_count = %u\n",mouse_count);
	Textlog::get().log("timer_count = %u\n",timer_count);
}
Exemplo n.º 4
0
bool FBProcessEvent(bool *quit)
{
	if(pend)
	{
		if(pend & 1) handle_mouse();
		if(pend & 2) handle_keyboard();
		pend = 0; //need to reset, since with repeated call is not updated here, would stuck
		return true;
	}
	return false;
}
Exemplo n.º 5
0
/**
 * The main method, contains a select loop. 
 * Checks for keyboard input, and if nothing is recevied,
 * processes the libspotfy events 
 */
int main(void)
{
    int select_ret;
    fd_set  read_set;
    struct timeval tv;

    launch();

    while(1) {
        FD_ZERO( &read_set );
        FD_SET(STDIN_FILENO, &read_set); /* keyboard input */

        tv.tv_sec = 0;
        tv.tv_usec = 1000000;
        select_ret = select ( 1, &read_set, 0, 0, &tv );

        switch(select_ret) 
        {
            case -1 :
                printf("error in select");
                break;
            
            case 0 :
                /* nothing has happend on the keyboard, timeout expired? */

                /* Process libspotify events */
                notify_events = 0;
                pthread_mutex_unlock(&notify_mutex);

                do {
                    debug("do, while(next_timeout == 0)");
                    sp_session_process_events(g_session, &next_timeout);
                    if( playlist_loading )check_playlist_status(g_playlist);
                } while (next_timeout == 0);

                pthread_mutex_lock(&notify_mutex);
                if( playlist_loading )check_playlist_status(g_playlist);

            default :
                debug("default");
                if( FD_ISSET (STDIN_FILENO, &read_set)) handle_keyboard(g_session, queue_entry); 
        }
    }
}
Exemplo n.º 6
0
void display(void)
{
  printError("pre display");

  // clear the screen (using chosen color earlier)
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glClearColor(1,1,1,0);

  // Set rotation matrix
  phi = ( phi < 2*PI ) ? phi+PI/100 : phi-2*PI+PI/100;

  // Translations for wings/blades
  mat4 rotation_wings = Ry(PI/2);

  // ---------------------------
  // Movement of camera with keyboard
  handle_keyboard(&cameraLocation, &lookAtPoint, &upVector, &movement_speed);

  // Move skybox after cameraLocation is changed by input handling
  skybox_transform = move_skybox(&cameraLocation);
  // Also move camera
  mat4 lookAtMatrix = lookAtv(cameraLocation,lookAtPoint,upVector);
  // ---------------------------


  glUseProgram(skybox_shaders);
  glUniformMatrix4fv(glGetUniformLocation(skybox_shaders, "lookAtMatrix"), 1, GL_TRUE,  lookAtMatrix.m);

  // Draw skybox
  glDisable(GL_DEPTH_TEST);
  glBindTexture(GL_TEXTURE_2D, skybox_tex);
  glUniformMatrix4fv(glGetUniformLocation(skybox_shaders, "transformMatrix"), 1, GL_TRUE,  skybox_transform.m);
  glUniform1i(glGetUniformLocation(skybox_shaders, "tex"), 0);
  DrawModel(skybox, ground_shaders, "in_Position", NULL, "inTexCoord");


  // Draw and texture ground
  glUseProgram(ground_shaders);
  glUniformMatrix4fv(glGetUniformLocation(ground_shaders, "lookAtMatrix"), 1, GL_TRUE,  lookAtMatrix.m);
  glEnable(GL_DEPTH_TEST);
  glBindTexture(GL_TEXTURE_2D, ground_tex);
  glUniform1i(glGetUniformLocation(ground_shaders, "tex"), 0);
  DrawModel(ground, ground_shaders, "in_Position", NULL, "inTexCoord");

  // Model program
  glUseProgram(program);
  glUniform3f(glGetUniformLocation(program, "camera_position"), cameraLocation.x, cameraLocation.y, cameraLocation.z);
  glUniformMatrix4fv(glGetUniformLocation(program, "lookAtMatrix"), 1, GL_TRUE, lookAtMatrix.m);

  // Draw teapot
  glUniformMatrix4fv(glGetUniformLocation(program, "transformMatrix"), 1, GL_TRUE,  trans_teapot.m);
  DrawModel(teapot, program, "in_Position", "in_Normal", NULL);

  // Draw roof
  glUniformMatrix4fv(glGetUniformLocation(program, "transformMatrix"), 1, GL_TRUE,  trans_roof.m);
  DrawModel(roof, program, "in_Position", "in_Normal", NULL);

  // Draw balcony
  glUniformMatrix4fv(glGetUniformLocation(program, "transformMatrix"), 1, GL_TRUE,  trans_balcony.m);
  DrawModel(balcony, program, "in_Position", "in_Normal", NULL);

  // Draw windmill
  glUniformMatrix4fv(glGetUniformLocation(program, "transformMatrix"), 1, GL_TRUE,  trans_mill.m);
  DrawModel(mill, program, "in_Position", "in_Normal", NULL);

  // Model 2
  for (size_t i = 0; i < 4; i++) {
    transformMatrix = Mult(trans_wings_up, Mult(trans_wings, Rx(phi+i*(PI/2))));
    glUniformMatrix4fv(glGetUniformLocation(program, "transformMatrix"), 1, GL_TRUE,  transformMatrix.m);
    DrawModel(wing, program, "in_Position", "in_Normal", NULL);
  }

  printError("display");

  glutSwapBuffers(); // Swap buffer so that GPU can use the buffer we uploaded to it and we can write to another
}