Exemplo n.º 1
0
/// @brief OBB merge method when the centers of two smaller OBB are close
inline OBB merge_smalldist(const OBB& b1, const OBB& b2)
{
  OBB b;
  b.To = (b1.To + b2.To) * 0.5;
  Quaternion3f q0, q1;
  q0.fromAxes(b1.axis);
  q1.fromAxes(b2.axis);
  if(q0.dot(q1) < 0)
    q1 = -q1;

  Quaternion3f q = q0 + q1;
  FCL_REAL inv_length = 1.0 / std::sqrt(q.dot(q));
  q = q * inv_length;
  q.toAxes(b.axis);


  Vec3f vertex[8], diff;
  FCL_REAL real_max = std::numeric_limits<FCL_REAL>::max();
  Vec3f pmin(real_max, real_max, real_max);
  Vec3f pmax(-real_max, -real_max, -real_max);

  computeVertices(b1, vertex);
  for(int i = 0; i < 8; ++i)
  {
    diff = vertex[i] - b.To;
    for(int j = 0; j < 3; ++j)
    {
      FCL_REAL dot = diff.dot(b.axis[j]);
      if(dot > pmax[j])
        pmax[j] = dot;
      else if(dot < pmin[j])
        pmin[j] = dot;
    }
  }

  computeVertices(b2, vertex);
  for(int i = 0; i < 8; ++i)
  {
    diff = vertex[i] - b.To;
    for(int j = 0; j < 3; ++j)
    {
      FCL_REAL dot = diff.dot(b.axis[j]);
      if(dot > pmax[j])
        pmax[j] = dot;
      else if(dot < pmin[j])
        pmin[j] = dot;
    }
  }

  for(int j = 0; j < 3; ++j)
  {
    b.To += (b.axis[j] * (0.5 * (pmax[j] + pmin[j])));
    b.extent[j] = 0.5 * (pmax[j] - pmin[j]);
  }

  return b;
}
Exemplo n.º 2
0
void Line::setOffsetB(double value)
{
    p_offset_b = value;

    computePrism();
    computeVertices();
}
Exemplo n.º 3
0
void InventorShape::computeShape() {
    Bnd_Box bounds;
    BRepBndLib::Add(shape->getShape(), bounds);
    bounds.SetGap(0.0);
    Standard_Real xMin, yMin, zMin, xMax, yMax, zMax;
    bounds.Get(xMin, yMin, zMin, xMax, yMax, zMax);
    Standard_Real deflection = ((xMax-xMin)+(yMax-yMin)+(zMax-zMin))/300.0 * 0.2;
    BRepMesh::Mesh(shape->getShape(), deflection);

    SoGroup* faces = new SoGroup();

    computeFaces(faces, shape->getShape());

    separator->addChild(faces);

    SoGroup* edges = new SoGroup();
    computeEdges(edges, shape->getShape());

    separator->addChild(edges);

    SoGroup* vertices = new SoGroup();
    computeVertices(vertices, shape->getShape());

    separator->addChild(vertices);
}
Exemplo n.º 4
0
	void ParticleSystem::update(sf::Time dt)
	{
		if (mEmitterActive && mInitializer && mAffector)
		{
			for (unsigned i = mParticles.size(); i < mMaxParticles; i++)
				addParticle();
			//if (mParticles.size() < mMaxParticles || mMaxParticles == 0)
			//	addParticle();

			for (auto& particle : mParticles) {
				(*mAffector)(particle, dt);
				particle.lifetime -= dt;
			}
			if (!mParticles.empty() && mParticles.front().lifetime <= sf::Time::Zero)
				mParticles.erase(mParticles.begin());

			computeVertices();
		}
		else
			std::cout << "\n\nUnable to update ParticleSystem\n"
			          << "3 possible causes:\n"
			          << "  - The Emitter hasn't been activated\n"
			          << "  - The Initializer hasn't been set\n"
			          << "  - The Affector hasn't been set\n\n";
	}
Exemplo n.º 5
0
//-----------------------------------------------------------------------------
// name: YHistoBin()
// desc: constructor
//-----------------------------------------------------------------------------
YHistoBin::YHistoBin()
{
    // default
    m_maxValue = 1;
    // default to 0 with slew of 1
    m_iValue.set( 0, 0, 2 );
    // height default
    m_iHeight.set( 0, .25, 5 );
    // width default
    m_iWidth.set( 0, .25, 5 );
    // set slew
    m_iColor.setSlew( 4.0f );
    
    // set text
    m_textValue.setWidth(1.0);
    m_textLabel.setWidth(1.0);
    
    // add
    this->addChild( &m_textLabel );
    this->addChild( &m_textValue );

    // state
    useDepth = false;
    texture = 0;
    
    // initial
    computeVertices();
}
Exemplo n.º 6
0
Line::Line(double x0, double y0, double z0, double x1, double y1, double z1)
{
    p_is_tagged = false;
    p_verts_computed = false;
    p_comment = "<No comment>";
    p_position_a.set(3, 1);
    p_position_b.set(3, 1);

    p_position_a[0] = x0;
    p_position_a[1] = y0;
    p_position_a[2] = z0;

    p_position_b[0] = x1;
    p_position_b[1] = y1;
    p_position_b[2] = z1;

    p_offset_a = 0;
    p_offset_b = 0;

    p_vertices.set(3, 10, 0);
    p_a.set(3, 1, 0);
    p_b.set(3, 1, 0);
    p_c.set(3, 1, 0);

    p_prism_side_a = 0.01;
    p_prism_side_b = 0.01;

    computePrism();
    computeVertices();
}
Exemplo n.º 7
0
void Line::setComment(QString str)
{
    p_comment = str;

    computePrism();
    computeVertices();
}
Exemplo n.º 8
0
void Line::setPositionB(Matrix<double> pos)
{
    p_position_b = pos;

    computePrism();
    computeVertices();
}
Exemplo n.º 9
0
void Line::setPrismSideB(double value)
{
    p_prism_side_b = value;

    computePrism();
    computeVertices();
}
Exemplo n.º 10
0
/// @brief OBB merge method when the centers of two smaller OBB are far away
inline OBB merge_largedist(const OBB& b1, const OBB& b2)
{
  OBB b;
  Vec3f vertex[16];
  computeVertices(b1, vertex);
  computeVertices(b2, vertex + 8);
  Matrix3f M;
  Vec3f E[3];
  Matrix3f::U s[3] = {0, 0, 0};

  // obb axes
  Vec3f& R0 = b.axis[0];
  Vec3f& R1 = b.axis[1];
  Vec3f& R2 = b.axis[2];

  R0 = b1.To - b2.To;
  R0.normalize();

  Vec3f vertex_proj[16];
  for(int i = 0; i < 16; ++i)
    vertex_proj[i] = vertex[i] - R0 * vertex[i].dot(R0);

  getCovariance(vertex_proj, NULL, NULL, NULL, 16, M);
  eigen(M, s, E);

  int min, mid, max;
  if (s[0] > s[1]) { max = 0; min = 1; }
  else { min = 0; max = 1; }
  if (s[2] < s[min]) { mid = min; min = 2; }
  else if (s[2] > s[max]) { mid = max; max = 2; }
  else { mid = 2; }


  R1.setValue(E[0][max], E[1][max], E[2][max]);
  R2.setValue(E[0][mid], E[1][mid], E[2][mid]);

  // set obb centers and extensions
  Vec3f center, extent;
  getExtentAndCenter(vertex, NULL, NULL, NULL, 16, b.axis, center, extent);

  b.To = center;
  b.extent = extent;

  return b;
}
Exemplo n.º 11
0
void ParticleNode::drawCurrent(sf::RenderTarget &target, sf::RenderStates states) const
{
    if(mNeedsVertexUpdate)
    {
        computeVertices();
        mNeedsVertexUpdate = false;
    }

    states.texture = &mTexture;
    target.draw(mVertexArray, states);
}
Exemplo n.º 12
0
//-----------------------------------------------------------------------------
// name: update()
// desc: ...
//-----------------------------------------------------------------------------
void YHistoBin::update( YTimeInterval dt )
{
    // interpolate
    m_iValue.interp( dt );
    m_iWidth.interp( dt );
    m_iHeight.interp( dt );
    m_iColor.interp( dt );
    
    // set
    this->col = m_iColor.actual();
    
    // compute vertices
    computeVertices();
}
Exemplo n.º 13
0
CTerrain::CTerrain(IDirect3DDevice9* device,
    std::string heightmapFileName,
    int numVertsPerRow,
    int numVertsPerCol,
    int cellSpacing,
    float heightScale)
{
    _device = device;
    _numVertsPerRow = numVertsPerRow;
    _numVertsPerCol = numVertsPerCol;
    _cellSpacing = cellSpacing;

    _numCellsPerRow = _numVertsPerRow - 1;
    _numCellsPerCol = _numVertsPerCol - 1;

    _width = _numCellsPerRow * _cellSpacing;
    _depth = _numCellsPerCol * _cellSpacing;

    _numVertices = _numVertsPerRow * _numVertsPerCol;
    _numTriangles = _numCellsPerRow * _numCellsPerCol * 2;

    _heightScale = heightScale;

    // 加载高度图
    if (!readRawFile(heightmapFileName))
    {
        ::MessageBox(0, _T("readRawFile - FAILED"), 0, 0);
        ::PostQuitMessage(0);
    }

    // 高度缩放
    for (unsigned int i = 0; i < _heightmap.size(); i++)
        _heightmap[i] *= heightScale;

    // 计算点点坐标
    if (!computeVertices())
    {
        ::MessageBox(0, _T("computeVertices - FAILED"), 0, 0);
        ::PostQuitMessage(0);
    }

    // 计算索引
    if (!computeIndices())
    {
        ::MessageBox(0, _T("computeIndices - FAILED"), 0, 0);
        ::PostQuitMessage(0);
    }
    computeNormals();
}
Exemplo n.º 14
0
void Line::alignWithVec(Matrix<double> vec)
{
    Matrix<double> new_vec = vecNormalize(vec)*vecLength(p_position_b-p_position_a);

    Matrix<double> middle(3, 1);
    middle[0] = p_position_a[0] + 0.5 * (p_position_b[0] - p_position_a[0]);
    middle[1] = p_position_a[1] + 0.5 * (p_position_b[1] - p_position_a[1]);
    middle[2] = p_position_a[2] + 0.5 * (p_position_b[2] - p_position_a[2]);

    p_position_a = middle - 0.5*new_vec;
    p_position_b = middle + 0.5*new_vec;

    computePrism();
    computeVertices();
}
Exemplo n.º 15
0
Terrain::Terrain(IDirect3DDevice9* device,
				 std::string heightmapFileName,
				 int numVertsPerRow,
				 int numVertsPerCol,
				 int cellSpacing,
				 float heightScale)
{
	_device         = device;
	_numVertsPerRow = numVertsPerRow;
	_numVertsPerCol = numVertsPerCol;
	_cellSpacing    = cellSpacing;

	_numCellsPerRow = _numVertsPerRow - 1;
	_numCellsPerCol = _numVertsPerCol - 1;

	_width = _numCellsPerRow * _cellSpacing;
	_depth = _numCellsPerCol * _cellSpacing;

	_numVertices  = _numVertsPerRow * _numVertsPerCol;
	_numTriangles = _numCellsPerRow * _numCellsPerCol * 2;

	_heightScale = heightScale;

	// load heightmap
	if( !readRawFile(heightmapFileName) )
	{
		::MessageBox(0, "readRawFile - FAILED", 0, 0);
		::PostQuitMessage(0);
	}

	// scale heights
	for(int i = 0; i < _heightmap.size(); i++)
		_heightmap[i] *= heightScale;

	// compute the vertices
	if( !computeVertices() )
	{
		::MessageBox(0, "computeVertices - FAILED", 0, 0);
		::PostQuitMessage(0);
	}

	// compute the indices
	if( !computeIndices() )
	{
		::MessageBox(0, "computeIndices - FAILED", 0, 0);
		::PostQuitMessage(0);
	}
}
Exemplo n.º 16
0
void ParticleComponent::renderCurrent(sf::RenderTarget & target, sf::RenderStates states)
{
	if (mTexture != nullptr)
	{
		if (mNeedsQuadUpdate)
		{
			computeQuads();
			mNeedsQuadUpdate = false;
		}

		if (mNeedsVertexUpdate)
		{
			computeVertices();
			mNeedsVertexUpdate = false;
		}

		states.texture = mTexture;
		target.draw(mVertices, states);
	}
}
Exemplo n.º 17
0
void Line::setCenter(Matrix<double> pos)
{
    Matrix<double> middle(3, 1);
    middle[0] = p_position_a[0] + 0.5 * (p_position_b[0] - p_position_a[0]);
    middle[1] = p_position_a[1] + 0.5 * (p_position_b[1] - p_position_a[1]);
    middle[2] = p_position_a[2] + 0.5 * (p_position_b[2] - p_position_a[2]);

    Matrix<double> translation(3, 1);
    translation[0] = - middle[0] + pos[0];
    translation[1] = - middle[1] + pos[1];
    translation[2] = - middle[2] + pos[2];

    translation.print(4);

    p_position_a += translation;
    p_position_b += translation;

    computePrism();
    computeVertices();
}
Exemplo n.º 18
0
Line::Line(Matrix<double> pos_a, Matrix<double> pos_b)
{
    p_is_tagged = false;
    p_verts_computed = false;
    p_comment = "<No comment>";
    p_position_a = pos_a;
    p_position_b = pos_b;
    p_offset_a = 0;
    p_offset_b = 0;

    p_vertices.set(3, 10, 0);
    p_a.set(3, 1, 0);
    p_b.set(3, 1, 0);
    p_c.set(3, 1, 0);

    p_prism_side_a = 0.01;
    p_prism_side_b = 0.01;

    computePrism();
    computeVertices();
}
Exemplo n.º 19
0
Line::Line(const Line &other)
{
    p_a = other.aVec();
    p_b = other.bVec();
    p_c = other.cVec();

    p_is_tagged = other.tagged();
    p_verts_computed = false;

    p_offset_a = other.offsetA();
    p_offset_b = other.offsetB();
    p_comment = other.comment();

    p_position_a = other.positionA();
    p_position_b = other.positionB();

    p_prism_side_a = other.prismSideA();
    p_prism_side_b = other.prismSideB();

    p_vertices.set(3, 10, 0);

    computePrism();
    computeVertices();
}