Пример #1
0
// while 循环
void CodeGenerator::While() {
    match("(");
    int Begin = CurLabel;
    string res = Expr();
    match(")");

    addQuad("J==", res, "1", itos(CurLabel + 2));
    int OUT = addQuad("J", "$", "$", "Unknow");
    match("{");
    Block();
    addQuad("J", "$", "$", itos(Begin));
    QuadList[OUT].name_res = itos(CurLabel);
    match("}");
}
Пример #2
0
template <typename PointInT> void
pcl::OrganizedFastMesh<PointInT>::makeQuadMesh (std::vector<pcl::Vertices>& polygons)
{
  int last_column = input_->width - triangle_pixel_size_columns_;
  int last_row = input_->height - triangle_pixel_size_rows_;

  int i = 0, index_down = 0, index_right = 0, index_down_right = 0, idx = 0;
  int y_big_incr = triangle_pixel_size_rows_ * input_->width,
      x_big_incr = y_big_incr + triangle_pixel_size_columns_;
  // Reserve enough space
  polygons.resize (input_->width * input_->height);

  // Go over the rows first
  for (int y = 0; y < last_row; y += triangle_pixel_size_rows_)
  {
    // Initialize a new row
    i = y * input_->width;
    index_right = i + triangle_pixel_size_columns_;
    index_down = i + y_big_incr;
    index_down_right = i + x_big_incr;

    // Go over the columns
    for (int x = 0; x < last_column; x += triangle_pixel_size_columns_,
                                     i += triangle_pixel_size_columns_,
                                     index_right += triangle_pixel_size_columns_,
                                     index_down += triangle_pixel_size_columns_,
                                     index_down_right += triangle_pixel_size_columns_)
    {
      if (isValidQuad (i, index_right, index_down_right, index_down))
        if (store_shadowed_faces_ || !isShadowedQuad (i, index_right, index_down_right, index_down))
          addQuad (i, index_right, index_down_right, index_down, idx++, polygons);
    }
  }
  polygons.resize (idx);
}
Пример #3
0
void Model::addBall(float radius, size_t step, size_t rstep, const glm::vec3 &center) {
    if (step < 2) {
        step = 2; // step < 2 => straight line
    }
    if (rstep < 3) {
        rstep = 2 * step; // rstep < 3 => flat polygon
    }

    float phi = 0, theta = 0, dPhi = Pi / (step), dTheta = 2.0f * Pi / rstep;

    step += 1;
    rstep += 1;

    reserveVertices((step) * (rstep));
    reserveIndices((step) * (rstep) * 2);

    glm::vec3 n;
    size_t i, j, k = mVertices.size();

    for (i = 0; i < rstep; i++, theta += dTheta) {
        for (j = 0, phi = 0; j < step; j++, phi += dPhi) {

            n.x = std::sin(phi)*std::cos(theta);
            n.y = std::cos(phi);
            n.z = std::sin(phi)*std::sin(theta);
            addVertex(Vertex(n, center+n*radius));

            size_t p = (i + 1) % rstep;
            size_t q = (j + 1) % step;
            addQuad(k+(i*step)+j, k+(p*step)+j, k+(p*step)+q, k+(i*step)+q);
        }
    }
}
Пример #4
0
void ofxParametricSurface::reload(){
    if (!isSetup) {
        ofLogError("ofxMathMesh") << "cannot reload if the surface is not setup";
        return;
    }
    clear();
    int uMinDomainPoint = round(ofMap(uMin, absUMin, absUMax, 0, uDomainPoints.size()-1));
    int uMaxDomainPoint = round(ofMap(uMax, absUMin, absUMax, 0, uDomainPoints.size()-1));
    int vMinDomainPoint = round(ofMap(vMin, absVMin, absVMax, 0, vDomainPoints.size()-1));
    int vMaxDomianPoint = round(ofMap(vMax, absVMin, absVMax, 0, vDomainPoints.size()-1));
    
    for (int u = uMinDomainPoint; u < uMaxDomainPoint; u++) {
        for (int v = vMinDomainPoint; v < vMaxDomianPoint; v++) {
            ofPoint value1 = valueForPoint(uDomainPoints[u], vDomainPoints[v]);
            ofPoint value2 = valueForPoint(uDomainPoints[u], vDomainPoints[v+1]);
            ofPoint value3 = valueForPoint(uDomainPoints[u+1], vDomainPoints[v+1]);
            ofPoint value4 = valueForPoint(uDomainPoints[u+1], vDomainPoints[v]);
            ParametricPosition one(uDomainPoints[u],vDomainPoints[v],value1);
            ParametricPosition two(uDomainPoints[u],vDomainPoints[v+1],value2);
            ParametricPosition three(uDomainPoints[u+1],vDomainPoints[v+1],value3);
            ParametricPosition four(uDomainPoints[u+1],vDomainPoints[v],value4);
            addQuad(one, two, three, four);
        }
    }
    
}
Пример #5
0
    void diamondSquareIterationByIdx() {
        if (iterations >= MAX_ITERATIONS)
            return;
        indicesEnabled = true;
        auto & previousItVertices = mesh.getVertices();
        auto previousItIndices = mesh.getIndices();
        mesh.clearIndices();
//        mesh.clear();
        iterations++;
        auto previousItIdx = previousItIndices.begin();
        while (previousItIdx != previousItIndices.end()) {
            
            IndexType bottomLeftIdx = *previousItIdx++;
            IndexType topLeftIdx = *previousItIdx++;
            IndexType topRightIdx = *previousItIdx++;
                                    previousItIdx++; // skip top right
            IndexType bottomRightIdx = *previousItIdx++;
                                    previousItIdx++; // skip bottom left
            
            ofVec3f bottomLeft = getVertex(bottomLeftIdx);
            ofVec3f topLeft = getVertex(topLeftIdx);
            ofVec3f topRight = getVertex(topRightIdx);
            ofVec3f bottomRight = getVertex(bottomRightIdx);
            
            
            IndexType middlePointIdx = addVertex(((bottomLeft + bottomRight + topRight + topLeft)/4.f));
            
            disturbMidpoint(getVertex(middlePointIdx), bottomLeft, topLeft, topRight, bottomRight);
            
            IndexType leftMidIdx = addVertex((topLeft + bottomLeft)/2.f);
            IndexType botMidIdx = addVertex((bottomRight + bottomLeft)/2.f);
            IndexType topMidIdx = addVertex((topRight + topLeft)/2.f);
            IndexType rightMidIdx = addVertex((bottomRight + topRight)/2.f);
            
            addQuad(bottomLeftIdx, leftMidIdx, middlePointIdx, botMidIdx);
            addQuad(leftMidIdx, topLeftIdx, topMidIdx, middlePointIdx);
            addQuad(middlePointIdx, topMidIdx, topRightIdx, rightMidIdx);
            addQuad(botMidIdx, middlePointIdx, rightMidIdx, bottomRightIdx);
            
        }

        std::cout << "Diamond Square iterations: " << iterations << " resulted in " << mesh.getNumVertices() << " vertices, " << mesh.getNumIndices() / 4 << " quads" << std::endl;
      generateVertexNormal(mesh);
      updateTexCoordinates();
        std::cout << "MinHeight: " << minHeight << " MaxHeight: " << maxHeight << std::endl;
        
    }
Пример #6
0
void CodeGenerator::If() {
    match("("); string res = Expr(); match(")");

    match("{");
    int ET = addQuad("J==", res, "1", itos(CurLabel + 2));
    int EF = addQuad("J", "$", "$", "Unknow");
    Block();
    int OUT = addQuad("J", "$", "$", "Unknow");
    QuadList[EF].name_res = itos(CurLabel);
    match("}");
    if(isNext("else")) {
        match("else"); match("{");
        Block();
        match("}");
    }
    QuadList[OUT].name_res = itos(CurLabel);
}
Пример #7
0
void HEC_FromFaceList::copyFromVertexData(VertexData& vd) {
	for(int i = 0; i < vd.getNumVertices(); ++i) {
		addVertex(vd.getVertex(i));
	}
	for(int i = 0; i < vd.getNumQuads(); ++i) {
		Quad& q = *vd.getQuadPtr(i);
		addQuad(q.a, q.b, q.c, q.d);
	}
}
Пример #8
0
void Galaxy::generate(int seed)
{
	srand(seed);
	int q = rand() % 3 +3; //random int betweeen 3 and 6
	for(int i = 0; i < q; i++)
	{
		Quadrant x = Quadrant();
		x.generate(seed + q);
		addQuad(x);
	}
}
Пример #9
0
// For循环
void CodeGenerator::For() {
    match("(");
    // init
    Assign();
    // cond
    int Begin = CurLabel;
    string res = Expr();
    addQuad("J==", res, "1", itos(CurLabel + 2));
    int OUT = addQuad("J", "$", "$", "Unknow");
    match(";");
    string inc = getToken().value;
    string op = getToken().value;
    match(")");
    match("{");
    Block();
    // step
    addQuad(op, inc, "$", inc);
    addQuad("J", "$", "$", itos(Begin));
    QuadList[OUT].name_res = itos(CurLabel);
    match("}");
}
Пример #10
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void GeometryBuilder::addQuadByVertices(const Vec3f& v0, const Vec3f& v1, const Vec3f& v2, const Vec3f& v3)
{
    Vec3fArray verts;
    verts.resize(4);
    verts[0] = v0;
    verts[1] = v1;
    verts[2] = v2;
    verts[3] = v3;

    uint firstVertexIdx = addVertices(verts);

    addQuad(firstVertexIdx, firstVertexIdx + 1, firstVertexIdx + 2, firstVertexIdx + 3);
}
Пример #11
0
Ogre::ManualObject* ProceduralShape::createCube(
	Ogre::SceneManager* i_pSceneMngr, 
	Ogre::SceneNode* i_pParent, 
	const Ogre::String& i_name,
	float i_size)
{
	// create ManualObject
	Ogre::ManualObject* manual = i_pSceneMngr->createManualObject(i_name);

	// define start and end point
	float &s = i_size;
	std::vector<Ogre::Vector3> p{
		Ogre::Vector3(s, -s, -s), 
		Ogre::Vector3(s, s, -s),
		Ogre::Vector3(-s, s, -s),
		Ogre::Vector3(-s, -s, -s),
		Ogre::Vector3(s, -s, s),
		Ogre::Vector3(s, s, s),
		Ogre::Vector3(-s, s, s),
		Ogre::Vector3(-s, -s, s)
	};

	std::vector<std::vector<int>> q{
		{ 0,1,2,3 },
		{ 1,5,6,2 },
		{ 2,6,7,3 },
		{ 3,7,4,0 },
		{ 0,4,5,1 },
		{ 4,7,6,5 }
	};

	std::vector<Ogre::Vector3> n{
		Ogre::Vector3(0.f, 0.f, -1.f),
		Ogre::Vector3(0.f, 1.f, 0.f),
		Ogre::Vector3(-1.f, 0.f, 0.f),
		Ogre::Vector3(0.f, -1.f, 0.f),
		Ogre::Vector3(1.f, 0.f, 0.f),
		Ogre::Vector3(0.f, 0.f, 1.f),
	};

	for (size_t i = 0; i < q.size(); ++i)
	{
		std::vector<Ogre::Vector3> clockwiseQuad{
			p[q[i][0]], p[q[i][1]], p[q[i][2]], p[q[i][3]] };
		addQuad(clockwiseQuad, n[i], 10, 10, Ogre::String("BeanOfLight/Avatar"), *manual);
	}

	i_pParent->attachObject(manual);

	return manual;
}
Пример #12
0
//--------------------------------------------------------------------------------------------------
/// Add a quad strip
/// 
/// Vertex ordering for quad strips:
/// <PRE>
///   v0    v2    v4    v6   Resulting quads:
///   *-----*-----*-----*       q1: v0, v1, v3, v2
///   |     |     |     |       q2: v2, v3, v5, v4
///   |     |     |     |       q3: v4, v5, v7, v6
///   |     |     |     |       
///   *-----*-----*-----*
///   v1    v3    v5    v7 </PRE>
/// 
/// \remarks There must be at least 4 entries in the \a indices array, and the total number of 
///          entries must be a multiple of 2.
//--------------------------------------------------------------------------------------------------
void GeometryBuilder::addQuadStrip(const UIntArray& indices)
{
    size_t numIndices = indices.size();
    CVF_ASSERT(numIndices >= 4);
    CVF_ASSERT(numIndices % 2 == 0);

    size_t numQuads = (numIndices - 2)/2;
    CVF_ASSERT(numQuads >= 1);

    size_t i;
    for (i = 0; i < numQuads; i++)
    {
        addQuad(indices[2*i], indices[2*i + 1], indices[2*i + 3], indices[2*i + 2]);
    }
}
Пример #13
0
// 函数块
void CodeGenerator::Block() {
    while(!isNext("}")) {
        CodeToken T = getToken();
        string value = T.value;
        if(value == "if") {
            If();
        } else if(value == "while") {
            While();
        } else if(value == "for") {
            For();
        } else if(value == "read") {
            match("("); addQuad("read", getToken().value, "$", "$"); match(")"); match(";");
        } else if(value == "write") {
            match("("); addQuad("write", getToken().value, "$", "$"); match(")"); match(";");
        } else if(value == "return") {
            addQuad("return", itos(getToken().num), "$", "$");   match(";");
        } else if(CodeToString(T) == "id") {
            CurToken--;
            Assign();
        } else {
            puts("函数块错误!!"); printf("in %d", CurLine()); exit(0);
        }
    }
}
Пример #14
0
//--------------------------------------------------------------------------------------------------
/// Add multiple quads
/// 
/// The default implementation utilizes addQuad() to add each quad separately.
/// 
/// \remarks There must be at least 4 entries in the \a indices array, and the total number of 
///          entries must be a multiple of 4.
//--------------------------------------------------------------------------------------------------
void GeometryBuilder::addQuads(const UIntArray& indices)
{
    size_t numIndices = indices.size();
    CVF_ASSERT(numIndices >= 4);
    CVF_ASSERT(numIndices % 4 == 0);

    size_t numQuads = numIndices/4;
    CVF_ASSERT(numQuads >= 1);
    CVF_ASSERT(4*numQuads == numIndices);

    size_t i;
    for (i = 0; i < numQuads; i++)
    {
        addQuad(indices[4*i], indices[4*i + 1], indices[4*i + 2], indices[4*i + 3]);
    }
}
Пример #15
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void GeometryBuilder::addQuads(const IntArray& indices)
{
    size_t numIndices = indices.size();
    CVF_ASSERT(numIndices >= 4);
    CVF_ASSERT(numIndices % 4 == 0);

    size_t numQuads = numIndices/4;
    CVF_ASSERT(numQuads >= 1);
    CVF_ASSERT(4*numQuads == numIndices);

    size_t i;
    for (i = 0; i < numQuads; i++)
    {
        CVF_ASSERT(indices[4*i] >= 0 && indices[4*i + 1] && indices[4*i + 2] && indices[4*i + 3]);
        addQuad(static_cast<uint>(indices[4*i]), static_cast<uint>(indices[4*i + 1]), static_cast<uint>(indices[4*i + 2]), static_cast<uint>(indices[4*i + 3]));
    }
}
Пример #16
0
  void Font::buildTextGeometry(const char * str, Vector2 const& offset, Geometry * geom, Color const& textColor)
  {
    if (!texture)
      return;

    Vector2 pos = offset;

    for (; *str; ++str)
    {
      int character = *str - 32;

      if (character >= 0 && character < 96)
      {
        Glyph & glyph = glyphs[character];
        addQuad(geom, glyph.topLeft + pos, glyph.bottomRight + pos, glyph.uvTopLeft, glyph.uvBottomRight, textColor);
        pos.x += glyph.advance;
      }
    }
  }
Пример #17
0
void CubeRenderer::begin(const Vector3& directionalLightPosition)
{
	m_started = true;

	m_dmaChain.addSrcCntTag(0, VIF_FLUSH());
	m_dmaChain.endPacket();

	//Vu1::instance()->clearCache();

	// Make sure that everything is finished

	Vu1::instance()->clearCache();

#ifndef PS2_EMU
	m_started = Vu1::instance()->getProgram(m_dmaChain, Vu1::CubeRenderer, 
											&CubeRendererVu1_CodeStart, 
											&CubeRendererVu1_CodeEnd);
#endif


	m_dmaChain.addSrcCntTag(0);
	m_dmaChain.add32(VIF_BASE(100));
	m_dmaChain.add32(VIF_OFFSET(600));
	m_dmaChain.add32(VIF_STCYCL(1, 1));
	m_dmaChain.add32(VIF_MSCAL(m_started));
	m_dmaChain.endPacket();

	// Add cubedata 
	// TODO: Use a refchain here.

	m_dmaChain.addSrcCntTag(VIF_STCYCL(1, 1), VIF_UNPACK(zenic::ps2::vif::V4_32, 1, 22));

	m_dmaChain.addFloat(directionalLightPosition.x);
	m_dmaChain.addFloat(directionalLightPosition.y);
	m_dmaChain.addFloat(directionalLightPosition.z);
	m_dmaChain.addFloat(1.0f);

	m_dmaChain.endPacket();

	m_dmaChain.addSrcCntTag(VIF_STCYCL(1, 1), VIF_UNPACK(zenic::ps2::vif::V4_32, 24, 23));

	addQuad(s_cubeCoords[1], s_cubeCoords[0], s_cubeCoords[3], s_cubeCoords[2]);
	addQuad(s_cubeCoords[4], s_cubeCoords[5], s_cubeCoords[6], s_cubeCoords[7]);
	addQuad(s_cubeCoords[0], s_cubeCoords[1], s_cubeCoords[5], s_cubeCoords[4]);
	addQuad(s_cubeCoords[7], s_cubeCoords[6], s_cubeCoords[2], s_cubeCoords[3]);
	addQuad(s_cubeCoords[5], s_cubeCoords[1], s_cubeCoords[2], s_cubeCoords[6]);
	addQuad(s_cubeCoords[0], s_cubeCoords[4], s_cubeCoords[7], s_cubeCoords[3]);

	m_dmaChain.endPacket();
}
Пример #18
0
 void VirtualFont::addCluster(const Cluster &cluster, const Vec3f &position)
 {
     for (auto &shape : cluster.shapes)
     {
         Vec2f p = properties.useMipmap ? position.xy() : Vec2f(snap(position.x), snap(position.y));
         
         Quad quad;
         auto glyph = cluster.font->fillQuad(quad, shape, p, sizeRatio);
         
         if (glyph)
         {
             if (!hasClip || clipQuad(quad, glyph->texture))
             {
                 auto batch = batchMap->getBatch(glyph->texture);
                 batch->addQuad(quad, position.z);
                 incrementSequence(batch);
             }
         }
     }
 }
BEGIN_JLIB_GRAPHICS_SHADER_NAMESPACE

postProcess::postProcess( entity::entityG *p, string fS ) : triangleCloud( p ), surfaceShader( fS, POSTPROCESSVERTEXSHADER )/*,
        _colour( colName ), _depth( depName )*/
    {
    setTriangleArraySize( 2 );
    setPointArraySize( 4 );

    addQuad( addPoint( math::triple( 1, 1, 0 ), math::triple( 0, 0, 0 ), math::vector2( 1, 1 ), math::colour4::WHITE ),
        addPoint( math::triple( 1, -1, 0 ), math::triple( 0, 0, 0 ), math::vector2( 1, -1 ), math::colour4::WHITE ),
        addPoint( math::triple( -1, -1, 0 ), math::triple( 0, 0, 0 ), math::vector2( -1, -1 ), math::colour4::WHITE ),
        addPoint( math::triple( -1, 1, 0 ), math::triple( 0, 0, 0 ), math::vector2( -1, 1 ), math::colour4::WHITE ) );

    triangleCloud::setShader( *this );

    //triangleCloud::shaderVariableSet().add( _colour );
    //triangleCloud::shaderVariableSet().add( _depth );
    triangleCloud::shaderVariableSet().setShader( *this );
    triangleCloud::setUseShaderVariableSet( );
    }
Пример #20
0
void Model::addPlane(const glm::vec3 &a, const glm::vec3 &b, const glm::vec3 &c, const glm::vec4 &texRect) {
    glm::vec3 normal = normalize(cross(c - b, a - b));
    glm::vec3 d = a + c - b;

    glm::vec2 t0(texRect.x, texRect.y);
    glm::vec2 t1(texRect.x + texRect.z, texRect.y + texRect.w);

    switch (mPrimitive) {
        case GLTriangles: {
            reserveIndices(6);
            size_t n = mVertices.size();
            addQuad(n+0, n+1, n+2, n+3);

            reserveVertices(4);
            addVertex(Vertex(glm::vec2(t1.x,t0.y), normal, c));
            addVertex(Vertex(glm::vec2(t1.x,t1.y), normal, d));
            addVertex(Vertex(glm::vec2(t0.x,t1.y), normal, a));
            addVertex(Vertex(glm::vec2(t0.x,t0.y), normal, b));
            break;
        }
    }
}
Пример #21
0
//--------------------------------------------------------------------------------------------------
/// Add one face 
/// 
/// The type of primitive added will be determined from the number of indices passed in \a indices
/// 
/// \remarks Currently, points and lines are not supported. Faces with more than 4 indices will
///          be triangulated using fanning
//--------------------------------------------------------------------------------------------------
void GeometryBuilder::addFace(const UIntArray& indices)
{
    size_t numIndices = indices.size();
    CVF_ASSERT(numIndices >= 3);

    if (numIndices == 3)
    {
        addTriangle(indices[0], indices[1], indices[2]);
    }
    else if (numIndices == 4)
    {
        addQuad(indices[0], indices[1], indices[2], indices[3]);
    }
    else
    {
        size_t numTriangles = numIndices - 2;
        size_t i;
        for (i = 0; i < numTriangles; i++)
        {
            addTriangle(indices[0], indices[i + 1], indices[i + 2]);
        }
    }
}
Пример #22
0
CardBuilder::CardBuilder(const CardSpecifications& specifications)
    : _specifications(specifications)
{
    float w = _specifications.width() / 2.0f;
    float h = _specifications.height() / 2.0f;
    float cr = _specifications.cornerRadius();
    int cd = _specifications.cornerDetail();

    int vertexCount = 8 * cd + 16;
    _vertices.reserve(vertexCount * 3);
    _textureCoordinates.reserve(vertexCount * 2);

    // upper left corner
    addVertex(cr - w, h - cr, cr / _specifications.width(),
        cr / _specifications.height());

    addVertex(-w, h - cr, 0.0f, cr / _specifications.height());

    float theta = 90.0f / float(cd);
    for (int i = 1; i < cd; ++i)
    {
        float radians = float(i) * theta * (3.1415926535898f / 180.0f);
        float dx = cr * cos(radians);
        float dy = cr * sin(radians);

        addVertex(cr - w - dx, h  - cr + dy,
            (cr - dx) / _specifications.width(),
            (cr - dy) / _specifications.height());
    }

    addVertex(cr - w, h, cr / _specifications.width(), 0.0f);

    // upper right corner
    addVertex(-_vertices[0], _vertices[1],
        1.0f - _textureCoordinates[0],
        _textureCoordinates[1]);

    int previousVertex = _vertices.size() - 6;
    int previousTexture = _textureCoordinates.size() - 4;

    int mirrorVertex = _vertices.size() - 12;
    int mirrorTexture = _textureCoordinates.size() - 8;

    for (int i = 0; i <= cd; ++i)
    {
        addVertex(-_vertices[mirrorVertex], _vertices[mirrorVertex + 1],
            1.0f - _textureCoordinates[mirrorTexture],
            _textureCoordinates[mirrorTexture + 1]);

        mirrorVertex -= 6;
        mirrorTexture -= 4;
    }

    // lower right corner
    addVertex(_vertices[previousVertex], -_vertices[previousVertex + 1],
        _textureCoordinates[previousTexture],
        1.0f - _textureCoordinates[previousTexture + 1]);

    previousVertex = _vertices.size() - 6;
    previousTexture = _textureCoordinates.size() - 4;

    mirrorVertex = _vertices.size() - 12;
    mirrorTexture = _textureCoordinates.size() - 8;

    for (int i = 0; i <= cd; ++i)
    {
        addVertex(_vertices[mirrorVertex], -_vertices[mirrorVertex + 1],
            _textureCoordinates[mirrorTexture],
            1.0f - _textureCoordinates[mirrorTexture + 1]);

        mirrorVertex -= 6;
        mirrorTexture -= 4;
    }

    // lower left corner
    addVertex(-_vertices[previousVertex], _vertices[previousVertex + 1],
        1.0f - _textureCoordinates[previousTexture],
        _textureCoordinates[previousTexture + 1]);

    previousVertex = _vertices.size() - 6;
    previousTexture = _textureCoordinates.size() - 4;

    mirrorVertex = _vertices.size() - 12;
    mirrorTexture = _textureCoordinates.size() - 8;

    for (int i = 0; i <= cd; ++i)
    {
        addVertex(-_vertices[mirrorVertex], _vertices[mirrorVertex + 1],
            1.0f - _textureCoordinates[mirrorTexture],
            _textureCoordinates[mirrorTexture + 1]);

        mirrorVertex -= 6;
        mirrorTexture -= 4;
    }
    // texture correction
    for (int i = 0; i < vertexCount; ++i)
    {
        int index = i * 2 + 1;
        _textureCoordinates[index] = 1.0f - _textureCoordinates[index];
    }

    // index creation
    int triangleCount = 16 * cd + 28;
    int middleTriangleCount = 8 * cd + 8;
    int topTriangleCount = (triangleCount - middleTriangleCount) / 2;

    _topIndices.reserve(topTriangleCount * 3);
    _middleIndices.reserve(middleTriangleCount * 3);
    _bottomIndices.reserve(topTriangleCount * 3);

    GLushort corners[5];
    int cornerSize = 2 * cd + 4;

    for (int i = 0; i < 5; ++i)
        corners[i] = cornerSize * i;

    for (int i = 0; i < 4; ++i)
    {
        int i4 = (i + 1) % 4;
        addQuads(corners[i], corners[i + 1] - 2, corners[i4] + 2, corners[i4]);
        addQuad(corners[i + 1] - 2, corners[i + 1] - 1, corners[i4] + 3,
            corners[i4] + 2);

        for (int j = 0; j < cd; ++j)
        {
            int k = 2 * (j + 1);
            addTriangles(corners[i], corners[i] + k, corners[i] + k + 2);
            addQuad(corners[i] + k, corners[i] + k + 1, corners[i] + k + 3,
                corners[i] + k + 2);
        }
    }

    addQuads(corners[0], corners[1], corners[2], corners[3]);
}
Пример #23
0
// 表达式
string CodeGenerator::Expr() {
    if(Tokens[CurToken].Type == String) {
        string res = newTemp("string");
        newConst("string", Tokens[CurToken].value);
        CurToken++;
        return res;
    }
    int L = CurToken, R;
    int cntBrac = 0;
    for(R = L; R < Tokens.size(); R++) {
        string val = Tokens[R].value;
        if(val == ";" || val == ")" && cntBrac == 0) break;
        if(val == "(") cntBrac++;
        if(val == ")") cntBrac--;
    }
    CurToken = R;

    map<string, int> Prior;
    Prior["("] = 10, Prior[")"] = 0;
    Prior["!"] = 1;
    Prior["%"] = Prior["*"] = Prior["/"] = 2;
    Prior["+"] = Prior["-"] = 3;
    Prior[">="] = Prior["<="] = Prior[">"] = Prior["<"] = 4;
    Prior["=="] = Prior["!="] = 5;
    Prior["&&"] = 6;
    Prior["||"] = 7;

    stack<string> Num, Op;
    for(int i = L; i < R; i++) {
        string Type = CodeToString(Tokens[i]);
        string val = Tokens[i].value;
        if(Type == "number" || Type == "id") {
            if(Type == "id") Num.push(val);
            else Num.push(newConst((string)(Tokens[i].Type == Integer ? "int" : "double"), itos(Tokens[i].num)));
        } else {
            if(val == "(") {
                Op.push(val);
            } else if(val == ")") {
                while(Op.top() != "(") {
                    string op = Op.top(); Op.pop();
                    string y = Num.top(); Num.pop();
                    if(op == "!") {
                        string res = newTemp(VarTable[y].Type); Num.push(res);
                        addQuad(op, y, "$", res);
                        continue;
                    }
                    string x = Num.top(); Num.pop();
                    string res = newTemp(VarTable[x].Type); Num.push(res);
                    if(op == ">=" || op == "<=" || op == "==" || op == "!=" || op == ">" || op == "<") {
                        addQuad("J" + op, x, y, itos(CurLabel + 3));
                        addQuad("=", res, "0", res);
                        addQuad("J", "$", "$", itos(CurLabel + 2));
                        addQuad("=", res, "1", res);
                    } else {
                        addQuad(op, x, y, res);
                    }
                }
                Op.pop();
            } else {
                while(!Op.empty() && Prior[val] >= Prior[Op.top()]) {
                    string op = Op.top(); Op.pop();
                    string y = Num.top(); Num.pop();
                    if(op == "!") {
                        string res = newTemp(VarTable[y].Type); Num.push(res);
                        addQuad(op, y, "$", res);
                        continue;
                    }
                    string x = Num.top(); Num.pop();
                    string res = newTemp(VarTable[x].Type); Num.push(res);
                    if(op == ">=" || op == "<=" || op == "==" || op == "!=" || op == ">" || op == "<") {
                        addQuad("J" + op, x, y, itos(CurLabel + 3));
                        addQuad("=", res, "0", res);
                        addQuad("J", "$", "$", itos(CurLabel + 2));
                        addQuad("=", res, "1", res);
                    } else {
                        addQuad(op, x, y, res);
                    }
                }
                Op.push(val);
            }
        }
    }
    while(!Op.empty()) {
        string op = Op.top(); Op.pop();
        string y = Num.top(); Num.pop();
        if(op == "!") {
            string res = newTemp(VarTable[y].Type); Num.push(res);
            addQuad(op, y, "$", res);
            continue;
        }
        string x = Num.top(); Num.pop();
        string res = newTemp(VarTable[x].Type); Num.push(res);
        if(op == ">=" || op == "<=" || op == "==" || op == "!=" || op == ">" || op == "<") {
            addQuad("J" + op, x, y, itos(CurLabel + 3));
            addQuad("=", res, "0", res);
            addQuad("J", "$", "$", itos(CurLabel + 2));
            addQuad("=", res, "1", res);
        } else {
            addQuad(op, x, y, res);
        }
    }
    return Num.top();
}
Пример #24
0
void CodeGenerator::Assign() {
    string arg1 = getToken().value; match("=");
    string arg2 = Expr();
    addQuad("=", arg1, arg2, arg1);
    match(";");
}
Пример #25
0
size_t VertexData::addQuadAndIndices(int a, int b, int c, int d) {
	addQuadIndices(a,b,c,d);
	return addQuad(a,b,c,d);
}
Пример #26
0
Ogre::ManualObject* ProceduralShape::createAvatar(
	Ogre::SceneManager* i_pSceneMngr,
	Ogre::SceneNode* i_pParent,
	const Ogre::String& i_name,
	float i_height,
	float i_width,
	float i_depth,
	float i_sameHeight,
	float i_seamWidth,
	float i_resolution,
	const Ogre::String& i_material)
{
	// create ManualObject
	Ogre::ManualObject* manual = i_pSceneMngr->createManualObject(i_name);

	// define start and end point
	const float &h = i_height / 2.f;
	const float &w = i_width / 2.f;
	const float &d = i_depth / 2.f;
	const float &sh = i_sameHeight;
	const float &sw = i_seamWidth / 2.f;

	std::vector<Ogre::Vector3> p{
		Ogre::Vector3(d, -w, -h), Ogre::Vector3(d, -sw, -h), Ogre::Vector3(-d, -sw, -h), Ogre::Vector3(-d, -w, -h), // 0, 1, 2, 3
		Ogre::Vector3(d, sw, -h), Ogre::Vector3(d, w, -h), Ogre::Vector3(-d, w, -h), Ogre::Vector3(-d, sw, -h), // 4, 5, 6, 7
		Ogre::Vector3(d, -w, -h + sh), Ogre::Vector3(d, -sw, -h + sh), Ogre::Vector3(d, sw, -h + sh), Ogre::Vector3(d, w, -h + sh), // 8, 9, 10, 11
		Ogre::Vector3(-d, w, -h + sh), Ogre::Vector3(-d, sw, -h + sh), Ogre::Vector3(-d, -sw, -h + sh), Ogre::Vector3(-d, -w, -h + sh), // 12, 13, 14, 15
		Ogre::Vector3(d, -w, h), Ogre::Vector3(d, w, h), Ogre::Vector3(-d, w, h), Ogre::Vector3(-d, -w, h), // 16, 17, 18, 19
	};

	std::vector<std::vector<std::vector<int>>> q{
		{ { 0, 1, 2, 3 }, { 9, 10, 13, 14 }, { 4, 5, 6, 7 } },
		{ { 5, 17, 18, 6 }, { 1, 9, 14, 2 } },
		{ { 17, 16, 19, 18 } },
		{ { 19, 16, 0, 3 }, { 10, 4, 7, 13 } },
		{ { 0, 8, 9, 1 }, { 4, 10 , 11, 5}, { 8, 16, 17, 11 } },
		{ { 2 ,14 ,15 ,3 }, {6, 12, 13, 7}, {12, 18, 19, 15 } }
	};

	std::vector<Ogre::Vector3> n{
		Ogre::Vector3(0.f, 0.f, 0.f),
		Ogre::Vector3(0.f, 1.f, 0.f),
		Ogre::Vector3(0.f, 0.f, 1.f),
		Ogre::Vector3(0.f, -1.f, 0.f),
		Ogre::Vector3(1.f, 0.f, 0.f),
		Ogre::Vector3(-1.f, 0.f, 0.f)
	};

	for (size_t f = 0; f < q.size(); f++) // for each face
	{
		for (size_t iq = 0; iq < q[f].size(); iq++) // for each quad
		{
			std::vector<Ogre::Vector3> clockwiseQuad{
				p[q[f][iq][0]], p[q[f][iq][1]], p[q[f][iq][2]], p[q[f][iq][3]] };
			
			size_t nCols = (size_t)ceil((clockwiseQuad[0] - clockwiseQuad[1]).length() / i_resolution);
			size_t nRows = (size_t)ceil((clockwiseQuad[0] - clockwiseQuad[3]).length() / i_resolution);
			addQuad(clockwiseQuad, n[f], nRows, nCols, i_material, *manual);
		}
	}

	i_pParent->attachObject(manual);

	return manual;
}
Пример #27
0
void Mesh::addFace(VertexList<Vertex>* vertexList, const Face& face) {
  if (face.type == Quad) 
    addQuad(vertexList, face);
  else 
    addTri(vertexList, face);
}
Пример #28
0
bool Magic3D::TextData::update(Object* object)
{
    if (object)
    {

    }
    Renderer* renderer = Renderer::getInstance();
    Font* font = getFont();
    std::vector<float> lines;

    if (!font)
    {
        return false;
    }

    float fsize = (textSize / 512.0f) / font->getLineHeightInPixels();
    float lineHeight = fsize * (font->getLineHeightInPixels() + 2.0f);

    int quadCount = getVerticesCount() / 4;

    if (quadCount < (int)text.size() - lastReturns)
    {
        lastReturns = 0;
        size_t tsize = text.size();
        for (size_t i = 0; i < tsize; i++)
        {
            if (text.at(i) == '\n')
            {
                lastReturns++;
                continue;
            }
            else if (renderer->hasMapBuffer() || ((int)i >= quadCount))
            {
                addQuad(0.0f, 0.0f, 1.0f, 1.0f, eAXIS_Z, false);
            }
        }

        createVbo();
        quadCount = getVerticesCount() / 4;
    }

    width = 0.0f;
    height = lineHeight;

    if (getVerticesCount() > 0)
    {        
        int quad = -1;
        float startX = 0.0f;
        float startY = 0.0f;
        float* buffer = mapBuffer();

        int lastIndex = 0;
        size_t tsize = text.size();
        for (size_t i = 0; i < tsize; i++)
        {
            int index = text.at(i);

            if (index < 0)
            {
                index = 256 + index;
            }

            FontChar* fchar = font->getChar(index);            

            if (text.at(i) == '\n')
            {
                lines.push_back(startX);
                if (width < startX)
                {
                    width = startX;
                }
                startX = 0.0f;
                if (invert)
                {
                    startY -= lineHeight;
                }
                else
                {
                    startY += lineHeight;
                }
                height += lineHeight;
                continue;
            }
            else
            {
                quad++;
            }

            float texX = fchar->x;
            float texY = 1.0f - fchar->y;
            float texW = fchar->width;
            float texH = fchar->height;

            float cwidth = fchar->width * font->getTextureWidth() * fsize;
            float cheight = fchar->height * font->getTextureHeight() * fsize;

            float coffsetX = fchar->offsetX * font->getTextureWidth() * fsize;
            float coffsetY = fchar->offsetY * font->getTextureHeight() * fsize;
            float cadvanceX = fchar->advanceX * font->getTextureWidth() * fsize;

            float ckernel = 0.0f;
            std::map<int, float>::const_iterator k = fchar->kernel.find(lastIndex);
            if (k != fchar->kernel.end())
            {
                ckernel = (*k).second * fsize;
            }

            setQuad(buffer, quad, startX + coffsetX + ckernel, startY + coffsetY * 0.5f, cwidth, cheight);
            if (invert)
            {
                setQuadTexture(buffer, quad, texX, texY - texH, texW, -texH);
            }
            else
            {
                setQuadTexture(buffer, quad, texX, texY, texW, texH);
            }


            startX += cadvanceX;
            lastIndex = index;
        }
        quad++;
        for (int i = quad; i < quadCount; i++)
        {
            setQuad(buffer, i, startX, startY, 0.0f, 0.0f);
        }

        lines.push_back(startX);
        if (width < startX)
        {
            width = startX;
        }

        width += (2.0f * fsize);

        quad = 0;
        int line = 0;
        tsize = text.size();
        for (size_t i = 0; i < tsize; i++)
        {
            if (text.at(i) != '\n')
            {
                float w = width * -0.5f;
                float diff = line < (int)lines.size() ? lines.at(line) : width;
                switch (textAlignment)
                {
                    case eHORIZONTAL_ALIGN_CENTER: w += (width - diff) * 0.5f; break;
                    case eHORIZONTAL_ALIGN_RIGHT:  w += (width - diff); break;
                    default: break;
                }

                if (invert)
                {
                    moveQuad(buffer, quad, w, height * 0.5f - lineHeight, 0.0f);
                }
                else
                {
                    moveQuad(buffer, quad, w, height * -0.5f, 0.0f);
                }
                quad++;
            }
            else
            {
                line++;
            }
        }

        unmapBuffer();
    }

    changed = false;

    box.corners[0] = Vector3(-width * 0.5f, -height * 0.5f, 0.0f);
    box.corners[1] = Vector3(width * 0.5f, height * 0.5f, 0.0f);
    return true;
}
Пример #29
0
void main()
{
  //Check grid coordinate in range
  ivec2 gridCoord = ivec2( gl_FragCoord.xy );
  if (gridCoord.x < 0 || gridCoord.x >= gridSize.x ||
      gridCoord.y < 0 || gridCoord.y >= gridSize.y)
  { discard; return; }

  bool found1=false, found2=false, inside=false;
  float yy1=0.0, yy2=0.0, xx1=0.0, xx2=0.0;

  //Get object pointer and object grid info
  int *ptrObj = ptrObjects + objectId * NODE_SIZE_OBJINFO;
  ivec2 objGridOrigin = ivec2( ptrObj[0], ptrObj[1] );
  ivec2 objGridSize   = ivec2( ptrObj[2], ptrObj[3] );
  int   objGridOffset = ptrObj[4];
  
  //Get object grid pointer
  coherent int *ptrObjGrid = ptrGrid + objGridOffset;

  //Check object grid coordinate in range
  ivec2 objGridCoord = gridCoord - objGridOrigin;
  if (objGridCoord.x < 0 || objGridCoord.x >= objGridSize.x ||
      objGridCoord.y < 0 || objGridCoord.y >= objGridSize.y)
  { discard; return; }

  //Get object grid cell pointer
  coherent int* ptrObjCell = ptrObjGrid
    + (objGridCoord.y * objGridSize.x + objGridCoord.x) * NUM_OBJCELL_COUNTERS;

  //Find cell origin
  vec2 cmin = gridOrigin + gridCoord * cellSize;

  //Transform quad coords into cell space
  vec2 q0 = (quad0 - cmin) / cellSize;
  vec2 q1 = (quad1 - cmin) / cellSize;
  vec2 q2 = (quad2 - cmin) / cellSize;

  //Check if quad intersects bottom edge
  quadIntersectionY( q0, q1, q2, 1.0, 0.0, 1.0, found1, found2, xx1, xx2 );
  if (found1 != found2)
  {
    //Walk all the cells to the left
    for (int x = (int)objGridCoord.x - 1; x >= 0; --x)
    {
      //Get object grid cell pointer
      coherent int *ptrObjCellAux = ptrObjGrid
        + (objGridCoord.y * objGridSize.x + x) * NUM_OBJCELL_COUNTERS;

      //Increase auxiliary vertical counter
      atomicAdd( ptrObjCellAux + OBJCELL_COUNTER_AUX, 1 );
    }
  }
  if (found1 || found2) inside = true;

  //Check if quad intersects right edge
  quadIntersectionY( q0.yx, q1.yx, q2.yx, 1.0, 0.0, 1.0, found1, found2, yy1, yy2 );
  if (found1)
  {
    //Add line spanning from intersection point to upper-right corner
    addLine( vec2( 1.0, yy1 ), vec2( 1.0, -0.25 ), ptrObjCell );
    inside = true;
  }
  if (found2)
  {
    //Add line spanning from intersection point to upper-right corner
    addLine( vec2( 1.0, yy2 ), vec2( 1.0, -0.25 ), ptrObjCell );
    inside = true;
  }

  //Check for additional conditions if these two failed
  if (!inside)
  {
    //Check if start point inside
    if (q0.x >= 0.0 && q0.x <= 1.0 && q0.y >= 0.0 && q0.y <= 1.0)
      inside = true;
    else
    {
      //Check if end point inside
      if (q2.x >= 0.0 && q2.x <= 1.0 && q2.y >= 0.0 && q2.y <= 1.0)
        inside = true;
      else
      {
        //Check if quad intersects top edge
        quadIntersectionY( q0, q1, q2, 0.0, 0.0, 1.0, found1, found2, xx1, xx2 );
        if (found1 || found2) inside = true;
        else
        {
          //Check if quad intersects left edge
          quadIntersectionY( q0.yx, q1.yx, q2.yx, 0.0, 0.0, 1.0, found1, found2, yy1, yy2 );
          if (found1 || found2) inside = true;
        }
      }
    }
  }

  if (inside)
  {
    //Add quad data to stream
    addQuad( q0,q1,q2, ptrObjCell );
  }

  discard;
}
Пример #30
0
void QuadList::addQuads(const std::vector<Quad> &quads, int x, int y)
{
	for (unsigned int i = 0; i < quads.size(); i++)
		addQuad(quads[i], x, y);
}