Ejemplo n.º 1
0
/*
 * this draws a backing rectangle for the plot and it
 * also creates a new svg element so our offsets can
 * be relative to this one plot.
 */
void setup_axis(struct plot *plot)
{
	int len;
	int fd = plot->fd;
	int bump_height = tick_font_size * 3 + axis_label_font_size;
	int local_legend_width = legend_width;

	if (plot->no_legend)
		local_legend_width = 0;

	plot->total_width = axis_x_off(graph_width) + graph_left_pad / 2 + local_legend_width;
	plot->total_height = axis_y() + tick_label_pad + tick_font_size;

	if (plot->add_xlabel)
		plot->total_height += bump_height;

	/* backing rect */
	snprintf(line, line_len, "<rect x=\"%d\" y=\"%d\" width=\"%d\" "
		 "height=\"%d\" fill=\"white\" stroke=\"none\"/>",
		 plot->start_x_offset,
		plot->start_y_offset, plot->total_width + 40,
		plot->total_height + 20);
	len = strlen(line);
	write_check(fd, line, len);

	snprintf(line, line_len, "<rect x=\"%d\" y=\"%d\" width=\"%d\" "
		 "filter=\"url(#shadow)\" "
		 "height=\"%d\" fill=\"white\" stroke=\"none\"/>",
		 plot->start_x_offset + 15,
		plot->start_y_offset, plot->total_width, plot->total_height);
	len = strlen(line);
	write_check(fd, line, len);
	plot->total_height += 20;
	plot->total_width += 20;

	if (plot->total_height + plot->start_y_offset > final_height)
		final_height = plot->total_height + plot->start_y_offset;
	if (plot->start_x_offset + plot->total_width + 40 > final_width)
		final_width = plot->start_x_offset + plot->total_width + 40;

	/* create an svg object for all our coords to be relative against */
	snprintf(line, line_len, "<svg x=\"%d\" y=\"%d\">\n", plot->start_x_offset, plot->start_y_offset);
	write_check(fd, line, strlen(line));

	snprintf(line, 1024, "<path d=\"M%d %d h %d V %d H %d Z\" stroke=\"black\" stroke-width=\"2\" fill=\"none\"/>\n",
		 axis_x(), axis_y(),
		 graph_width + graph_inner_x_margin * 2, axis_y_off(graph_height) - graph_inner_y_margin,
		 axis_x());
	len = strlen(line);
	write_check(fd, line, len);
}
Ejemplo n.º 2
0
void set_xlabel(struct plot *plot, char *label)
{
	int len;
	int fd = plot->fd;
	snprintf(line, line_len, "<text x=\"%d\" y=\"%d\" font-family=\"%s\" "
		 "font-weight=\"bold\" "
		 "font-size=\"%d\" fill=\"black\" style=\"text-anchor: %s\">%s</text>\n",
		 axis_x_off(graph_width / 2),
		 axis_y() + tick_font_size * 3 + axis_label_font_size / 2,
		 font_family,
		 axis_label_font_size, "middle", label);
	len = strlen(line);
	write_check(fd, line, len);

}
Ejemplo n.º 3
0
void onIdle() {
  float angle = glutGet(GLUT_ELAPSED_TIME) / 1000.0 * 45;  // 45° per second
  glm::vec3 axis_y(0, 1, 0);
  glm::mat4 anim = glm::rotate(glm::mat4(1.0f), glm::radians(angle), axis_y);

  glm::mat4 model = glm::translate(glm::mat4(1.0f), glm::vec3(0.0, 0.0, -4.0));
  glm::mat4 view = glm::lookAt(glm::vec3(0.0, 2.0, 0.0), glm::vec3(0.0, 0.0, -4.0), glm::vec3(0.0, 1.0, 0.0));
  glm::mat4 projection = glm::perspective(45.0f, 1.0f*screen_width/screen_height, 0.1f, 10.0f);

  glm::mat4 mvp = projection * view * model * anim;

  glUseProgram(program);
  glUniformMatrix4fv(uniform_mvp, 1, GL_FALSE, glm::value_ptr(mvp));
  glutPostRedisplay();
}
Ejemplo n.º 4
0
// TODO: Remove hardcoded values
inline void flua_setTransform(
    GLint flua_transformAttr,
    BPVector3<Float>* pos,
    BPVector3<Float>* rot)
{
    //float angle = glutGet(GLUT_ELAPSED_TIME) / 1000.0 * 15;  // 45° per second
    glm::vec3 axis_y(0.0, 1.0, 0.0);
    glm::mat4 rotation = \
                         glm::rotate(flua_identityMatrix, rot->_x, flua_xAxis) *  // X axis
                         glm::rotate(flua_identityMatrix, rot->_y, flua_yAxis) *  // Y axis
                         glm::rotate(flua_identityMatrix, rot->_z, flua_zAxis);   // Z axis

    glm::mat4 translation = glm::translate(flua_identityMatrix, glm::vec3(pos->_x, pos->_y, -pos->_z));
    glm::mat4 mvp = flua_viewAndProjectionMatrix * translation * rotation;

    glUniformMatrix4fv(flua_transformAttr, 1, GL_FALSE, glm::value_ptr(mvp));
}
Ejemplo n.º 5
0
void idle ()
{
  glm::mat4 model = glm::translate (glm::mat4 (1.0f), glm::vec3 (0.0, 0.0, -4.0));
  glm::mat4 view = glm::lookAt (glm::vec3 (0.0, 2.0, 0.0), glm::vec3 (0.0, 0.0, -4.0), glm::vec3 (0.0, 1.0, 0.0));
  glm::mat4 projection = glm::perspective (45.0f, 1.0f*screen_width/screen_height, 0.1f, 10.0f);
  float angle = glutGet (GLUT_ELAPSED_TIME) / 1000.0 * 45;  // 45 degree per second
  glm::vec3 axis_y (0, 1.0, 0);
  glm::mat4 anim = \
    glm::rotate(glm::mat4(1.0f), angle*3.0f, glm::vec3(1, 0, 0)) *  // X axis
    glm::rotate(glm::mat4(1.0f), angle*2.0f, glm::vec3(0, 1, 0)) *  // Y axis
    glm::rotate(glm::mat4(1.0f), angle*4.0f, glm::vec3(0, 0, 1));   // Z axis
  glm::mat4 mvp = projection * view * model * anim;
  //  float move = sinf (glutGet (GLUT_ELAPSED_TIME) / 1000.0 * (2*3.14) /5);
  
  glUseProgram (program);
  glUniformMatrix4fv (uniform_mvp, 1, GL_FALSE, glm::value_ptr(mvp));
  glutPostRedisplay ();
}
Ejemplo n.º 6
0
void idle()
{
	glm::mat4 model = glm::translate(glm::mat4(1.0f), glm::vec3(0.0, 0.0, -4.0));
	glm::mat4 view = glm::lookAt(glm::vec3(0.0, 2.0, 0.0), glm::vec3(0.0, 0.0, -4.0), glm::vec3(0.0, 1.0, 0.0));
	glm::mat4 projection = glm::perspective(45.0f, 1.0f*screen_width/screen_height, 0.1f, 10.0f);

	float angle = glutGet(GLUT_ELAPSED_TIME) / 1000.0 *45; //bring this line back.
	glm::vec3 axis_y(0.0, 1.0, 0.0);//the axis we are gong to spin about.
	glm::mat4 anim = glm::rotate(glm::mat4(1.0f), angle, axis_y);
	//do the maths to get the rotation matrix
	glm::mat4 mvp = projection * view * model * anim;//and add it into the global matrix
		//now, if we were to do this in a game, that would result in the entire world
		//rotating. maybe that's what you want, in which case, this is how you do it. but 
		//to rotate a single object, this is not how you would actually do it. but it is 
		//quick and simple and works for now, so it will do for now.
	glUniformMatrix4fv(uniform_mvp, 1, GL_FALSE, glm::value_ptr(mvp));
	glUseProgram(program);
	glutPostRedisplay();
}
Ejemplo n.º 7
0
/*
 * this draws a backing rectangle for the plot and it
 * also creates a new svg element so our offsets can
 * be relative to this one plot.
 */
void setup_axis_spindle(struct plot *plot)
{
	int len;
	int fd = plot->fd;
	int bump_height = tick_font_size * 3 + axis_label_font_size;

	legend_x_off = -60;

	plot->total_width = axis_x_off(graph_width) + legend_width;
	plot->total_height = axis_y() + tick_label_pad + tick_font_size;

	if (plot->add_xlabel)
		plot->total_height += bump_height;

	/* backing rect */
	snprintf(line, line_len, "<rect x=\"%d\" y=\"%d\" width=\"%d\" "
		 "height=\"%d\" fill=\"white\" stroke=\"none\"/>",
		 plot->start_x_offset,
		plot->start_y_offset, plot->total_width + 10,
		plot->total_height + 20);
	len = strlen(line);
	write_check(fd, line, len);

	snprintf(line, line_len, "<rect x=\"%d\" y=\"%d\" width=\"%d\" "
		 "filter=\"url(#shadow)\" "
		 "height=\"%d\" fill=\"white\" stroke=\"none\"/>",
		 plot->start_x_offset + 15,
		plot->start_y_offset, plot->total_width - 30,
		plot->total_height);
	len = strlen(line);
	write_check(fd, line, len);
	plot->total_height += 20;

	if (plot->total_height + plot->start_y_offset > final_height)
		final_height = plot->total_height + plot->start_y_offset;
	if (plot->start_x_offset + plot->total_width + 40 > final_width)
		final_width = plot->start_x_offset + plot->total_width + 40;

	/* create an svg object for all our coords to be relative against */
	snprintf(line, line_len, "<svg x=\"%d\" y=\"%d\">\n", plot->start_x_offset, plot->start_y_offset);
	write_check(fd, line, strlen(line));

}
Ejemplo n.º 8
0
/*
 * create evenly spread out ticks along the xaxis.  if tick only is set
 * this just makes the ticks, otherwise it labels each tick as it goes
 */
void set_xticks(struct plot *plot, int num_ticks, int first, int last)
{
	int pixels_per_tick;
	double step;
	int i;
	int tick_y = axis_y_off(graph_tick_len) + graph_inner_y_margin;
	int tick_x = axis_x();
	int tick_only = plot->add_xlabel == 0;

	int text_y = axis_y() + tick_label_pad;

	char *middle = "middle";
	char *start = "start";

	step = find_step(first, last, num_ticks);
	/*
	 * We don't want last two ticks to be too close together so subtract
	 * 20% of the step from the interval
	 */
	num_ticks = (double)(last - first - step) / step + 1;
	pixels_per_tick = graph_width * step / (double)(last - first);

	for (i = 0; i < num_ticks; i++) {
		char *anchor;
		if (i != 0) {
			snprintf(line, line_len, "<rect x=\"%d\" y=\"%d\" width=\"2\" height=\"%d\" style=\"stroke:none;fill:black;\"/>\n",
				tick_x, tick_y, graph_tick_len);
			write_check(plot->fd, line, strlen(line));
			anchor = middle;
		} else {
			anchor = start;
		}

		if (!tick_only) {
			if (step >= 1)
				snprintf(line, line_len, "<text x=\"%d\" y=\"%d\" font-family=\"%s\" font-size=\"%d\" "
					"fill=\"black\" style=\"text-anchor: %s\">%d</text>\n",
					tick_x, text_y, font_family, tick_font_size, anchor,
					(int)(first + step * i));
			else
				snprintf(line, line_len, "<text x=\"%d\" y=\"%d\" font-family=\"%s\" font-size=\"%d\" "
					"fill=\"black\" style=\"text-anchor: %s\">%.2f</text>\n",
					tick_x, text_y, font_family, tick_font_size, anchor,
					first + step * i);
			write_check(plot->fd, line, strlen(line));
		}
		tick_x += pixels_per_tick;
	}

	if (!tick_only) {
		if (step >= 1)
			snprintf(line, line_len, "<text x=\"%d\" y=\"%d\" font-family=\"%s\" font-size=\"%d\" "
				"fill=\"black\" style=\"text-anchor: middle\">%d</text>\n",
				axis_x_off(graph_width - 2),
				text_y, font_family, tick_font_size, last);
		else
			snprintf(line, line_len, "<text x=\"%d\" y=\"%d\" font-family=\"%s\" font-size=\"%d\" "
				"fill=\"black\" style=\"text-anchor: middle\">%.2f</text>\n",
				axis_x_off(graph_width - 2),
				text_y, font_family, tick_font_size, (double)last);
		write_check(plot->fd, line, strlen(line));
	}
}
Ejemplo n.º 9
0
void display (void) {
  movement();
  for (int i=0; i<NUMENTITIES; i++) {
    entitiesArray[i]->update(entitiesArray, NUMENTITIES);
  }


  glm::vec3 axis_y(0, 1, 0);
  glm::mat4 anim;

  glm::mat4 model;
  glm::mat4 projection;
  glm::mat4 current_mvp;

  glClearColor(1.0, 1.0, 1.0, 1.0);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  
	//1st screen top
  glViewport(0, SCREENHEIGHT/2+1, SCREENWIDTH, SCREENHEIGHT/2);
  view = glm::lookAt(player1->viewSrc, player1->viewDest, player1->viewUp);
  projection = glm::perspective(45.0f, 1.0f*SCREENWIDTH/SCREENHEIGHT, 0.1f, 100.0f);
  //Map
  DrawTrack();

  //PLAYER1
  anim = glm::rotate(glm::mat4(1.0f),degToRad(player1->angle), axis_y);

  model = glm::translate(glm::mat4(1.0f), player1->pos);
  current_mvp = projection * view * model * anim;

 drawObject(player1, current_mvp, model, view);

 //PLAYER2
 anim = glm::rotate(glm::mat4(1.0f), degToRad(player2->angle), axis_y);
 model = glm::translate(glm::mat4(1.0f), player2->pos);
 current_mvp = projection * view * model * anim;

 drawObject(player2, current_mvp, model, view);

  //Weapon
  if(WeaTimer < 5000){
	 anim = glm::rotate(glm::mat4(1.0f), degToRad(weapon->angle), axis_y);
	 model = glm::translate(glm::mat4(1.0f), weapon->pos);
	 current_mvp = projection * view * model * anim;

	 drawObject(weapon, current_mvp, model, view);
  }
  if(WeaTimer2 < 5000){
	 anim = glm::rotate(glm::mat4(1.0f), degToRad(weapon2->angle), axis_y);
	 model = glm::translate(glm::mat4(1.0f), weapon2->pos);
	 current_mvp = projection * view * model * anim;

	 drawObject(weapon2, current_mvp, model, view);
  }


//---------------------------


	//2ed screen, bottom
  glViewport(0, 0, SCREENWIDTH, SCREENHEIGHT/2);
  view = glm::lookAt(player2->viewSrc, player2->viewDest, player2->viewUp);
  //Map
  DrawTrack();

  //PLAYER1
  anim = glm::rotate(glm::mat4(1.0f),degToRad(player1->angle), axis_y);
  model = glm::translate(glm::mat4(1.0f), player1->pos);
  current_mvp = projection * view * model * anim;

 drawObject(player1, current_mvp, model, view);

 //PLAYER2
 anim = glm::rotate(glm::mat4(1.0f),degToRad(player2->angle) , axis_y);
 model = glm::translate(glm::mat4(1.0f), player2->pos);
 current_mvp = projection * view * model * anim;

 drawObject(player2, current_mvp, model, view);

  if(WeaTimer < 5000){
	 anim = glm::rotate(glm::mat4(1.0f), degToRad(weapon->angle), axis_y);
	 model = glm::translate(glm::mat4(1.0f), weapon->pos);
	 current_mvp = projection * view * model * anim;

	 drawObject(weapon, current_mvp, model, view);
  }
  if(WeaTimer2 < 5000){
	 anim = glm::rotate(glm::mat4(1.0f), degToRad(weapon2->angle), axis_y);
	 model = glm::translate(glm::mat4(1.0f), weapon2->pos);
	 current_mvp = projection * view * model * anim;

	 drawObject(weapon2, current_mvp, model, view);
  }


 glutSwapBuffers();
}
Ejemplo n.º 10
0
QImage Plotter::makePlot()
{
  QImage img=QImage(width,height,QImage::Format_RGB32);
  img.fill(0xffffff);
  QPainter painter(&img);
  painter.setFont(QFont(painter.font().family(),_fs));
  //Отступы
  QFontMetrics metrics(painter.font());
  std::vector<int> lens;
  foreach(QString str,_text_y)
    lens.push_back(str.size());

  float ident_left;
  std::vector<int>::const_iterator it, it2;
  for(int i=0;i<lens.size(); i++)
  {
    it2 = std::max_element(lens.begin(), lens.end());
    if(lens.at(i)==*it2)
    {
      ident_left=metrics.width(_text_y[i])+metrics.width(_text_y[i])/5;
      break;
    }
  }

  float ident_right=metrics.width(_text_x[_text_x.size()-1])+metrics.width(_text_x[_text_x.size()-1])/5;

  //Шаги и отступы снизу и сверху
  float step_x=(width-ident_right-ident_left)/_text_x.size();
  float step_y=height/(_text_y.size()+1);
  float ident_bottom=step_y+_fs;
  float ident_top=step_y+_fs;
  step_y=(height-ident_top-ident_bottom)/(_text_y.size());
  //Оси
  QLineF axis_x(ident_left,height-ident_bottom,width-ident_right,height-ident_bottom);
  QLineF axis_y(ident_left,height-ident_bottom,ident_left,ident_top);

  //Черточки и подписи
  QVector<QLineF> x_hyphen;
  float hx_size=step_x/10;
  float hy_size=step_y/10;
  QList<QRectF> text_x_pos;

  QStringList sl_x = _text_x.split(";",QString::SkipEmptyParts);
  for(int i=0; i<sl_x.size();i++)
  {
    if(i<sl_x.size()-1)
      x_hyphen.append(QLineF(ident_left+(i+1)*step_x,height-ident_bottom-hx_size,ident_left+(i+1)*step_x,height-ident_bottom));

    QFontMetrics metrics(painter.font());

    if(i==sl_x.size()-1)
    {
      text_x_pos.append(QRectF(ident_left+(i+1)*step_x,height-ident_bottom+_fs+hy_size*2,step_x,ident_bottom-_fs-hy_size*2));
      //text_x_pos.append(QRectF(x,y,w,h))
    }
    else
    {
      //text_x_pos.append(QPointF(ident_left+(i+1)*step_x-metrics.width(text_x[i])/2,height-ident_bottom+font+hy_size*2))
      text_x_pos.append(QRectF(ident_left+(i+1)*step_x-metrics.width(sl_x[i])/2,height-ident_bottom+_fs+hy_size*2,step_x,ident_bottom-_fs-hy_size*2));
    }
  }

  QVector<QLineF> y_hyphen;
  QList<QPointF> text_y_pos;
  QStringList sl_y = _text_y.split(";",QString::SkipEmptyParts);
  for(int i=0; i<sl_y.size();i++)
  {
    if(i<sl_y.size()-1)
      y_hyphen.append(QLineF(ident_left,height-ident_bottom-(i+1)*step_y,ident_left+hy_size,height-ident_bottom-(i+1)*step_y));

    QFontMetrics metrics(painter.font());

    if(i==sl_y.size()-1)
      text_y_pos.append(QPointF(ident_left-metrics.width(sl_y[i])/2,ident_top/2+_fs/2));
    else
      text_y_pos.append(QPointF(ident_left-metrics.width(sl_y[i])-hy_size,height-ident_bottom-(i+1)*step_y+_fs/2));
  }

  //Точки графика
  QVector<QPoint> graph_points;
  QVector<QLineF> dot_line_x;
  QVector<QLineF> dot_line_y;

  int dataCount = scriptEngine->evaluate("results.length").toInteger();


  for(int i=0;i<dataCount; i++)
  {
    QScriptValue index = QScriptValue(i);
    scriptEngine->globalObject().setProperty("index",index);
    float curResult = (float)scriptEngine->evaluate("results[index]").toNumber();

    graph_points.append(QPoint(ident_left+step_x*(i+1),height-(ident_bottom+curResult*step_y)));
    dot_line_x.append(QLineF(QPointF(ident_left,graph_points[graph_points.size()-1].y()),graph_points[graph_points.size()-1]));
    dot_line_y.append(QLineF(QPointF(graph_points[graph_points.size()-1].x(),height-ident_bottom),graph_points[graph_points.size()-1]));
  }

  //Перья для рисования
  QPen axis_pen(Qt::black);
  axis_pen.setWidth(4);

  QPen dot_pen(Qt::black);
  dot_pen.setWidth(1);
  dot_pen.setStyle(Qt::DotLine);

  QPen main_pen(Qt::black);
  main_pen.setWidth(2);

  QPen point_pen(Qt::red);
  point_pen.setWidth(4);

  //Рисуем
  //Оси
  painter.setRenderHint(QPainter::Antialiasing);
  painter.setPen(axis_pen);
  painter.drawLine(axis_x);
  painter.drawLine(axis_y);
  //Черточки и подписи
  painter.setPen(main_pen);
  painter.drawLines(x_hyphen);
  painter.drawLines(y_hyphen);
  for(int i=0; i<text_x_pos.size(); i++)
  {
    if(i==text_x_pos.size()-1)
    {
      QFont nf(painter.font());
      nf.setWeight(QFont::Bold);
      painter.setFont(nf);
      painter.drawText(text_x_pos[i],QString(sl_x[i]));
      nf.setWeight(QFont::Normal);
      painter.setFont(nf);
    }
    else
      painter.drawText(text_x_pos[i],Qt::TextWordWrap,QString(sl_x[i]));
  }

  for(int i=0;i<text_y_pos.size();i++)
  {
    if(i==text_y_pos.size()-1)
    {
      QFont nf(painter.font());
      nf.setWeight(QFont::Bold);
      painter.setFont(nf);
      painter.drawText(text_y_pos[i],QString(sl_y[i]));
      nf.setWeight(QFont::Normal);
      painter.setFont(nf);
    }
    else
      painter.drawText(text_y_pos[i],QString(sl_y[i]));
  }
  //График
  QPolygon p(graph_points);
  painter.drawPolyline(p);
  //Пунктирные линии
  painter.setRenderHint(QPainter::Antialiasing,false);
  painter.setPen(dot_pen);
  painter.drawLines(dot_line_x);
  painter.drawLines(dot_line_y);
  //Точки графика
  painter.setRenderHint(QPainter::Antialiasing);
  painter.setPen(point_pen);
  painter.drawPoints(p);
  return img;
}