//#include "import.h"/*void Add_Mesh(MESH *new_mesh){ if(mesh_head) //if head!=NULL => there are items in the list { mesh_tail->o_pnext = new_mesh; mesh_tail = new_mesh; } else //if there are no values => point head { //and tail to new mesh mesh_head = mesh_tail = new_mesh; }}void Add_Material(MATERIAL *new_mat){ if(mat_head) { mat_tail->m_pnext = new_mat; mat_tail = new_mat; } else { mat_head = mat_tail = new_mat; }}*//*This is line 31*/MESH MeshResize(MESH array, int new_len){ MESH *new_array = NULL; new_array = new MESH[new_len]; for(int x=0; x<new_len-1; x++) new_array[x] = array; delete[] array; return new_array;}MATERIAL MatResize(MATERIAL array, int new_len){ MATERIAL *new_array = NULL; new_array = new MATERIAL[new_len]; for(int x=0; x<new_len-1; x++) new_array[x] = array; //delete[] array; return new_array;}void Import(apstring fname){ apstring dummy; //materials defined here //MATERIAL Material = (MESH*)0; //MATERIAL *mat_head = NULL; //points to head of list //MATERIAL *mat_tail = NULL; //points to tail of list infile.open(fname); while(!infile.eof()) { infile>>dummy; if(dummy == "*MESH") { //Add_Mesh(Mesh); //Mesh->o_pnext = MESH; Mesh_len++; //Mesh = MeshResize(Mesh, Mesh_len); Import_Obj(); } Draw_Triangles(); } infile.close();}void Import_Obj(){ apstring dummy; Vector3 temp_vertex; for(int x=0; dummy != ("*GEOMOBJECT" || "*LIGHTOBJECT"); x++) //Imports everything under the *GEOMOBJECT heading { infile >> dummy; if(dummy == "*MESH_NUMVERTEX") //Inputs number of vertices in the mesh { infile >> dummy; Mesh[x].num_vertex = atoi(dummy.c_str()); Mesh[x].vertex = new Mesh[x].num_vertex; } if(dummy == "*MESH_NUMFACES") //Inputs number of faces on the mesh { infile >> dummy; Mesh[x].num_faces = atoi(dummy.c_str()); Mesh[x].face = new Mesh[x].num_faces; Mesh[x].fnormal = new Vector3[Mesh[x].num_faces]; Mesh[x].vnormal = new Vector3[(Mesh[x].num_faces)*3]; } if(dummy == "*MESH_VERTEX_LIST") //Inputs all vertices into a { infile >> dummy; for( int x=0; x < Mesh[x].num_vertex; x++) { infile >> dummy >> dummy; infile >> dummy; Mesh[x].vertex.x = atof(dummy.c_str()); infile >> dummy; Mesh[x].vertex.z = atof(dummy.c_str()); infile >> dummy; Mesh[x].vertex.y = atof(dummy.c_str()); } } if(dummy == "*MESH_FACE_LIST") { infile >> dummy; for( int x=0; x < Mesh[x].num_faces; x++) { infile >> dummy >> dummy >> dummy; infile >> dummy; Mesh[x].face.x = atoi(dummy.c_str()); infile >> dummy >> dummy; Mesh[x].face.y = atoi(dummy.c_str()); infile >> dummy >> dummy; Mesh[x].face.z = atoi(dummy.c_str()); infile >> dummy; Mesh[x].dir.x = atoi(dummy.c_str()); infile >> dummy; Mesh[x].dir.y = atoi(dummy.c_str()); infile >> dummy; Mesh[x].dir.z = atoi(dummy.c_str()); infile >> dummy >> dummy >> dummy >> dummy; } } if(dummy == "*MESH_NORMALS") { for(int x=0; x<Mesh[x].numfaces; x++) { infile >> dummy; if(dummy == "*MESH_FACENORMAL") { infile >> dummy >> dummy; infile >> dummy; Mesh[x].fnormal[x].x = atof(dummy.c_str()); infile >> dummy; Mesh[x].fnormal[x].y = atof(dummy.c_str()); infile >> dummy; Mesh[x].fnormal[x].z = atof(dummy.c_str()); } if(dummy == "*MESH_VERTEXNORMAL") { for(int y=0; y<3; y++) { infile >> dummy; infile >> dummy; Mesh[x].vnormal[(2*(x-1)+x)+0].x = atof(dummy.c_str()); infile >> dummy; Mesh[x].vnormal[(2*(x-1)+x)+1].y = atof(dummy.c_str()); infile >> dummy; Mesh[x].vnormal[(2*(x-1)+x)+2].z = atof(dummy.c_str()); infile >> dummy; } } } } }}apstring Resize(apstring String, int Num){ apstring temp_String=""; int temp_strlen = String.length(); for(int x = 0; x < (temp_strlen-Num); x++) temp_String += String[x]; return temp_String;}GLuint Draw_Triangles() //Rewrite to draw triangles{ Vector3 vector; Vector3 vector2; int a, b, c; map=glGenLists(1); glNewList(map,GL_COMPILE); for(int x=0; x<Mesh_len; x++) { glColor4f( 1, 1, 1, 1); for(int face = 0; face < Mesh[x].num_faces; face++) { //DRAWS THE FACE NORMAL glNormal3f(Mesh[x].fnormal[x].x, Mesh[x].fnormal[x].y, Mesh[x].fnormal[x].z); glBegin(GL_TRIANGLES); //DRAWS VERTEX NORMALS FOR SMOOTH SHADING a = Mesh[x].face[face].x; b = Mesh[x].face[face].y; c = Mesh[x].face[face].z; glNormal3f(Mesh[x].vnormal[(2*(face-1)+face)+0].x, Mesh[x].vnormal[(2*(face-1)+face)+0].y, Mesh[x].vnormal[(2*(face-1)+face)+0].z); glVertex3f(Mesh[x].vertex[a].x, Mesh[x].vertex[a].y, Mesh[x].vertex[a].z); glNormal3f(Mesh[x].vnormal[(2*(face-1)+face)+1].x, Mesh[x].vnormal[(2*(face-1)+face)+1].y, Mesh[x].vnormal[(2*(face-1)+face)+1].z); glVertex3f(Mesh[x].vertex[b].x, Mesh[x].vertex[b].y, Mesh[x].vertex[b].z); glNormal3f(Mesh[x].vnormal[(2*(face-1)+face)+2].x, Mesh[x].vnormal[(2*(face-1)+face)+2].y, Mesh[x].vnormal[(2*(face-1)+face)+2].z); glVertex3f(Mesh[x].vertex[c].x, Mesh[x].vertex[c].y, Mesh[x].vertex[c].z); glEnd(); } } glEndList(); glColor4f(1, 1, 1, 1); return map;}
Here is the header file for it
//Following code is for importing ASCII filesint Num_Vertices;int Num_Faces;//char *filename;unsigned int map;ifstream infile;ofstream outfile;//apmatrix<float> Vertices( 3, 8, 0);//apmatrix<float> Face( 6, 12, 0);//apstring dummy_vector;apstring fname;struct RGB{ float r, g, b;};struct LAYER{ apstring Name, Class, Location, Filter; int Subno, Noise_level; float Amount, Angle, Blur, Blur_offset, Noise_amt, Noise_size, Noise_phase; POINT Offset, Tiling; //LAYER l_pnext;};struct MATERIAL{ int Mat_ID; apstring Mat_name, Mat_file; //Shading, //Falloff, //XP_type; RGB rgb_Ambient, rgb_Diffuse, rgb_Specular; float //Shine, //Shine_Strength, Transparency; //Wiresize, //XP_Falloff, //Selffillum; //LAYER Diffuse; //MATERIAL *m_pnext = (MATERIAL*)0;};struct MESH{ int num_vertex, num_faces, num_t_vertex, //number of textured vertices mat_id; Vector3* vertex; //holds xyz values for vertices Vector3* face; //holds 3 values for triangle vertices Vector3* dir; //holds 3 values for winding polygon Vector3* fnormal; //holds 3 values for face normals Vector3* vnormal; //holds 3 values for vertex normals //MATERIAL *mat_ref = NULL; //MESH *o_pnext = NULL; //points to next object in list};MESH Mesh[1];int Mesh_len = 1;MATERIAL Material[1];int Mat_len = 1;//void Add_Mesh(MESH *new_mesh); //NOT NEEDED//void Add_Material(MATERIAL *new_mat); //NOT NEEDEDvoid Import(apstring fname);apstring Resize(apstring String, int Num);GLuint Draw_Triangles();MESH MeshResize(MESH array, int new_len);MATERIAL MatResize(MATERIAL array, int new_len);#include "import.cpp"
Here are some of the definitions like "Vector3"
#include <windows.h> // Header File For Windows#include <stdio.h> // Header File For Standard Input/Output#include <math.h>#include <fstream.h>#include <apstring.h>#include <apmatrix.h>#include <stdarg.h>#include <gl\gl.h> // Header File For The OpenGL32 Library#include <gl\glu.h> // Header File For The GLu32 Library#include <gl\glaux.h> // Header File For The Glaux Library#include "glut.h"#define SCREEN_WIDTH 800 // We want our screen width 800 pixels#define SCREEN_HEIGHT 600 // We want our screen height 600 pixelsstruct Vector3{ Vector3() {} // default constructor Vector3(float X, float Y, float Z) { x = X; y = Y; z = Z;} Vector3 operator-(Vector3 vector) { return Vector3( x - vector.x, y - vector.y, z - vector.z);} Vector3 operator+(Vector3 vector) { return Vector3( x + vector.x, y + vector.y, z + vector.z);} Vector3 operator=(Vector3 vector) { return Vector3( x = vector.x, y = vector.y, z = vector.z);} /*Vector3 operator/(Vector3 vector, float num) { return Vector3( vector.x/3, vector.y/3, vector.z/3);}*/ float x, y, z; Vector3 *v_pnext;};Vector3 Cross(Vector3 vector1, Vector3 vector2){ Vector3 temp_vector; temp_vector.x = (vector1.z * vector2.y) - (vector1.y * vector2.z); temp_vector.y = (vector1.x * vector2.z) - (vector1.z * vector2.x); temp_vector.z = (vector1.y * vector2.x) - (vector1.x * vector2.y); return temp_vector;}float Magnitude(Vector3 vector){ return sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z);}Vector3 Normalize(Vector3 vector){ float len = Magnitude(vector); vector.x /= len; vector.y /= len; vector.z /= len; return vector;}/*//vector1 is the normal, vector2 is the test vertex//if return > 0 => vector2 is in front of plane//if return = 0 => vector2 is on the plane//if return < 0 => vector2 is behind the planeVector3 Plane_Equ(Vector3 vector1, Vector3 vector2){ Vector3 temp_vector; temp_vector.x = vector1.x * vector2.x; temp_vector.y = vector1.y * vector2.y; temp_vector.z = vector1.z * vector2.z; temp_vector = Magnitude(vector2) + temp_vector; return temp_vector;}*///Initializebool keys[256]; // Array Used For The Keyboard Routinebool active=TRUE; // Window Active Flag Set To TRUE By Defaultbool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Defaultbool light; //Lighting ON/OFFbool blend; //Blending OFF/ONbool lp; //'L' pressed?bool fp; //'F' pressed?bool bp; //'B' pressed?const float piover180 = 0.0174532925f;POINT MousePos; //Holds mouse position in a two variable structconst int Z_Buffer = 32;int middleX = SCREEN_WIDTH >> 1;int middleY = SCREEN_HEIGHT >> 1;int loop;GLuint filter;//include files that require main.h definitions#include "texture.h"#include "player.h"#include "import.cpp"//#include "font.h"#include "particles.h"
i hope this helps out
[edited by - adam17 on March 12, 2003 11:24:09 AM]