Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

renderglobj.h

Go to the documentation of this file.
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 <cstdio>
00026 #include <ctype.h>
00027 #include <cstdlib>
00028 #include <math.h>
00029 
00030 #include <string>
00031 #include <algorithm>
00032 #include <unistd.h>     // needed to sleep.
00033 
00034 using namespace std;
00035 
00036 
00037 #include "triangle.h"
00038 #include "vector.h"
00039 #include "matrix.h"
00040 #include "point3d.h"
00041 #include "util.h"
00042 
00043 //#include <GL/glut.h>
00044 //#include <GL/gl.h>    // Header File For The OpenGL32 Library
00045 //#include <GL/glu.h>   // Header File For The GLu32 Library
00046 
00047 #include "../../configs/configGL.h"
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 
00111 //  !!!!!!!!!!!!!!!!!!!!!!!! -- come from chpMSLMatrix.h -- 1/5/01
00112 
00113 // rotate MSLMatrix
00114 void rotate_x_MSLMatrix(double sita, MSLMatrix& m);
00115 void rotate_y_MSLMatrix(double sita, MSLMatrix& m);
00116 void rotate_z_MSLMatrix(double sita, MSLMatrix& m);
00117 // point rotation
00118 MSLVector point_x_rotation(const double& sita, const MSLVector& p1);
00119 MSLVector point_y_rotation(const double& sita, const MSLVector& p1);
00120 MSLVector point_z_rotation(const double& sita, const MSLVector& p1);
00121 // cross product of MSLVector v1 and MSLVector v2, v1 X v2 = v
00122 void crossproduct(const MSLVector& v1, const MSLVector& v2, MSLVector& v);
00123 // v = normalize the v1 X v2
00124 void normalMSLVector(const MSLVector& v1, const MSLVector& v2, MSLVector& v);
00125 // caculate the rpy angle from the orientation MSLMatrix
00126 MSLVector irpy(const MSLMatrix& R);
00127 // caculate the MSLMatrix corresponding to the rpy rotation
00128 MSLMatrix rpy(const MSLVector& v);
00129 // MSLVector v rotate around any unit MSLVector axis which orginates from the origin
00130 MSLVector free_rotate(const MSLVector& axis, const MSLVector& v, double sita);
00131 // MSLMatrix m rotate around any unit MSLVector axis which orginates from the origin
00132 MSLMatrix free_rotate(const MSLVector& axis, const MSLMatrix& m, double sita);
00133 
00134 
00135 
00136 
00137 //int strcasecmp __P ((__const char *__s1, __const char *__s2));
00138 
00139 /* case insensitive string equality test */
00140 string UPPER(string _str);
00141 
00142 //#define       SAME(_a, _b)    (UPPER(string(_a)) == UPPER(string(_b)))
00143 int cmp_nocase(const string &a, const string &b);
00144 #define SAME(_a, _b)    !cmp_nocase(_a, _b)
00145 
00146 
00147 typedef struct{
00148   double x;
00149   double y;
00150   double z;
00151 } mslGLVertex;
00152 
00153 typedef struct{
00154   double x;
00155   double y;
00156   double z;
00157 } mslGLNormal;
00158 
00159 typedef struct{
00160   double x;
00161   double y;
00162   double z;
00163 } mslGLTexCoord;
00164 
00165 
00166 /* Image type - contains height, width, and data */
00168 class Image {
00169 public:
00170     unsigned long sizeX;
00171     unsigned long sizeY;
00172     char *data;
00173 
00174     Image();
00175     ~Image();
00176 };
00177 
00179 class mslGLMaterial
00180 {
00181 public:
00182   int ID;
00183   char Name[MAXNAME_LENGTH];
00184 
00185   GLuint TextureHandle;
00186   Image * TextureImage;
00187   char  TextureName[MAXNAME_LENGTH];
00188 
00189   GLfloat Diffuse[3];
00190   GLfloat Specular[3];
00191   GLfloat Ambient[3];
00192   GLfloat Color[3];
00193 
00194   GLfloat Alpha;
00195   float Shininess;
00196 
00197   float Su;
00198   float Sv;
00199 
00200   char Reflect[MAXNAME_LENGTH];
00201 
00202   int AmbientOn;
00203   int SpecularOn;
00204   int DiffuseOn;
00205   int ShininessOn;
00206   int AlphaOn;
00207   int ReflectOn;
00208   int TwosideOn;
00209   int TextureOn;
00210 
00211   mslGLMaterial();
00212   ~mslGLMaterial();
00213 
00214   void SetMaterial();
00215   int ImageLoad(int id, string path, string filename);
00216   void Clear();
00217 
00218   void Print();
00219 };
00220 
00221 
00223 class mslGLFace
00224 {
00225  public:
00226   int NumberOfPoint;
00227   int NumberOfNormal;
00228   int NumberOfTexCoord;
00229 
00230   mslGLVertex * VerticeCoord;
00231   mslGLNormal * NormalCoord;
00232   mslGLTexCoord * TextureCoord;
00233 
00234   int NormalOn;
00235   int TextureOn;
00236   int ColorOn;
00237 
00238   int MaterialID;
00239 
00240   mslGLFace();
00241   ~mslGLFace();
00242 
00243   void AddVertex(const mslGLVertex& ver);
00244   void AddNormal(const mslGLNormal& nor);
00245   void AddTexCoord(const mslGLTexCoord& tex);
00246 
00247   void AddVertex(const MSLVector& ver);
00248   void AddNormal(const MSLVector& nor);
00249   void AddTexCoord(const MSLVector& tex);
00250 
00251   void Clear();
00252 
00253   void PrintVertex();
00254 
00255   void DrawFace();
00256 };
00257 
00258 
00259 
00261 class mslGLObject
00262 {
00263  public:
00264 
00265   int ID;
00266   string Name;
00267 
00268   int NumberOfMaterial;
00269   mslGLMaterial * ObjectMaterialLib;
00270 
00271   int NumberOfFace;
00272   mslGLFace * ObjectFaceLib; 
00273   
00274   float Position[3], Orientation[3];
00275   float Scale[3];
00276 
00277   float BoundingBoxMin[3];
00278   float BoundingBoxMax[3];
00279 
00280   //mslGLObject(string path);
00281   mslGLObject();
00282   ~mslGLObject();
00283 
00284   int ReadModelFile(const string& path, const string& filename);
00285 
00286   MSLPoint3d PointCurrentState(const MSLPoint3d& po, int mode);
00287 
00288   list<MSLTriangle> SetBoundingBoxTriangle(int mode);
00289 
00290   void LoadMaterialFile(const string& path, const string& name);
00291   int  SetCurrentMaterialID(char * name);
00292   void SetMaterial(int matid);
00293   void AddMaterial(const string& path, const mslGLMaterial& mat);
00294   void AddFace(const mslGLFace& face);
00295   void ParseTexture(char * next, mslGLMaterial * mat);
00296   void Clear();
00297 
00298   void ObjectDraw();
00299   void ObjectBoundingBoxDraw();
00300   void ObjectHighlight();
00301 
00302   void SetObjectPosition(const MSLVector& pos);
00303   void SetObjectOrientation(const MSLVector& ori);
00304   void SetObjectScale(const MSLVector& sca);
00305 
00306   void SetBodyPositionChange(const MSLVector& posc);
00307   void SetBodyOrientationChange(const MSLVector& oric);
00308   void SetBodyScaleChange(const MSLVector& scac);
00309 
00310   void PrintFace();
00311   void PrintMaterial();
00312   void PrintState();
00313 };
00314 
00315 
00316 //  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -- come from generalfunction.h -- 1/5/01
00317 mslGLNormal NormalCompute(const mslGLVertex& v1, const mslGLVertex& v2, 
00318                           const mslGLVertex& v3);
00319 //  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -- come from generalfunction.h -- 1/5/01
00320 
00321 
00322 #endif
00323 
Motion Strategy Library


Web page maintained by Steve LaValle