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


Web page maintained by Steve LaValle
Partial support provided by NSF CAREER Award IRI-970228 (LaValle), Honda Research.
Contributors: Anna Atramentov, Peng Cheng, James Kuffner, Steve LaValle, and Libo Yang.