Beispiel #1
0
/* Recursively print a node hierarchy to a file stream in the .obj format */
void printNode(MODL *model, NODE *node, float parentOffset[3], FILE *ofp)
{
    //add this nodes offset to it's parent (accumulating as we recurse)
    float nodeOffset[3];
    for(int i=0; i<3; i++) nodeOffset[i] = parentOffset[i] + node->position[i];

    //the mesh if further offset by a pivot offset (and then should be rotated but not done here yet)
    float meshOffset[3];
    for(int i=0; i<3; i++) meshOffset[i] = nodeOffset[i] + node->pivot[i];
    
    //draw the mesh for this node if it has one
    if(node->meshID != -1)
    {
	printMesh(model, model->meshes[node->meshID], meshOffset, ofp);	
    }

    //recurse and print the child nodes if it has any
    if(node->hasChildren != 0)
    {
	//just recurses to the first child which will then itself recurse to 
	//any remaining siblings, see next block down
	printNode(model, model->nodes[node->childID], nodeOffset, ofp); 
    }

    //recurse and print the current node's siblings if it has any
    if(node->hasSibling != 0)
    {
	//NOTE: siblings all share the same original parent offset
	printNode(model, model->nodes[node->siblingID], parentOffset, ofp);
    }
}
void
ElementFragmentAlgorithm::sanityCheck()
{
  // Make sure there are no remaining TempNodes
  if (_temp_nodes.size() > 0)
  {
    _ostream << "_temp_nodes size > 0.  size=" << _temp_nodes.size() << std::endl;
    printMesh();
    exit(1);
  }
}
Beispiel #3
0
void keyboardInput(unsigned char key, int x, int y) {
	__UNUSED(x);
	__UNUSED(y);
	switch(key) {
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9': {
			int initEdges = mesh->numEdges;
			int initPolys = mesh->numFaces;
			int targetEdges = MAX(6, (1.0f - 0.1f * (int)(key - '0')) * mesh->numEdges);
			while(mesh->numEdges > targetEdges) {
				if(!reduce(mesh)) break;
			}
			printf("Mesh successfully reduced by %c0%%. From %d to %d edges, %d to %d polys.\n",
				key, initEdges, mesh->numEdges, initPolys, mesh->numFaces);
			break;
		}
		case '`':
			reduce(mesh);
			printf("Mesh successfully reduced by one vertex.\n");
			break;
		case 'v':
			lines = 1 - lines;
			printf("Display mode changed. ");
			if(lines) printf("Drawing with GL_LINES.\n");
			else printf("Drawing with GL_TRIANGLES.\n");
			break;
		case 'p':
			printMesh(mesh, stdout);
			break;
		case 'q':
			exit(0);
			break;
		case 'r':
			reset();
			printf("Mesh successfully reset.\n");
			break;
		case 'm':
			changeCostFunc(mesh, melaxCost);
			printf("Cost function changed to Melax.\n");
			break;
		case 's':
			changeCostFunc(mesh, simpleCost);
			printf("Cost function changed to Simple.\n");
			break;
		case '+':
			zoom += 1;
			break;
		case '-':
			zoom -= 1;
			break;
		default: break;

	}
	glutPostRedisplay();
}