Example #1
0
void draw_line(Raycreator* rc, Coord start, Coord end, Color color){
  double s[2], e[2];

  get_screen_pos(rc, start, s);
  get_screen_pos(rc, end, e);

  glColor4f(color.r,color.g,color.b,color.a);
  glBegin(GL_LINES);
  glVertex3f(s[0], s[1], 0);
  glVertex3f(e[0],e[1], 0);
  glEnd();
}
int ShapeEditor::get_closest_point( QPoint p_pos ) {
	
	int move_idx=-1;
		
	float closest=999999;
	for (int i=0;i<shape->get_stream_size();i++) {
		
			
		QPoint pos=get_screen_pos( shape->get_index_pos( i ), shape->get_index_value( i ) );
		
		float dist=sqrtf( powf(pos.x()-p_pos.x(),2.0) + powf(pos.y()-p_pos.y(),2.0) );
			
		if (dist<closest && dist<GRAB_NEAR_TO) {
				
			closest=dist;
			move_idx=i;
		}
	}
	
	return move_idx;
}
void ShapeEditor::paintEvent(QPaintEvent *e) {
	
	QPainter p(this);
	
	if (skin.bg.isNull())
		p.fillRect(0,0,width(),height(),skin.bg_col);
	else
		p.drawPixmap(0,0,skin.bg);
	
	if (!shape)
		return;
	
	int w=width();
	
	int h=height();
	
	p.setPen( skin.zero_col );
	
	float none,zero;
	
	QPoint zerop=get_screen_pos( 0, skin.zero_pos );
	
	p.drawLine( 0, zerop.y(), width(), zerop.y() );
	
	p.setPen( skin.line_col );
	
	int prev_y;
	for (int i=0;i<w;i++) {
		
		float c=(float)i/(float)w;
		
		float v=shape->get_value( c );
		
		v-=shape->get_min();
		v/=shape->get_max()-shape->get_min();
		
		int y = lrint(v*(float)h);
		
		if (shape->has_display_inverted())
			y=h-y;
		
		
		if (i==0)
			prev_y=y;
		p.drawLine(i,prev_y,i,y);
		
		prev_y=y;

	}
		
	QPen pen( skin.point_col );
	pen.setWidth(3);
	p.setPen( pen );
	
	for (int i=0;i<shape->get_stream_size();i++) {
		
		QPoint pos=get_screen_pos( shape->get_index_pos( i ), shape->get_index_value( i ) );
		
		p.drawPoint(pos);
		
	}
	
}
Example #4
0
void draw_wireframe(Raycreator* rc, Ranges* r){
  if(GRID_ON == 0){
    return;
  }

  double base_x = r->xmin, base_y = r->ymin, base_z = r->zmin;
  if(GRID_BASE == 0){
    base_x = get_base(r->xmin);
    base_y = get_base(r->ymin);
    base_z = get_base(r->zmin);
  }

  if(GRID_SPACING < 0){
    GRID_SPACING = (r->xmax - r->xmin)/3.0;
  }
  int ys = floor((r->ymax - base_y)/GRID_SPACING) + 1;
  int xs = floor((r->xmax - base_x)/GRID_SPACING) + 1;
  int zs = floor((r->zmax - base_z)/GRID_SPACING) + 1;

  Coord max_corner;
  double max_distance = -1;
  for(int corner_x = 0; corner_x < 2; corner_x++){
    for(int corner_y = 0; corner_y < 2; corner_y++){
      for(int corner_z = 0; corner_z < 2; corner_z++){
        Coord corner;
        corner.x = (corner_x == 0) ? r->xmin : r->xmax;
        corner.y = (corner_y == 0) ? r->ymin : r->ymax;
        corner.z = (corner_z == 0) ? r->zmin : r->zmax;

        double new_distance = distance_Coord(rc->eye, corner);
        if(max_distance < new_distance){
          max_corner = corner;
          max_distance = new_distance;
        }
      }
    }
  }

  Coord start, end;
  Color color = {1.0,1.0,1.0,1.0};

  start = max_corner;
  start.x = r->xmin;
  end = max_corner;
  end.x = r->xmax;

  draw_line(rc, start, end, color);

  color.a = 0.3;
  for(int c = 0; c < xs; c++){
    start = max_corner;
    end = max_corner;

    start.x = base_x + c * GRID_SPACING;
    end.x = start.x;
    end.x = start.x;

    start.z = r->zmin;
    end.z = r->zmax;

    draw_line(rc, start, end, color);

    start = max_corner;
    end = max_corner;

    start.x = base_x + c * GRID_SPACING;
    end.x = start.x;

    start.y = r->ymin;
    end.y = r->ymax;

    draw_line(rc, start, end, color);
  }


  start = max_corner;
  start.y = r->ymin;
  end = max_corner;
  end.y = r->ymax;

  color.a = 1.0;
  draw_line(rc, start, end, color);
  color.a = 0.3;

  for(int c = 0; c < ys; c++){
    start = max_corner;
    end = max_corner;

    start.y = base_y + c * GRID_SPACING;
    end.y = start.y;

    start.z = r->zmin;
    end.z = r->zmax;

    draw_line(rc, start, end, color);

    start = max_corner;
    end = max_corner;

    start.y = base_y + c * GRID_SPACING;
    end.y = start.y;

    start.x = r->xmin;
    end.x = r->xmax;

    draw_line(rc, start, end, color);
  }


  start = max_corner;
  start.z = r->zmin;
  end = max_corner;
  end.z = r->zmax;

  color.a = 1.0;
  draw_line(rc, start, end, color);
  color.a  = 0.3;

  for(int c = 0; c < zs; c++){
    start = max_corner;
    end = max_corner;

    start.z = base_z + c * GRID_SPACING;
    end.z = start.z;

    start.x = r->xmin;
    end.x = r->xmax;

    draw_line(rc, start, end, color);

    start = max_corner;
    end = max_corner;

    start.z = base_z + c * GRID_SPACING;
    end.z = start.z;

    start.y = r->ymin;
    end.y = r->ymax;

    draw_line(rc, start, end, color);
  }

  char n[20];
  if(NUMBERS){
    glRasterPos2f(-1,-1);
    glColor4f(1.0,1.0,1.0,1.0);
    glutBitmapString(GLUT_BITMAP_HELVETICA_18, "HACK");

    Coord pos;
    double p[2];
    pos = max_corner;
    for(double c = 0; c < xs; c++){
      pos.x = base_x + c * GRID_SPACING;
      get_screen_pos(rc, pos, p);
      glRasterPos2f(p[0],p[1]);
      glColor4f(1.0,1.0,1.0,1.0);
      sprintf(n, "%2.2f", pos.x);
      glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, n);
      //drawStrokeText(n, p[0], p[1], 0);
    }

    pos = max_corner;
    for(double c = 0; c < ys; c++){
      pos.y = base_y + c * GRID_SPACING;
      get_screen_pos(rc, pos, p);
      glRasterPos2f(p[0],p[1]);
      glColor4f(1.0,1.0,1.0,1.0);
      sprintf(n, "%2.2f", pos.y);
      glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, n);
    }

    pos = max_corner;
    for(double c = 0; c < zs; c++){
      pos.z = base_z + c * GRID_SPACING;
      get_screen_pos(rc, pos, p);
      glRasterPos2f(p[0],p[1]);
      glColor4f(1.0,1.0,1.0,1.0);
      sprintf(n, "%2.2f", pos.z);
      glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, n);
    }

    pos = max_corner;
    pos.x += pos.x > r->xmin ? ((-r->xmax + r->xmin)*1.05) : ((r->xmax - r->xmin)*1.05);
    get_screen_pos(rc, pos, p);
    glRasterPos2f(p[0], p[1]);
    glColor4f(1.0,1.0,1.0,1.0);
    sprintf(n, "Qx");
    glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, n);

    pos = max_corner;
    pos.y += pos.y > r->ymin ? ((-r->ymax + r->ymin)*1.05) : ((r->ymax - r->ymin)*1.05);
    get_screen_pos(rc, pos, p);
    glRasterPos2f(p[0], p[1]);
    glColor4f(1.0,1.0,1.0,1.0);
    sprintf(n, "Qy");
    glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, n);

    pos = max_corner;
    pos.z += pos.z > r->zmin ? ((-r->zmax + r->zmin)*1.05) : ((r->zmax - r->zmin)*1.05);
    get_screen_pos(rc, pos, p);
    glRasterPos2f(p[0], p[1]);
    glColor4f(1.0,1.0,1.0,1.0);
    sprintf(n, "Qz");
    glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, n);
  }
}