std::list<std::shared_ptr<I_Object>> SceneSettingReader::readObjects()
{
    std::list<std::shared_ptr<I_Object>> objects;
    settings_.beginGroup(OBJECTS_GROUP);
    const int size = settings_.beginReadArray("objects");
    for (int i = 0; i < size; ++i)
    {
        settings_.setArrayIndex(i);
        if (settings_.value("type").toString() == "sphere")
        {
            objects.push_back(std::shared_ptr<I_Object>(readSphere()));
        }
        else if (settings_.value("type").toString() == "triangle")
        {
            objects.push_back(std::shared_ptr<I_Object>(readTriangle()));
        }
        else if (settings_.value("type").toString() == "quad")
        {
            objects.push_back(std::shared_ptr<I_Object>(readQuad()));
        }
        else if (settings_.value("type").toString() == "model")
        {
            objects.push_back(std::shared_ptr<I_Object>(readModel()));
        }
        else
        {
            std::cout << "Error: object type is not valid"
                << settings_.value("type").toString().toStdString() << std::endl;
        }
    }
    settings_.endArray();
    settings_.endGroup();
    return objects;
}
Ejemplo n.º 2
0
 void XMLMesh::startElement(const xmlChar *name, const xmlChar **attrs) {
   switch (state) {
   case OUTSIDE:
     if (xmlStrcasecmp(name, (xmlChar *) "mesh") == 0) {
       readMesh(name, attrs);
       state = INSIDE_MESH;
     }
     break;
   case INSIDE_MESH:
     if (xmlStrcasecmp(name, (xmlChar *) "vertices") == 0) {
       readVertices(name, attrs);
       state = INSIDE_VERTICES;
     }
     else if (xmlStrcasecmp(name, (xmlChar *) "cells") == 0) {
       readCells(name, attrs);
       state = INSIDE_CELLS;
     }
     break;
   case INSIDE_VERTICES:
     if (xmlStrcasecmp(name, (xmlChar *) "vertex") == 0)
       readVertex(name, attrs);
     break;
   case INSIDE_CELLS:
     if (xmlStrcasecmp(name, (xmlChar *) "interval") == 0) {
       readInterval(name, attrs);
     } else if (xmlStrcasecmp(name, (xmlChar *) "triangle") == 0) {
       readTriangle(name, attrs);
     } else if (xmlStrcasecmp(name, (xmlChar *) "tetrahedron") == 0) {
       readTetrahedron(name, attrs);
     }
     break;
   default:
     break;
   }
 };
Ejemplo n.º 3
0
int main(void) {
    char type;
    int countFigures = 0;
    int countRectangles = 0;
    int countCircles = 0;
    int countTriangles = 0;
    Rectangle rectangles[10];
    Circle circles[10];
    Triangle triangles[10];
    
    float pointX;
    float pointY;
    
    while(scanf("%c", &type) == 1) {
        if (type == '*') {
            break;
        } else if (type == 'r') {
            readRectangle(countFigures, countRectangles, rectangles);
            countRectangles++;                        
            countFigures++;
        } else if (type == 'c') {
            readCircle(countFigures, countCircles, circles);
            countCircles++;
            countFigures++;
        } else if (type == 't') {
            readTriangle(countFigures, countTriangles, triangles);
            countTriangles++;
            countFigures++;
        } else {
            continue;
        }
    }
    
    int pointIndex = 1;
    while(scanf("%f %f\n", &pointX, &pointY) == 2) {
        if (pointX >= 9999 && pointY >= 9999) {
            break;
        } else {
            checkInFigure(rectangles, countRectangles,
                            circles, countCircles,
                            triangles, countTriangles,
                            pointIndex, pointX, pointY);
            pointIndex++;
        }
    } 
    
    
    return 0;
}
Ejemplo n.º 4
0
void ModelFactory::readItems()
{
    bool eof = false;
    std::string current = readerObj->readWord(eof);

    while (!eof)
    {
        if (strcmp("f", current.data()) == 0)
            model->addPolygon(readTriangle());
        else if (strcmp("v", current.data()) == 0)
            model->addPoint(readPoint3D());
       // else if (strcmp("vt", current.data()) == 0)
       //     model->addTexture(readPoint2D());
        else if (strcmp("vn", current.data()) == 0)
            model->addNormal(readPoint3D());
        current = readerObj->readWord(eof);
    }
}
Ejemplo n.º 5
0
ShapePointer SceneLoader::readShape(const QDomElement &element) const {
  QString shapeType;
  if (!readAttributeAsString(element, "type", shapeType)) {
    return ShapePointer(NULL);
  }

  MaterialPointer shapeMaterial = readMaterial(element);
  if (shapeMaterial == NULL) {
    return ShapePointer(NULL);
  }

  if (shapeType == "plane") {
    return readPlane(element, shapeMaterial);
  }
  if (shapeType == "sphere") {
    return readSphere(element, shapeMaterial);
  }
  if (shapeType == "cylinder") {
    return readCylinder(element, shapeMaterial);
  }
  if (shapeType == "cone") {
    return readCone(element, shapeMaterial);
  }
  if (shapeType == "triangle") {
    return readTriangle(element, shapeMaterial);
  }
  if (shapeType == "box") {
    return readBox(element, shapeMaterial);
  }
  if (shapeType == "torus") {
    return readTorus(element, shapeMaterial);
  }
  if (shapeType == "model") {
    return readMeshModel(element, shapeMaterial);
  }

  std::cerr << "Scene parsing error: unknown shape type '" << shapeType.toUtf8().constData() << "'" << std::endl;
  return ShapePointer(NULL);
}