예제 #1
0
static void idle(void){
	static float last_t = 0.0f;
	float this_t = glutGet(GLUT_ELAPSED_TIME)/1000.0f;
	if(this_t-last_t > 1.0f/61.0f){
		if(renderdiff){
			diffrCalculate();
			redisplay = true;
		}
		if(rotating) redisplay = true;
		idleArcball();
		last_t = this_t;
	}
	

	static uint last_time=0;
	static uint this_time=0;
	
	if(animation&&!pause){
		if(ani_frame >= ani_files)ani_frame = 0;
		else if(ani_frame < 0) ani_frame += ani_files;
		this_time=glutGet(GLUT_ELAPSED_TIME);
		if(this_time-last_time>=ani_speed){
			redisplay=true;
			parseCoords(ani_matrix[ani_frame],"\t");
			ani_frame++;
			last_time=this_time;
		}
	}
	
	if(redisplay){
		redisplay=false;
		countFPS();
		glutPostRedisplay();
	}
}
예제 #2
0
bool GraphMLHandler::characters(const QString& ch)
{
  // Assuming only proper data
  if(ch.trimmed().isEmpty())
    return true;
  parseCoords(ch);
  return true;
}
예제 #3
0
    //==============================================================================
    Drawable* parseSVGElement (const XmlPath& xml)
    {
        if (! xml->hasTagNameIgnoringNamespace ("svg"))
            return nullptr;

        DrawableComposite* const drawable = new DrawableComposite();

        setDrawableID (*drawable, xml);

        SVGState newState (*this);

        if (xml->hasAttribute ("transform"))
            newState.addTransform (xml);

        newState.elementX = getCoordLength (xml->getStringAttribute ("x",      String (newState.elementX)), viewBoxW);
        newState.elementY = getCoordLength (xml->getStringAttribute ("y",      String (newState.elementY)), viewBoxH);
        newState.width    = getCoordLength (xml->getStringAttribute ("width",  String (newState.width)),    viewBoxW);
        newState.height   = getCoordLength (xml->getStringAttribute ("height", String (newState.height)),   viewBoxH);

        if (newState.width  <= 0) newState.width  = 100;
        if (newState.height <= 0) newState.height = 100;

        Point<float> viewboxXY;

        if (xml->hasAttribute ("viewBox"))
        {
            const String viewBoxAtt (xml->getStringAttribute ("viewBox"));
            String::CharPointerType viewParams (viewBoxAtt.getCharPointer());
            Point<float> vwh;

            if (parseCoords (viewParams, viewboxXY, true)
                 && parseCoords (viewParams, vwh, true)
                 && vwh.x > 0
                 && vwh.y > 0)
            {
                newState.viewBoxW = vwh.x;
                newState.viewBoxH = vwh.y;

                int placementFlags = 0;

                const String aspect (xml->getStringAttribute ("preserveAspectRatio"));

                if (aspect.containsIgnoreCase ("none"))
                {
                    placementFlags = RectanglePlacement::stretchToFit;
                }
                else
                {
                    if (aspect.containsIgnoreCase ("slice"))        placementFlags |= RectanglePlacement::fillDestination;

                    if (aspect.containsIgnoreCase ("xMin"))         placementFlags |= RectanglePlacement::xLeft;
                    else if (aspect.containsIgnoreCase ("xMax"))    placementFlags |= RectanglePlacement::xRight;
                    else                                            placementFlags |= RectanglePlacement::xMid;

                    if (aspect.containsIgnoreCase ("yMin"))         placementFlags |= RectanglePlacement::yTop;
                    else if (aspect.containsIgnoreCase ("yMax"))    placementFlags |= RectanglePlacement::yBottom;
                    else                                            placementFlags |= RectanglePlacement::yMid;
                }

                newState.transform = RectanglePlacement (placementFlags)
                                        .getTransformToFit (Rectangle<float> (viewboxXY.x, viewboxXY.y, vwh.x, vwh.y),
                                                            Rectangle<float> (newState.width, newState.height))
                                        .followedBy (newState.transform);
            }
        }
        else
        {
            if (viewBoxW == 0)  newState.viewBoxW = newState.width;
            if (viewBoxH == 0)  newState.viewBoxH = newState.height;
        }

        newState.parseSubElements (xml, *drawable);

        drawable->setContentArea (RelativeRectangle (RelativeCoordinate (viewboxXY.x),
                                                     RelativeCoordinate (viewboxXY.x + newState.viewBoxW),
                                                     RelativeCoordinate (viewboxXY.y),
                                                     RelativeCoordinate (viewboxXY.y + newState.viewBoxH)));
        drawable->resetBoundingBoxToContentArea();

        return drawable;
    }
예제 #4
0
    //==============================================================================
    Drawable* parseSVGElement (const XmlElement& xml)
    {
        if (! xml.hasTagName ("svg"))
            return nullptr;

        DrawableComposite* const drawable = new DrawableComposite();

        drawable->setName (xml.getStringAttribute ("id"));

        SVGState newState (*this);

        if (xml.hasAttribute ("transform"))
            newState.addTransform (xml);

        newState.elementX = getCoordLength (xml.getStringAttribute ("x", String (newState.elementX)), viewBoxW);
        newState.elementY = getCoordLength (xml.getStringAttribute ("y", String (newState.elementY)), viewBoxH);
        newState.width    = getCoordLength (xml.getStringAttribute ("width", String (newState.width)), viewBoxW);
        newState.height   = getCoordLength (xml.getStringAttribute ("height", String (newState.height)), viewBoxH);

        if (newState.width <= 0)  newState.width  = 100;
        if (newState.height <= 0) newState.height = 100;

        if (xml.hasAttribute ("viewBox"))
        {
            const String viewBoxAtt (xml.getStringAttribute ("viewBox"));
            String::CharPointerType viewParams (viewBoxAtt.getCharPointer());
            float vx, vy, vw, vh;

            if (parseCoords (viewParams, vx, vy, true)
                 && parseCoords (viewParams, vw, vh, true)
                 && vw > 0
                 && vh > 0)
            {
                newState.viewBoxW = vw;
                newState.viewBoxH = vh;

                int placementFlags = 0;

                const String aspect (xml.getStringAttribute ("preserveAspectRatio"));

                if (aspect.containsIgnoreCase ("none"))
                {
                    placementFlags = RectanglePlacement::stretchToFit;
                }
                else
                {
                    if (aspect.containsIgnoreCase ("slice"))
                        placementFlags |= RectanglePlacement::fillDestination;

                    if (aspect.containsIgnoreCase ("xMin"))
                        placementFlags |= RectanglePlacement::xLeft;
                    else if (aspect.containsIgnoreCase ("xMax"))
                        placementFlags |= RectanglePlacement::xRight;
                    else
                        placementFlags |= RectanglePlacement::xMid;

                    if (aspect.containsIgnoreCase ("yMin"))
                        placementFlags |= RectanglePlacement::yTop;
                    else if (aspect.containsIgnoreCase ("yMax"))
                        placementFlags |= RectanglePlacement::yBottom;
                    else
                        placementFlags |= RectanglePlacement::yMid;
                }

                const RectanglePlacement placement (placementFlags);

                newState.transform
                    = placement.getTransformToFit (Rectangle<float> (vx, vy, vw, vh),
                                                   Rectangle<float> (0.0f, 0.0f, newState.width, newState.height))
                               .followedBy (newState.transform);
            }
        }
        else
        {
            if (viewBoxW == 0)
                newState.viewBoxW = newState.width;

            if (viewBoxH == 0)
                newState.viewBoxH = newState.height;
        }

        newState.parseSubElements (xml, drawable);

        drawable->resetContentAreaAndBoundingBoxToFitChildren();
        return drawable;
    }
예제 #5
0
bool ofxOBJModel::load(string path) {
	bHasNormals = false;
	bHasTexCoords = false;
	filePath = path;
	path = ofToDataPath(path, true);
	
	string line;
	
	for(int i = 0; i < meshes.size(); i++) {
		delete meshes[i];
	}
	meshes.clear();
	
	ObjMesh *currMesh = NULL;
	
	// this is a list of all points
	// that we can drop after parsing
	vector<ofPoint> points; 
	vector<ofPoint> normals;
	vector<ofPoint> texCoords;
	
	// obj file format vertexes are 1-indexed
	points.push_back(ofPoint());
	normals.push_back(ofPoint());
	texCoords.push_back(ofPoint());
	ifstream myfile (path.c_str());
	if (myfile.is_open()) {
		while (! myfile.eof()) {
			getline (myfile,line);
			
			
			// parse the obj format here.
			//
			// the only things we're interested in is
			// lines beginning with 'g' - this says start of new object
			// lines beginning with 'v ' - coordinate of a vertex
			// lines beginning with 'vn ' - vertex normals                   -- todo
			// lines beginning with 'vt ' - texcoords (either 2 or 3 values) -- todo
			// lines beginning with 'f ' - specifies a face of a shape
			// 			we take each number before the slash as the index
			// 			of the vertex to join up to create a face.
			
			if(line.find("g ")==0) { // new object definition
				currMesh = new ObjMesh(line.substr(2));
				meshes.push_back(currMesh);
			} else if(line.find("v ")==0) { // new vertex
				points.push_back(parseCoords(line));
			} else if(line.find("vn ")==0) {
				bHasNormals = true;
				normals.push_back(parseCoords(line));
			} else if(line.find("vt ")==0) {
				bHasTexCoords = true;
				texCoords.push_back(parseCoords(line));
			} else if(line.find("f ")==0) { // face definition
				
				if(currMesh!=NULL) {
					line = line.substr(2); // lop off "f "
					vector<string> indices = split(line, ' ');
					// remove any texcoords (/xxx's)
					
					ObjFace *face = new ObjFace();
					for(int i = 0; i < indices.size(); i++) {
						vector<string> parts = ofSplitString(indices[i], "/");
						
						// first index is always a point
						face->points.push_back(points[atoi(parts[0].c_str())]);

						if(parts.size()==2) {
							face->texCoords.push_back(texCoords[atoi(parts[1].c_str())]);
						} else if(parts.size()==3) {
							face->normals.push_back(normals[atoi(parts[2].c_str())]);
							if(parts[1]!="") {
								face->texCoords.push_back(texCoords[atoi(parts[1].c_str())]);
							}
						}

					}
					currMesh->addFace(face);
				}
			}				
		}
		
		
		myfile.close();
//#define NORMALIZE_TEXCOORDS 
#ifdef NORMALIZE_TEXCOORDS
			ofPoint pmin(FLT_MAX, FLT_MAX);
			ofPoint pmax(FLT_MIN, FLT_MIN);
			for(int i = 0; i < texCoords.size(); i++) {
				if(texCoords[i].x<pmin.x) pmin.x = texCoords[i].x;
				if(texCoords[i].y<pmin.y) pmin.y = texCoords[i].y;
				
				if(texCoords[i].x>pmax.x) pmax.x = texCoords[i].x;
				if(texCoords[i].y>pmax.y) pmax.y = texCoords[i].y;
			}
			
			for(int k = 0; k < meshes.size(); k++) 
			for(int i = 0; i < meshes[k]->faces.size(); i++) 
				for(int j = 0; j < meshes[k]->faces[i]->texCoords.size(); j++) {
					ofPoint p = meshes[k]->faces[i]->texCoords[j];
					
					p.x = ofMap(p.x, pmin.x, pmax.x, 0, 1);
					p.y = ofMap(p.y, pmin.y, pmax.y, 0, 1);
					
					meshes[k]->faces[i]->texCoords[j] = p;

				}
#endif
		loadVbo();
		ofLog(OF_LOG_NOTICE, "Successfully loaded %s\n-----\nVertices: %d\nMeshes: %d\nNormals: %d\nTexCoords: %d\n", path.c_str(), points.size(), meshes.size(), normals.size(), texCoords.size());
		
		return true;
	} else {
		ofLog(OF_LOG_ERROR, "Couldn't find the OBJ file %s\n", path.c_str());
		return false;
	}
}
예제 #6
0
int main(int argc,char *argv[] ){

	uint obj_index=0;
	uint coords_index=0;

	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA | GLUT_MULTISAMPLE | GLUT_ALPHA | GLUT_STENCIL);
	glutInitWindowSize(600,600);
	glutInitWindowPosition(100,100);
	glutCreateWindow("partViewer3D");
	
	int err = glewInit();
    if (GLEW_OK != err) {
        // problem: glewInit failed, something is seriously wrong
        printf("GLEW Error: %s\n", glewGetErrorString(err));
        return 1;
    } 
	
	//////////* Command line argument processing */////////////
	for(uint i=0;i<argc;i++){
		if(strcmp(argv[i],"-obj")==0){
			obj_index=i+1;
			use_obj=true;
			break;
		}
	}
	for(uint i=0;i<argc;i++){
		if(strcmp((argv[i]+strlen(argv[i])-4),".dat")==0){
			coords_index=i;
			break;
		}
	}
	if(argc > 4){
		animation=true;
		ani_files=argc-3;
		printf("ani_files:%d\n",ani_files);
		ani_matrix=malloc(ani_files*sizeof(*ani_matrix));
		for(uint i=0;i<ani_files;i++){
			ani_matrix[i]=malloc(strlen(argv[i+3])*sizeof(ani_matrix));
			strcpy(ani_matrix[i], argv[i+coords_index]);
		}
	}
	/////////////////////////////////////////////////////////////
	
	if(!animation) parseCoords(argv[coords_index],"\t");
	else parseCoords(ani_matrix[0],"\t");
	for(uint i = 0; i < nPart; i++){
		particle[i].selected = 0;
		particle[i].hidden = 0;
		particle[i].solid = 0;
	}
	if(use_obj)parseObj(argv[obj_index]);
	init();
	glutDisplayFunc(display);
	glutIdleFunc(idle);
	glutReshapeFunc(reshape);
	
	glutKeyboardFunc(keyDown);
	glutKeyboardUpFunc(keyUp);
	glutSpecialFunc(specialDown);
	glutSpecialUpFunc(specialUp);
	glutMouseFunc(onMouse);
	glutMotionFunc(onMotion);
	
	glutMainLoop();
	
	return 1;
}