rt_parse.h
Go to the documentation of this file.00001
00026 #ifndef _RT_PARSE_H_
00027 #define _RT_PARSE_H_
00028
00029 #include "rt_vectors.h"
00030 #include <vector>
00031
00032
00033
00034
00035 class rt_Light;
00036 class rt_Object;
00037 class rt_Group;
00038 class rt_Sphere;
00039 class rt_Triangle;
00040 class rt_TriMesh;
00041 class rt_Material;
00042
00043
00044 #define MAX_PARSER_TOKEN_LENGTH 100
00045
00046 class rt_parse
00047 {
00048 public:
00049
00052 rt_parse();
00053
00058 rt_parse(const char *filename);
00059
00062 ~rt_parse();
00063
00069 Vec3f getBackgroundColor() { return background_color; }
00070
00076 Vec3f getAmbientLight() { return ambient_light; }
00077
00080 int getNumLights() { return (int)(lights.size()); }
00081
00084 int getNumMaterials() { return (int)(materials.size()); }
00085
00090 rt_Light* getLight(unsigned int i)
00091 {
00092 if((i < 0) || (i >= lights.size()))
00093 {
00094 cout<<"ERROR: request for light "<<i<<", which is outside "<<
00095 "acceptable indices. There are "<<lights.size()<<" lights.\n";
00096 exit(-1);
00097 }
00098 rt_Light *result = lights[i];
00099 assert(result != NULL);
00100 return result;
00101 }
00102
00107 rt_Material* getMaterial(unsigned int i)
00108 {
00109 if((i < 0) || (i >= materials.size()))
00110 {
00111 cout<<"ERROR: request for material "<<i<<", which is outside "<<
00112 "acceptable indices. There are "<<lights.size()<<" lights.\n";
00113 exit(-1);
00114 }
00115 rt_Material *result = materials[i];
00116 assert (result != NULL);
00117 return result;
00118 }
00119
00124 rt_Group* getGroup()
00125 {
00126 return group;
00127 }
00128
00133 Vec3f getEye() { return eye; }
00134
00139 Vec3f getCenter() { return center; }
00140
00145 Vec3f getUp() { return up; }
00146
00151 float getFovy() { return fovy; }
00152
00153 private:
00154
00159 void rt_parse_initialize();
00160
00165 void eatWhitespace(void);
00166
00169 int getToken(char token[MAX_PARSER_TOKEN_LENGTH]);
00170
00173 Vec3f readVec3f();
00174
00177 float readFloat();
00178
00181 int readInt();
00182
00185 void parseFile();
00186
00189 void parseBackground();
00190
00193 void parseLights();
00194
00197 void parseCamera();
00198
00201 void parseMaterials();
00202
00205 void parseMaterialIndex();
00206
00210 rt_Group* parseGroup();
00211
00214 rt_Sphere* parseSphere();
00215
00218 rt_Triangle* parseTriangle();
00219
00222 rt_TriMesh* parseTriMesh();
00223
00224
00225 rt_Group *group;
00227 Vec3f background_color;
00228 Vec3f ambient_light;
00229 Vec3f eye;
00230 Vec3f center;
00231 Vec3f up;
00232 float fovy;
00234 FILE *file;
00236 int parse_char;
00237 int curline;
00239 std::vector<rt_Light *> lights;
00240 std::vector<rt_Material *> materials;
00241 rt_Material *current_material;
00242 };
00243
00244 #endif
Generated on Wed Mar 16 19:55:27 2005 for Graphics Project 3 by
1.3.7