void Game::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); qglColor(this->hudColor); this->renderText(-0.95,0.9,-.5, QString("FPS: ") + QString::number(fps)); this->renderText(-0.95,0.8,-.5, QString("Poziom: ") + QString::number(currentLevel)); this->renderText(-0.95,0.7,-.5, QString("Krysztaly: ") + QString::number(this->cristals.length()), this->cristalFont); /*this->renderText(-1,0.7,-.5, QString("Player pos: (") + QString::number(this->player.getPosition()->x) + QString(", ") + QString::number(this->player.getPosition()->y) + QString(", ") + QString::number(this->player.getPosition()->z) + QString(")")); */ qglColor(this->titleTextColor); this->renderText(-0.8,0,-.5, this->titleText, this->titleFont); glRotatef(this->angleX, 1, 0, 0); glRotatef(this->angleY, 0, 1, 0); glRotatef(this->angleZ, 0, 0, 1); Point3f *p = player.getPosition(); glScalef(scaleWorld, scaleWorld, scaleWorld); //pilka ma srodek w p(x,y) -10 +10 za gabaryty if(p->x > 490 && levelWidth-510 > p->x) { levelTranslate.x = p->x; } //pilka ma na spodzie y=0 if(p->y > 500 && levelHeight-510 > p->y) { levelTranslate.y = p->y; } glTranslatef(-levelTranslate.x, -levelTranslate.y, 0); //map for(int i=0; i < mapTiles.length(); i++){ glPushMatrix(); Point3f *p = mapTiles[i]->getPosition(); glTranslatef(p->x, p->y, p->z); models[mapTiles[i]->getModelId()].render(); glPopMatrix(); } //cristals for(int i=0; i < cristals.length(); i++){ glPushMatrix(); Point3f *p = cristals[i]->getPosition(); glTranslatef(p->x, p->y, p->z); glRotatef(cristals[i]->rotateZ, 1,1,1); cristals[i]->rotateZ += 0.6; models[cristals[i]->getModelId()].render(); glPopMatrix(); } //player glTranslatef(p->x, p->y, p->z); //glPushMatrix(); this->rotateX += this->player.getForce().x * 1.5; glRotatef(this->rotateX * -1, 0,0,1 ); //glPopMatrix(); models[player.getModelId()].render(); frames++; }
/******************************************************* * drawHeaderInfo() * * Description: Paints the selected and pending unit info * to the header region of the battle map. * * Inputs: none * * Outputs: none * * Return: none *******************************************************/ void GLWidget::drawHeaderInfo() { for (int i = 0; i < battleMap.cellsTall; i++) { for (int j = 0; j < battleMap.cellsWide; j++) { if (battleMap.gridCell[i][j].unit->status != NO_UNIT) { if (battleMap.gridCell[i][j].unit->isPending) { // Draw information header. glColor4f( 0.2f, 0.2f, 0.2f, 0.9f ); glBegin (GL_QUADS); glVertex3f (15, GLWidget::height() - 20, 0.0); glVertex3f (15 + 250, GLWidget::height() - 20, 0.0); glVertex3f (15 + 250, GLWidget::height() - 20 - 110, 0.0); glVertex3f (15, GLWidget::height() - 20 - 110, 0.0); glEnd(); qglColor(Qt::white); char *tmpString = (char*)malloc(256); string displayString = ""; int vLoc = GLWidget::height() - 40; // Unit name. QFont nameFont = GLWidget::font(); nameFont.setBold(true); renderText (30, vLoc, 0.0, battleMap.gridCell[i][j].unit->name, nameFont); vLoc -= 15; // Unit hit points. itoa(battleMap.gridCell[i][j].unit->hitPoints, tmpString, 10); displayString = "Health: "; displayString.append(tmpString); displayString.append(" / "); itoa(battleMap.gridCell[i][j].unit->totalHitPoints, tmpString, 10); displayString.append(tmpString); renderText (30, vLoc, 0.0, displayString.c_str()); vLoc -= 15; // Unit attack power. itoa(battleMap.gridCell[i][j].unit->attackPower, tmpString, 10); displayString = "Attack Power: "; displayString.append(tmpString); renderText (30, vLoc, 0.0, displayString.c_str()); vLoc -= 15; // Unit attack range. itoa(battleMap.gridCell[i][j].unit->attackRange, tmpString, 10); displayString = "Attack Range: "; displayString.append(tmpString); renderText (30, vLoc, 0.0, displayString.c_str()); vLoc -= 15; // Unit movement rate. itoa(battleMap.gridCell[i][j].unit->movementRange, tmpString, 10); displayString = "Movement Rate: "; displayString.append(tmpString); renderText (30, vLoc, 0.0, displayString.c_str()); vLoc -= 15; // Unit action time. itoa(battleMap.gridCell[i][j].unit->actionTime, tmpString, 10); displayString = "Action Time: "; displayString.append(tmpString); displayString.append("%"); renderText (30, vLoc, 0.0, displayString.c_str()); vLoc -= 15; } } if (battleMap.gridCell[i][j].isSelected && battleMap.gridCell[i][j].isUnit) { // Draw information header. glColor4f( 0.2f, 0.0f, 0.0f, 0.9f ); glBegin (GL_QUADS); glVertex3f (GLWidget::width() - 265, GLWidget::height() - 20, 0.0); glVertex3f (GLWidget::width() - 15, GLWidget::height() - 20, 0.0); glVertex3f (GLWidget::width() - 15, GLWidget::height() - 20 - 110, 0.0); glVertex3f (GLWidget::width() - 265, GLWidget::height() - 20 - 110, 0.0); glEnd(); qglColor(Qt::white); char *tmpString = (char*)malloc(256); string displayString = ""; int vLoc = GLWidget::height() - 40; // Unit name. QFont nameFont = GLWidget::font(); nameFont.setBold(true); renderText (GLWidget::width() - 250, vLoc, 0.0, battleMap.gridCell[i][j].unit->name, nameFont); vLoc -= 15; // Unit hit points. itoa(battleMap.gridCell[i][j].unit->hitPoints, tmpString, 10); displayString = "Health: "; displayString.append(tmpString); displayString.append(" / "); itoa(battleMap.gridCell[i][j].unit->totalHitPoints, tmpString, 10); displayString.append(tmpString); renderText (GLWidget::width() - 250, vLoc, 0.0, displayString.c_str()); vLoc -= 15; // Unit attack power. itoa(battleMap.gridCell[i][j].unit->attackPower, tmpString, 10); displayString = "Attack Power: "; displayString.append(tmpString); renderText (GLWidget::width() - 250, vLoc, 0.0, displayString.c_str()); vLoc -= 15; // Unit attack range. itoa(battleMap.gridCell[i][j].unit->attackRange, tmpString, 10); displayString = "Attack Range: "; displayString.append(tmpString); renderText (GLWidget::width() - 250, vLoc, 0.0, displayString.c_str()); vLoc -= 15; // Unit movement rate. itoa(battleMap.gridCell[i][j].unit->movementRange, tmpString, 10); displayString = "Movement Rate: "; displayString.append(tmpString); renderText (GLWidget::width() - 250, vLoc, 0.0, displayString.c_str()); vLoc -= 15; // Unit action time. itoa(battleMap.gridCell[i][j].unit->actionTime, tmpString, 10); displayString = "Action Time: "; displayString.append(tmpString); displayString.append("%"); renderText (GLWidget::width() - 250, vLoc, 0.0, displayString.c_str()); vLoc -= 15; } } } }
void MyGLWidget::draw() { qglColor(Qt::red); glBegin(GL_QUADS); glNormal3f(0,0,-1); glVertex3f(-1,-1,0); glVertex3f(-1,1,0); glVertex3f(1,1,0); glVertex3f(1,-1,0); glEnd(); glBegin(GL_TRIANGLES); glNormal3f(0,-1,0.707); glVertex3f(-1,-1,0); glVertex3f(1,-1,0); glVertex3f(0,0,1.2); glEnd(); glBegin(GL_TRIANGLES); glNormal3f(1,0, 0.707); glVertex3f(1,-1,0); glVertex3f(1,1,0); glVertex3f(0,0,1.2); glEnd(); glBegin(GL_TRIANGLES); glNormal3f(0,1,0.707); glVertex3f(1,1,0); glVertex3f(-1,1,0); glVertex3f(0,0,1.2); glEnd(); glBegin(GL_TRIANGLES); glNormal3f(-1,0,0.707); glVertex3f(-1,1,0); glVertex3f(-1,-1,0); glVertex3f(0,0,1.2); glEnd(); // glBegin(GL_QUADS); // glNormal3f(-1.0,0,0); // glVertex3f(-1,-1,0); // glVertex3f(-1,1,0); // glVertex3f(-1,1,1); // glVertex3f(-1,-1,1); // glEnd(); // glBegin(GL_QUADS); // glNormal3f(0,1.0,0); // glVertex3f(-1,1,0); // glVertex3f(1,1,0); // glVertex3f(1,1,1); // glVertex3f(-1,1,1); // glEnd(); // glBegin(GL_QUADS); // glNormal3f(1.0,0,0); // glVertex3f(1,1,0); // glVertex3f(1,-1,0); // glVertex3f(1,-1,1); // glVertex3f(1,1,1); // glEnd(); // glBegin(GL_QUADS); // glNormal3f(0,-1.0,0); // glVertex3f(1,-1,0); // glVertex3f(-1,-1,0); // glVertex3f(-1,-1,1); // glVertex3f(1,-1,1); // glEnd(); // glBegin(GL_QUADS); // glNormal3f(0,0,1.0); // glVertex3f(-1,-1,1); // glVertex3f(-1,1,1); // glVertex3f(1,1,1); // glVertex3f(1,-1,1); // glEnd(); }
void ssr::QOpenGLPlotter::_draw_source(source_buffer_list_t::const_iterator& source, unsigned int index) { float scale = 1.0f; bool selected = false; bool soloed = false; if (_selected_sources_map.find(index) != _selected_sources_map.end()) { selected = true; } if (_soloed_sources.find(source->id) != _soloed_sources.end()) { soloed = true; } // check if source is selected if (selected) scale = 2.0f; // dummy id to prevend mouse action glLoadName(DUMMYINDEX); // draw shadow texture glEnable(GL_TEXTURE_2D); //glEnable(GL_ALPHA_TEST); glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, _source_shadow_texture); glPushMatrix(); glTranslatef(0.015f, -0.015f, 0.01f); gluQuadricTexture(_glu_quadric, GL_TRUE ); gluDisk(_glu_quadric, 0.0f, 0.163f * scale,LEVELOFDETAIL,1); glPopMatrix(); glDisable(GL_TEXTURE_2D); //glDisable(GL_ALPHA_TEST); glDisable(GL_BLEND); // make sure that source is drawn on top //if (selected) glTranslatef(0.0f, 0.0f, 0.2f); //else glTranslatef(0.0f, 0.0f, 0.1f); // TODO: make it more elegant // source id glLoadName(NAMESTACKOFFSET + index * NAMESTACKSTEP + 1); // draw source glColor3f(1.0f, 1.0f, 1.0f); // white gluDisk(_glu_quadric, 0.0f, 0.15f * scale, LEVELOFDETAIL, 1); // fill source qglColor(_color_vector[source->id%_color_vector.size()]); gluPartialDisk(_glu_quadric, 0.0f, 0.125f * scale, LEVELOFDETAIL, 1, 0.0f, 360.0f); // draw solo indication if (soloed) { gluPartialDisk(_glu_quadric, 0.2f * scale, 0.22f * scale, LEVELOFDETAIL, 1, 55.0f, 70.0f); gluPartialDisk(_glu_quadric, 0.2f * scale, 0.22f * scale, LEVELOFDETAIL, 1, 235.0f, 70.0f); } // choose color if (source->mute) glColor3f(0.5f, 0.5f, 0.5f); else qglColor(_color_vector[source->id%_color_vector.size()]); // draw ring around source gluDisk(_glu_quadric, 0.14f * scale, 0.15f * scale, LEVELOFDETAIL, 1); // volume slider id; It is accessible only when source selected if (selected) glLoadName(NAMESTACKOFFSET + index * NAMESTACKSTEP + 2); // plot level meter frame in black glBegin(GL_TRIANGLE_FAN); glVertex3f( -0.1f * scale, -0.2f * scale, 0.0f); glVertex3f( -0.1f * scale, -0.25f * scale, 0.0f); glVertex3f( 0.1f * scale, -0.25f * scale, 0.0f); glVertex3f( 0.1f * scale, -0.2f * scale, 0.0f); glEnd(); if (selected) { // plot volume slider glBegin(GL_TRIANGLES); glVertex3f((-0.09f * scale + (20.0f*log10(source->gain)+50.0f)/62.0f * 0.18f * scale ) - 0.015f * scale, -0.29f * scale, 0.0f); glVertex3f((-0.09f * scale + (20.0f*log10(source->gain)+50.0f)/62.0f * 0.18f * scale ) + 0.015f * scale, -0.29f * scale, 0.0f); glVertex3f((-0.09f * scale + (20.0f*log10(source->gain)+50.0f)/62.0f * 0.18f * scale ), -0.26f * scale, 0.0f); glEnd(); } if (source->fixed_position) { // draw cross glBegin(GL_TRIANGLES); glVertex3f( -0.02f * scale, 0.005f * scale, 0.0f); glVertex3f( -0.02f * scale, -0.005f * scale, 0.0f); glVertex3f( 0.02f * scale, 0.005f * scale, 0.0f); glVertex3f( 0.02f * scale, 0.005f * scale, 0.0f); glVertex3f( -0.02f * scale, -0.005f * scale, 0.0f); glVertex3f( 0.02f * scale, -0.005f * scale, 0.0f); glVertex3f( -0.005f * scale, -0.02f * scale, 0.0f); glVertex3f( 0.005f * scale, -0.02f * scale, 0.0f); glVertex3f( 0.005f * scale, 0.02f * scale, 0.0f); glVertex3f( 0.005f * scale, 0.02f * scale, 0.0f); glVertex3f( -0.005f * scale, 0.02f * scale, 0.0f); glVertex3f( -0.005f * scale, -0.02f * scale, 0.0f); glEnd(); } // plot level meter background white glColor3f(1.0f, 1.0f, 1.0f); glBegin(GL_TRIANGLE_FAN); glVertex3f( -0.09f * scale, -0.21f * scale, 0.0f); glVertex3f( -0.09f * scale, -0.24f * scale, 0.0f); glVertex3f( 0.09f * scale, -0.24f * scale, 0.0f); glVertex3f( 0.09f * scale, -0.21f * scale, 0.0f); glEnd(); // plot audio level in green glColor3f(0.2275f, 0.9373f, 0.2275f); // signal_level in dB float signal_level = 20.0f * log10(source->signal_level + 0.00001f); // min -100 dB // only values up to 0 dB can be shown signal_level = std::min(signal_level, 0.0f); // TODO: color glBegin(GL_TRIANGLE_FAN); glVertex3f( -0.09f * scale, -0.21f * scale, 0.0f); glVertex3f( -0.09f * scale, -0.24f * scale, 0.0f); glVertex3f( -0.09f * scale + (signal_level + 50.0f)/50.0f * 0.18f * scale, -0.24f * scale, 0.0f); glVertex3f( -0.09f * scale + (signal_level + 50.0f)/50.0f * 0.18f * scale, -0.21f * scale, 0.0f); glEnd(); // display source name if (_allow_displaying_text) { qglColor(_color_vector[source->id%_color_vector.size()]); QFont f = font(); f.setPointSize(static_cast<int>(_zoom_factor/STDZOOMFACTOR*font().pointSize() + 0.5f)); renderText(0.18f * scale, 0.13f * scale, 0.0f, source->name.c_str(), f); } // dummy id to prevend mouse action glLoadName(DUMMYINDEX); // plot orientation of plane wave if (source->model == Source::plane) { // rotate glRotatef(static_cast<GLfloat>(source->orientation.azimuth), 0.0f, 0.0f, 1.0f); if (source->mute) glColor3f(0.5f, 0.5f, 0.5f); else qglColor(_color_vector[source->id%_color_vector.size()]); // plot ring segments gluPartialDisk(_glu_quadric, 0.18f * scale, 0.19f * scale, LEVELOFDETAIL, 1, 105.0f, 75.0f); gluPartialDisk(_glu_quadric, 0.18f * scale, 0.19f * scale, LEVELOFDETAIL, 1, 0.0f, 90.0f); // plot bars glBegin(GL_TRIANGLE_FAN); glVertex3f(-0.005f * scale, -0.36f * scale, 0.0f); glVertex3f( 0.005f * scale, -0.36f * scale, 0.0f); glVertex3f( 0.005f * scale, -0.18f * scale, 0.0f); glVertex3f(-0.005f * scale, -0.18f * scale, 0.0f); glEnd(); glBegin(GL_TRIANGLE_FAN); glVertex3f( 0.005f * scale, 0.36f * scale, 0.0f); glVertex3f(-0.005f * scale, 0.36f * scale, 0.0f); glVertex3f(-0.005f * scale, 0.18f * scale, 0.0f); glVertex3f( 0.005f * scale, 0.18f * scale, 0.0f); glEnd(); // plot arrow glBegin(GL_TRIANGLE_FAN); // lower branch glVertex3f( 0.277f * scale, 0.0f, 0.0f); glVertex3f( 0.25f * scale, -0.028f * scale, 0.0f); glVertex3f( 0.25f * scale, -0.04f * scale, 0.0f); glVertex3f( 0.29f * scale, 0.0f, 0.0f); glEnd(); glBegin(GL_TRIANGLE_FAN); // upper branch glVertex3f( 0.29f * scale, 0.0f, 0.0f); glVertex3f( 0.25f * scale, 0.04f * scale, 0.0f); glVertex3f( 0.25f * scale, 0.028f * scale, 0.0f); glVertex3f( 0.277f * scale, 0.0f, 0.0f); glEnd(); glBegin(GL_TRIANGLE_FAN); // root glVertex3f( 0.18f * scale, 0.005f * scale, 0.0f); glVertex3f( 0.18f * scale, -0.005f * scale, 0.0f); glVertex3f( 0.285f * scale, -0.005f * scale, 0.0f); glVertex3f( 0.285f * scale, 0.005f * scale, 0.0f); glEnd(); } else if (source->model == Source::directional) { // rotate glRotatef((GLfloat)(source->orientation.azimuth), 0.0f, 0.0f, 1.0f); qglColor(_color_vector[source->id%_color_vector.size()]); // plot ring gluPartialDisk(_glu_quadric, 0.18f * scale, 0.19f * scale, LEVELOFDETAIL, 1, 105.0f, 346.0f); // id of direction handle glLoadName(NAMESTACKOFFSET + index * NAMESTACKSTEP + 3); // plot arrow glBegin(GL_TRIANGLE_FAN); // lower branch glVertex3f( 0.277f * scale, 0.0f, 0.0f); glVertex3f( 0.25f * scale, -0.028f * scale, 0.0f); glVertex3f( 0.25f * scale, -0.04f * scale, 0.0f); glVertex3f( 0.29f * scale, 0.0f, 0.0f); glEnd(); glBegin(GL_TRIANGLE_FAN); // upper branch glVertex3f( 0.29f * scale, 0.0f, 0.0f); glVertex3f( 0.25f * scale, 0.04f * scale, 0.0f); glVertex3f( 0.25f * scale, 0.028f * scale, 0.0f); glVertex3f( 0.277f * scale, 0.0f, 0.0f); glEnd(); glBegin(GL_TRIANGLE_FAN); // root glVertex3f( 0.18f * scale, 0.005f * scale, 0.0f); glVertex3f( 0.18f * scale, -0.005f * scale, 0.0f); glVertex3f( 0.285f * scale, -0.005f * scale, 0.0f); glVertex3f( 0.285f * scale, 0.005f * scale, 0.0f); glEnd(); } }
void ChallengeViewer::sceneCompletedHook() { // create a map with names and scores qglColor(Qt::black); QMultiMap<int, QStringList> scores; for (World::ObjectsIterator it = world->objects.begin(); it != world->objects.end(); ++it) { AsebaFeedableEPuck *epuck = dynamic_cast<AsebaFeedableEPuck*>(*it); if (epuck) { QStringList entry; entry << epuck->name << QString::number(epuck->port) << QString::number((int)epuck->energy) << QString::number((int)epuck->score); scores.insert((int)epuck->score, entry); renderText(epuck->pos.x, epuck->pos.y, 10, epuck->name, labelFont); } } // build score texture QImage scoreBoard(512, 256, QImage::Format_ARGB32); scoreBoard.setDotsPerMeterX(2350); scoreBoard.setDotsPerMeterY(2350); QPainter painter(&scoreBoard); //painter.fillRect(scoreBoard.rect(), QColor(224,224,255,196)); painter.fillRect(scoreBoard.rect(), QColor(224,255,224,196)); // draw lines painter.setBrush(Qt::NoBrush); QPen pen(Qt::black); pen.setWidth(2); painter.setPen(pen); painter.drawRect(scoreBoard.rect()); pen.setWidth(1); painter.setPen(pen); painter.drawLine(22, 34, 504, 34); painter.drawLine(312, 12, 312, 247); painter.drawLine(312, 240, 504, 240); // draw title painter.setFont(titleFont); painter.drawText(35, 28, "name"); painter.drawText(200, 28, "port"); painter.drawText(324, 28, "energy"); painter.drawText(430, 28, "points"); // display entries QMapIterator<int, QStringList> it(scores); it.toBack(); int pos = 61; while (it.hasPrevious()) { it.previous(); painter.drawText(200, pos, it.value().at(1)); pos += 24; } it.toBack(); painter.setFont(entryFont); pos = 61; while (it.hasPrevious()) { it.previous(); painter.drawText(35, pos, it.value().at(0)); painter.drawText(335, pos, it.value().at(2)); painter.drawText(445, pos, it.value().at(3)); pos += 24; } glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); GLuint tex = bindTexture(scoreBoard, GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glCullFace(GL_FRONT); glColor4d(1, 1, 1, 0.75); for (int i = 0; i < 4; i++) { glPushMatrix(); glTranslated(world->w/2, world->h/2, 50); glRotated(90*i, 0, 0, 1); glBegin(GL_QUADS); glTexCoord2d(0, 0); glVertex3d(-20, -20, 0); glTexCoord2d(1, 0); glVertex3d(20, -20, 0); glTexCoord2d(1, 1); glVertex3d(20, -20, 20); glTexCoord2d(0, 1); glVertex3d(-20, -20, 20); glEnd(); glPopMatrix(); } glCullFace(GL_BACK); glColor3d(1, 1, 1); for (int i = 0; i < 4; i++) { glPushMatrix(); glTranslated(world->w/2, world->h/2, 50); glRotated(90*i, 0, 0, 1); glBegin(GL_QUADS); glTexCoord2d(0, 0); glVertex3d(-20, -20, 0); glTexCoord2d(1, 0); glVertex3d(20, -20, 0); glTexCoord2d(1, 1); glVertex3d(20, -20, 20); glTexCoord2d(0, 1); glVertex3d(-20, -20, 20); glEnd(); glPopMatrix(); } deleteTexture(tex); glDisable(GL_TEXTURE_2D); glColor4d(7./8.,7./8.,1,0.75); glPushMatrix(); glTranslated(world->w/2, world->h/2, 50); glBegin(GL_QUADS); glVertex3d(-20,-20,20); glVertex3d(20,-20,20); glVertex3d(20,20,20); glVertex3d(-20,20,20); glVertex3d(-20,20,0); glVertex3d(20,20,0); glVertex3d(20,-20,0); glVertex3d(-20,-20,0); glEnd(); glPopMatrix(); // save image static int imageCounter = 0; if (savingVideo) grabFrameBuffer().save(QString("frame%0.bmp").arg(imageCounter++), "BMP"); }
void TimelineGL::paintGL() { glReady = true; if(!Global::viewerGL->glReady) { Global::viewerSortChanged = true; Global::viewerGL->glReady = true; } //Efface GLbitfield clearFlag = GL_COLOR_BUFFER_BIT; if(format().stencil()) clearFlag |= GL_STENCIL_BUFFER_BIT; if(format().depth()) clearFlag |= GL_DEPTH_BUFFER_BIT; glClear(clearFlag); qglClearColor(Global::colorTextBlack); QRectF _drawingBoundingRect; scroll = scroll + ( scrollDest - scroll) / (Global::inertie); showLegend = showLegend + ((qreal)showLegendDest - showLegend) / (Global::inertie); showLinkedRenders = showLinkedRenders + ((qreal)showLinkedRendersDest - showLinkedRenders) / (Global::inertie); showLinkedTags = showLinkedTags + ((qreal)showLinkedTagsDest - showLinkedTags) / (Global::inertie); showHashedTags = showHashedTags + ((qreal)showHashedTagsDest - showHashedTags) / (Global::inertie); tagSnap = tagSnap + ((qreal)tagSnapDest - tagSnap) / (Global::inertie); tagSnapSlow = tagSnapSlow + ((qreal)tagSnapSlowDest - tagSnapSlow) / (Global::inertie * 2); visibleRect = QRectF(scroll, size()); glScissor(Global::timelineHeaderSize.width(), 0, width() - Global::timelineHeaderSize.width(), height()); glPushMatrix(); glTranslatef(qRound(-scroll.x()), qRound(-scroll.y()), 0); if(Global::timeline) _drawingBoundingRect = _drawingBoundingRect.united(Global::timeline ->paintTimeline(true)); if(Global::currentProject) _drawingBoundingRect = _drawingBoundingRect.united(Global::currentProject->paintTimeline(true)); if(Global::timeline) _drawingBoundingRect = _drawingBoundingRect.united(Global::timeline ->paintTimeline()); if(Global::currentProject) _drawingBoundingRect = _drawingBoundingRect.united(Global::currentProject->paintTimeline()); glPopMatrix(); drawingBoundingRect = _drawingBoundingRect; Global::breathing = Global::breathing + (Global::breathingDest - Global::breathing) / 50.; if(( Global::breathing > 0.90) && (Global::breathingDest == 1)) Global::breathingDest = 0; else if((Global::breathing < 0.10) && (Global::breathingDest == 0)) Global::breathingDest = 1; Global::breathingFast = Global::breathingFast + (Global::breathingFastDest - Global::breathingFast) / 20.; if(( Global::breathingFast > 0.90) && (Global::breathingFastDest == 1)) Global::breathingFastDest = 0; else if((Global::breathingFast < 0.10) && (Global::breathingFastDest == 0)) Global::breathingFastDest = 1; Global::breathingPics = Global::breathingPics + (Global::breathingPicsDest - Global::breathingPics) / 200.; if(( Global::breathingPics > 0.90) && (Global::breathingPicsDest == 1)) Global::breathingPicsDest = 0; else if((Global::breathingPics < 0.10) && (Global::breathingPicsDest == 0)) Global::breathingPicsDest = 1; if(showLegend > 0.01) { //Background qreal legendBaseSize = qBound(200., height() * 0.75, 400.); QRectF legendRect = QRectF(width() - legendBaseSize * 1.2, height() - showLegend * legendBaseSize, legendBaseSize * 1.2, legendBaseSize); qglColor(Global::colorAlternateStrong); GlRect::drawRect(legendRect); //Circles legendBaseSize *= 0.8; glPushMatrix(); glTranslatef(qRound(legendRect.center().x()), qRound(legendRect.center().y()), 0); qreal angle = -M_PI/2, angleStep = 0; glBegin(GL_QUAD_STRIP); QMapIterator<QString, QPair<QColor, qreal> > colorForMetaIterator(Global::colorForMeta); while(colorForMetaIterator.hasNext()) { colorForMetaIterator.next(); angleStep = 2 * M_PI * colorForMetaIterator.value().second * showLegend; qreal legendRadiusL = legendBaseSize; qreal legendRadiusS = legendBaseSize * 0.8; qglColor(colorForMetaIterator.value().first); for(qreal angleSmooth = angle ; angleSmooth <= angle + angleStep ; angleSmooth += 0.01) { glVertex2f(qCos(angleSmooth) * legendRadiusL/2, qSin(angleSmooth) * legendRadiusL/2); glVertex2f(qCos(angleSmooth) * legendRadiusS/2, qSin(angleSmooth) * legendRadiusS/2); } angle += angleStep; } glEnd(); //Text legendBaseSize *= 1.1; angle = -M_PI/2; QMapIterator<QString, QPair<QColor, qreal> > colorForMetaIteratorText(Global::colorForMeta); while(colorForMetaIteratorText.hasNext()) { colorForMetaIteratorText.next(); angleStep = 2*M_PI * colorForMetaIteratorText.value().second * showLegend; angle += angleStep/2; QString tagCategory = QString("%1 (%2%)").arg(colorForMetaIteratorText.key().toUpper()).arg(qFloor(colorForMetaIteratorText.value().second * 100)); QPoint pt(qCos(angle) * legendBaseSize/2, qSin(angle) * legendBaseSize/2); QColor color = Qt::white; color.setAlpha(colorForMetaIteratorText.value().first.alpha()); //Draw text qglColor(color); bool textFound = false; if(categories.count() > 1000) categories.clear(); foreach(GlText category, categories) { if(category.text == tagCategory) { category.drawText(pt - QPoint(category.size.width() / 2, 0)); textFound = true; } } if(!textFound) { GlText category; category.setStyle(QFontMetrics(Global::font).boundingRect(tagCategory).size(), Qt::AlignLeft, Global::font); category.drawText(tagCategory, pt - QPoint(category.size.width() / 2, 0)); categories << category; } angle += angleStep/2; } glPopMatrix(); }
void board::draw() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0, 0.0, -24.0); glRotatef(rotationX, 1.0, 0.0, 0.0); glRotatef(rotationY, 0.0, 1.0, 0.0); glRotatef(rotationZ, 0.0, 0.0, 1.0); //------------------------------------------ glActiveTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); bindTexture(QImage(":/image/modified.png")); glBegin(GL_QUADS); // Up face (y = 1.0f) qglColor(Qt::white); glTexCoord2f(0.0, 0.0);glVertex3f( 10.0f, 10.0f, 1.0f); glTexCoord2f(1.0, 0.0);glVertex3f(-10.0f, 10.0f, 1.0f); glTexCoord2f(1.0, 1.0);glVertex3f(-10.0f, -10.0f, 1.0f); glTexCoord2f(0.0, 1.0);glVertex3f( 10.0f, -10.0f, 1.0f); glEnd(); glDisable(GL_TEXTURE_2D); glBegin(GL_QUADS); // Bottom face (y = 1.0f) qglColor(Qt::white); glVertex3f( 10.0f, -10.0f, -1.0f); glVertex3f(-10.0f, -10.0f, -1.0f); glVertex3f(-10.0f, 10.0f, -1.0f); glVertex3f( 10.0f, 10.0f, -1.0f); // Front face (z = 1.0f) qglColor(QColor(200,76,70)); glVertex3f( 10.0f, -10.0f, 1.0f); glVertex3f( 0.0f, -10.0f, 1.0f); glVertex3f( 0.0f, -10.0f, -1.0f); glVertex3f( 10.0f, -10.0f, -1.0f); qglColor(QColor(244,188,88)); glVertex3f( 0.0f, -10.0f, 1.0f); glVertex3f(-10.0f, -10.0f, 1.0f); glVertex3f(-10.0f, -10.0f, -1.0f); glVertex3f( 0.0f, -10.0f, -1.0f); // Back face (z = -1.0f) qglColor(QColor(35,148,147)); glVertex3f( 10.0f, 10.0f, -1.0f); glVertex3f( 0.0f, 10.0f, -1.0f); glVertex3f( 0.0f, 10.0f, 1.0f); glVertex3f( 10.0f, 10.0f, 1.0f); qglColor(QColor(163,189,110)); glVertex3f( 0.0f, 10.0f, -1.0f); glVertex3f(-10.0f, 10.0f, -1.0f); glVertex3f(-10.0f, 10.0f, 1.0f); glVertex3f( 0.0f, 10.0f, 1.0f); // Right face (x = -1.0f) qglColor(QColor(35,148,147)); glVertex3f(10.0f, 10.0f, 1.0f); glVertex3f(10.0f, 0.0f, 1.0f); glVertex3f(10.0f, 0.0f, -1.0f); glVertex3f(10.0f, 10.0f, -1.0f); qglColor(QColor(200,76,70)); glVertex3f(10.0f, 0.0f, 1.0f); glVertex3f(10.0f, -10.0f, 1.0f); glVertex3f(10.0f, -10.0f, -1.0f); glVertex3f(10.0f, 0.0f, -1.0f); // Left face (x = 1.0f) qglColor(QColor(163,189,110)); glVertex3f(-10.0f, 0.0f, 1.0f); glVertex3f(-10.0f, 10.0f, 1.0f); glVertex3f(-10.0f, 10.0f, -1.0f); glVertex3f(-10.0f, 0.0f, -1.0f); qglColor(QColor(244,188,88)); glVertex3f(-10.0f, -10.0f, 1.0f); glVertex3f(-10.0f, 0.0f, 1.0f); glVertex3f(-10.0f, 0.0f, -1.0f); glVertex3f(-10.0f, -10.0f, -1.0f); glEnd(); // End of drawing color-cube }
//void AmplitudeWidget::drawChannelAmplitudeFilled(Channel *ch, QPainter &p) void AmplitudeWidget::drawChannelAmplitudeFilledGL(Channel *ch) { View *view = gdata->view; ChannelLocker channelLocker(ch); ZoomLookup *z = &ch->amplitudeZoomLookup; // baseX is the no. of chunks a pixel must represent. double baseX = view->zoomX() / ch->timePerChunk(); z->setZoomLevel(baseX); double currentChunk = ch->chunkFractionAtTime(view->currentTime()); double leftFrameTime = currentChunk - ((view->currentTime() - view->viewLeft()) / ch->timePerChunk()); int n = 0; int baseElement = int(floor(leftFrameTime / baseX)); if(baseElement < 0) { n -= baseElement; baseElement = 0; } int lastBaseElement = int(floor(double(ch->totalChunks()) / baseX)); //double heightRatio = double(height()) / dBRange(); double heightRatio = double(height()) / range(); //int firstN = n; //int lastN = firstN; //Q3PointArray bottomPoints(width()*2); Array1d<MyGLfloat2d> vertexArray(width()*2); int pointIndex = 0; //int topBottomPointIndex = 0; if (baseX > 1) { // More samples than pixels int theWidth = width(); //if(baseElement + theWidth > z->size()) z->setSize(baseElement + theWidth); if(lastBaseElement > z->size()) z->setSize(lastBaseElement); for(; n < theWidth && baseElement < lastBaseElement; n++, baseElement++) { myassert(baseElement >= 0); ZoomElement &ze = z->at(baseElement); //if(!z->hasValue(baseElement)) { if(!ze.isValid()) { if(!calcZoomElement(ze, ch, baseElement, baseX)) continue; } int y = height() - 1 - toInt((ze.high() - offsetInv()) * heightRatio); //bottomPoints.setPoint(topBottomPointIndex++, n, y); //bottomPoints.setPoint(topBottomPointIndex++, n, height()); vertexArray[pointIndex++] = MyGLfloat2d(n, y); vertexArray[pointIndex++] = MyGLfloat2d(n, height()); //lastN = n; } //p.setPen(Qt::NoPen); //p.setBrush(gdata->shading1Color()); //p.drawRect(firstN, 0, lastN, height()); //p.setPen(gdata->shading2Color()); //p.drawLineSegments(bottomPoints, 0, topBottomPointIndex/2); qglColor(gdata->shading2Color()); glVertexPointer(2, GL_FLOAT, 0, vertexArray.begin()); glDrawArrays(GL_QUAD_STRIP, 0, pointIndex); } else { //baseX <= 1 float err = 0.0; float val = 0.0; int intChunk = (int) floor(leftFrameTime); // Integer version of frame time double stepSize = 1.0 / baseX; // So we skip some pixels float x = 0.0f, y; //double start = 0 - stepSize; double start = (double(intChunk) - leftFrameTime) * stepSize; double stop = width() + (2 * stepSize); //int squareSize = (int(sqrt(stepSize)) / 2) * 2 + 1; //make it an odd number //int halfSquareSize = squareSize/2; double dn = start; int totalChunks = ch->totalChunks(); if(intChunk < 0) { dn += stepSize * -intChunk; intChunk = 0; } //bottomPoints.setPoint(topBottomPointIndex++, toInt(dn), height()); //vertexArray[pointIndex++] = MyGLfloat2d((GLfloat)dn, height()); //firstN = toInt(dn); for(; dn < stop && intChunk < totalChunks; dn += stepSize, intChunk++) { AnalysisData *data = ch->dataAtChunk(intChunk); myassert(data); if(!data) continue; err = data->correlation(); val = calculateElement(data); //p.setPen(QPen(colorBetween(colorGroup().background(), ch->color, val), 1)); x = dn; y = height() - 1 - ((val - offsetInv()) * heightRatio); //bottomPoints.setPoint(topBottomPointIndex++, x, y); vertexArray[pointIndex++] = MyGLfloat2d(x, y); vertexArray[pointIndex++] = MyGLfloat2d(x, height()); //lastN = x; } //bottomPoints.setPoint(topBottomPointIndex, bottomPoints.point(topBottomPointIndex-1).x(), height()); //if(pointIndex > 0) { // vertexArray[pointIndex] = MyGLfloat2d(vertexArray[pointIndex-1].x, height()); // pointIndex++; //} myassert(pointIndex <= width()*2); //p.setPen(Qt::NoPen); //p.setBrush(gdata->shading1Color()); //p.drawRect(firstN, 0, lastN, height()); //p.setPen(gdata->shading2Color()); //p.setBrush(gdata->shading2Color()); //p.drawPolygon(bottomPoints, false, 0, topBottomPointIndex); qglColor(gdata->shading2Color()); glVertexPointer(2, GL_FLOAT, 0, vertexArray.begin()); glDrawArrays(GL_QUAD_STRIP, 0, pointIndex); } }