Ejemplo n.º 1
0
void hgeh::render_circle_slice( HGE *hge, const Vec2D center, float radius, int segments, float begin, float end, DWORD color )
{
	const float increment = ( end - begin ) / segments;
	float theta = begin;
	
	typedef std::vector<Vec2D> Positions;
	Positions positions;
	for( int i = 0; i < segments; ++i )
	{
		Vec2D p = Vec2D( std::cos( theta ), std::sin( theta ) );
		p *= radius;
		p += center;
		positions.push_back( p );
		theta += increment;
	}
	
	for( Positions::iterator it = positions.begin(); it != positions.end(); )
	{
		Vec2D p1 = *it;
		++it;
		Vec2D p2;
		if( it != positions.end() ) {
			p2 = *it;
		}
		else {
			break;
		}
		hge->Gfx_RenderLine( p1.x, p1.y, p2.x, p2.y, color );
	}
}
Ejemplo n.º 2
0
void hgeh::render_circle_slice( HGE *hge, float x, float y, float radius, int segments, float begin, float end, DWORD color )
{
	const float increment = ( end - begin ) / segments;
	float theta = begin;
	
	const Vec2D center( x, y );
	
	typedef std::vector<Vec2D> Positions;
	Positions positions;
	for( int i = 0; i < segments + 1; ++i )
	{
		Vec2D p = Vec2D( std::cos( theta ), std::sin( theta ) );
		p *= radius;
		p += center;
		positions.push_back( p );
		theta += increment;
	}
	
	render_lines( hge, positions, color );
	
	Vec2D first = Vec2D( std::cos( begin ), std::sin( begin ) ) * radius + center;
	Vec2D last = Vec2D( std::cos( end ), std::sin( end ) ) * radius + center;
	//-1 correct point
	hge->Gfx_RenderLine( center.x - 1, center.y, first.x, first.y, color );
	hge->Gfx_RenderLine( center.x, center.y, last.x, last.y, color );
}
Ejemplo n.º 3
0
bool XTCReader::read(Positions &positions, Topology *topology) {
#if HAVE_GROMACS
  if (setjmp(gromacs_error_handler())) THROW("Failed to read XTC");

  int step = 0;
  real time = 0;
  matrix box;
  real prec = 0;
  gmx_bool bOK = 0;
  int ret;

  if (first) {
    ret = read_first_xtc(p->file, &natoms, &step, &time, box, &p->x, &prec,
                         &bOK);
     first = false;

  } else
    ret = read_next_xtc(p->file, natoms, &step, &time, box, p->x, &prec, &bOK);

  if (!ret) return false;

  Vector3D bounds = Vector3D(box[0][0], box[1][1], box[2][2]) * 10;
  LOG_DEBUG(3, "Read XTC frame: ret=" << ret << " natoms=" << natoms
            << " step=" << step << " time=" << time << " box=" << bounds
            << " prec=" << prec << " bOK=" << bOK);

  vector<Vector3D> _box(3);
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++)
      _box[i][j] = box[i][j] * 10;
  positions.setBox(_box);

  // Get number of atoms
  unsigned count;
  if (topology) count = topology->getAtoms().size();
  else count = natoms;
  if (natoms < (int)count) count = natoms;

  for (unsigned i = 0; i < count; i++) {
    // Get atom index
    unsigned index = 0;
    if (topology) index = topology->getAtoms()[i].getIndex();
    if (!index) index = i;

    // Store the position
    Vector3D pos = Vector3D(((rvec *)p->x)[index][0], ((rvec *)p->x)[index][1],
                            ((rvec *)p->x)[index][2]) * 10;
    positions.push_back(pos);

    LOG_DEBUG(5, "XTC: " << i << '/' << count << ' ' << pos);
  }

  return true;

#else
  THROWS("Not compiled with Gromacs support");
#endif
}
Ejemplo n.º 4
0
void hgeh::render_solid_circle_slice( HGE *hge, const Vec2D center, float radius, int segments, float begin, float end, DWORD color )
{
	const float increment = ( end - begin ) / segments;
	float theta = begin;
	
	typedef std::vector<Vec2D> Positions;
	Positions positions;
	for( int i = 0; i < segments; ++i )
	{
		Vec2D p = Vec2D( std::cos( theta ), std::sin( theta ) );
		p *= radius;
		p += center;
		positions.push_back( p );
		theta += increment;
	}
	
	for( Positions::iterator it = positions.begin(); it != positions.end(); )
	{
		Vec2D p1 = *it;
		++it;
		Vec2D p2;
		if( it != positions.end() ) {
			p2 = *it;
		}
		else {
			p2 = *positions.begin();
		}
		
		hgeTriple t;
		t.blend = BLEND_DEFAULT;
		t.tex = 0;
		
		hgeVertex v;
		v.col = color;
		v.tx = 0.0;
		v.ty = 0.0;
		
		v.x = center.x;
		v.y = center.y;
		t.v[0] = v;
		
		v.x = p1.x;
		v.y = p1.y;
		t.v[1] = v;
		
		v.x = p2.x;
		v.y = p2.y;
		t.v[2] = v;
		
		hge->Gfx_RenderTriple( &t );
	}
}
Ejemplo n.º 5
0
void XYZReader::read(Positions &positions, Topology *topology) {
  istream &stream = source.getStream();
  vector<string> tokens;
  char line[1024];

  // Read header line
  stream.getline(line, 1024);
  if (stream.fail()) THROWS("Failed to read XYZ");

  // Get atom count
  String::tokenize(line, tokens);
  if (tokens.size() < 1) THROW("Missing atom count in XYZ");

  unsigned count = String::parseU32(tokens[0]);
  unsigned lineNum = 1;

  // Reset
  positions.clear();
  if (topology) topology->clear();

  // Read atoms and positions
  while (!stream.fail() && count) {
    stream.getline(line, 1024);
    lineNum++;

    tokens.clear();
    String::tokenize(line, tokens);

    if (tokens.size() < 1 || !isdigit(tokens[0][0])) continue;
    if (tokens.size() < 5) THROWS("Invalid XYZ file at line: " << lineNum);

    if (topology) {
      Atom atom(tokens[1]);
      atom.setIndex(String::parseU32(tokens[0]));
      topology->add(atom);
    }

    positions.push_back(Vector3D(String::parseDouble(tokens[2]),
                                 String::parseDouble(tokens[3]),
                                 String::parseDouble(tokens[4])));

    count--;
  }

  positions.init();

  if (count) THROWS("Failed reading XYZ, expected " << count << " more atoms");
}
Ejemplo n.º 6
0
void hgeh::render_circle( HGE *hge, float x, float y, float radius, int segments, DWORD color )
{
	const float increment = math::PI2 / segments;
	float theta = 0.0f;
	
	const Vec2D center( x, y );
	
	typedef std::vector<Vec2D> Positions;
	Positions positions;
	for( int i = 0; i < segments; ++i )
	{
		Vec2D p = Vec2D( std::cos( theta ), std::sin( theta ) );
		p *= radius;
		p += center;
		positions.push_back( p );
		theta += increment;
	}
	
	render_lines( hge, positions, color, true );
}