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