Esempio n. 1
0
	//-----------------------------------------------------------------------
	void gkMovableShape::setAtlasQuad(const AtlasPacker::PackResult& quad)
	{
		mMaterial = static_cast<gkVtxTexture*>(quad.texture)->getMaterial();
		RectF tex_coords = quad.node->getRect().contractedCopy(1).relativeTo(
			quad.texture->getWidth(), quad.texture->getHeight());

		const BoundingBox& bb = getBoundingBox();

		if (getParentContainer() && !(getParentContainer()->getVisible()))
		{
			mMULcolor.a = 0;
			mADDcolor.a = 0;
		}

		_lock();

		// TOP-LEFT
		_addVertex(
			D3DXVECTOR2(bb.getMinX(), -bb.getMinY()), 
			D3DXVECTOR2(tex_coords.left, tex_coords.top), 
			//D3DXVECTOR2(0, 0), 
			VTXCOLOR_TO_D3DXCOLOR(mMULcolor), VTXCOLOR_TO_D3DXCOLOR(mADDcolor));

		// BOTTOM-LEFT
		_addVertex(
			D3DXVECTOR2(bb.getMinX(), -bb.getMaxY()), 
			D3DXVECTOR2(tex_coords.left, tex_coords.bottom), 
			//D3DXVECTOR2(0, 1), 
			VTXCOLOR_TO_D3DXCOLOR(mMULcolor), VTXCOLOR_TO_D3DXCOLOR(mADDcolor));

		// BOTTOM-RIGHT
		_addVertex(
			D3DXVECTOR2(bb.getMaxX(), -bb.getMaxY()), 
			D3DXVECTOR2(tex_coords.right, tex_coords.bottom), 
			//D3DXVECTOR2(1, 1), 
			VTXCOLOR_TO_D3DXCOLOR(mMULcolor), VTXCOLOR_TO_D3DXCOLOR(mADDcolor));

		// TOP-RIGHT
		_addVertex(
			D3DXVECTOR2(bb.getMaxX(), -bb.getMinY()), 
			D3DXVECTOR2(tex_coords.right, tex_coords.top), 
			//D3DXVECTOR2(1, 0), 
			VTXCOLOR_TO_D3DXCOLOR(mMULcolor), VTXCOLOR_TO_D3DXCOLOR(mADDcolor));

		_unlock();
	}
Esempio n. 2
0
void Mesh::addRow()
{
    // Create new vertices 2d (temporary).
    IndexVector2d newVertices2d;
    resizeVertices2d(newVertices2d, nColumns(), nRows()+1);

    // Top displacement of points already there.
    qreal topMoveProp = 1.0f/(nRows()-1) - 1.0f/nRows();

    // Add a point at each row.
    int k = nVertices();
    for (int x=0; x<nColumns(); x++)
    {
        // Get left and right vertices.
        QPointF top    = getVertex2d(x, 0);
        QPointF bottom = getVertex2d(x, nRows()-1);
        QPointF diff   = bottom - top;

        // First pass: move middle points.
        for (int y=1; y<nRows()-1; y++)
        {
            QPointF p = getVertex2d(x, y);
            p -= diff * y * topMoveProp;
            _rawSetVertex( _vertices2d[x][y], p );
        }

        // Create and add new point.
        QPointF newPoint = bottom - diff * 1.0f/nRows();
        _addVertex(newPoint);

        // Assign new vertices 2d.
        for (int y=0; y<nRows()-1; y++)
            newVertices2d[x][y] = _vertices2d[x][y];

        // The new point.
        newVertices2d[x][nRows()-1] = k;

        // The rightmost point.
        newVertices2d[x][nRows()]   = _vertices2d[x][nRows()-1];

        k++;
    }

    // Copy new mapping.
    _vertices2d = newVertices2d;

    // Increment number of columns.
    _nRows++;

    // Reorder.
    _reorderVertices();
}
Esempio n. 3
0
// vertices 0..3 = 4 corners
//
void Mesh::addColumn()
{
    // Create new vertices 2d (temporary).
    IndexVector2d newVertices2d;
    resizeVertices2d(newVertices2d, nColumns()+1, nRows());

    // Left displacement of points already there.
    qreal leftMoveProp = 1.0f/(nColumns()-1) - 1.0f/nColumns();

    // Add a point at each row.
    int k = nVertices();
    for (int y=0; y<nRows(); y++)
    {
        // Get left and right vertices.
        QPointF left  = getVertex2d( 0,            y );
        QPointF right = getVertex2d( nColumns()-1, y );
        QPointF diff  = right - left;

        // First pass: move middle points.
        for (int x=1; x<nColumns()-1; x++)
        {
            QPointF p = getVertex2d(x, y);
            p -= diff * x * leftMoveProp;
            _rawSetVertex( _vertices2d[x][y], p );
        }

        // Create and add new point.
        QPointF newPoint = right - diff * 1.0f/nColumns();
        _addVertex(newPoint);

        // Assign new vertices 2d.
        for (int x=0; x<nColumns()-1; x++)
            newVertices2d[x][y] = _vertices2d[x][y];

        // The new point.
        newVertices2d[nColumns()-1][y] = k;

        // The rightmost point.
        newVertices2d[nColumns()][y]   = _vertices2d[nColumns()-1][y];

        k++;
    }

    // Copy new mapping.
    _vertices2d = newVertices2d;

    // Increment number of columns.
    _nColumns++;

    // Reorder.
    _reorderVertices();
}
Esempio n. 4
0
void VertexArray::finalize()
{
  if(_data3.size()){
    std::set<ElementData<3>, ElementDataLessThan<3> >::iterator it = _data3.begin();
    for(; it != _data3.end(); it++){
      for(int i = 0; i < 3; i++){
        _addVertex(it->x(i), it->y(i), it->z(i));
        _addNormal(it->nx(i), it->ny(i), it->nz(i));
        _addColor(it->r(i), it->g(i), it->b(i), it->a(i));
        _addElement(it->ele());
      }
    }
    _data3.clear();
  }
  _barycenters.clear();
}
Esempio n. 5
0
void VertexArray::add(double *x, double *y, double *z, SVector3 *n, unsigned char *r,
                      unsigned char *g, unsigned char *b, unsigned char *a,
                      MElement *ele, bool unique, bool boundary)
{
  int npe = getNumVerticesPerElement();

  if(boundary && npe == 3){
    ElementData<3> e(x, y, z, n, r, g, b, a, ele);
    ElementDataLessThan<3>::tolerance = (float)(CTX::instance()->lc * 1.e-12);
    std::set<ElementData<3>, ElementDataLessThan<3> >::iterator it = _data3.find(e);
    if(it == _data3.end())
      _data3.insert(e);
    else
      _data3.erase(it);
    return;
  }

  // enabling this will reduce memory and rendering time; but will increase the
  // time it takes to create the vertex array
#if 0
  if(unique){
    Barycenter pc(0.0F, 0.0F, 0.0F);
    for(int i = 0; i < npe; i++)
      pc += Barycenter(x[i], y[i], z[i]);
    BarycenterLessThan::tolerance = (float)(CTX::instance()->lc * 1.e-12);
    if(_barycenters.find(pc) != _barycenters.end())
      return;
    _barycenters.insert(pc);
  }
#endif

  for(int i = 0; i < npe; i++){
    _addVertex((float)x[i], (float)y[i], (float)z[i]);
    if(n) _addNormal((float)n[i].x(), (float)n[i].y(), (float)n[i].z());
    if(r && g && b && a) _addColor(r[i], g[i], b[i], a[i]);
    _addElement(ele);
  }
}