示例#1
0
void RawEntity::init2(std::vector<float>& vertices, std::vector<unsigned int>& indices)
{
	glGenVertexArrays(1, &m_vaoID);
	glBindVertexArray(m_vaoID);

	unsigned int EBO;
	glGenBuffers(1, &EBO);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount() * sizeof(unsigned int), &indices[0], GL_STATIC_DRAW);

	unsigned int VBO;
	glGenBuffers(1, &VBO);
	glBindBuffer(GL_ARRAY_BUFFER, VBO);
	glBufferData(GL_ARRAY_BUFFER, vertexCount() * sizeof(float), &vertices[0], GL_STATIC_DRAW);

	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);
	glEnableVertexAttribArray(0);

	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));
	glEnableVertexAttribArray(1);

	glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(5 * sizeof(float)));
	glEnableVertexAttribArray(2);

	glBindVertexArray(0);

	m_vboList.push_back(VBO);
	m_vboList.push_back(EBO);
}
示例#2
0
void DrawExecution::drawArrays() const
{
    gl::glBindVertexArray(m_drawImpl.glVertexArray);
    gl::glDrawArrays(m_drawImpl.state.rasterizerState().primitive(),
                     0u,
                     vertexCount());
}
示例#3
0
bool Polygon<T>::pointInPolygon(const T& lat, const T& lon) const {
	size_t sides = vertexCount();

	if ( std::vector< Coord<T> >::front() == std::vector< Coord<T> >::back() )
		--sides;

	if ( sides < 3 ) return false;

	int j = sides - 1;
	bool oddCrossings = false;

	for ( size_t i = 0; i < sides; j = i++ ) {
		// Skip segments where lat falls outside the segments vertical
		// boundings
		if ( !(((*this)[j].lat < lat && (*this)[i].lat >= lat) ||
		       ((*this)[i].lat < lat && (*this)[j].lat >= lat)) )
			continue;

		T x0;
		T diffLon, diffSegLon;

		diffLon = sub(lon, (*this)[i].lon);
		diffSegLon = sub((*this)[j].lon, (*this)[i].lon);

		x0 = (lat-(*this)[i].lat)*diffSegLon /
		     ((*this)[j].lat - (*this)[i].lat);

		// Crossing on left side
		if ( x0 < diffLon )
			oddCrossings = !oddCrossings;
	}

	return oddCrossings;
}
示例#4
0
void Grid::render()
{
    // Bind the vertex array object to set up our vertex buffers and index buffer
    m_vao.bind();

    glDrawArrays(GL_LINES, 0, vertexCount());

    m_vao.release();
}
示例#5
0
文件: polygon.cpp 项目: mivihe/luola2
bool ConvexPolygon::hasPoint(const Point &point) const
{
    for(int i=0;i<vertexCount();++i) {
        glm::vec2 side = vertex(i+1) - vertex(i);
        glm::vec2 p = point - vertex(i);
        float k = side.x*p.y - side.y*p.x;
        if(k<0)
            return false;
    }
    return true;
}
示例#6
0
文件: mesh.cpp 项目: kiirala/demotool
GLfloat* Mesh::normalArray() {
  if (!n_array) n_array = new GLfloat[vertexCount() * 3];

  int a_pos = 0;
  for (std::vector<Vertex>::iterator i = vertices.begin() ;
       i != vertices.end() ; i++) {
    n_array[a_pos] = (*i).normal.x;
    n_array[a_pos + 1] = (*i).normal.y;
    n_array[a_pos + 2] = (*i).normal.z;
    a_pos += 3;
  }
  return n_array;
}
示例#7
0
文件: mesh.cpp 项目: kiirala/demotool
GLfloat* Mesh::vertexArray() {
  if (!v_array) v_array = new GLfloat[vertexCount() * 3];

  int a_pos = 0;
  for (std::vector<Vertex>::iterator i = vertices.begin() ;
       i != vertices.end() ; i++) {
    v_array[a_pos] = (*i).loc.x;
    v_array[a_pos + 1] = (*i).loc.y;
    v_array[a_pos + 2] = (*i).loc.z;
    a_pos += 3;
  }
  return v_array;
}
示例#8
0
void GLDynamicLine::paintGL(const QMatrix4x4 &m_mProj, const QMatrix4x4 &m_mView, const QMatrix4x4 &m_mModel, const QMatrix2x2 &m_selectionBounds)
{
    if(!m_built) return;
    QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
    m_program->bind();
    m_program->setUniformValue(m_projMatrixLoc, m_mProj);
    m_program->setUniformValue(m_mvMatrixLoc, m_mView * m_mModel);
    m_program->setUniformValue(m_diagVertices2DLoc, m_selectionBounds);

    m_program->setUniformValue(m_colourVectorLoc, m_colour_stroke);
    glDrawArrays(GL_LINE_LOOP, 0, vertexCount());

    m_program->release();
}
示例#9
0
void TexturedGeometry::setTextureCount(int value)
{
    if (value < 1)
        value = 1;
    if (value == nb_tex)
        return;
    nb_tex = value;
    allocate(vertexCount());
    if (a.size()-1 < value) { // the first is position
        for (int i = a.size()-1; i < value; ++i)
            a << Attribute(TypeFloat, 2, (i+1)* 2*sizeof(float));
    } else {
        a.resize(value + 1);
    }
}
示例#10
0
QgsRectangle QgsMeshDataProvider::extent() const
{
  QgsRectangle rec;
  rec.setMinimal();
  for ( int i = 0; i < vertexCount(); ++i )
  {
    QgsMeshVertex v = vertex( i );
    rec.setXMinimum( std::min( rec.xMinimum(), v.x() ) );
    rec.setYMinimum( std::min( rec.yMinimum(), v.y() ) );
    rec.setXMaximum( std::max( rec.xMaximum(), v.x() ) );
    rec.setYMaximum( std::max( rec.yMaximum(), v.y() ) );
  }
  return rec;

}
示例#11
0
void GLRasterTexture::paintGL(const QMatrix4x4 &m_mProj, const QMatrix4x4 &m_mView, const QMatrix4x4 &m_mModel)
{
    if(!m_built) return;
    QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
    m_program->bind();
    m_program->setUniformValue(m_projMatrixLoc, m_mProj);
    m_program->setUniformValue(m_mvMatrixLoc, m_mView * m_mModel);

    m_texture.bind();
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

    glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount());

    m_program->release();
}
示例#12
0
文件: mesh.cpp 项目: kiirala/demotool
GLfloat* Mesh::texcoordArray() {
  if (!texcoord_array) {
    if (texcoords.size() == 0)
      return 0;
    assert(texcoords.size() == vertices.size());
    texcoord_array = new GLfloat[vertexCount() * 2];
  }

  int a_pos = 0;
  for (std::vector<Point>::iterator i = texcoords.begin() ;
       i != texcoords.end() ; i++) {
    texcoord_array[a_pos] = (*i).x;
    texcoord_array[a_pos + 1] = (*i).y;
    a_pos += 2;
  }
  return texcoord_array;
}
示例#13
0
QgsPointV2 QgsAbstractGeometryV2::centroid() const
{
    // http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon
    // Pick the first ring of first part for the moment

    int n = vertexCount( 0, 0 );
    if ( n == 1 )
    {
        return vertexAt( QgsVertexId( 0, 0, 0 ) );
    }

    double A = 0.;
    double Cx = 0.;
    double Cy = 0.;
    int i = 0, j = 1;
    if ( vertexAt( QgsVertexId( 0, 0, 0 ) ) != vertexAt( QgsVertexId( 0, 0, n - 1 ) ) )
    {
        i = n - 1;
        j = 0;
    }
    for ( ; j < n; i = j++ )
    {
        QgsPointV2 vi = vertexAt( QgsVertexId( 0, 0, i ) );
        QgsPointV2 vj = vertexAt( QgsVertexId( 0, 0, j ) );
        double d = vi.x() * vj.y() - vj.x() * vi.y();
        A += d;
        Cx += ( vi.x() + vj.x() ) * d;
        Cy += ( vi.y() + vj.y() ) * d;
    }

    if ( A < 1E-12 )
    {
        Cx = Cy = 0.;
        for ( int i = 0; i < n - 1; ++i )
        {
            QgsPointV2 vi = vertexAt( QgsVertexId( 0, 0, i ) );
            Cx += vi.x();
            Cy += vi.y();
        }
        return QgsPointV2( Cx / ( n - 1 ), Cy / ( n - 1 ) );
    }
    else
    {
        return QgsPointV2( Cx / ( 3. * A ), Cy / ( 3. * A ) );
    }
}
示例#14
0
文件: polygon.cpp 项目: mivihe/luola2
bool ConvexPolygon::circleCollision(const Point &p, float r, const glm::vec2 &v, Point &cp, glm::vec2 &normal) const
{
    for(int i=0;i<vertexCount();++i) {
        // Check if the circle is moving away from the edge
        const glm::vec2 &n = m_normals[i];
        if(glm::dot(v, n) >= 0)
            continue;

        // Leading point on the circle
        Point lead = n * r;
        Point lp0 = p - lead;

        // lp0 - lp1 form the line to test
        Point lp1 = lp0 + v;

        // Check if circle will collide with the edge during this timestep
        const Point &e0 = vertex(i);
        Point icp;
        if(algorithm::lineIntersection(e0, vertex(i+1), lp0, lp1, icp)) {
            // Intersection!
            cp = icp + lead;
            normal = n;
            return true;
        }

        // Check if circle will collide with the corner in this timestep
        glm::vec2 w = vertex(i) - p;
        float ww = glm::dot(w, w);
        float a = glm::dot(v, v);
        float b = glm::dot(w, v);
        float c = ww - r*r;

        float root = b*b - a*c;
        if(root >= 0) {
            float t = (-b - glm::sqrt(root)) / a;
            if(t >= 0 && t <= 1) {
                cp = p - v * t;
                normal = n;
                return true;
            }
        }
    }

    return false;
}
示例#15
0
文件: mesh.cpp 项目: kiirala/demotool
GLfloat* Mesh::colourArray() {
  if (!col_array) {
    if (colours.size() == 0)
      return 0;
    assert(colours.size() == vertices.size());
    col_array = new GLfloat[vertexCount() * 3];
  }
  
  int a_pos = 0;
  for (std::vector<Colour>::iterator i = colours.begin() ;
       i != colours.end() ; i++) {
    col_array[a_pos] = i->r;
    col_array[a_pos + 1] = i->g;
    col_array[a_pos + 2] = i->b;
    a_pos += 3;
  }
  return col_array;
}
示例#16
0
void Grid::generateVertexData( QVector<float>& vertices,
                               QVector<unsigned int>& indices )
{
    Q_UNUSED( indices );
    vertices.resize( vertexCount() * 3);
    //indices.resize( 6 * m_xDivisions * m_yDivisions );

    float x2 = m_width / 2.0f;
    float y2 = m_height / 2.0f;
    float iFactor = static_cast<float>( m_height ) / static_cast<float>( m_yDivisions );
    float jFactor = static_cast<float>( m_width ) / static_cast<float>( m_xDivisions );
    int vertexIndex = 0;


    for ( int i = 0; i <= m_yDivisions; ++i )
    {
        float y = iFactor * i - y2;
        vertices[vertexIndex] = -x2;
        vertices[vertexIndex+1] = 0.0f;
        vertices[vertexIndex+2] = y;
        
        vertices[vertexIndex+3] = x2;
        vertices[vertexIndex+4] = 0.0f;
        vertices[vertexIndex+5] = y;
        
        vertexIndex += 6;
    }
    
    for ( int j = 0; j <= m_xDivisions; ++j )
    {
        float x = jFactor * j - x2;
        vertices[vertexIndex] = x;
        vertices[vertexIndex+1] = 0.0f;
        vertices[vertexIndex+2] = -y2;
        
        vertices[vertexIndex+3] = x;
        vertices[vertexIndex+4] = 0.0f;
        vertices[vertexIndex+5] = y2;
        
        vertexIndex += 6;
    }
}
示例#17
0
void QgsMapToolSimplify::updateSimplificationPreview()
{
  QgsVectorLayer* vl = currentVectorLayer();

  double layerTolerance = QgsTolerance::toleranceInMapUnits( mTolerance, vl, mCanvas->mapSettings(), mToleranceUnits );
  mReducedHasErrors = false;
  mReducedVertexCount = 0;
  int i = 0;
  Q_FOREACH ( const QgsFeature& fSel, mSelectedFeatures )
  {
    if ( QgsGeometry* g = fSel.constGeometry()->simplify( layerTolerance ) )
    {
      mReducedVertexCount += vertexCount( g );
      mRubberBands[i]->setToGeometry( g, vl );
      delete g;
    }
    else
      mReducedHasErrors = true;
    ++i;
  }

  mSimplifyDialog->updateStatusText();
  mSimplifyDialog->enableOkButton( !mReducedHasErrors );
}
示例#18
0
// --- Properties ---------------------------------------------------------- //
/// Returns the number of points in the delaunay triangulation.
int DelaunayTriangulation::size() const
{
    return vertexCount();
}
示例#19
0
std::shared_ptr<QgsMeshMemoryDatasetGroup> QgsMeshCalcUtils::create( const QString &datasetGroupName ) const
{
  const auto dp = mMeshLayer->dataProvider();
  std::shared_ptr<QgsMeshMemoryDatasetGroup> grp;
  for ( int group_i = 0; group_i < dp->datasetGroupCount(); ++group_i )
  {
    const auto meta = dp->datasetGroupMetadata( group_i );
    const QString name = meta.name();
    if ( name == datasetGroupName )
    {
      grp = std::make_shared<QgsMeshMemoryDatasetGroup>();
      grp->isScalar = meta.isScalar();
      grp->type = meta.dataType();
      grp->maximum = meta.maximum();
      grp->minimum = meta.minimum();
      grp->name = meta.name();

      int count = ( meta.dataType() == QgsMeshDatasetGroupMetadata::DataOnFaces ) ? dp->faceCount() : dp->vertexCount();
      for ( int dataset_i = 0; dataset_i < dp->datasetCount( group_i ); ++dataset_i )
      {
        const QgsMeshDatasetIndex index( group_i, dataset_i );
        const auto dsMeta = dp->datasetMetadata( index );
        std::shared_ptr<QgsMeshMemoryDataset> ds = create( grp->type );
        ds->maximum = dsMeta.maximum();
        ds->minimum = dsMeta.minimum();
        ds->time = dsMeta.time();
        ds->valid = dsMeta.isValid();

        const QgsMeshDataBlock block = dp->datasetValues( index, 0, count );
        Q_ASSERT( block.count() == count );
        for ( int value_i = 0; value_i < count; ++value_i )
          ds->values[value_i] = block.value( value_i );

        const QgsMeshDataBlock active = dp->areFacesActive( index, 0, dp->faceCount() );
        Q_ASSERT( active.count() == dp->faceCount() );
        for ( int value_i = 0; value_i < dp->faceCount(); ++value_i )
          ds->active[value_i] = active.active( value_i );

        grp->addDataset( ds );
      }

      break;
    }
  }
  return grp;
}
示例#20
0
void*
StreamedMesh::internalStreamPtr()
{    
    if (vertexBufferSize() == 0)
    {
        LOG ("Error, internal vertex buffer size is 0");
        return 0;
    }

    if (!_vertexBufferCpuMemory)
    {
        _vertexBufferCpuMemory = (float*)malloc(sizeof(float)*vertexBufferSize());
    }

    // stash the buffer and put it in an array
    std::map <uint32_t, float*> streamMap;

    for (auto it = _vertexStreams.begin();
        it != _vertexStreams.end();
        it++)
    {
        streamMap.insert (std::make_pair(it->first, it->second->stream()));
    }

    const std::vector <VertexElement>& declaration = _vertexDeclaration->getDeclaration();
    float* vb = (float*)_vertexBufferCpuMemory;

    for (uint32_t i = 0; i < vertexCount(); i++)
    {    
        for (uint32_t j = 0; j < declaration.size()-1; j++)
        {
            VertexElement element = declaration[j];
            VertexStream* stream = 0;
            if (findStream (stream, element))
            {
                uint32_t streamId = VertexStream::id(*stream);
                auto streamIt =  streamMap.find(streamId);

                if (streamIt != streamMap.end() &&
                    streamIt->second)
                {
                    for (uint32_t k = 0; k < stream->stride(); k++)
                    {
                        *vb++ = streamIt->second[k];
                    }
                    streamIt->second += stream->stride();
                }
                else
                {
                    uint32_t stride = IVertexDeclaration::elementToSize(element.type());
                    for (uint32_t k = 0; k < stride; stride++)
                    {
                        *vb++ = 0;
                    }
                }
            }
            else
            {
                // can't find a stream for this element.
                // warn user, and 0 the buffer for the stride size
                uint32_t stride = IVertexDeclaration::elementToSize(element.type());
                for (uint32_t k = 0; k < stride; stride++)
                {
                    *vb++ = 0;
                }
            }
        }
    }

    return _vertexBufferCpuMemory;
}
int MatrixGraph::edgesCount() const {
  return vertexCount() ? iMatrix[0].size() : 0;
}
示例#22
0
文件: polygon.cpp 项目: mivihe/luola2
void ConvexPolygon::booleanDifference(const ConvexPolygon &hole, std::vector<ConvexPolygon> &list) const
{
    // Special case: this polygon is entirely swallowed by the hole
    if(hole.envelopes(*this))
        return;

    // Special case: the hole is entirely inside this polygon
    if(envelopes(hole)) {
        Points p1, p2;
        splitPolygon(*this, hole, p1, p2);
        ConvexPolygon::make(p1, list);
        ConvexPolygon::make(p2, list);
        return;
    }

    // Common case: hole intersects with this polygon.
    std::vector<bool> visited(vertexCount());
    std::queue<unsigned int> queue;
    queue.push(0);

    // Perform intersection
    unsigned int oldsize = list.size();
    Points poly;
    while(!queue.empty()) {
        int i = queue.front();
        while(i < vertexCount()) {
            // Stop if we've already been here
            if(visited[i])
                break;
            visited[i] = true;

            // Include point if it is not inside the hole
            bool inhole = hole.hasPoint(vertex(i));
            if(!inhole)
                poly.push_back(vertex(i));

            // Check for intersections
            Point isect[2];
            int isectv[2];
            findIntersections(*this, i, i+1, hole, isect, isectv);

            if(isectv[0] >= 0) {
                // Intersection found: this is the start of a hole,
                // except when this edge started inside the hole.
                poly.push_back(isect[0]);
                if(!inhole) {
                    // Start tracing the hole
                    int j = isectv[0];
                    do {
                        // Check for intersections
                        // The first hole edge may intersect with another edges
                        Point hisect[2];
                        int hisectv[2];
                        findIntersections(hole, j+1, j, *this, hisect, hisectv);

                        // There is always one intersection (the one that got us here)
                        if((j == isectv[0] && hisectv[1] >= 0) || (j != isectv[0] && hisectv[0] >= 0)) {
                            // Pick the intersection that is not the one we came in on
                            Point ip;
                            int iv;
                            if(hisectv[1] < 0 || glm::distance2(hisect[0],isect[0]) > glm::distance(hisect[1],isect[0])) {
                                ip = hisect[0];
                                iv = hisectv[0];
                            } else {
                                ip = hisect[1];
                                iv = hisectv[1];
                            }

                            queue.push(i+1);

                            // Avoid adding duplicate point of origin
                            if(glm::distance2(poly.front(), ip) > 0.0001)
                                poly.push_back(ip);
                            i = iv;
                            break;
                        } else {
                            // No intersections? Just add the hole vertex then
                            poly.push_back(hole.vertex(j));
                        }
 
                        if(--j < 0)
                            j = hole.vertexCount() - 1;
                    } while(j != isectv[0]);
                }
            }
            ++i;
        }

        // Partition the generated polygon into convex polygons
        // and add them to the list.
        if(poly.size() >= 3) {
            try {
                ConvexPolygon::make(poly, list);
            } catch(const algorithm::GeometryException &e) {
                // Bad polygons generated... The algorithm works well
                // enough most of the time, let's just roll back the error.
                int changes = list.size() - oldsize;
#ifndef NDEBUG
                cerr << "booleanDifference error: " << e.what() << " (" << changes << " change(s) rolled back)\n";
#endif
                while(changes-->0)
                    list.pop_back();
                list.push_back(*this);
                return;
            }
        }
        poly.clear();
        queue.pop();
    }
}
示例#23
0
//--------------------------------------------------------------------------------------------------
/// Convert indexed primitive set to unsigned short if possible
/// 
/// \return  The number of primitive sets that was converted.
//--------------------------------------------------------------------------------------------------
int DrawableGeo::convertFromUIntToUShort()
{
    int numConverted = 0;

    Collection<PrimitiveSet> myCollection;

    size_t numPrimitiveObjects = m_primitiveSets.size();
    size_t iPrim;
    for (iPrim = 0; iPrim < numPrimitiveObjects; iPrim++)
    {
        PrimitiveSet* primitive = m_primitiveSets[iPrim].p();

        PrimitiveSetIndexedUInt* primitiveSetUInt = dynamic_cast<PrimitiveSetIndexedUInt*>(primitive);
        PrimitiveSetIndexedUIntScoped* primitiveSetUIntScoped = dynamic_cast<PrimitiveSetIndexedUIntScoped*>(primitive);
		if (vertexCount() < std::numeric_limits<ushort>::max() && primitiveSetUInt)
        {
            const UIntArray* uiIndices = primitiveSetUInt->indices();
            
            ref<UShortArray> indices = new UShortArray;

            if (uiIndices)
            {
                size_t uiArraySize = uiIndices->size();
                
                indices->resize(uiArraySize);
                
                size_t j;
                for (j = 0; j < uiArraySize; j++)
                {
                    indices->set(j, static_cast<ushort>(uiIndices->get(j)));
                }                
            }
            
            ref<PrimitiveSetIndexedUShort> prim = new PrimitiveSetIndexedUShort(primitive->primitiveType());
            prim->setIndices(indices.p());

            myCollection.push_back(prim.p());
            numConverted++;
        }
        else if (vertexCount() < std::numeric_limits<ushort>::max() && primitiveSetUIntScoped)
        {
            const UIntArray* uiIndices = primitiveSetUIntScoped->indices();
            size_t uiArraySize = uiIndices->size();

            ref<UShortArray> indices = new UShortArray;
            indices->resize(uiArraySize);

            size_t j;
            for (j = 0; j < uiArraySize; j++)
            {
                indices->set(j, static_cast<ushort>(uiIndices->get(j)));
            }

            ref<PrimitiveSetIndexedUShortScoped> prim = new PrimitiveSetIndexedUShortScoped(primitive->primitiveType());
            prim->setIndices(indices.p(), primitiveSetUIntScoped->scopeFirstElement(), primitiveSetUIntScoped->scopeElementCount());

            myCollection.push_back(prim.p());
            numConverted++;
        }
        else
        {
            myCollection.push_back(primitive);
        }
    }

    m_primitiveSets.clear();
    m_primitiveSets = myCollection;

    return numConverted;
}
示例#24
0
 inline polyline_vertex_iter Polyline::vend() { 
   return polyline_vertex_iter(this, (ssize_t)vertexCount());
 }
示例#25
0
 void EvaluatorModel::drawingRoutine() const {
     glDrawArrays(GL_LINES, 0, vertexCount());
 }
示例#26
0
 inline polyline_vertex_const_iter Polyline::vend() const { 
   return polyline_vertex_const_iter(this, vertexCount());
 }