示例#1
0
void PendulumApplication::clientMoveAndDisplay()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//simple dynamics world doesn't handle fixed-time-stepping
	m_dt = getDeltaTimeMicroseconds()/1000000.f;
	temp += m_dt;
	///step the simulation
	if (m_dynamicsWorld)
	{
		m_dynamicsWorld->stepSimulation(m_dt);
		//optional but useful: debug drawing
		m_dynamicsWorld->debugDrawWorld();
	}
	btTransform trans;
	m_pendulumBody->getMotionState()->getWorldTransform(trans);
	Integrator_rk4();
	trans.getOrigin() = btVector3(0,20,0)+pol2cart(m_r.m_value,m_theta.m_value);
	//printf("%f %f %f\n",m_position.x(),m_po sition.y(),m_position.z());
	m_pendulumBody->getMotionState()->setWorldTransform(trans);
    m_r.m_value = m_r.m_value + 0.1 * sin (temp);
	//draw the rope
	btVector3 anchor(0,20,0);
	glLineWidth(2.0);
	glBegin(GL_LINES);
	glVertex3fv(anchor.m_floats);
	glVertex3fv(trans.getOrigin());
	glEnd();

	renderme();
	swapBuffers();
}
示例#2
0
文件: ex1.c 项目: ZhaoXiyu/UMJI-VG101
int main(){
	ComplexCart zcs[]={{3,4.0/5.0},{0,log(4)},{45.245,0.235}};
	ComplexPol zcd[sizeof(zcs)/sizeof(ComplexCart)]={0};
	ComplexPol zps[]={{3.0,PI/17.0},{4,PI/9},{1,PI/12}};
	ComplexCart zpd[sizeof(zps)/sizeof(ComplexPol)]={0};
	cart2pol(zcs,zcd,sizeof(zcs)/sizeof(ComplexCart));
	pol2cart(zps,zpd,sizeof(zps)/sizeof(ComplexPol));
	return 0;
}
示例#3
0
int main(int argc, char** argv)
{
	double r=0, phi=0, z[2];
	
	printf("Input r: ");
	scanf("%lf", &r);
	printf("Input phi: ");
	scanf("%lf", &phi);

	pol2cart(r, phi, z);

	printf("Point z = (a,b) is: (%.2f, %.2f)\n", z[0], z[1]);

	return EXIT_SUCCESS;
}
示例#4
0
文件: display.c 项目: rogerhu/dd-wrt
void draw_graphics(struct gps_data_t *gpsdata)
{
    int i, x, y;
    char buf[20];

    if (gpsdata->satellites != 0) {
	i = (int)min(width, height);

	set_color("White");
	(void)XFillRectangle(XtDisplay(draww),pixmap,drawGC,0,0,width,height);

	/* draw something in the center */
	set_color("Grey");
	draw_arc(width / 2, height / 2, 6);

	/* draw the 45 degree circle */
#ifdef PCORRECT
#define FF	0.7 /* sin(45) ~ 0.7 */
#else
#define FF	0.5
#endif
	draw_arc(width / 2, height / 2, (unsigned)((i - RM) * FF));
#undef FF

	set_color("Black");
	draw_arc(width / 2, height / 2, (unsigned)(i - RM));

	pol2cart(0, 0, &x, &y);
	set_color("Black");
	(void)XDrawString(XtDisplay(draww),pixmap, drawGC, x, y, "N", 1);
	pol2cart(90, 0, &x, &y);
	set_color("Black");
	(void)XDrawString(XtDisplay(draww),pixmap, drawGC, x+2, y, "E", 1);
	pol2cart(180, 0, &x, &y);
	set_color("Black");
	(void)XDrawString(XtDisplay(draww),pixmap, drawGC, x, y+10, "S", 1);
	pol2cart(270, 0, &x, &y);
	set_color("Black");
	(void)XDrawString(XtDisplay(draww),pixmap, drawGC, x-5,y, "W", 1);

	/* Now draw the satellites... */
	for (i = 0; i < gpsdata->satellites; i++) {
	    pol2cart((double)gpsdata->azimuth[i], 
		     (double)gpsdata->elevation[i], 
		     &x, &y);
	    if (gpsdata->ss[i] < 10) 
		set_color("Black");
	    else if (gpsdata->ss[i] < 30)
		set_color("Red");
	    else if (gpsdata->ss[i] < 35)
		set_color("Yellow");
	    else if (gpsdata->ss[i] < 40)
		set_color("Green3");
	    else
		set_color("Green1");
	    if (gpsdata->PRN[i] > GPS_PRNMAX) {
		/* SBAS satellites */
		XPoint vertices[5];
		/*@ -type @*/
		vertices[0].x = x;
		vertices[0].y = y-IDIAM;
		vertices[1].x = x+IDIAM;
		vertices[1].y = y;
		vertices[2].x = x;
		vertices[2].y = y+IDIAM;
		vertices[3].x = x-IDIAM;
		vertices[3].y = y;
		vertices[4].x = x;
		vertices[4].y = y-IDIAM;
		/*@ +type -compdef @*/
		if (gpsdata->used[i])
		    (void)XFillPolygon(XtDisplay(draww), pixmap, drawGC,
				       vertices, 5, Convex, CoordModeOrigin);
		else
		    (void)XDrawLines(XtDisplay(draww), pixmap, drawGC,
				     vertices, 5, CoordModeOrigin);
	    } else {
		/* ordinary GPS satellites */
		if (gpsdata->used[i])
		    (void)XFillArc(XtDisplay(draww), pixmap, drawGC,
			   x - IDIAM, y - IDIAM,	/* x,y */
			   2*IDIAM+1, 2*IDIAM+1,	/* width, height */
			   0, 360 * 64			/* angle1, angle2 */
			);
		else
		    (void)XDrawArc(XtDisplay(draww), pixmap, drawGC,
			   x - IDIAM, y - IDIAM,	/* x,y */
			   2*IDIAM+1, 2*IDIAM+1,	/* width, height */
			   0, 360 * 64			/* angle1, angle2 */
			);
	    }
	    /*@ +compdef @*/
	    (void)snprintf(buf, sizeof(buf), "%-3d", gpsdata->PRN[i]);
	    set_color("Black");
	    (void)XDrawString(XtDisplay(draww), pixmap, drawGC, x,y+17, buf,3);
		
	}
	(void)XCopyArea(XtDisplay(draww), pixmap, XtWindow(draww), drawGC,
		  0, 0, width, height, 0, 0);
    }
}
示例#5
0
void SkyView::paintEvent(QPaintEvent *)
{
	// Draw stuff in drawing area
	int w= width();
	int h= height();
	QPainter painter(this);
	painter.setPen(Qt::gray);
	QRect r1(0, 0, w-1, h-1);
	QBrush br1(Qt::white);
	painter.fillRect(r1, br1);

	draw_arc(painter, w/2, h / 2, 6);

	// draw the 45 degree circle
	int i = min(w, h);
	draw_arc(painter, w / 2, h / 2, (unsigned)((i - RM) * 0.7));

	painter.setPen(Qt::black);
	draw_arc(painter, w / 2, h / 2, (unsigned)(i - RM));
	
	int x, y;
	pol2cart(w, h, 0, 0, &x, &y);
	painter.drawText(x, y, "N");
	pol2cart(w, h, 90, 0, &x, &y);
	painter.drawText(x + 2, y, "E");
	pol2cart(w, h, 180, 0, &x, &y);
	painter.drawText(x, y + 10, "S");
	pol2cart(w, h, 270, 0, &x, &y);
	painter.drawText(x - 5, y, "W");

	if(gpsdata == NULL)
		return;

	QFont serifFont("Times", 6);
	painter.setFont(serifFont);
	
	/* Now draw the satellites... */
	for (int i = 0; i < gpsdata->satellites_visible; i++) {
		QColor col;
		pol2cart(w, h, (double)gpsdata->azimuth[i], 
				 (double)gpsdata->elevation[i], &x, &y);
		if (gpsdata->ss[i] < 10) 
			col= Qt::black;
		else if (gpsdata->ss[i] < 30)
			col= Qt::red;
		else if (gpsdata->ss[i] < 35)
			col= Qt::yellow;
		else if (gpsdata->ss[i] < 40)
			col= Qt::darkGreen;
		else
			col= Qt::green;

		painter.setPen(col);
		br1.setColor(col);
		painter.setBrush(br1);

		if (gpsdata->PRN[i] > GPS_PRNMAX) {
				/* SBAS satellites */
			QPoint vertices[5];

			vertices[0].setX(x);
			vertices[0].setY(y-IDIAM);
			vertices[1].setX(x+IDIAM);
			vertices[1].setY(y);
			vertices[2].setX(x);
			vertices[2].setY(y+IDIAM);
			vertices[3].setX(x-IDIAM);
			vertices[3].setY(y);
			vertices[4].setX(x);
			vertices[4].setY(y-IDIAM);

	
			if (gpsdata->used[i])
				painter.drawPolygon(vertices, 4);
			else
				painter.drawPolyline(vertices, 5);
	
		} else {
				/* ordinary GPS satellites */
			if (gpsdata->used[i])
				painter.drawChord(x - IDIAM, y - IDIAM, 2 * IDIAM + 1, 2 * IDIAM + 1, 0, 360 * 64);
			else
				painter.drawArc(x - IDIAM, y - IDIAM, 2 * IDIAM + 1, 2 * IDIAM + 1, 0, 360 * 64);
		}
		QString buf;
		buf.setNum(gpsdata->PRN[i]);
		painter.setPen(Qt::black);
		painter.drawText(x, y+14, buf);
	}
}