Exemple #1
0
/// Clic de la souris
void mouseClick(int button, int state, int x, int y)
{
    /// si boutton souris 1 enfonce alors
	if((button == GLUT_LEFT_BUTTON) && (state == GLUT_UP) && calib)
	{
		//Ici par moment j'ai moi aussi l'erreur, la seule chose que ça fait c'est que ça ne rentre pas dans changeObject.
		//On avait une piste, qui était qu'un flux vidéo n'est peut être pas constant, car en castant DANS changeObject, on arrive des fois
		//a des images qui sont vide. Donc dataPtr pourrait être vide par moment, mais en faisant ce test ça ne change rien.
		//cela dit, ce n'est pas notre priorité pour le moment vu qu'il n'empêche pas le programme de tourner comme il faut
		try
		{	changeObjectColor(x, y);}
		catch( ... )
		{ printf("Erreur inconnue.\n");}
	}
    else if ( (button == GLUT_LEFT_BUTTON) && (state == GLUT_DOWN) && !calib )
    {
		 mousedw(x, y, button);
    }
    else
    {
        left_button_state = false;
    }
	printf("fin manip souris\n");
}
void myWindow::OnRender(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    //////////////////////////////////////
    // View and Projection Matrices Setting
    //
    // View (camera) Matrix
    this->view_matrix = glm::lookAt ( glm::vec3 ( 8.0, 0.0, 3.0 ),
                                      glm::vec3 ( 0.0, 0.0, 0.0 ),
                                      glm::vec3 ( 0.0, 0.0, 1.0 ) );

    // Projection Matrix
    glm::mat4 projection_matrix = glm::mat4 ( 1.0f );
    projection_matrix = glm::infinitePerspective( 52.0f , (float)this->width / (float)this->height, 0.1f);

    glUseProgram( this->programHandle );

    // Bind View MAtrix
    GLuint location_view_matrix = glGetUniformLocation( this->programHandle, "ViewMatrix"); 
    if( location_view_matrix >= 0 ) 
	{ 
		glUniformMatrix4fv( location_view_matrix, 1, GL_FALSE, &view_matrix[0][0]); 
	}

    // Bind View MAtrix
    GLuint location_projection_matrix = glGetUniformLocation( this->programHandle, "ProjectionMatrix"); 
    if( location_projection_matrix >= 0 ) 
	{ 
		glUniformMatrix4fv( location_projection_matrix, 1, GL_FALSE, &projection_matrix[0][0]); 
	}
    //
    ///////////////////////////////////////////
    

    //////////////////////////////////////
    // Bind Light Settings
    glm::vec4 light_position = glm::vec4( 8.0f, 8.0f, 2.0f, 1.0f );
    glm::vec3 light_intensity = glm::vec3( 1.0f, 1.0f, 1.0f );
       
    GLuint location_light_position = glGetUniformLocation( this->programHandle, "LightPosition"); 
    if( location_light_position >= 0 ) 
	{ 
        glUniform4fv( location_light_position, 1, &light_position[0]); 
	}

    GLuint location_light_intensity = glGetUniformLocation( this->programHandle, "Ld"); 
    if( location_light_intensity >= 0 ) 
	{ 
		glUniform3fv( location_light_intensity, 1, &light_intensity[0]); 
	}
    //
    ///////////////////////////////////////////


    // Drawwing Grid
    changeObjectColor(0.5, 0.5, 0.5);
    glm::mat4 model_matrix_grid = glm::mat4 ( 1.0f );
    this->renderGrid(model_matrix_grid);

    // ARM
    glm::mat4 model_matrix = glm::mat4 ( 1.0f );
    changeObjectColor(0.8, 0.8, 0.3);
    
    // Rotaci\F3n de ejemplo
    model_matrix = glm::rotate (model_matrix, -95.0f, glm::vec3( 1.0, 0.0, 1.0));

    this->renderArm(model_matrix);
    
    glutSwapBuffers();
}