void WorldLoader::readString(std::string s){
    jsonRoot = parseJSON(s);
    JSONValue& jo = *jsonRoot;
    
    if (!serverMode){
        //Read and load the textures
        std::cout<<"Reading textures\n";
        std::vector<std::string> textures = jo["textures"].keys();
        
        for (std::vector<std::string>::iterator it=textures.begin(); it!=textures.end(); it++){
            //std::cout<<*it<<std::endl;
            tm.addTexture(*jo["textures"][*it],*it);
        }
    }
    //Read Projection details..
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(parseDouble(*jo["projection"]["fov"]),
                    parseDouble(*jo["projection"]["aspectRatio"]),
                    parseDouble(*jo["projection"]["near"]),
                    parseDouble(*jo["projection"]["far"])
    );

    //std::cout<<jo.stringise()<<std::endl;

    //load objects..
    int objectsCount = jo["objects"].length();
    //std::cout<<"Loading "<<objectsCount<<" objects."<<std::endl;
    for (int i=0; i<objectsCount; i++){
        GLObject* glo;
        if (*jo["objects"][i]["type"] == "cube"){
            glo = new GLCube();
            glo->setTextureManager(&tm);
            glo->setTexturePrefix(*jo["objects"][i]["texturePrefix"]);
            if (serverMode){
                jo["objects"][i].setMapValue("oid",parseJSON("\"" + getNewRandomOID() + "\""));
            }
            glo->setObjectID(*jo["objects"][i]["oid"]);
            
            
            //set up transformations..
            double position[3], rotation[3], size[3];
            std::istringstream  issp(*jo["objects"][i]["position"]),
                                isso(*jo["objects"][i]["orientation"]),
                                isss(*jo["objects"][i]["dimensions"]);
            
            issp>>position[0]>>position[1]>>position[2];
            isso>>rotation[0]>>rotation[1]>>rotation[2];
            isss>>size[0]>>size[1]>>size[2];
            glo->setPosition(position[0], position[1], position[2]);
            glo->setRotation(rotation[0], rotation[1], rotation[2]);
            glo->setSize(size[0], size[1], size[2]);
        }else{
Ejemplo n.º 2
0
void plotpaths(char* fileName, TFltPrV& ret) {
	int distance[10000];
	for (int i = 0; i < 10000; distance[i++] = 0);

	int lineCount = 1;
	std::ifstream inputFile(fileName);
	for (std::string line; std::getline(inputFile, line);) {
		std::istringstream isss(line);
		int a, c;
		double b, d;
		isss >> a;
		ret.Add(TFltPr(lineCount++, a));
	}
}
Ejemplo n.º 3
0
void Parser::firstline(std::string ligne, IHttpRequest* req)
{
	int count2 = 0;
	std::string nono[10];
	std::string urisepare[2];
	std::istringstream iss(ligne);

	while ( std::getline( iss, nono[count2] , ' ' ) )
		count2++;

	count2 = 0;
	std::istringstream isss(nono[1]);
	while ( std::getline( isss, urisepare[count2] , '?' ) )
		count2++;

	req->setCommand(nono[0]);
	req->setUri(urisepare[0]);
	std::cout << nono[2].find("\r") << std::endl;
	req->setProtocol(nono[2].substr(0,nono[2].find("\r")));
	if (count2 >= 1)
		req->setUriQuery(urisepare[1]);

}
Ejemplo n.º 4
0
void plotPR(char* fileName, TFltPrV& ret) {
	int distance[10000];
	for (int i = 0; i < 10000; distance[i++] = 0);

	std::ifstream inputFile(fileName);
	for (std::string line; std::getline(inputFile, line);) {
		std::istringstream isss(line);
		int a, c;
		double b, d;
		isss >> a >> b >> c >> d;

		int val = (int)(d * 1000);
		val -= (val % 100);
		if (val >= 10000) continue;
		//double idd = std::stold(line);
		printf("%d\n", val);
		distance[val]++;
	}

	for (int i = 0; i < 10000; ++i) {
		if (distance[i] == 0) continue;
		ret.Add(TFltPr(i, distance[i]));
	}
}