void Plot::DrawAxis( float offx, float offy, float min, float max, float xdiv, float ydiv, float step_x, float step_y ) { // Calcolo la proporzione del grafico float eps = (float) this->w() / 300.0; // Calcolo la lunghezza degli assi float x_axis = (float) this->max_data * xdiv; // Imposto il colore glColor3ub( 255u, 255u, 255u ); // Imposto la dimensione della linea glLineWidth( (GLfloat) eps ); // Disegno gli assi del piano cartesiano glBegin( GL_LINES ); // Controllo se l'asse delle ascisse è visibile if ( min <= 0 && max >= 0 ) { // Asse delle ascisse glVertex2f( (GLfloat) offx, (GLfloat) offy ); glVertex2f( (GLfloat) offx + (GLfloat) x_axis, (GLfloat) offy ); glVertex2f( (GLfloat) offx + (GLfloat) x_axis, (GLfloat) offy - 4 ); glVertex2f( (GLfloat) offx + (GLfloat) x_axis, (GLfloat) offy + 3 ); } // Asse delle ordinate glVertex2f( (GLfloat) offx, (GLfloat) offy + max * ydiv ); glVertex2f( (GLfloat) offx, (GLfloat) offy + min * ydiv ); glEnd(); // Imposto il carattere del testo gl_font( FL_HELVETICA, (int) ( 8.0 * eps ) ); // Controllo se l'asse delle ascisse è visibile if ( min <= 0 && max >= 0 ) { // Disegno la nomenclatura dell'asse delle ascisse gl_draw( "x", offx + x_axis - (float) gl_width( "x" ) + 8.0 * (GLfloat) eps, offy ); } // Disegno la nomenclatura dell'asse delle ordinate gl_draw( "y", offx + 6.0 * (GLfloat) eps, offy + max * ydiv + (float) gl_width( "y" ) ); // Imposto il colore glColor3ub( 255u, 255u, 255u ); // Imposto la dimensione della linea glLineWidth( (GLfloat) eps ); // Imposto il carattere del testo gl_font( FL_HELVETICA, (int) ( 8.0 * eps ) ); // Buffer del testo char buffer[20]; // Iteratore float i; // Controllo se si vuole disegnare il righello nell'asse delle ascisse if ( this->x_ruler_step ) { // Flag di controllo bool alternate = false; // Disegno le tacche dell'asse delle ascisse for ( i = 0; i <= (float) this->data_set[0].size; i += step_x ) { // Calcolo la posizione verticale float xpos = offx + i * xdiv; // Disegno le tacche dell'asse glBegin( GL_LINES ); glVertex2f( (GLfloat) xpos, (GLfloat) offy ); glVertex2f( (GLfloat) xpos, (GLfloat) offy - 5 * eps ); glEnd(); // Controllo se si stanno usando numeri molto piccoli if ( step_x < 1.0 ) snprintf( buffer, 20, "%.2f", i * this->x_ruler_step ); else snprintf( buffer, 20, "%.1f", i * this->x_ruler_step ); // Disegno il valore della tacca nell'asse if ( (float) this->data_set[0].size / step_x < 5.0 || !alternate ) gl_draw( buffer, (float) xpos - (float) gl_width( buffer ) / 2.0f, offy - 17.0 * eps ); // Visualizzo le etichette a sbalzi alternate = ( alternate ) ? false : true; } } // Disegno le tacche dell'asse delle ordinate for ( i = min; i <= max; i += step_y ) { // Calcolo la posizione verticale float ypos = offy + i * ydiv; // Disegno le tacche dell'asse glBegin( GL_LINES ); glVertex2f( (GLfloat) offx, (GLfloat) ypos ); glVertex2f( (GLfloat) offx + 5 * eps, (GLfloat) ypos ); glEnd(); // Controllo se si stanno usando numeri molto piccoli if ( step_y < 1.0 ) snprintf( buffer, 20, "%.2f", i ); else snprintf( buffer, 20, "%.1f", i ); // Disegno il valore della tacca nell'asse gl_draw( buffer, (float) offx - (float) gl_width( buffer ) - 10, ypos - 3 ); } }
void Drawable::update_model_matrix() { model_matrix_ = glm::translate(glm::mat4(1.0f), glm::vec3(gl_x(), gl_y()-gl_height(), 0.0f)); //model_matrix_ = glm::rotate(model_matrix_, radsToDegrees(-xFacing_+(3.0f/2.0f)*M_PI), glm::vec3(0.0f, 1.0f, 0.0f)); model_matrix_ = glm::scale(model_matrix_, glm::vec3(gl_width(), gl_height(), 0.0f)); }
void Floor::update_model_matrix() { model_matrix_ = glm::translate(glm::mat4(1.0f), glm::vec3(gl_x(), gl_y(), -0.01f)); model_matrix_ = glm::scale(model_matrix_, glm::vec3(gl_width(), gl_height(), 0.0f)); }
float gl_width(const char* s) {return gl_width(s, strlen(s));}