00001 //---------------------------------------------------------------------- 00002 // The Motion Strategy Library (MSL) 00003 //---------------------------------------------------------------------- 00004 // 00005 // Copyright (c) 1998-2001 Iowa State University and Steve LaValle. 00006 // All Rights Reserved. 00007 // 00008 // Permission to use, copy, and distribute this software and its 00009 // documentation is hereby granted free of charge, provided that 00010 // (1) it is not a component of a commercial product, and 00011 // (2) this notice appears in all copies of the software and 00012 // related documentation. 00013 // 00014 // Iowa State University and the author make no representations 00015 // about the suitability or fitness of this software for any purpose. 00016 // It is provided "as is" without express or implied warranty. 00017 //---------------------------------------------------------------------- 00018 00019 // This file was written by Peng Cheng (chp@cs.iastate.edu) 00020 00021 #ifndef MSL_RENDERGLOBJ_H 00022 #define MSL_RENDERGLOBJ_H 00023 00024 #include <fstream.h> 00025 #include <stdio.h> 00026 #include <ctype.h> 00027 #include <string.h> 00028 #include <stdlib.h> 00029 #include <math.h> 00030 #include <unistd.h> // needed to sleep. 00031 00032 #include <LEDA/file.h> 00033 #include <LEDA/list.h> 00034 #include <LEDA/matrix.h> 00035 #include <LEDA/point.h> 00036 #include <LEDA/d3_point.h> 00037 #include <LEDA/polygon.h> 00038 #include <LEDA/random.h> 00039 #include <LEDA/stream.h> 00040 #include <LEDA/string.h> 00041 #include <LEDA/vector.h> 00042 00043 #include "3Dtriangle.h" 00044 00045 #include <GL/glut.h> 00046 #include <GL/gl.h> // Header File For The OpenGL32 Library 00047 #include <GL/glu.h> // Header File For The GLu32 Library 00048 00049 #define BUFFER_SIZE 4096 00050 #define FACE_SIZE 2048 00051 #define CHUNK 2048 00052 #define MAX_MTL_FILES 512 00053 #define MAXNAME_LENGTH 50 00054 00055 // !!!!!!!!!!!!!!!!!!!!!!!!!!! -- originally from chpdef.h -- 1/5/01 00056 #define MinX -100.0 00057 #define MinY -100.0 00058 #define MaxX 100.0 00059 #define MaxY 100.0 00060 #define MinZ 100.0 00061 #define MaxZ 300.0 00062 #define RESET_ID 200 00063 #define RADIO_GROUP1 201 00064 #define RECORD_PATH_ID 202 00065 #define DISPLAY_PATH_ID 203 00066 #define NEW_PATH_ID 204 00067 #define VIEW_ORIENTATION_ID 205 00068 #define BODY_SELECTION_ID 206 00069 #define TEXTURE_ON_OFF_ID 207 00070 #define SINGLE_MULTI_VIEW_ID 208 00071 #define RELOAD_MODEL_ID 209 00072 #define TRANSPARENCY_ADJUST_ID 210 00073 #define BEGIN_FLIGHT_ID 211 00074 #define PLANE_LAND_ID 212 00075 #define MODEL_FLY_ID 213 00076 #define CREATE_OBJECT_ID 214 00077 #define DELETE_OBJECT_ID 215 00078 #define CURRENT_OBJECT_ID 216 00079 #define CREATE_OBJECT_OVER_ID 217 00080 #define CREATE_POINT_ID 218 00081 #define CREATE_POINT_OVER_ID 219 00082 #define CURRENT_TEXTURE_ID 220 00083 #define OBJECT_SELECTION_ID 221 00084 #define PLAN_ID 222 00085 #define ANIMATE_ID 223 00086 #define SET_INITIAL_ID 224 00087 #define SAVE_GEOMETRY_ID 225 00088 #define SET_GOAL_ID 226 00089 #define ANIMATE_PAUSE_ID 227 00090 #define SAVE_CONFIG_ID 228 00091 #define AUTOMATIC_PLAN_ID 229 00092 #define LIGHT_COMPONENT_SELECTION_ID 230 00093 #define LIGHT_MODE_SELECTION_ID 231 00094 #define ANIMATION_RATE_ID 232 00095 #define LOAD_CONFIG_ID 233 00096 #define SINGLE_VIEW 300 00097 #define MULTI_VIEW 301 00098 #define OBSTACLE_MODE 302 00099 #define ROBOT_MODE 303 00100 #define Z_MOVE_MODE 304 00101 #define SCALE_MOVE_MODE 305 00102 #define ORI_MOVE_MODE 306 00103 #define SELECT_BOUNDINGBOX_ID 307 00104 #define SHOW_BOUNDINGBOX_ID 308 00105 #define HIDE_BOUNDINGBOX_ID 309 00106 #define SUN_LIGHT_MODE 310 00107 #define EYE_LIGHT_MODE 311 00108 // !!!!!!!!!!!!!!!!!!!!!!!! -- originally from chpdef.h -- 1/5/01 00109 00110 #include "LEDA/REDEFINE_NAMES.h" 00111 00112 // !!!!!!!!!!!!!!!!!!!!!!!! -- come from chpmatrix.h -- 1/5/01 00113 00114 // rotate matrix 00115 void rotate_x_matrix(double sita, matrix& m); 00116 void rotate_y_matrix(double sita, matrix& m); 00117 void rotate_z_matrix(double sita, matrix& m); 00118 // point rotation 00119 vector point_x_rotation(const double& sita, const vector& p1); 00120 vector point_y_rotation(const double& sita, const vector& p1); 00121 vector point_z_rotation(const double& sita, const vector& p1); 00122 // cross product of vector v1 and vector v2, v1 X v2 = v 00123 void crossproduct(const vector& v1, const vector& v2, vector& v); 00124 // v = normalize the v1 X v2 00125 void normalvector(const vector& v1, const vector& v2, vector& v); 00126 // caculate the rpy angle from the orientation matrix 00127 vector irpy(const matrix& R); 00128 // caculate the matrix corresponding to the rpy rotation 00129 matrix rpy(const vector& v); 00130 // vector v rotate around any unit vector axis which orginates from the origin 00131 vector free_rotate(const vector& axis, const vector& v, double sita); 00132 // matrix m rotate around any unit vector axis which orginates from the origin 00133 matrix free_rotate(const vector& axis, const matrix& m, double sita); 00134 00135 // !!!!!!!!!!!!!!!!!!!!!!!! -- come from chpmatrix.h -- 1/5/01 00136 00137 00138 00139 /* case insensitive string equality test */ 00140 #define SAME(_a, _b) (strcasecmp(_a,_b) == 0) 00141 00142 typedef struct{ 00143 double x; 00144 double y; 00145 double z; 00146 } mslGLVertex; 00147 00148 typedef struct{ 00149 double x; 00150 double y; 00151 double z; 00152 } mslGLNormal; 00153 00154 typedef struct{ 00155 double x; 00156 double y; 00157 double z; 00158 } mslGLTexCoord; 00159 00160 00161 /* Image type - contains height, width, and data */ 00163 class Image { 00164 public: 00165 unsigned long sizeX; 00166 unsigned long sizeY; 00167 char *data; 00168 00169 Image(); 00170 ~Image(); 00171 }; 00172 00174 class mslGLMaterial 00175 { 00176 public: 00177 int ID; 00178 char Name[MAXNAME_LENGTH]; 00179 00180 GLuint TextureHandle; 00181 Image * TextureImage; 00182 char TextureName[MAXNAME_LENGTH]; 00183 00184 GLfloat Diffuse[3]; 00185 GLfloat Specular[3]; 00186 GLfloat Ambient[3]; 00187 GLfloat Color[3]; 00188 00189 GLfloat Alpha; 00190 float Shininess; 00191 00192 float Su; 00193 float Sv; 00194 00195 char Reflect[MAXNAME_LENGTH]; 00196 00197 int AmbientOn; 00198 int SpecularOn; 00199 int DiffuseOn; 00200 int ShininessOn; 00201 int AlphaOn; 00202 int ReflectOn; 00203 int TwosideOn; 00204 int TextureOn; 00205 00206 mslGLMaterial(); 00207 ~mslGLMaterial(); 00208 00209 void SetMaterial(); 00210 int ImageLoad(int id, string path, string filename); 00211 void Clear(); 00212 00213 void Print(); 00214 }; 00215 00216 00218 class mslGLFace 00219 { 00220 public: 00221 int NumberOfPoint; 00222 int NumberOfNormal; 00223 int NumberOfTexCoord; 00224 00225 mslGLVertex * VerticeCoord; 00226 mslGLNormal * NormalCoord; 00227 mslGLTexCoord * TextureCoord; 00228 00229 int NormalOn; 00230 int TextureOn; 00231 int ColorOn; 00232 00233 int MaterialID; 00234 00235 mslGLFace(); 00236 ~mslGLFace(); 00237 00238 void AddVertex(const mslGLVertex& ver); 00239 void AddNormal(const mslGLNormal& nor); 00240 void AddTexCoord(const mslGLTexCoord& tex); 00241 00242 void AddVertex(const vector& ver); 00243 void AddNormal(const vector& nor); 00244 void AddTexCoord(const vector& tex); 00245 00246 void Clear(); 00247 00248 void PrintVertex(); 00249 00250 void DrawFace(); 00251 }; 00252 00253 00254 00256 class mslGLObject 00257 { 00258 public: 00259 00260 int ID; 00261 string Name; 00262 00263 int NumberOfMaterial; 00264 mslGLMaterial * ObjectMaterialLib; 00265 00266 int NumberOfFace; 00267 mslGLFace * ObjectFaceLib; 00268 00269 float Position[3], Orientation[3]; 00270 float Scale[3]; 00271 00272 float BoundingBoxMin[3]; 00273 float BoundingBoxMax[3]; 00274 00275 //mslGLObject(string path); 00276 mslGLObject(); 00277 ~mslGLObject(); 00278 00279 int ReadModelFile(const string& path, const string& filename); 00280 00281 d3_point PointCurrentState(const d3_point& po, int mode); 00282 00283 list<polygon> SetBoundingBoxPolygon(); 00284 list<Triangle> SetBoundingBoxTriangle(int mode); 00285 void GenerateGeomFile(file_ostream& fout, int mode); 00286 00287 void LoadMaterialFile(const string& path, const string& name); 00288 int SetCurrentMaterialID(char * name); 00289 void SetMaterial(int matid); 00290 void AddMaterial(const string& path, const mslGLMaterial& mat); 00291 void AddFace(const mslGLFace& face); 00292 void ParseTexture(char * next, mslGLMaterial * mat); 00293 void Clear(); 00294 00295 void ObjectDraw(); 00296 void ObjectBoundingBoxDraw(); 00297 void ObjectHighlight(); 00298 00299 void SetObjectPosition(const vector& pos); 00300 void SetObjectOrientation(const vector& ori); 00301 void SetObjectScale(const vector& sca); 00302 00303 void SetBodyPositionChange(const vector& posc); 00304 void SetBodyOrientationChange(const vector& oric); 00305 void SetBodyScaleChange(const vector& scac); 00306 00307 void PrintFace(); 00308 void PrintMaterial(); 00309 void PrintState(); 00310 }; 00311 00312 00313 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -- come from generalfunction.h -- 1/5/01 00314 mslGLNormal NormalCompute(const mslGLVertex& v1, const mslGLVertex& v2, 00315 const mslGLVertex& v3); 00316 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -- come from generalfunction.h -- 1/5/01 00317 00318 00319 #include "LEDA/UNDEFINE_NAMES.h" 00320 00321 #endif 00322