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 // RenderGL was written by Peng Cheng (chp@cs.iastate.edu) 00020 // Modifications made by Steve LaValle (lavalle@cs.iatate.edu) 00021 00022 #ifndef MSL_RENDERGL_H 00023 #define MSL_RENDERGL_H 00024 00025 #include <GL/glut.h> 00026 #include <GL/gl.h> 00027 //#include <vector.h> 00028 //#include <string> 00029 00030 #include "render.h" 00031 #include "triangle.h" 00032 #include "renderglobj.h" 00033 #include "vector.h" 00034 #include "defs.h" 00035 #include "util.h" 00036 #include "mslio.h" 00037 00039 class RenderGL: public Render 00040 { 00041 protected: 00042 vector<int> EnvIndex; 00043 vector<int> BodyIndex; 00044 00045 float WindowX, WindowY, WindowZ; 00046 00047 float BoundingBoxMin[3]; 00048 float BoundingBoxMax[3]; 00049 00050 float Orientation[3]; 00051 float Position[3]; 00052 00053 // view parameters 00054 float Fov, AspectRatio, Near, Far; 00055 float EyeX, EyeY, EyeZ; 00056 float VpX, VpY, VpZ; 00057 float VupX, VupY, VupZ; 00058 float ViewLength; // the distance from the eye to the center of the scene 00059 00060 // unit MSLVector for the viewer coordinate 00061 MSLVector VCoordZ, VCoordY, VCoordX; 00062 MSLVector VRpy; 00063 00064 MSLVector DefVCoordZ, DefVCoordY, DefVCoordX; 00065 MSLVector DefVRpy; 00066 00067 MSLVector RpyModification; 00068 00069 // unit MSLVector for the scene coordinate 00070 MSLVector SCoordZ, SCoordY, SCoordX; 00071 00072 // light position 00073 float LightPosX, LightPosY, LightPosZ; 00074 00075 // number of object(robots and obstacles) 00076 int NumberOfObject; 00077 int NumberOfBody; 00078 int NumberOfEnvObj; 00079 00080 // robot and obstacle model information list 00081 mslGLObject ** SceneBodyLib; 00082 mslGLObject ** SceneEnvObjLib; 00083 00084 // used to control the original scale, position of object 00085 MSLVector EnvTransform; 00086 MSLVector BodyTransform; 00087 00088 // used for gui control 00089 int MainWindow; 00090 00091 // control varibles 00092 int SelectObjectID; 00093 int CurrentObject; 00094 00095 // mouse control parameter 00096 int CurrentMouseButton, CurrentMouseState; 00097 int CurrentKeyboard; 00098 float LastX, LastY; 00099 float ChangeRate; 00100 float AnimationTimeScaleTmp; 00101 00102 // method to load the configuration 00103 void LoadConfig(); 00104 00105 // method to add new object into scene 00106 void AddBodyObject(mslGLObject * obj); 00107 void AddEnvObject(mslGLObject * obj); 00108 00109 // method to get object according to object ID 00110 mslGLObject* WhichObject(int id); 00111 void SceneRender(); 00112 00113 // method to set the position of light 00114 void SetLightPos(); 00115 00116 // method to set the change of orientation and position 00117 void SetSceneOrientationChange(const MSLVector& oric); 00118 void SetScenePositionChange(const MSLVector& posc); 00119 00120 // method to set the body or environment obstacles' position and orientation 00121 void SetBodyState(const MSLVector& state); 00122 void SetEnvState(const MSLVector& state); 00123 00124 // method to draw the bounding box 00125 void DrawBoundingBox(); 00126 00127 void DrawPath(); 00128 00129 void InitData(); 00130 void InitGeometry(list<MSLTriangle> triangles); 00131 void DrawBodies(const MSLVector &x); 00132 void DrawEnv(); 00133 void NormCrossProduct(float v1[3], float v2[3], float out[3]); 00134 void Normalize(float v[3]); 00135 00136 void ShowCoordinateFrame(); 00137 00138 public: 00139 Gui *G; 00140 00141 RenderGL(); 00142 RenderGL(string filepath); 00143 RenderGL(Scene *s, string filepath); 00144 virtual ~RenderGL(); 00145 00146 // method to reset the scene 00147 virtual void Reset(); 00148 00149 virtual void Init(); 00150 virtual void MainLoop(Gui *g); 00151 00152 static void GlutIdleProcessing(); 00153 static void GlutDrawEnvironment(); 00154 static void GlutReshape(int w, int h); 00155 static void GlutMouse(int button, int state, int x, int y); 00156 static void GlutMouseMove( int x, int y ); 00157 static void GlutKeyboard(unsigned char Key, int x, int y); 00158 00159 }; 00160 00161 00162 #endif