void init_aCORN_calcs(struct aCORN_EMirror* M) {
    assert(M);
    init_j0n(); // do this here to be sure!

    M->V0 = wireplaneVOffset(M->wire_radius, M->wire_spacing) * M->E0/2;
    printf("Initializing aCORN geometry with mirror field %g V/cm, finite wire effect %.2f V.\n", M->E0, M->V0);
    if(M->wire_dz) {
        M->V0 += M->wire_dz * M->E0;
        printf("\twith positional voltage shift to effective %.2f V\n", M->V0);
    }

    double l0[MAX_BESSEL_TERMS] = {0};
    double l1[MAX_BESSEL_TERMS] = {0};
    M->lowerField.dz = M->mirror_length/M->mirror_radius;
    addCircle(l0, M->entrance_radius / M->mirror_radius, M->V0);
    initDoubleBessel(&M->lowerField, l0, l1);

    double c0[MAX_BESSEL_TERMS] = {0};
    double c1[MAX_BESSEL_TERMS] = {0};
    //addCircle(c0, 0.9, M->upperLeakage*M->V0);
    //addCircle(c0, M->plate_radius / M->bore_radius, -M->upperLeakage*M->V0);
    addCircle(c0, M->exit_radius / M->bore_radius, M->V0);
    M->upperField.dz = 12./M->bore_radius;
    initDoubleBessel(&M->upperField, c0, c1);
}
void LightCycle::addLayeredCircles() {
	Posn innerwheelLeft((-1 * CIRCLE_DISTANCE / 2.0f) - 8, CIRCLE_OFFSET_Y);
	Posn innerwheelRight((CIRCLE_DISTANCE / 2.0f) - 8, CIRCLE_OFFSET_Y);
	innerwheelLeft.setCanvas(c_width, c_height);
	innerwheelRight.setCanvas(c_width, c_height);
	Component c1 = addCircle(innerwheelLeft, 0.12f, GL_POLYGON);
	Component c2 = addCircle(innerwheelRight, 0.12f, GL_POLYGON);
	Component c3 = addCircle(innerwheelLeft, 0.10f, GL_POLYGON);
	Component c4 = addCircle(innerwheelRight, 0.10f, GL_POLYGON);
	components.push_back(make_pair("grayLeft", c1));
	components.push_back(make_pair("grayRight", c2));
	components.push_back(make_pair("blackLeft", c3));
	components.push_back(make_pair("blackRight", c4));
}
예제 #3
0
파일: canvas.cpp 프로젝트: Andreas665/qt
Main::Main(QGraphicsScene& c, QWidget* parent, const char* name, Qt::WindowFlags f) :
    Q3MainWindow(parent,name,f),
    canvas(c)
{
    editor = new FigureEditor(canvas,this);
    QMenuBar* menu = menuBar();

    Q3PopupMenu* file = new Q3PopupMenu( menu );
    file->insertItem("&Fill canvas", this, SLOT(init()), Qt::CTRL+Qt::Key_F);
    file->insertItem("&Erase canvas", this, SLOT(clear()), Qt::CTRL+Qt::Key_E);
    file->insertItem("&New view", this, SLOT(newView()), Qt::CTRL+Qt::Key_N);
    file->insertSeparator();
    file->insertItem("&Print...", this, SLOT(print()), Qt::CTRL+Qt::Key_P);
    file->insertSeparator();
    file->insertItem("E&xit", qApp, SLOT(quit()), Qt::CTRL+Qt::Key_Q);
    menu->insertItem("&File", file);

    Q3PopupMenu* edit = new Q3PopupMenu( menu );
    edit->insertItem("Add &Circle", this, SLOT(addCircle()), Qt::ALT+Qt::Key_C);
    edit->insertItem("Add &Hexagon", this, SLOT(addHexagon()), Qt::ALT+Qt::Key_H);
    edit->insertItem("Add &Polygon", this, SLOT(addPolygon()), Qt::ALT+Qt::Key_P);
    edit->insertItem("Add Spl&ine", this, SLOT(addSpline()), Qt::ALT+Qt::Key_I);
    edit->insertItem("Add &Text", this, SLOT(addText()), Qt::ALT+Qt::Key_T);
    edit->insertItem("Add &Line", this, SLOT(addLine()), Qt::ALT+Qt::Key_L);
    edit->insertItem("Add &Rectangle", this, SLOT(addRectangle()), Qt::ALT+Qt::Key_R);
    edit->insertItem("Add &Sprite", this, SLOT(addSprite()), Qt::ALT+Qt::Key_S);
    edit->insertItem("Create &Mesh", this, SLOT(addMesh()), Qt::ALT+Qt::Key_M );
    edit->insertItem("Add &Alpha-blended image", this, SLOT(addButterfly()), Qt::ALT+Qt::Key_A);
    menu->insertItem("&Edit", edit);

    Q3PopupMenu* view = new Q3PopupMenu( menu );
    view->insertItem("&Enlarge", this, SLOT(enlarge()), Qt::SHIFT+Qt::CTRL+Qt::Key_Plus);
    view->insertItem("Shr&ink", this, SLOT(shrink()), Qt::SHIFT+Qt::CTRL+Qt::Key_Minus);
    view->insertSeparator();
    view->insertItem("&Rotate clockwise", this, SLOT(rotateClockwise()), Qt::CTRL+Qt::Key_PageDown);
    view->insertItem("Rotate &counterclockwise", this, SLOT(rotateCounterClockwise()), Qt::CTRL+Qt::Key_PageUp);
    view->insertItem("&Zoom in", this, SLOT(zoomIn()), Qt::CTRL+Qt::Key_Plus);
    view->insertItem("Zoom &out", this, SLOT(zoomOut()), Qt::CTRL+Qt::Key_Minus);
    view->insertItem("Translate left", this, SLOT(moveL()), Qt::CTRL+Qt::Key_Left);
    view->insertItem("Translate right", this, SLOT(moveR()), Qt::CTRL+Qt::Key_Right);
    view->insertItem("Translate up", this, SLOT(moveU()), Qt::CTRL+Qt::Key_Up);
    view->insertItem("Translate down", this, SLOT(moveD()), Qt::CTRL+Qt::Key_Down);
    view->insertItem("&Mirror", this, SLOT(mirror()), Qt::CTRL+Qt::Key_Home);
    menu->insertItem("&View", view);

    menu->insertSeparator();

    Q3PopupMenu* help = new Q3PopupMenu( menu );
    help->insertItem("&About", this, SLOT(help()), Qt::Key_F1);
    help->setItemChecked(dbf_id, TRUE);
    menu->insertItem("&Help",help);

    statusBar();

    setCentralWidget(editor);

    printer = 0;

    init();
}
예제 #4
0
/*public*/
void
OffsetCurveBuilder::getLineCurve(const CoordinateSequence *inputPts,
		double distance, vector<CoordinateSequence*>& lineList)
{
	// a zero or negative width buffer of a line/point is empty
	if (distance<= 0.0) return;

	init(distance);

	if (inputPts->getSize() < 2) {
		switch (endCapStyle) {
			case BufferOp::CAP_ROUND:
				addCircle(inputPts->getAt(0), distance);
				break;
			case BufferOp::CAP_SQUARE:
				addSquare(inputPts->getAt(0), distance);
				break;
			// default is for buffer to be empty (e.g. for a butt line cap);
		}
	} else {
		computeLineBufferCurve(*inputPts);
	}
	CoordinateSequence *lineCoord=vertexList->getCoordinates();
	lineList.push_back(lineCoord);
}
예제 #5
0
void ofxCirclePacker :: addCircles( int numOfCircles, int color )
{
	for( int i=0; i<numOfCircles; i++ )
	{
		addCircle( color );
	}
}
/*public*/
void
OffsetCurveBuilder::getLineCurve(const CoordinateSequence *inputPts,
		double distance, vector<CoordinateSequence*>& lineList)
{
	// a zero or negative width buffer of a line/point is empty
	if (distance<= 0.0) return;

	init(distance);

	if (inputPts->getSize() <= 1) {
		switch (bufParams.getEndCapStyle()) {
			case BufferParameters::CAP_ROUND:
				addCircle(inputPts->getAt(0), distance);
				break;
			case BufferParameters::CAP_SQUARE:
				addSquare(inputPts->getAt(0), distance);
				break;
			default:
				// default is for buffer to be empty
				// (e.g. for a butt line cap);
				break;
		}
	} else {
		computeLineBufferCurve(*inputPts);
	}

	// NOTE: we take ownership of lineCoord here ...
	CoordinateSequence *lineCoord=vertexList->getCoordinates();

	// ... and we give it away here
	lineList.push_back(lineCoord);
}
예제 #7
0
//--------------------------------------------------------------
void ofApp::draw(){
    
    ofEnableDepthTest(); //Enable z-buffering
    //Set a gradient background from white to gray
    ofBackgroundGradient( ofColor( 0 ), ofColor( 128 ) );
	//if we're using the camera, start it.
	//everything that you draw between begin()/end() shows up from the view of the camera
    camera.begin();
    ofMesh mesh;
    for(unsigned int i = 1; i < points.size(); i++){
		ofVec3f nextPoint = points[i];
        addCircle(nextPoint, mesh);
    }
    if(drawMode)
    {
        mesh.draw();
    }
    else
    {
        mesh.drawWireframe();
    }
    camera.end();
    ofSetColor(255);
    ofDrawBitmapString("'c' toggle camera \n 'm' toggle wireframe", ofPoint(20,20));
    
}
CircleList::CircleList(DominoList *dominolist)
{
    head = new Circle(dominolist);
    head->next = 0;
    tail = head;
    while (!(dominolist->isEmpty())) {
        addCircle(dominolist);
    }
}
예제 #9
0
파일: qbezier.cpp 프로젝트: Afreeca/qt
int QBezier::shifted(QBezier *curveSegments, int maxSegments, qreal offset, float threshold) const
{
    Q_ASSERT(curveSegments);
    Q_ASSERT(maxSegments > 0);

    if (x1 == x2 && x1 == x3 && x1 == x4 &&
        y1 == y2 && y1 == y3 && y1 == y4)
        return 0;

    --maxSegments;
    QBezier beziers[10];
redo:
    beziers[0] = *this;
    QBezier *b = beziers;
    QBezier *o = curveSegments;

    while (b >= beziers) {
        int stack_segments = b - beziers + 1;
        if ((stack_segments == 10) || (o - curveSegments == maxSegments - stack_segments)) {
            threshold *= qreal(1.5);
            if (threshold > qreal(2.0))
                goto give_up;
            goto redo;
        }
        ShiftResult res = shift(b, o, offset, threshold);
        if (res == Discard) {
            --b;
        } else if (res == Ok) {
            ++o;
            --b;
            continue;
        } else if (res == Circle && maxSegments - (o - curveSegments) >= 2) {
            // add semi circle
            if (addCircle(b, offset, o))
                o += 2;
            --b;
        } else {
            b->split(b+1, b);
            ++b;
        }
    }

give_up:
    while (b >= beziers) {
        ShiftResult res = shift(b, o, offset, threshold);

        // if res isn't Ok or Split then *o is undefined
        if (res == Ok || res == Split)
            ++o;

        --b;
    }

    Q_ASSERT(o - curveSegments <= maxSegments);
    return o - curveSegments;
}
예제 #10
0
UINT cagdChangeCircleCenter(UINT id, CCagdPoint center, int segments) {
	if (cagdGetSegmentType(id) != CAGD_SEGMENT_WCIRCLE)
		return -1;
	CCagdPoint *ctlPt = list[id].ctlPt;
	CCagdPoint radius = list[id].radius;
	cagdFreeSegment(id);
	UINT nId = addCircle(center,radius,ctlPt,segments);
	ctlPt->circle = nId;
	return nId;
}
예제 #11
0
파일: drawdialoggl.c 프로젝트: doolin/ntdda
static void
handleLButtonUp(HWND hDlg, LPARAM lParam)
{

#if OPENGL
  	double p1x,p1y,p2x,p2y;
	  float red, green, blue;
#endif

  /* These two lines are the only real platform dependent code in here.
   * Once the mouse position is grabbed, the math is similar.
   */
   ptNew.x = LOWORD(lParam); ptNew.y = HIWORD(lParam);
			DPtoLP(hdc, &ptNew, 1);

  /* We insist on actually being inside the drawing area...
   */
			if(ptNew.x <= maxSize && 
      ptNew.x >= 0       && 
      ptNew.y <= maxSize && 
      ptNew.y >= 0       && 
      inside) 
   {
			   SetROP2(hdc, R2_COPYPEN);
				  SelectObject(hdc, hCurrentPen);

     /* TODO: Turn this into a swicth on tool. */
			  	if(tool==joint) 
         addJoint(hDlg);
      else if (tool==fixedpoint || tool==loadpoint) 
         addTriangle(hDlg);
      else if (tool==measpoint || tool==holepoint) 
         addCircle(hDlg);
  	} 
   else /* outside drawing area */
   { 
	     SetROP2(hdc, R2_NOT);
    		if(!tool && inside) 
      {
	    				MoveToEx(hdc, ptBegin.x, ptBegin.y, NULL);
	     			LineTo(hdc, ptOld.x, ptOld.y);
	   		}
	 	}
	 	ReleaseCapture();
//			ReleaseDC(hDlg, hdc);

}  /* close handleMouseUp() */
예제 #12
0
void GameManager::update()
{
	_player.update(_click, _mouseX, _mouseY, _keyState, &_food);
	int jump = _food.update();
	_background.update(jump);
	
	checkPlayerCollision();
	
	if(jump){
		float x = 0;
		float y = 0;
		_food.getPos(&x, &y);
		addCircle(x, y, GC::FOOD_CIRCLE_SPEED, GC::FOOD_CIRCLE_START_SIZE, GC::FOOD_CIRCLE_MAX_SIZE);
	}
	updateCircles();
	
}
예제 #13
0
GameManager::GameManager() :
	_go( true ),
	_click( false ),
	_mouseX( GC::SCREEN_WIDTH/2 ),
	_mouseY( GC::SCREEN_HEIGHT/2 ),
	_keyState( SDL_GetKeyboardState(NULL) ),
	_player( GC::PLAYER_SPEED, GC::PLAYER_ACCELERATION, GC::SCREEN_WIDTH/2, GC::SCREEN_HEIGHT/2 ),
	_food( GC::SCREEN_WIDTH, GC::SCREEN_HEIGHT ),
	_circles(  ),
	_background(  ),
	_window( SDL_CreateWindow("THING", 10, 10, GC::SCREEN_WIDTH, GC::SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE) ),
	_renderer( SDL_CreateRenderer(_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC) )
{
	float x = 0;
	float y = 0;
	_food.getPos(&x, &y);
	addCircle(x, y, GC::FOOD_CIRCLE_SPEED, GC::FOOD_CIRCLE_START_SIZE, GC::FOOD_CIRCLE_MAX_SIZE);
}
예제 #14
0
void GameManager::checkPlayerCollision()
{
	int size = _player.getSize();
	float xHead = 0;
	float yHead = 0;
	
	_player.getHeadPos(&xHead, &yHead);
	
	for(int i = 5; i < size; i++){
		float xBody;
		float yBody;
		
		_player.getBodyPartPos(i, &xBody, &yBody);
		
		float xDist = xBody - xHead;
		float yDist = yBody - yHead;
		
		float totDist = sqrt(xDist*xDist + yDist*yDist);
		
		if(totDist < 5){
			addCircle(xBody, yBody, GC::PLAYER_CIRCLE_SPEED, GC::PLAYER_CIRCLE_START_SIZE, 400);
		}
	}
	/*
	float xHead = 0;
	float yHead = 0;
	
	_player.getHeadPos(&xHead, &yHead);
	
	for(std::vector<Circle>::iterator it = _circles.begin() + 20; it < _circles.end(); ++it){
		
		it->getPos(&xBody, &yBody);
		
		float xDist = xHead - xBody;
		float yDist = yHead - yBody;
		float totDist = sqrt(xDist*xDist + yDist*yDist);
		if(totDist<5){
			addCircle(xBody, yBody, GC::PLAYER_CIRCLE_SPEED, GC::PLAYER_CIRCLE_START_SIZE, 400);
			break;
		}
	}
	*/
	
}
예제 #15
0
void GameManager::updateCircles()
{
	
	float x = 0;
	float y = 0;
	_player.getHeadPos(&x, &y);
	
	float maxRad = GC::PLAYER_CIRCLE_MAX_SIZE * _player.getHeadVel() / GC::PLAYER_SPEED;
	
	
	/*if(maxRad < GC::PLAYER_CIRCLE_MIN_SIZE){
		maxRad = GC::PLAYER_CIRCLE_MIN_SIZE;
	}
	//*/
	
	
	
	
	addCircle(x, y, GC::PLAYER_CIRCLE_SPEED, GC::PLAYER_CIRCLE_START_SIZE, maxRad);
	
	
	
	
	
	
	//addCircle(x, y, GC::PLAYER_CIRCLE_SPEED, GC::PLAYER_CIRCLE_START_SIZE, GC::PLAYER_CIRCLE_MAX_SIZE);
	
	//iterate through circles vector
	for(std::vector<Circle>::iterator it = _circles.begin(); it < _circles.end(); ++it){
		//if(_circles.size() == 0) {printf("empty\n"); break;}
		float radius = 0;
		float maxRadius = 0;
		it->update();
		radius = it->getRadius();
		maxRadius = it->getMaxRadius();
		if(radius > maxRadius){
			_circles.erase(it);
		}
	}
	
	
}
예제 #16
0
void MapBox::drawCircle()
{
    if (m_markerObjects.count() < 1) return;

    QGeoMapPixmapObject * p1 = m_markerObjects.at(0);

    // center of the circle
    QGeoCoordinate center = p1->coordinate();

    // the circle's radius, in meters, defaults to 3000 km
    qreal radius = 3000000;

    // if a 2nd marker object is given, evaluate its distance to the first one to get the circle's radius.
    if (m_markerObjects.count() >= 2) {
        QGeoMapPixmapObject * p2 = m_markerObjects.at(1);

        radius = center.distanceTo(p2->coordinate());
    }

    QGeoMapCircleObject * circle = addCircle(center, radius);
    m_mapWidget->lastCircle = circle;
}
void dtCollisionAvoidance::addObtacles(const dtCrowdAgent& ag, const dtCrowdQuery& query)
{
	reset();
	const dtCrowdAgentEnvironment* agEnv = query.getAgentEnvironment(ag.id);

	// Add neighbours as obstacles.
	for (unsigned j = 0; j < agEnv->nbNeighbors; ++j)
	{
		const dtCrowdAgent& nei = *query.getAgent(agEnv->neighbors[j].idx);
		addCircle(nei.position, nei.radius, nei.velocity, nei.desiredVelocity);
	}

	// Append neighbour segments as obstacles.
	for (int j = 0; j < agEnv->boundary.getSegmentCount(); ++j)
	{
		const float* s = agEnv->boundary.getSegment(j);

		if (dtTriArea2D(ag.position, s, s+3) < 0.f)
			continue;

		addSegment(s, s+3);
	}
}
예제 #18
0
파일: menu.cpp 프로젝트: serman/muncyt
void menu::initParticles() {
	ofLogNotice("oooooooooo ----- initParticles()");
	// add objects
	removeParticles();	// primero borrar las que pudiera haber, porsiaca.
	for (int i=0; i<150; i++) {
		// circulos
		float distR = ofRandom(W_HEIGHT/2)*0.8;
		float angTmp = ofRandom(TWO_PI);
//		addCircle(ofPoint(ofGetWidth()/2+ofRandom(200)-100, W_HEIGHT/2+ofRandom(200)-100));
		addCircle(ofPoint(ofGetWidth()/2+distR*cos(angTmp), W_HEIGHT/2+distR*sin(angTmp)));
		
		distR = ofRandom(W_HEIGHT/2)*0.8;
		angTmp = ofRandom(TWO_PI);
		// rectangulos
//		addBox(ofPoint(ofGetWidth()/2+ofRandom(200)-100, W_HEIGHT/2+ofRandom(200)-100));
		addBox(ofPoint(ofGetWidth()/2+distR*cos(angTmp), W_HEIGHT/2+distR*sin(angTmp)));
	}
	ptoMed_circles = ptoMedio(circles);
	ptoMed_boxes = ptoMedio(boxes);
	
	bAddCircle = false;
	bAddBox = false;

}
예제 #19
0
/*!
  Add a circle to display (not for tracking) from its center, 3 points (including the center) defining the plane that contain
  the circle and its radius.

  \param p1 : Center of the circle.
  \param p2,p3 : Two points on the plane containing the circle. With the center of the circle we have 3 points
  defining the plane that contains the circle.
  \param radius : Radius of the circle.
  \param name : The optional name of the circle.
*/
void
vpMbKltTracker::initCircle(const vpPoint& p1, const vpPoint &p2, const vpPoint &p3, const double radius,
    const int /*idFace*/, const std::string &name)
{
  addCircle(p1, p2, p3, radius, name);
}
예제 #20
0
void MapBox::testDateline()
{
    m_mapWidget->setCenter(QGeoCoordinate(0.0, 180.0));
    m_mapWidget->setZoomLevel(5.0);

    QList<QGeoCoordinate> dateline;

    dateline << QGeoCoordinate(-15.0, 180.0);
    dateline << QGeoCoordinate(15.0, 180.0);

    QGeoMapPolylineObject *datelineObject = new QGeoMapPolylineObject();
    datelineObject->setPath(dateline);
    QPen p(Qt::DashLine);
    p.setColor(Qt::black);
    p.setWidth(2);
    //p.setCosmetic(true);
    datelineObject->setPen(p);

    m_mapWidget->addMapObject(datelineObject);

    addRectangle(QGeoCoordinate(-5.0, 179.0), QGeoCoordinate(-6.0, -179.0));
    addCircle(QGeoCoordinate(-7.0, 180.0), 50000.0);

    QList<QGeoCoordinate> polyline;

    polyline << QGeoCoordinate(-3.0, 180.0);
    polyline << QGeoCoordinate(-4.0, 179.0);
    polyline << QGeoCoordinate(-4.0, -179.0);

    addPolyline(polyline);

    QList<QGeoCoordinate> polygon;

    polygon << QGeoCoordinate(0.0, 180.0);
    polygon << QGeoCoordinate(-2.0, 179.0);
    polygon << QGeoCoordinate(-2.0, -179.0);

    addPolygon(polygon);

    QPixmap pixmap(48, 48);
    QPainter pixmapPainter(&pixmap);
    pixmapPainter.fillRect(pixmap.rect(), Qt::yellow);
    pixmapPainter.setPen(QPen(Qt::black));
    pixmapPainter.setBrush(QBrush(Qt::black));

    QFont font = pixmapPainter.font();
    font.setPointSize(8);
    pixmapPainter.setFont(font);

    pixmapPainter.drawText(pixmap.rect(), Qt::AlignCenter, "Pixmap");

    addPixmap(QGeoCoordinate(6.0, 180.0), QPoint(-1 * pixmap.width() / 2, -1 * pixmap.width() / 2), pixmap);

    addText(QGeoCoordinate(4.0, 180.0), QString("Text"));

    QList<QGeoCoordinate> route;

    route << QGeoCoordinate(3.0, 180.0);
    route << QGeoCoordinate(2.5, 179.0);
    route << QGeoCoordinate(1.5, 179.0);
    route << QGeoCoordinate(1.0, 180.0);
    route << QGeoCoordinate(1.5, -179.0);
    route << QGeoCoordinate(2.5, -179.0);

    addFakeRoute(route, 3);

    QGraphicsEllipseItem *ellipseItem = new QGraphicsEllipseItem(QRectF(0.0, 0.0, 96.0, 48.0));
    ellipseItem->setBrush(Qt::red);

    addCustom(QGeoCoordinate(10.0, 180.0), QPoint(-48, -24), ellipseItem);
}
예제 #21
0
Main::Main(QCanvas& c, QWidget* parent, const char* name, WFlags f) :
    QMainWindow(parent,name,f),
    canvas(c)
{
    editor = new FigureEditor(canvas,this); // 繼承canvas view而來
    QMenuBar* menu = menuBar();

    QPopupMenu* file = new QPopupMenu( menu ); // 當parent被刪除,則子類別也會被刪除
    file->insertItem("&Fill canvas", this, SLOT(init()), CTRL+Key_F);
    file->insertItem("&Erase canvas", this, SLOT(clear()), CTRL+Key_E);
    file->insertItem("&New view", this, SLOT(newView()), CTRL+Key_N);
    file->insertSeparator();
    file->insertItem("&Print...", this, SLOT(print()), CTRL+Key_P);
    file->insertSeparator();
    file->insertItem("E&xit", qApp, SLOT(quit()), CTRL+Key_Q);
    menu->insertItem("&File", file); // 建立一個工具列名為File的label

    QPopupMenu* edit = new QPopupMenu( menu );
    edit->insertItem("Add &Circle", this, SLOT(addCircle()), ALT+Key_C);
    edit->insertItem("Add &Hexagon", this, SLOT(addHexagon()), ALT+Key_H);
    edit->insertItem("Add &Polygon", this, SLOT(addPolygon()), ALT+Key_P);
    edit->insertItem("Add Spl&ine", this, SLOT(addSpline()), ALT+Key_I);
    edit->insertItem("Add &Text", this, SLOT(addText()), ALT+Key_T);
    edit->insertItem("Add &Line", this, SLOT(addLine()), ALT+Key_L);
    edit->insertItem("Add &Rectangle", this, SLOT(addRectangle()), ALT+Key_R);
    edit->insertItem("Add &Sprite", this, SLOT(addSprite()), ALT+Key_S);
    edit->insertItem("Create &Mesh", this, SLOT(addMesh()), ALT+Key_M );
    edit->insertItem("Add &Alpha-blended image", this, SLOT(addButterfly()), ALT+Key_A);
    menu->insertItem("&Edit", edit);

    QPopupMenu* view = new QPopupMenu( menu );
    view->insertItem("&Enlarge", this, SLOT(enlarge()), SHIFT+CTRL+Key_Plus);
    view->insertItem("Shr&ink", this, SLOT(shrink()), SHIFT+CTRL+Key_Minus);
    view->insertSeparator();
    view->insertItem("&Rotate clockwise", this, SLOT(rotateClockwise()), CTRL+Key_PageDown);
    view->insertItem("Rotate &counterclockwise", this, SLOT(rotateCounterClockwise()), CTRL+Key_PageUp);
    view->insertItem("&Zoom in", this, SLOT(zoomIn()), CTRL+Key_Plus);
    view->insertItem("Zoom &out", this, SLOT(zoomOut()), CTRL+Key_Minus);
    view->insertItem("Translate left", this, SLOT(moveL()), CTRL+Key_Left);
    view->insertItem("Translate right", this, SLOT(moveR()), CTRL+Key_Right);
    view->insertItem("Translate up", this, SLOT(moveU()), CTRL+Key_Up);
    view->insertItem("Translate down", this, SLOT(moveD()), CTRL+Key_Down);
    view->insertItem("&Mirror", this, SLOT(mirror()), CTRL+Key_Home);
    menu->insertItem("&View", view);

    options = new QPopupMenu( menu );
    dbf_id = options->insertItem("Double buffer", this, SLOT(toggleDoubleBuffer()));
    options->setItemChecked(dbf_id, TRUE);
    menu->insertItem("&Options",options);

    menu->insertSeparator();

    QPopupMenu* help = new QPopupMenu( menu );
    help->insertItem("&About", this, SLOT(help()), Key_F1);
    help->setItemChecked(dbf_id, TRUE); // 很奇怪,當TRUE時,把dbf_id打勾,不懂
    menu->insertItem("&Help",help);

    statusBar();
    // 返回這個窗口的狀態條。如果沒有的話
    // statusBar()會創建一個空的狀態條,並且如果需要也創建一個工具提示組。

    setCentralWidget(editor);

    printer = 0;

    init();
}
예제 #22
0
//--------------------------------------------------------------
void testApp::setup() {
	
	ofSetVerticalSync(true);
	ofBackgroundHex(0x000000);
	ofSetLogLevel(OF_LOG_NOTICE);
	ofEnableAntiAliasing();

	box2d.init();
	box2d.setGravity(0, 0);
	box2d.setFPS(30.0);

	isKeyPressed = false;
	isMousePressed = false;
	
	// add objects
	for (int i=0; i<200; i++) {
		// circulos
		addCircle(ofPoint(ofGetWidth()/2+ofRandom(100), ofGetHeight()/2+ofRandom(100)));
				  
		// rectangulos
		addBox(ofPoint(ofGetWidth()/2+ofRandom(100), ofGetHeight()/2+ofRandom(100)));
	}
	bAddCircle = false;
	bAddBox = false;
	
	ptoMed_circles = ptoMedio(circles);
	ptoMed_boxes = ptoMedio(boxes);
	
	bola.loadImage("images/dot.png");
	ladoPart1 = 5;
	ladoPart2 = 10;
	
	coloresBN.push_back(ofColor(0));
	coloresBN.push_back(ofColor(150));
	coloresBN.push_back(ofColor(255));
	
	bDraw4Forces = true;
	
	fRed = true;
	
	borde.clear();
	ofColor ctmp = ofColor::black;
	borde.setFillColor(ctmp);
	//http://www.openframeworks.cc/documentation/graphics/ofPath.html#show_setPolyWindingMode
	borde.setPolyWindingMode(OF_POLY_WINDING_ODD);
	// rectangulo 
	borde.rectangle(0,0,ofGetWidth(),ofGetHeight());
	borde.setCircleResolution(60);
	borde.circle(ofGetWidth()/2,ofGetHeight()/2,ofGetHeight()/2*0.95);
	
	
	// fbos
	fbo1.allocate(ofGetHeight()/2,ofGetHeight()/2);
	fbo2.allocate(ofGetHeight()/2,ofGetHeight()/2);
	fbo3.allocate(ofGetHeight()/2,ofGetHeight()/2);
	fbo4.allocate(ofGetHeight()/2,ofGetHeight()/2);
	
	fbo1.begin();	ofClear(255,255,255,0);	fbo1.end();
	fbo2.begin();	ofClear(255,255,255,0);	fbo2.end();
	fbo3.begin();	ofClear(255,255,255,0);	fbo3.end();
	fbo4.begin();	ofClear(255,255,255,0);	fbo4.end();	
	
	bDrawFbos = false;
	
}
예제 #23
0
파일: menu.cpp 프로젝트: serman/muncyt
//--------------------------------------------------------------
void menu::update(float d1) {
	
//	ofLogNotice("Update");
	if(bAddCircle) {
		ofLogNotice("Update-AddCircle");
		addCircle(ofPoint(ofGetMouseX(),ofGetMouseY()));
	}
	if(bAddBox) {
		addBox(ofPoint(ofGetMouseX(),ofGetMouseY()));
	}
	
	box2d.update();	
	
	if(!bAddCircle && !bAddBox) {
		ofVec2f mouse(ofGetMouseX(), ofGetMouseY());

		int ncircles = circles.size();
		int nboxes = boxes.size();
		int ntot = ncircles+nboxes;
		
		// = Fuerzas entre particulas
		// Se puede hacer estadistico por ahora
		// Tambien se puede hacer por densidades:
		// - calcular pto medio de cada tipo de particula y carga total
		// - calcular la fuerza ejercida sobre cada particula por todos los grupos de particulas
		ptoMed_circles = ptoMedio(circles);
		ptoMed_boxes = ptoMedio(boxes);
		if(swFuerzaDensidad) {
			for(int i=0; i<circles.size(); i++) {
				float dis1 = ptoMed_circles.distance(circles[i].get()->getPosition());
				float dis2 = ptoMed_boxes.distance(circles[i].get()->getPosition());
				if(dis1 > minDisInt) circles[i].get()->addRepulsionForce(ptoMed_circles, 2*(ncircles/ntot)/dis1);
				if(dis2 > minDisInt) circles[i].get()->addAttractionPoint(ptoMed_boxes, 2*(nboxes/ntot)/dis2);
			}
			for(int i=0; i<boxes.size(); i++) {
				float dis1 = ptoMed_boxes.distance(boxes[i].get()->getPosition());
				float dis2 = ptoMed_circles.distance(boxes[i].get()->getPosition());
				if(dis1 > minDisInt) boxes[i].get()->addRepulsionForce(ptoMed_boxes, 2*(nboxes/ntot)/dis1);
				if(dis2 > minDisInt) boxes[i].get()->addAttractionPoint(ptoMed_circles, 2*(ncircles/ntot)/dis2);
			}
		}
		
		
		// = Interaccion mouse/TUIOs:
		// Solo se da si el mouse esta en la zona de confinamiento
		// y depende de si el mouse is Pressed o no:
		
		// pressed: 
		//  - REPULSION circulo y ATRACCION box: si dist-mouse < distMinima
		//  - ATRACCION circulo y REPULSION box: si dist-mouse > distMaxima
		// 
		
		// o poner los tuios impares con atraccion y los impares con repulsion (<<== probemos esta)
		interaccion_point(mouse, !	isMousePressed);
		
		// interaccion TUIOS
		
		
		
		// = Fuerza de confinamiento
		for(int i=0; i<circles.size(); i++) {
			float dis = centro.distance(circles[i].get()->getPosition());
			if(dis > distConf) circles[i].get()->addAttractionPoint(centro, 0.5);//3, 9);
		}
		for(int i=0; i<boxes.size(); i++) {
			float dis = centro.distance(boxes[i].get()->getPosition());
			if(dis > distConf) boxes[i].get()->addAttractionPoint(centro, 0.5);//3, 9);
		}
	
	}
	
	bAddCircle=false;
	bAddBox=false;

	// - - - - TUIOS - - - - 
    //tuioClient.getMessage();

	// botones (tangibleHandler's ==> touchElements)
//    buttonCollide.update_prev(anillo.getParticlePosition());
//    buttonSpeed1.update_prev(anillo.getParticlePosition());
//    buttonSpeed2.update_prev(anillo.getParticlePosition());
    
//	touchElements.update();
	
	// cursores recibidos
    hands.update();
	
	// recorrer el vector de cursores que hay en hands (tangiblesHandler) e interactuar si esta dentro del círculo
//	int ttAct = ofGetElapsedTimeMillis();
//	float sqLim = (radioInt*radioInt)*0.9;
//	int limTime = floor(1000/ofGetFrameRate())+20;
	for(int i=0; i<hands.objectsCol.size(); i++) {
		//		ofLogNotice("handShadow num: " + ofToString(i));
		handShadow * h = (handShadow *) hands.objectsCol[i];
		//ofLogNotice("Id: " + ofToString(h->cursor_id) + "  x,y: " + ofToString(h->x)+"/"+ofToString(h->y)+ "   age: " + ofToString(h->age));

		bool bPar = false;
		if(h->cursor_id%2 == 0)		   bPar = true;
		   
		interaccion_point(ofPoint(h->x,h->y), bPar);
		
	}
    interactionUpdate();
	
	
}
예제 #24
0
파일: main.cpp 프로젝트: s0n4m/physics-2d
LRESULT		CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	// this is the main message handler of the system
	PAINTSTRUCT		ps;	// used in WM_PAINT
	HDC				hdc;	// handle to a device context

	TwEventWin(hwnd, msg, wparam, lparam);


	// what is the message 
	switch(msg)
	{	
	case WM_CREATE: 
		{
			// do initialization stuff here
			return(0);
		} 
	case WM_LBUTTONDOWN:
		{
			addCircle(LOWORD(lparam), HIWORD(lparam));
			break;
		}
		break;

	case WM_RBUTTONDOWN:
		{
			renderer->setAirjetActive(true);
			addAirjet(LOWORD(lparam), HIWORD(lparam));
		}
		break;

	case WM_MOUSEWHEEL:
		{
			float v = ((signed short)HIWORD(wparam) > 0) ? 0.5f : -0.5f;
			renderer->changeZoom(v);
		}
		break;

	case WM_RBUTTONUP:
		{
			renderer->setAirjetActive(false);
		}
		break;
	
	case WM_MOUSEMOVE:
		{
			if (renderer->airjetActive())
				addAirjet(LOWORD(lparam), HIWORD(lparam));
		}
		break;

	case WM_KEYDOWN:
		{
			// Handle any non-accelerated key commands
			switch (wparam)
			{
			case VK_ESCAPE:
			case VK_F12:
				PostMessage(hwnd, WM_CLOSE, 0, 0);
				return (0);
			case VK_RIGHT:
				
				break;
			case VK_SPACE:
				{
					setPause();
				}
				break;

			case 65: // A
				renderer->changePosition(+0.5f, 0);
				break;
			case 66: // B
				toggleSpring();
				break;
			case 67: // C
				addMultipleCircles();
				break;
			case 68: // D
				renderer->changePosition(-0.5f, 0);
				break;
			case 83: // S
				renderer->changePosition(0, +0.5f);
				break;
			case 87: // W
				renderer->changePosition(0, -0.5f);
				break;
			case 82: // R
				renderer->resetView();
				break;
			default:
				break;


			}
			break;
		}

	case WM_PAINT: 
		{
			// validate the window
			hdc = BeginPaint(hwnd,&ps);	 
			EndPaint(hwnd,&ps);
			return(0);
		} 

	case WM_DESTROY: 
		{
			// kill the application			
			PostQuitMessage(0);

			return(0);
		}

	default:
		break;

	} // end switch

	// process any messages that we didn't take care of 
	return (DefWindowProc(hwnd, msg, wparam, lparam));

} // end WinProc
//--------------------------------------------------------------
void ofxBox2dCompoundShape::addCircle( float ax, float ay, float aradius ) {
    addCircle( ofxBox2dCompoundShape::Circle(ax, ay, aradius ));
}
예제 #26
0
//--------------------------------------------------------------
void testApp::update() {
	
	ofLogNotice("Update");
	if(bAddCircle) {
		ofLogNotice("Update-AddCircle");
		addCircle(ofPoint(ofGetMouseX(),ofGetMouseY()));
	}
	if(bAddBox) {
		addBox(ofPoint(ofGetMouseX(),ofGetMouseY()));
	}
	
	box2d.update();	
	
	if(!bAddCircle && !bAddBox) {
		ofVec2f mouse(ofGetMouseX(), ofGetMouseY());
		float minDis = ofGetMousePressed() ? 300 : 200;

		ofVec2f center(ofGetWidth()/2.0, ofGetHeight()/2.0);
		float distConf = ofGetHeight()/2.0*0.9;

		float minDisInt = 25;
		int ncircles = circles.size();
		int nboxes = boxes.size();
		int ntot = ncircles+nboxes;
		
		// = Fuerzas entre particulas
		// Se puede hacer estadistico por ahora
		// Tambien se puede hacer por densidades:
		// - calcular pto medio de cada tipo de particula y carga total
		// - calcular la fuerza ejercida sobre cada particula por todos los grupos de particulas
		ptoMed_circles = ptoMedio(circles);
		ptoMed_boxes = ptoMedio(boxes);
		if(true) {
			for(int i=0; i<circles.size(); i++) {
				float dis1 = ptoMed_circles.distance(circles[i].get()->getPosition());
				float dis2 = ptoMed_boxes.distance(circles[i].get()->getPosition());
				if(dis1 > minDisInt) circles[i].get()->addRepulsionForce(ptoMed_circles, 2*(ncircles/ntot)/dis1);
				if(dis2 > minDisInt) circles[i].get()->addAttractionPoint(ptoMed_boxes, 2*(nboxes/ntot)/dis2);
			}
			for(int i=0; i<boxes.size(); i++) {
				float dis1 = ptoMed_boxes.distance(boxes[i].get()->getPosition());
				float dis2 = ptoMed_circles.distance(boxes[i].get()->getPosition());
				if(dis1 > minDisInt) boxes[i].get()->addRepulsionForce(ptoMed_boxes, 2*(nboxes/ntot)/dis1);
				if(dis2 > minDisInt) boxes[i].get()->addAttractionPoint(ptoMed_circles, 2*(ncircles/ntot)/dis2);
			}
		}
		
		
		// = Interaccion mouse/TUIOs:
		// Solo se da si el mouse esta en la zona de confinamiento
		// y depende de si el mouse is Pressed o no:
		
		// pressed: 
		//  - REPULSION circulo y ATRACCION box: si dist-mouse < distMinima
		//  - ATRACCION circulo y REPULSION box: si dist-mouse > distMaxima
		// 
		
		// o poner los tuios impares con atraccion y los impares con repulsion
		float fFuerza = 5.0;
		if(mouse.distance(center)<distConf) {
			if(isMousePressed) {
				for(int i=0; i<circles.size(); i++) {
					float dis = mouse.distance(circles[i].get()->getPosition());
					if(dis < minDis) circles[i].get()->addRepulsionForce(mouse, 0.2f*fFuerza/dis);//3, 9);
					else circles[i].get()->addAttractionPoint(mouse, 4.2*fFuerza/dis);//4.0);
				}
				for(int i=0; i<boxes.size(); i++) {
					float dis = mouse.distance(boxes[i].get()->getPosition());
					if(dis < minDis) boxes[i].get()->addRepulsionForce(mouse, 1.8*fFuerza/dis);
					else boxes[i].get()->addRepulsionForce(mouse, 1.9*fFuerza/dis);//4.0);
				}
			}
			else {
				for(int i=0; i<circles.size(); i++) {
					float dis = mouse.distance(circles[i].get()->getPosition());
					if(dis < minDis) circles[i].get()->addAttractionPoint(mouse, 1.5*fFuerza/dis);//3, 9);
					else circles[i].get()->addRepulsionForce(mouse, 0.9*fFuerza/dis);//4.0);
				}
				for(int i=0; i<boxes.size(); i++) {
					float dis = mouse.distance(boxes[i].get()->getPosition());
					if(dis < minDis) boxes[i].get()->addAttractionPoint(mouse, 1.8*fFuerza/dis);
					else boxes[i].get()->addAttractionPoint(mouse, 1.9*fFuerza/dis);//4.0);
				}
			}
		}
		
		
		// = Fuerza de confinamiento
		for(int i=0; i<circles.size(); i++) {
			float dis = center.distance(circles[i].get()->getPosition());
			if(dis > distConf) circles[i].get()->addAttractionPoint(center, 0.9);//3, 9);
		}
		for(int i=0; i<boxes.size(); i++) {
			float dis = center.distance(boxes[i].get()->getPosition());
			if(dis > distConf) boxes[i].get()->addAttractionPoint(center, 0.9);//3, 9);
		}
	
	}
	
	bAddCircle=false;
	bAddBox=false;

}