当前位置: 首页>>代码示例>>C++>>正文


C++ Coord::motor_r方法代码示例

本文整理汇总了C++中Coord::motor_r方法的典型用法代码示例。如果您正苦于以下问题:C++ Coord::motor_r方法的具体用法?C++ Coord::motor_r怎么用?C++ Coord::motor_r使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Coord的用法示例。


在下文中一共展示了Coord::motor_r方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init_control

void init_control(Coord& _coord) {
  coord = &_coord;

  motor_r = &_coord.motor_r();
  motor_l = &_coord.motor_l();
  Point* pos = &_coord.pos();

  _w = motor_r->x + motor_l->x;
  _h = motor_l->y + motor_l->x;

  double dx = pos->x - motor_l->x;
  double dy = motor_l->y - pos->y;

  _ll = sqrt(dx*dx + dy*dy);

  dx = motor_r->x - pos->x;

  _lr = sqrt(dx*dx + dy*dy);
  
  glut_loop = new thread([]() {
      int argc = 1;
      char* argv = (char*)"";

      glutInit(&argc, &argv);
      glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);

      // Create the window
      glutInitWindowSize (500, 500);
      glutInitWindowPosition (100, 100);
      glutCreateWindow("V-Plotter Simulator");

      glClearColor(0.0, 0.0, 0.0, 0.0);
      
      glEnable(GL_DEPTH_TEST);

      timer(0);
      
      glutDisplayFunc([]() {
	  glClear(GL_COLOR_BUFFER_BIT);
	  glLoadIdentity();


	  // cout << "pos:     (" << pos->x << ";" << pos->y << ")" << endl;
	  // cout << "motor_l: (" << motor_l->x << ";" << motor_l->y << ")" << endl;
	  // cout << "motor_r: (" << motor_r->x << ";" << motor_r->y << ")" << endl;

	  // draw motors
	  glBegin(GL_QUADS);
	  glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	  glVertex3f( motor_l->x - 5,  motor_l->y - 5, 0);
	  glVertex3f( motor_l->x + 5,  motor_l->y - 5, 0);
	  glVertex3f( motor_l->x + 5,  motor_l->y + 5, 0);
	  glVertex3f( motor_l->x - 5,  motor_l->y + 5, 0);

	  glVertex3f( motor_r->x - 5,  motor_r->y - 5, 0);
	  glVertex3f( motor_r->x + 5,  motor_r->y - 5, 0);
	  glVertex3f( motor_r->x + 5,  motor_r->y + 5, 0);
	  glVertex3f( motor_r->x - 5,  motor_r->y + 5, 0);
	  glEnd();

	  // draw trace
	  glColor4f(0, 0, 1, 1);
	  for (auto trace : traces) {
	    glBegin(GL_LINE_STRIP);
	    for (Point* p : *trace)
	      glVertex3f(p->x, p->y, 0);
	    glEnd();
	  }

	  if (curr_trace) {
	    glBegin(GL_LINE_STRIP);
	    for (Point* p : *curr_trace)
	      glVertex3f(p->x, p->y, 0);
	    glEnd();
	  }

	  // draw printer
	  Point* pos = get_pos(*coord);
	  glBegin(GL_LINES);
	  if (curr_trace) glColor4f(0, 0, 1, 1);
	  else glColor3f(0, 1, 0);

	  glVertex3f(pos->x - 10, pos->y - 10, 0);
	  glVertex3f(pos->x + 10, pos->y + 10, 0);

	  glVertex3f(pos->x + 10, pos->y - 10, 0);
	  glVertex3f(pos->x - 10, pos->y + 10, 0);

	  // draw strings
	  glColor3f(1, 0, 0);
	  glVertex3f(motor_l->x, motor_l->y, 0);
	  glVertex3f(pos->x,     pos->y, 0);
	  
	  glVertex3f(motor_r->x, motor_r->y, 0);
	  glVertex3f(pos->x,     pos->y, 0);
	  glEnd();

	  glFlush();
	});

//.........这里部分代码省略.........
开发者ID:SchwarzChristian,项目名称:V-Plotter,代码行数:101,代码来源:control_sim.cpp


注:本文中的Coord::motor_r方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。