00001 //---------------------------------------------------------------------- 00002 // The Motion Strategy Library (MSL) 00003 //---------------------------------------------------------------------- 00004 // 00005 // Copyright (c) University of Illinois and Steven M. 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 // The University of Illinois 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 <stdlib.h> 00028 #include <math.h> 00029 #include <unistd.h> // needed to sleep. 00030 #include <string> 00031 #include <algorithm> 00032 00033 00034 #include "triangle.h" 00035 #include "vector.h" 00036 #include "matrix.h" 00037 #include "point3d.h" 00038 00039 #include <GL/glut.h> 00040 #include <GL/gl.h> // Header File For The OpenGL32 Library 00041 #include <GL/glu.h> // Header File For The GLu32 Library 00042 00043 #define BUFFER_SIZE 4096 00044 #define FACE_SIZE 2048 00045 #define CHUNK 2048 00046 #define MAX_MTL_FILES 512 00047 #define MAXNAME_LENGTH 50 00048 00049 // !!!!!!!!!!!!!!!!!!!!!!!!!!! -- originally from chpdef.h -- 1/5/01 00050 #define MinX -100.0 00051 #define MinY -100.0 00052 #define MaxX 100.0 00053 #define MaxY 100.0 00054 #define MinZ 100.0 00055 #define MaxZ 300.0 00056 #define RESET_ID 200 00057 #define RADIO_GROUP1 201 00058 #define RECORD_PATH_ID 202 00059 #define DISPLAY_PATH_ID 203 00060 #define NEW_PATH_ID 204 00061 #define VIEW_ORIENTATION_ID 205 00062 #define BODY_SELECTION_ID 206 00063 #define TEXTURE_ON_OFF_ID 207 00064 #define SINGLE_MULTI_VIEW_ID 208 00065 #define RELOAD_MODEL_ID 209 00066 #define TRANSPARENCY_ADJUST_ID 210 00067 #define BEGIN_FLIGHT_ID 211 00068 #define PLANE_LAND_ID 212 00069 #define MODEL_FLY_ID 213 00070 #define CREATE_OBJECT_ID 214 00071 #define DELETE_OBJECT_ID 215 00072 #define CURRENT_OBJECT_ID 216 00073 #define CREATE_OBJECT_OVER_ID 217 00074 #define CREATE_POINT_ID 218 00075 #define CREATE_POINT_OVER_ID 219 00076 #define CURRENT_TEXTURE_ID 220 00077 #define OBJECT_SELECTION_ID 221 00078 #define PLAN_ID 222 00079 #define ANIMATE_ID 223 00080 #define SET_INITIAL_ID 224 00081 #define SAVE_GEOMETRY_ID 225 00082 #define SET_GOAL_ID 226 00083 #define ANIMATE_PAUSE_ID 227 00084 #define SAVE_CONFIG_ID 228 00085 #define AUTOMATIC_PLAN_ID 229 00086 #define LIGHT_COMPONENT_SELECTION_ID 230 00087 #define LIGHT_MODE_SELECTION_ID 231 00088 #define ANIMATION_RATE_ID 232 00089 #define LOAD_CONFIG_ID 233 00090 #define SINGLE_VIEW 300 00091 #define MULTI_VIEW 301 00092 #define OBSTACLE_MODE 302 00093 #define ROBOT_MODE 303 00094 #define Z_MOVE_MODE 304 00095 #define SCALE_MOVE_MODE 305 00096 #define ORI_MOVE_MODE 306 00097 #define SELECT_BOUNDINGBOX_ID 307 00098 #define SHOW_BOUNDINGBOX_ID 308 00099 #define HIDE_BOUNDINGBOX_ID 309 00100 #define SUN_LIGHT_MODE 310 00101 #define EYE_LIGHT_MODE 311 00102 // !!!!!!!!!!!!!!!!!!!!!!!! -- originally from chpdef.h -- 1/5/01 00103 00104 00105 // !!!!!!!!!!!!!!!!!!!!!!!! -- come from chpMSLMatrix.h -- 1/5/01 00106 00107 // rotate MSLMatrix 00108 void rotate_x_MSLMatrix(double sita, MSLMatrix& m); 00109 void rotate_y_MSLMatrix(double sita, MSLMatrix& m); 00110 void rotate_z_MSLMatrix(double sita, MSLMatrix& m); 00111 // point rotation 00112 MSLVector point_x_rotation(const double& sita, const MSLVector& p1); 00113 MSLVector point_y_rotation(const double& sita, const MSLVector& p1); 00114 MSLVector point_z_rotation(const double& sita, const MSLVector& p1); 00115 // cross product of MSLVector v1 and MSLVector v2, v1 X v2 = v 00116 void crossproduct(const MSLVector& v1, const MSLVector& v2, MSLVector& v); 00117 // v = normalize the v1 X v2 00118 void normalMSLVector(const MSLVector& v1, const MSLVector& v2, MSLVector& v); 00119 // caculate the rpy angle from the orientation MSLMatrix 00120 MSLVector irpy(const MSLMatrix& R); 00121 // caculate the MSLMatrix corresponding to the rpy rotation 00122 MSLMatrix rpy(const MSLVector& v); 00123 // MSLVector v rotate around any unit MSLVector axis which orginates from the origin 00124 MSLVector free_rotate(const MSLVector& axis, const MSLVector& v, double sita); 00125 // MSLMatrix m rotate around any unit MSLVector axis which orginates from the origin 00126 MSLMatrix free_rotate(const MSLVector& axis, const MSLMatrix& m, double sita); 00127 00128 00129 00130 00131 int strcasecmp __P ((__const char *__s1, __const char *__s2)); 00132 00133 /* case insensitive string equality test */ 00134 #define UPPER(_str) transform(_str.begin(), _str.end(), _str.begin(), toupper) 00135 #define SAME(_a, _b) (UPPER(string(_a)) == UPPER(string(_b))) 00136 00137 typedef struct{ 00138 double x; 00139 double y; 00140 double z; 00141 } mslGLVertex; 00142 00143 typedef struct{ 00144 double x; 00145 double y; 00146 double z; 00147 } mslGLNormal; 00148 00149 typedef struct{ 00150 double x; 00151 double y; 00152 double z; 00153 } mslGLTexCoord; 00154 00155 00156 /* Image type - contains height, width, and data */ 00158 class Image { 00159 public: 00160 unsigned long sizeX; 00161 unsigned long sizeY; 00162 char *data; 00163 00164 Image(); 00165 ~Image(); 00166 }; 00167 00169 class mslGLMaterial 00170 { 00171 public: 00172 int ID; 00173 char Name[MAXNAME_LENGTH]; 00174 00175 GLuint TextureHandle; 00176 Image * TextureImage; 00177 char TextureName[MAXNAME_LENGTH]; 00178 00179 GLfloat Diffuse[3]; 00180 GLfloat Specular[3]; 00181 GLfloat Ambient[3]; 00182 GLfloat Color[3]; 00183 00184 GLfloat Alpha; 00185 float Shininess; 00186 00187 float Su; 00188 float Sv; 00189 00190 char Reflect[MAXNAME_LENGTH]; 00191 00192 int AmbientOn; 00193 int SpecularOn; 00194 int DiffuseOn; 00195 int ShininessOn; 00196 int AlphaOn; 00197 int ReflectOn; 00198 int TwosideOn; 00199 int TextureOn; 00200 00201 mslGLMaterial(); 00202 ~mslGLMaterial(); 00203 00204 void SetMaterial(); 00205 int ImageLoad(int id, string path, string filename); 00206 void Clear(); 00207 00208 void Print(); 00209 }; 00210 00211 00213 class mslGLFace 00214 { 00215 public: 00216 int NumberOfPoint; 00217 int NumberOfNormal; 00218 int NumberOfTexCoord; 00219 00220 mslGLVertex * VerticeCoord; 00221 mslGLNormal * NormalCoord; 00222 mslGLTexCoord * TextureCoord; 00223 00224 int NormalOn; 00225 int TextureOn; 00226 int ColorOn; 00227 00228 int MaterialID; 00229 00230 mslGLFace(); 00231 ~mslGLFace(); 00232 00233 void AddVertex(const mslGLVertex& ver); 00234 void AddNormal(const mslGLNormal& nor); 00235 void AddTexCoord(const mslGLTexCoord& tex); 00236 00237 void AddVertex(const MSLVector& ver); 00238 void AddNormal(const MSLVector& nor); 00239 void AddTexCoord(const MSLVector& tex); 00240 00241 void Clear(); 00242 00243 void PrintVertex(); 00244 00245 void DrawFace(); 00246 }; 00247 00248 00249 00251 class mslGLObject 00252 { 00253 public: 00254 00255 int ID; 00256 string Name; 00257 00258 int NumberOfMaterial; 00259 mslGLMaterial * ObjectMaterialLib; 00260 00261 int NumberOfFace; 00262 mslGLFace * ObjectFaceLib; 00263 00264 float Position[3], Orientation[3]; 00265 float Scale[3]; 00266 00267 float BoundingBoxMin[3]; 00268 float BoundingBoxMax[3]; 00269 00270 //mslGLObject(string path); 00271 mslGLObject(); 00272 ~mslGLObject(); 00273 00274 int ReadModelFile(const string& path, const string& filename); 00275 00276 MSLPoint3d PointCurrentState(const MSLPoint3d& po, int mode); 00277 00278 list<MSLTriangle> SetBoundingBoxTriangle(int mode); 00279 00280 void LoadMaterialFile(const string& path, const string& name); 00281 int SetCurrentMaterialID(char * name); 00282 void SetMaterial(int matid); 00283 void AddMaterial(const string& path, const mslGLMaterial& mat); 00284 void AddFace(const mslGLFace& face); 00285 void ParseTexture(char * next, mslGLMaterial * mat); 00286 void Clear(); 00287 00288 void ObjectDraw(); 00289 void ObjectBoundingBoxDraw(); 00290 void ObjectHighlight(); 00291 00292 void SetObjectPosition(const MSLVector& pos); 00293 void SetObjectOrientation(const MSLVector& ori); 00294 void SetObjectScale(const MSLVector& sca); 00295 00296 void SetBodyPositionChange(const MSLVector& posc); 00297 void SetBodyOrientationChange(const MSLVector& oric); 00298 void SetBodyScaleChange(const MSLVector& scac); 00299 00300 void PrintFace(); 00301 void PrintMaterial(); 00302 void PrintState(); 00303 }; 00304 00305 00306 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -- come from generalfunction.h -- 1/5/01 00307 mslGLNormal NormalCompute(const mslGLVertex& v1, const mslGLVertex& v2, 00308 const mslGLVertex& v3); 00309 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -- come from generalfunction.h -- 1/5/01 00310 00311 00312 #endif 00313