Exemplo n.º 1
0
void load_obj_files( void )
{
   DIR *dp;
   struct dirent *dentry;
   char directory_name[100];

   log_string( "World state: loading objs" );
   snprintf( directory_name, 100, "%s", HOTBOOT_DIR );
   dp = opendir( directory_name );
   dentry = readdir( dp );
   while( dentry )
   {
      /*
       * Added by Tarl 3 Dec 02 because we are now using CVS 
       */
      if( !str_cmp( dentry->d_name, "CVS" ) )
      {
         dentry = readdir( dp );
         continue;
      }
      if( dentry->d_name[0] != '.' )
         read_obj_file( directory_name, dentry->d_name );
      dentry = readdir( dp );
   }
   closedir( dp );
   return;
}
Exemplo n.º 2
0
CGTKObjFile* cgtkObjFileAlloc(const char* filename) {
	CGTKObjFile* objFile;

	if (filename == NULL) {
	    return NULL;
	}

	objFile = (CGTKObjFile*) malloc(sizeof(CGTKObjFile));

	if (objFile == NULL) {
	    return NULL;
	}

	memset(objFile, 0, sizeof(CGTKObjFile));

	/* read file and save to object, clean up and return if the file is not a
    ** valid .obj file.
	*/
	if (!read_obj_file(filename, objFile)) {
		CGTK_DUMP_ERROR("Could not read obj file.");
	    free(objFile);
		return NULL;
	}

	return objFile;
}
Exemplo n.º 3
0
static struct mesh *snis_read_model(char *filename)
{
	int l = strlen(filename);

	if (strcasecmp(&filename[l - 3], "obj") == 0)
		return read_obj_file(filename);
	else if (strcasecmp(&filename[l - 3], "stl") == 0)
		return read_stl_file(filename);
	else {
		printf("bad filename='%s', filename[l - 3] = '%s'\n",
			filename, &filename[l - 4]);
		return NULL;
	}
}
Exemplo n.º 4
0
int main(int argc, char **argv) {

	vector<vertex> vertices;
	vector<triangle> triangles;

	read_obj_file("cube.obj", &vertices, &triangles);

	int T = triangles.size();

	instanceVertexCount = T * 3;
	instanceVertices = (GLfloat*)malloc((sizeof(GLfloat)) * 3 * instanceVertexCount);
	instanceNormals = (GLfloat*)malloc((sizeof(GLfloat)) * 3 * instanceVertexCount);

	vertex* verts = (vertex*)instanceVertices;
	vertex* norms = (vertex*)instanceNormals;

	for (int i = 0; i < T; ++i)
	{
		triangle t = triangles[i];
		vertex v1 = vertices[t.i1];
		vertex v2 = vertices[t.i2];
		vertex v3 = vertices[t.i3];
		verts[i * 3 + 0] = v1;
		verts[i * 3 + 1] = v2;
		verts[i * 3 + 2] = v3;
		vertex n = vertex_normal(v1, v2, v3);
		norms[i * 3 + 0] = n;
		norms[i * 3 + 1] = n;
		norms[i * 3 + 2] = n;

	}

	for (int i = 0; i < T * 9; ++i) {

		instanceVertices[i] *= CUBE_SCALE;

	}

	/*GLuint tex_cube = SOIL_load_OGL_cubemap
		(
		"posx.jpg",
		"negx.jpg",
		"posy.jpg",
		"negy.jpg",
		"posz.jpg",
		"negz.jpg",
		SOIL_LOAD_RGB,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_MIPMAPS
		);*/


	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowPosition(300, 32);//optional
	glutInitWindowSize(1024, 768); //optional
	glutCreateWindow("Particle Window!");
	glewInit();

	init();

	// register callbacks
	glutKeyboardFunc(keyboard);
	glutTimerFunc(FRAME_MSEC, onFrame, 0);
	//glutDisplayFunc(display);

	printf("OpenGL version supported by this platform (%s): \n", (char const*)glGetString(GL_VERSION));

	glutMainLoop();

	return 0;
}
Exemplo n.º 5
0
int main(int argc, char **argv)
{
	int cycles_to_run;
	
	char *machine_code; // This will hold our "ASCII Object File"
	
	char debug_command[180]="init";
	char *cmdptr;
	unsigned int dbg_addr;
	
		printf("6502 simulator front end for CS 2208a.\n\n");

		// Did the user specify an object file on the command line?
		// If not... help them.
		if(argc < 3) {
			printf("Usage: %s [ASCII Object File name] [# cycles to simulate] {-d}\n",argv[0]);
			printf(" e.g.: %s test.obj 3000 -d\n\n",argv[0]);
			exit(-1);
		}
	
		// Read the object file into a string.
		machine_code = read_obj_file(argv[1]);
	
	// Fire up the system RAM
	initMem();
	
	// Load the object file from the string into our simulated RAM,
	// starting at memory location 'code_location'.
	loadMem(machine_code,code_location);

		// We did something horribly underhanded in read_obj_file()... 
		// we allocated memory with 'malloc' and then passed back a pointer.
		// But note that the onus is on us, the C programmer, to _remember_ 
		// that we did that and free up the memory when it's no longer needed.
		// Not a big deal here, but imagine a bigger program where you're keeping
		// track of hundreds of mallocs and frees. Now you know why C programs
		// leak memory like the titanic.
		free(machine_code);

	
	// Initialize the 6502
	init6502();
	reset6502();
	
	PC = code_location; // Make sure the program counter points to our code!
	
	
	// All set to run the simulator now!
	
	
	// Everything below is just fanciness to give you a rudimentry 6502 debugger
	// to help with your assignment. Without the fancyness, all we're really doing
	// is one call:
	//
	// exec6502(num_cycles);
	
	
	// Run in debug mode, if requested
	if( (argc > 3) && (!strcmp(argv[3],"-d"))) {

		printf("Running in DEBUG MODE.\n\nType '?' for help.\n");
		
		// Debug loop
		while(strcmp(debug_command,"quit")) {

			
			//dumpMem(0x0021); // Check the value we stored to the zero page
			//dumpMem(0x01FF); // Peek at the top of the stack. Remember, the stack
						     // is hard-coded to addresses $0100–$01FF.
			//dump6502reg();	// print registers to the screen
			
			printf("debug> ");
			
			if( (gets(debug_command))[0] != '\0'){
			
			  cmdptr = strtok(debug_command," ");
			
			  switch(cmdptr[0]) {
			
				case 'p':
					if(cmdptr = strtok(NULL," ")) {
					  sscanf(cmdptr, "%x", &dbg_addr);
					  dumpMem((WORD)dbg_addr);
					}
					break;
				
				case 'r':
					dump6502reg();
					break;
					
				case 's':
					exec6502(1); // Execute 1 command
					break;
					
				case '?':
					printf("\n\np [0xAddress] - print value at memory location\n");
					printf("r - print register values\n");
					printf("s - step through program\n");
					printf("quit - exit\n\n");
					break;
			
				default:
					(cmdptr[0] % 2) ? printf("Herp.\n") : printf("Derp.\n");
					
			  }
			}
						
		}
	} else {
	// Otherwise, run in regular mode.
		exec6502(atoi(argv[2]));
	}
}