Beispiel #1
0
QVRVNCViewer::QVRVNCViewer(int& argc, char* argv[]) :
    _wantExit(false),
    _argc(argc),
    _argv(argv),
    _vncClient(NULL),
    _vncWidth(0),
    _vncHeight(0)
{
    _qvrApp = this;
    bool haveScreenDef = false;
    bool haveValidScreenDef = false;
    for (int i = 1; i < _argc; i++) {
        if (strcmp(_argv[i], "--wall") == 0 && i < _argc - 1) {
            haveScreenDef = true;
            haveValidScreenDef = parseWall(_argv[i + 1], _screenWall);
            _screenType = screenTypeWall;
            removeArgs(_argc, _argv, i, 2);
        } else if (strncmp(_argv[i], "--wall=", 7) == 0) {
            haveScreenDef = true;
            haveValidScreenDef = parseWall(_argv[i] + 7, _screenWall);
            _screenType = screenTypeWall;
            removeArgs(_argc, _argv, i, 1);
        } else if (strcmp(_argv[i], "--cylinder") == 0 && i < _argc - 1) {
            haveScreenDef = true;
            haveValidScreenDef = parseCylinder(_argv[i + 1], _screenCylinder);
            _screenType = screenTypeCylinder;
            removeArgs(_argc, _argv, i, 2);
        } else if (strncmp(_argv[i], "--cylinder=", 11) == 0) {
            haveScreenDef = true;
            haveValidScreenDef = parseCylinder(_argv[i] + 11, _screenCylinder);
            _screenType = screenTypeCylinder;
            removeArgs(_argc, _argv, i, 1);
        }
    }
    if (!haveScreenDef)
        std::cerr << "No screen geometry given; using default wall" << std::endl;
    else if (!haveValidScreenDef)
        std::cerr << "Screen geometry invalid; falling back to default wall" << std::endl;
    if (!haveScreenDef || !haveValidScreenDef) {
        _screenType = screenTypeWall;
        _screenWall[0] = -1.0f;
        _screenWall[1] = -1.0f + QVRObserverConfig::defaultEyeHeight;
        _screenWall[2] = -3.0f;
        _screenWall[3] = +1.0f;
        _screenWall[4] = -1.0f + QVRObserverConfig::defaultEyeHeight;
        _screenWall[5] = -3.0f;
        _screenWall[6] = -1.0f;
        _screenWall[7] = +1.0f + QVRObserverConfig::defaultEyeHeight;
        _screenWall[8] = -3.0f;
    }
}
Beispiel #2
0
GeometryPtr parseGeometry(TiXmlElement *g)
{
  GeometryPtr geom;
  if (!g) return geom;

  TiXmlElement *shape = g->FirstChildElement();
  if (!shape)
  {
    logError("Geometry tag contains no child element.");
    return geom;
  }

  std::string type_name = shape->ValueStr();
  if (type_name == "sphere")
  {
    Sphere *s = new Sphere();
    resetPtr(geom,s);
    if (parseSphere(*s, shape))
      return geom;
  }
  else if (type_name == "box")
  {
    Box *b = new Box();
    resetPtr(geom,b);
    if (parseBox(*b, shape))
      return geom;
  }
  else if (type_name == "cylinder")
  {
    Cylinder *c = new Cylinder();
    resetPtr(geom,c);
    if (parseCylinder(*c, shape))
      return geom;
  }
  else if (type_name == "mesh")
  {
    Mesh *m = new Mesh();
    resetPtr(geom,m);
    if (parseMesh(*m, shape))
      return geom;
  }
  else
  {
    logError("Unknown geometry type '%s'", type_name.c_str());
    return geom;
  }

  return GeometryPtr();
}
Beispiel #3
0
my_shared_ptr<Geometry> parseGeometry(TiXmlElement *g)
{
  my_shared_ptr<Geometry> geom;
  if (!g) return geom;

  TiXmlElement *shape = g->FirstChildElement();
  if (!shape)
  {
    logError("Geometry tag contains no child element.");
    return geom;
  }

  const std::string type_name = shape->ValueTStr().c_str();
  if (type_name == "sphere")
  {
    Sphere *s = new Sphere();
    geom.reset(s);
    if (parseSphere(*s, shape))
      return geom;
  }
  else if (type_name == "box")
  {
    Box *b = new Box();
    geom.reset(b);
    if (parseBox(*b, shape))
      return geom;
  }
  else if (type_name == "cylinder")
  {
    Cylinder *c = new Cylinder();
    geom.reset(c);
    if (parseCylinder(*c, shape))
      return geom;
  }
  else if (type_name == "mesh")
  {
    Mesh *m = new Mesh();
    geom.reset(m);
    if (parseMesh(*m, shape))
      return geom;    
  }
  else
  {
    logError("Unknown geometry type '%s'", type_name.c_str());
    return geom;
  }
  
  return my_shared_ptr<Geometry>();
}
Beispiel #4
0
void SceneParser::parseObjects(void)
{
    if(currentToken == Scanner::StreamDone)
        return;
    else{
        while(errorFlag == false && currentToken != Scanner::StreamDone)
        {
            acceptToken(Scanner::Id);
            string tokenText = scanner.tokenText();

            if(tokenText == "sphere")
                parseSphere();
            else if(tokenText == "box")
                parseBox();
            else if(tokenText == "plane")
                parsePlane();
            else if(tokenText == "triangle")
                parseTriangle();
            else if(tokenText == "mesh")
                parseMesh();
            else if(tokenText == "cone")
                parseCone();
            else if(tokenText == "cylinder")
                parseCylinder();
            else if(tokenText == "pointlight")
                parsePointLight();
            else if(tokenText == "directionallight")
                parseDirectionalLight();
            else if(tokenText == "spotlight")
                parseSpotlight();
            else if(tokenText == "arealight")
                parseAreaLight();
            else{
                error("undefined command: " + tokenText);
            }

            advance();
        }
    }
}
Beispiel #5
0
Scene* Parser::parseScene(){
	///
	xml_node scene = root.child("scene");

	// optional name
	Scene* _s;
	if (scene.attribute("name") != NULL)
		_s = new Scene(scene.attribute("name").value());
	else
		_s = Scene::New();

	// optional settings
	xml_node op;
	op = scene.child("background");
	float x, y, z;
	if (op != NULL)
	{
		const char* back = op.text().as_string();
		sscanf(back, "%f %f %f", &x, &y, &z);

		_s->backgroundColor = Color(x, y, z);
		scene.remove_child("background");
	}
	op = scene.child("ambient");
	if (op != NULL)
	{
		const char* amb = op.text().as_string();
		sscanf(amb, "%f %f %f", &x, &y, &z);

		_s->ambientLight = Color(x, y, z);
		scene.remove_child("ambient");
	}

	// processing the objets in the scene
	xml_object_range<xml_node_iterator> objets = scene.children();
	Light* light;
	for (xml_node_iterator sceneElement = objets.begin(); sceneElement != objets.end(); ++sceneElement) {

		if (strcmp(sceneElement->name(), "mesh") == 0)
			_s->addActor(parseMesh(sceneElement));

		if (strcmp(sceneElement->name(), "sphere") == 0)
			_s->addActor(parseSphere(sceneElement));

		if (strcmp(sceneElement->name(), "box") == 0)
			_s->addActor(parseBox(sceneElement));

		if (strcmp(sceneElement->name(), "cone") == 0)
			_s->addActor(parseCone(sceneElement));

		if (strcmp(sceneElement->name(), "cylinder") == 0)
			_s->addActor(parseCylinder(sceneElement));

		else if (strcmp(sceneElement->name(), "light") == 0){
			light = parseLight(sceneElement);
			_s->addLight(light);
		}
	}

	return _s;
}