// stub boost::shared_ptr<Solid> Repository::newSolid(SolidEnum type) { switch(type) { case ROCK: { BitmapImage rockImage("images/rock.bmp"); NewtonianMass * pm = new NewtonianMass(1000,2000,20,Vector2d(120,120),Vector2d(0,.1),0.,.1); boost::shared_ptr<Solid> rock ( new SimpleSolid( pm, new BitmapImage(rockImage) ) ); return rock; } case BIG_ROCK: { BitmapImage rockImage("images/rock.bmp"); NewtonianMass * pm = new NewtonianMass(5000,10000,35,Vector2d(720,320),Vector2d(0,-.1),0.,.03); boost::shared_ptr<Solid> rock ( new SimpleSolid( pm, new BitmapImage(rockImage) ) ); return rock; } case ALIEN: { boost::shared_ptr<Image> pa1( new BitmapImage("images/alien1-1.bmp") ); boost::shared_ptr<Image> pa2( new BitmapImage("images/alien1-2.bmp") ); boost::shared_ptr<Image> pa3( new BitmapImage("images/alien1-3.bmp") ); AnimatedImage * pa( new AnimatedImage(pa1,5) ); pa->add(pa2); pa->add(pa3); NewtonianMass * pm = new NewtonianMass(100,2000,12,Vector2d(500,300), Vector2d(-.1,0),0,0) ; boost::shared_ptr<Mass> pBaseAlienMass( pm ); Mass * alienMass = new DamageMass(pBaseAlienMass, 1000); boost::shared_ptr<Solid> alien(new SimpleSolid( alienMass, pa) ); return alien; } default: throw(0); } }
void DependentSource::drawBottomArrow(QPainter &p) { const int _x = (int)x() - 16; const int _y = (int)y() - 32; if (p.pen().color() == m_selectedCol) p.setPen(Qt::black); p.setBrush(Qt::black); p.drawLine(_x + 11, _y + 40, _x + 21, _y + 40); QPointArray pa3(3); pa3[0] = QPoint(_x + 21, _y + 40); pa3[1] = QPoint(_x + 16, _y + 37); pa3[2] = QPoint(_x + 16, _y + 43); p.drawPolygon(pa3); }
bool hitboxCollision(int a_x,int a_y,int a_width,int a_height,float a_angle, int b_x,int b_y,int b_width,int b_height,float b_angle) { Point pa1(a_x, a_y); Point pa2(a_x + cos (a_angle*PI/180) * a_width ,a_y - sin (a_angle*PI/180) * a_width); Point pa3(a_x + cos (a_angle*PI/180) * a_width + sin (a_angle*PI/180) * a_height, a_y - sin (a_angle*PI/180) * a_width + cos (a_angle*PI/180) * a_height); Point pa4(a_x + sin (a_angle*PI/180) * a_height, a_y + cos (a_angle*PI/180) * a_height); Point pb1(b_x, b_y); Point pb2(b_x + cos (b_angle*PI/180) * b_width ,b_y - sin (b_angle*PI/180) * b_width); Point pb3(b_x + cos (b_angle*PI/180) * b_width + sin (b_angle*PI/180) * b_height, b_y - sin (b_angle*PI/180) * b_width + cos (b_angle*PI/180) * b_height); Point pb4(b_x + sin (b_angle*PI/180) * b_height, b_y + cos (b_angle*PI/180) * b_height); Line la1(pa1,pa2); Line la2(pa2,pa3); Line la3(pa3,pa4); Line la4(pa4,pa1); Line lb1(pb1,pb2); Line lb2(pb2,pb3); Line lb3(pb3,pb4); Line lb4(pb4,pb1); if(segmentIntersection(la1,lb1)) return true; if(segmentIntersection(la1,lb2)) return true; if(segmentIntersection(la1,lb3)) return true; if(segmentIntersection(la1,lb4)) return true; if(segmentIntersection(la2,lb1)) return true; if(segmentIntersection(la2,lb2)) return true; if(segmentIntersection(la2,lb3)) return true; if(segmentIntersection(la2,lb4)) return true; if(segmentIntersection(la3,lb1)) return true; if(segmentIntersection(la3,lb2)) return true; if(segmentIntersection(la3,lb3)) return true; if(segmentIntersection(la3,lb4)) return true; if(segmentIntersection(la4,lb1)) return true; if(segmentIntersection(la4,lb2)) return true; if(segmentIntersection(la4,lb3)) return true; if(segmentIntersection(la4,lb4)) return true; return false; /* vector<Point*>intersections; intersections.push_back(lineIntersection(la1,lb1)); intersections.push_back(lineIntersection(la1,lb2)); intersections.push_back(lineIntersection(la1,lb3)); intersections.push_back(lineIntersection(la1,lb4)); intersections.push_back(lineIntersection(la2,lb1)); intersections.push_back(lineIntersection(la2,lb2)); intersections.push_back(lineIntersection(la2,lb3)); intersections.push_back(lineIntersection(la2,lb4)); intersections.push_back(lineIntersection(la3,lb1)); intersections.push_back(lineIntersection(la3,lb2)); intersections.push_back(lineIntersection(la3,lb3)); intersections.push_back(lineIntersection(la3,lb4)); intersections.push_back(lineIntersection(la4,lb1)); intersections.push_back(lineIntersection(la4,lb2)); intersections.push_back(lineIntersection(la4,lb3)); intersections.push_back(lineIntersection(la4,lb4)); int x_min=0;int x_max=0; int y_max=0;int y_min=0; if(a_width*a_height>b_width*b_height) { x_min = pa1.x; x_min=min(x_min,pa2.x); x_min=min(x_min,pa3.x); x_min=min(x_min,pa4.x); x_max = pa1.x; x_max=max(x_max,pa2.x); x_max=max(x_max,pa3.x); x_max=max(x_max,pa4.x); y_min = pa1.y; y_min=min(y_min,pa2.y); y_min=min(y_min,pa3.y); y_min=min(y_min,pa4.y); y_max = pa1.y; y_max=max(y_max,pa2.y); y_max=max(y_max,pa3.y); y_max=max(y_max,pa4.y); }else { x_min = pb1.x; x_min=min(x_min,pb2.x); x_min=min(x_min,pb3.x); x_min=min(x_min,pb4.x); x_max = pb1.x; x_max=max(x_max,pb2.x); x_max=max(x_max,pb3.x); x_max=max(x_max,pb4.x); y_min = pb1.y; y_min=min(y_min,pb2.y); y_min=min(y_min,pb3.y); y_min=min(y_min,pb4.y); y_max = pb1.y; y_max=max(y_max,pb2.y); y_max=max(y_max,pb3.y); y_max=max(y_max,pb4.y); } int cont=0; for(int i=0;i<(int)intersections.size();i++) { Point* point=intersections[i]; if(point!=NULL) { if(point->x > x_min && point->x < x_max && point->y > y_min && point->y < y_max) { cont++; } } } vector<Point*>::iterator i; for ( i = intersections.begin() ; i < intersections.end(); i++ ) { delete * i; } if(cont>=8) return true; */ return false; }