void GameView::draw() { window->clear(sf::Color(0x00, 0x00, 0xFF, 0x00)); sf::View view; for(size_t i = 0; i < toDraw.size(); ++i) { ViewLayer viewKey = toDraw[i]; Displayable* disp = viewMap[viewKey]; disp->getView().setCenter(centers[viewKey]); disp->display(); disp->getView().setSize(window->getDefaultView().getSize()/zooms[viewKey]); window->setView(disp->getView()); for(std::vector<sf::Drawable*>::iterator drawableIt = drawableMap[viewKey].begin(); drawableIt != drawableMap[viewKey].end(); ++drawableIt) { sf::Drawable* drawable = *drawableIt; window->draw(*drawable); } } window->display(); for(std::vector<ViewLayer>::iterator keyIt = toDraw.begin(); keyIt != toDraw.end(); ++keyIt) { drawableMap[*keyIt].clear(); } }
std::string Fixel::Shader::fragment_shader_source (const Displayable& fixel) { std::string source = "in float include; \n" "out vec3 color;\n" "flat in float value_out;\n" "in vec3 fragmentColour;\n"; if (fixel.use_discard_lower()) source += "uniform float lower;\n"; if (fixel.use_discard_upper()) source += "uniform float upper;\n"; source += "void main(){\n"; if (fixel.use_discard_lower()) source += " if (value_out < lower) discard;\n"; if (fixel.use_discard_upper()) source += " if (value_out > upper) discard;\n"; source += std::string(" color = fragmentColour;\n"); source += "}\n"; return source; }
void repaint( list<Displayable *> dList, XInfo &xinfo) { list<Displayable *>::const_iterator begin = dList.begin(); list<Displayable *>::const_iterator end = dList.end(); //XClearWindow( xinfo.display, xinfo.window ); move to event loop while( begin != end ) { Displayable *d = *begin; d->paint(xinfo); begin++; } //XFlush( xinfo.display ); same here }
void Overlay::reset_colourmap(const ColourMapButton&) { QModelIndexList indices = image_list_view->selectionModel()->selectedIndexes(); Displayable* overlay = nullptr; for (size_t i = 0, N = indices.size(); i < N; ++i) { overlay = dynamic_cast<Displayable*> (image_list_model->get_image (indices[i])); overlay->reset_windowing(); } // Reset the min/max adjust button fields of last selected overlay if(overlay) { min_value->setValue(overlay->intensity_min()); max_value->setValue(overlay->intensity_max()); } updateGL(); }
bool Column::gotHealth(Displayable& helicopter){ //column has no health if(orbo == NULL){ return false; } int heliY1 = helicopter.getY() - (orbo->getHeight() / 4); int heliY2 = heliY1 + helicopter.getHeight() + (orbo->getHeight() / 4); int orbMidpointY = orbo->getY() + (orbo->getHeight() / 2); if((orbMidpointY < heliY2) && (orbMidpointY > heliY1)){ return true; } return false; }
//repaint function void repaint( XInfo &xinfo) { list<Displayable *>::const_iterator begin = listofd.begin(); list<Displayable *>::const_iterator end = listofd.end(); // draw into the buffer // note that a window and a pixmap are “drawables” XFillRectangle(xinfo.display, xinfo.pixmap, xinfo.gc[0], 0, 0, xinfo.width, xinfo.height); while( begin != end ) { Displayable *d = *begin; d->paint(xinfo); // the displayables know about the pixmap begin++; } // copy buffer to window XCopyArea(xinfo.display, xinfo.pixmap, xinfo.window, xinfo.gc[0], 0, 0, xinfo.width, xinfo.height, // region of pixmap to copy 0, 0); // position to put top left corner of pixmap in window XFlush( xinfo.display ); }
bool Column::missileStrike(Displayable& helicopter){ //column has no gunner -> column has no missiles associated with it if(missiles == NULL || missiles->empty()){ return false; } int heliY1 = helicopter.getY(); int heliY2 = heliY1 + helicopter.getHeight(); std::list<Missile*>::iterator missile = missiles->begin(); //loop through missiles and see if one has hit our hero for(int i = 0; i < missiles->size(); i++, missile++){ if(((*missile)->getY() < heliY2) && ((*missile)->getY() > heliY1)){//helicopter struck by missile missiles->erase(missile); return true; } } return false; }
std::string Slice::Shader::fragment_shader_source (const Displayable& object) { std::string source = object.declare_shader_variables () + "uniform sampler3D tex;\n" "in vec3 texcoord;\n" "out vec4 color;\n"; source += "void main() {\n" " if (texcoord.s < 0.0 || texcoord.s > 1.0 ||\n" " texcoord.t < 0.0 || texcoord.t > 1.0 ||\n" " texcoord.p < 0.0 || texcoord.p > 1.0) discard;\n" " color = texture (tex, texcoord.stp);\n" " float amplitude = " + std::string (ColourMap::maps[object.colourmap].amplitude) + ";\n" " if (isnan(amplitude) || isinf(amplitude)) discard;\n"; if (object.use_discard_lower()) source += " if (amplitude < lower) discard;\n"; if (object.use_discard_upper()) source += " if (amplitude > upper) discard;\n"; if (object.use_transparency()) source += " if (amplitude < alpha_offset) discard;\n" " color.a = clamp ((amplitude - alpha_offset) * alpha_scale, 0, alpha);\n"; if (!ColourMap::maps[object.colourmap].special) { source += " amplitude = clamp ("; if (object.scale_inverted()) source += "1.0 -"; source += " scale * (amplitude - offset), 0.0, 1.0);\n "; } source += ColourMap::maps[object.colourmap].glsl_mapping; source += "}\n"; return source; }
std::string NodeOverlay::Shader::fragment_shader_source (const Displayable& object) { assert (object.colourmap == 5); std::string source = object.declare_shader_variables () + "uniform sampler3D tex;\n" "in vec3 texcoord;\n" "out vec4 color;\n" "void main() {\n" " if (texcoord.s < 0.0 || texcoord.s > 1.0 ||\n" " texcoord.t < 0.0 || texcoord.t > 1.0 ||\n" " texcoord.p < 0.0 || texcoord.p > 1.0) discard;\n" " color = texture (tex, texcoord.stp);\n" " color.a = color.a * alpha;\n"; source += " " + std::string (ColourMap::maps[object.colourmap].glsl_mapping); source += "}\n"; return source; }
void MainWindow::onTreeItemClicked(QTreeWidgetItem* item, int col) { Displayable* d = 0; // magic numbers need to turn into constants... // don't know where to put them right now... switch(item->type()) { case 1000: d = (Score*)item; break; case 1001: d = (Staff*)item; break; case 1002: d = (Voice*)item; break; } if(d) { disconnect(m_selection); // set m_selection m_selection = d; connect(ui->refreshButton,SIGNAL(clicked()),m_selection,SLOT(refresh())); connect(m_selection,SIGNAL(previewChanged()),this,SLOT(onRefreshButtonClicked())); // set pixmap label if(d->image()) ui->pixmap->setPixmap(QPixmap::fromImage(*d->image())); else d->refresh(); ui->listWidget->clear(); QList<Phrase*>& list = d->getPhraseList(); for(int i = 0; i < list.size(); i++) new PhraseWidgetListItem(list.at(i),ui->listWidget); delete &list; // set contentEdit ui->contentEdit->setPlainText(d->content()); // set nameEdit ui->nameEdit->setText(d->name()); } }
std::string AbstractFixel::Shader::geometry_shader_source (const Displayable& fixel) { std::string source = "layout(points) in;\n" "layout(triangle_strip, max_vertices = 4) out;\n" "in vec3 v_dir[];\n" "in vec2 v_fixel_metrics[];\n" "uniform mat4 MVP;\n" "uniform float length_mult;\n" "uniform vec3 colourmap_colour;\n" "uniform float line_thickness;\n"; switch (color_type) { case Direction: break; case CValue: source += "uniform float offset, scale;\n"; break; } if (fixel.use_discard_lower()) source += "uniform float lower;\n"; if (fixel.use_discard_upper()) source += "uniform float upper;\n"; source += "flat out vec3 fColour;\n" "void main() {\n"; if (fixel.use_discard_lower()) source += " if (v_fixel_metrics[0].y < lower) return;\n"; if (fixel.use_discard_upper()) source += " if (v_fixel_metrics[0].y > upper) return;\n"; switch (length_type) { case Unity: source += " vec4 line_offset = length_mult * vec4 (v_dir[0], 0);\n"; break; case Amplitude: source += " vec4 line_offset = length_mult * v_fixel_metrics[0].x * vec4 (v_dir[0], 0);\n"; break; case LValue: source += " vec4 line_offset = length_mult * v_fixel_metrics[0].y * vec4 (v_dir[0], 0);\n"; break; } switch (color_type) { case CValue: if (!ColourMap::maps[colourmap].special) { source += " float amplitude = clamp ("; if (fixel.scale_inverted()) source += "1.0 -"; source += " scale * (v_fixel_metrics[0].y - offset), 0.0, 1.0);\n"; } source += std::string (" vec3 color;\n") + ColourMap::maps[colourmap].glsl_mapping + " fColour = color;\n"; break; case Direction: source += " fColour = normalize (abs (v_dir[0]));\n"; break; default: break; } source += " vec4 start = MVP * (gl_in[0].gl_Position - line_offset);\n" " vec4 end = MVP * (gl_in[0].gl_Position + line_offset);\n" " vec4 line = end - start;\n" " vec4 normal = normalize(vec4(-line.y, line.x, 0.0, 0.0));\n" " vec4 thick_vec = line_thickness * normal;\n" " gl_Position = start - thick_vec;\n" " EmitVertex();\n" " gl_Position = start + thick_vec;\n" " EmitVertex();\n" " gl_Position = end - thick_vec;\n" " EmitVertex();\n" " gl_Position = end + thick_vec;\n" " EmitVertex();\n" " EndPrimitive();\n" "}\n"; return source; }
/* function to repaint a display list Checking collisions with mountain NOTE: all the conditions for mountains are different cannot use helper function to reduce the code */ int repaint(XInfo &xinfo) { list<Displayable *>::const_iterator begin = dList.begin(); list<Displayable *>::const_iterator end = dList.end(); int status = 1; //1: nothing happened 0:landed 2: crushed float slop; int ship_point; int i; float length; float height; float expecty; int extra; int real_y; vector<int> x; vector<int> y; //big black rectangle to clear background XFillRectangle(xinfo.display, xinfo.pixmap, xinfo.gc[0], 0 , 0 , xinfo.width, xinfo.height); //draw display list while (begin != end) { Displayable *d = *begin; d->paint(xinfo); begin++; } //check if the ship landed if ( (ship.getY() >= lefty && pad.getx() <= ship.getX()+40 && ship.getX() <= leftx ) || (ship.getY() >= righty && rightx <= ship.getX()+40 && ship.getX() < rightx+pad2.getl()) ) { if(ship.getspeed() > 2) { status = 2; } else { status = 0; } } if(ship.getX() < pad.getx() ) { /*mountain 1*/ x = mountain1.getx(); y = mountain1.gety(); vector<int> indexs = findPoints(ship.getX(), ship.getX()+40, x); vector<int> points; for(int j = 0; j < indexs.size(); j ++ ) { points.push_back(y[indexs[j]]); } real_y = ship.getY(); // right point if(ship.getX() +40 < pad.getx()) { ship_point = ship.getX()+40; i = FindInterval( x, ship_point); if ( i == 0 ) { length = x[i] - 0; height = y[i] - 500; slop = height / length; extra = 500; } else if( i == x.size() ) { length = pad.getx() - x[i-1]; height = pad.gety() - y[i-1]; slop = height / length; extra = y[i-1] - x[i-1]*slop; } else { length = x[i] - x[i-1]; height = y[i] - y[i-1]; slop = height / length; extra = y[i] - x[i]*slop; } expecty = ship_point * slop +extra; if ( real_y >= expecty) { status = 2; } } // left point if( status == 1) { ship_point = ship.getX(); i = FindInterval( x, ship_point); if ( i == 0 ) { length = x[i] - 0; height = y[i] - 500; slop = height / length; extra = 500; } else if( i == x.size() ) { length = pad.getx() - x[i-1]; height = pad.gety() - y[i-1]; slop = height / length; extra = y[i-1] - x[i-1]*slop; } else { length = x[i] - x[i-1]; height = y[i] - y[i-1]; slop = height / length; extra = y[i] - x[i]*slop; } expecty = ship_point * slop +extra; if ( real_y >= expecty) { status = 2; } } //line if(lower(points, ship.getY()) && status == 1) { status = 2; } } else if( ship.getX() < pad2.getx() && ship.getX()+40 > pad.getx() + pad.getl() ) { //mountain 3 x = mountain3.getx(); y = mountain3.gety(); vector<int> indexs = findPoints(ship.getX(), ship.getX()+40, x); vector<int> points; for(int j = 0; j < indexs.size(); j ++ ) { points.push_back(y[indexs[j]]); } real_y = ship.getY(); //right point if(ship.getX() +40 > pad.getx() +pad.getl() && ship.getX() +40 < pad2.getx()) { ship_point = ship.getX()+40; i = FindInterval( x, ship_point); if ( i == 0 ) { length = x[i] - pad.getx()+pad.getl(); height = y[i] - pad.gety(); slop = height / length; extra = y[i] - x[i] *slop; } else if( i == x.size() ) { length = pad2.getx() - x[i-1]; height = pad2.gety() - y[i-1]; slop = height / length; extra = y[i-1] - x[i-1]*slop; } else { length = x[i] - x[i-1]; height = y[i] - y[i-1]; slop = height / length; extra = y[i] - x[i]*slop; } expecty = ship_point * slop +extra; if ( real_y >= expecty) { status = 2; } } //left point if(ship.getX() < pad2.getx() && ship.getX() > pad.getx() + pad.getl()) { if(status == 1) { ship_point = ship.getX(); i = FindInterval( x, ship_point); if ( i == 0 ) { length = x[i] - pad.getx()+pad.getl(); height = y[i] - pad.gety(); slop = height / length; extra = pad.gety() - (pad.getx()+pad.getl()) *slop; } else if( i == x.size() ) { length = pad2.getx() - x[i-1]; height = pad2.gety() - y[i-1]; slop = height / length; extra = y[i-1] - x[i-1]*slop; } else { length = x[i] - x[i-1]; height = y[i] - y[i-1]; slop = height / length; extra = y[i] - x[i]*slop; } expecty = ship_point * slop +extra; cout << "real_y " << real_y << endl; cout << "expecty" << expecty << endl; if ( real_y >= expecty) { status = 2; } } } //line if(lower(points,ship.getY()) && status == 1) { status = 2; } } else if( ship.getX() +40< 800 && ship.getX()+40 > pad2.getx() + pad2.getl() ) { x = mountain2.getx(); y = mountain2.gety(); vector<int> indexs = findPoints(ship.getX(), ship.getX()+40, x); vector<int> points; for(int j = 0; j < indexs.size(); j ++ ) { points.push_back(y[indexs[j]]); } real_y = ship.getY(); //right point ship_point = ship.getX()+40; i = FindInterval( x, ship_point); if ( i == 0 ) { length = x[i] - pad2.getx()+pad.getl(); height = y[i] - pad2.gety(); slop = height / length; extra = y[i] - x[i] *slop; } else if( i == x.size() ) { length = 0 - x[i-1]; height = 800 - y[i-1]; slop = height / length; extra = y[i-1] - x[i-1]*slop; } else { length = x[i] - x[i-1]; height = y[i] - y[i-1]; slop = height / length; extra = y[i] - x[i]*slop; } expecty = ship_point * slop +extra; if ( real_y >= expecty) { status = 2; } //left point if(ship.getX() > pad2.getx() &&ship.getX() < 800) { if(status == 1) { ship_point = ship.getX(); i = FindInterval( x, ship_point); if ( i == 0 ) { length = x[i] - pad2.getx()+pad2.getl(); height = y[i] - pad2.gety(); slop = height / length; extra = pad2.gety() - (pad2.getx()+pad2.getl()) *slop; } else if( i == x.size() ) { length = 0 - x[i-1]; height = 800 - y[i-1]; slop = height / length; extra = y[i-1] - x[i-1]*slop; } else { length = x[i] - x[i-1]; height = y[i] - y[i-1]; slop = height / length; extra = y[i] - x[i]*slop; } expecty = ship_point * slop +extra; if ( real_y >= expecty) { status = 2; } } } //line if(lower(points, ship.getY()) && status == 1) { status = 2; } } XCopyArea(xinfo.display , xinfo.pixmap, xinfo.window , xinfo.gc[0], 0,0,xinfo.width,xinfo.height,(xinfo.width-800)/2,(xinfo.height-600)/2); XFlush(xinfo.display); return status; }
std::string Fixel::Shader::vertex_shader_source (const Displayable& fixel) { std::string source = "layout (location = 0) in vec3 pos;\n" "layout (location = 1) in vec3 prev;\n" "layout (location = 2) in vec3 next;\n" "layout (location = 3) in float value;\n" "uniform mat4 MVP;\n" "uniform float line_length;\n" "uniform float max_value;\n" "uniform bool scale_line_length_by_value;\n" "flat out float value_out;\n" "out vec3 fragmentColour;\n"; switch (color_type) { case Direction: break; case Colour: source += "uniform vec3 const_colour;\n"; break; case Value: source += "uniform float offset, scale;\n"; break; } source += "void main() {\n" " vec3 centre = pos;\n" " vec3 dir = next;\n" " if ((gl_VertexID % 2) > 0) {\n" " centre = prev;\n" " dir = -pos;\n" " }\n" " value_out = value;\n" " if (scale_line_length_by_value)\n" " gl_Position = MVP * vec4 (centre + line_length * value * dir,1);\n" " else\n" " gl_Position = MVP * vec4 (centre + line_length * dir,1);\n"; switch (color_type) { case Colour: source += " fragmentColour = const_colour;\n"; break; case Value: if (!ColourMap::maps[colourmap].special) { source += " float amplitude = clamp ("; if (fixel.scale_inverted()) source += "1.0 -"; source += " scale * (value_out - offset), 0.0, 1.0);\n"; } source += std::string (" vec3 color;\n") + ColourMap::maps[colourmap].mapping + " fragmentColour = color;\n"; break; case Direction: source += " fragmentColour = normalize (abs (dir));\n"; break; default: break; } source += "}\n"; return source; }