00001
00002
00003
00004
00005 #ifndef CAJUN_SIM_UTIL_H
00006 #define CAJUN_SIM_UTIL_H
00007
00008 #define REAL2SIM_DIST_RATIO 1
00009 #define SIM2REAL_DIST_RATIO 1/REAL2SIM_DIST_RATIO
00010
00011 #define POSX 0
00012 #define POSY 1
00013 #define POSZ 2
00014
00015 #define ANGLEX 0
00016 #define ANGLEY 1
00017 #define ANGLEZ 2
00018
00019 #include "data_type.H"
00020 #include "milkshapeModel.H"
00021 #include "cb_time.H"
00022 #include <cstring>
00023 #include <string>
00024 #include <vector>
00025
00026 namespace cajun
00027 {
00029 struct color_node_t
00030 {
00031 double r;
00032 double g;
00033 double b;
00034 };
00035
00037 class chart_color_t
00038 {
00039 double m_r, m_g, m_b;
00040 public:
00041 chart_color_t () {};
00042 chart_color_t (double red, double green, double blue)
00043 {
00044 set (red, green, blue);
00045 }
00046 double red () { return m_r; };
00047 double blue () { return m_b; };
00048 double green () { return m_g; };
00049
00050 void set (double red, double green, double blue)
00051 {
00052 m_r = red;
00053 m_g = green;
00054 m_b = blue;
00055 };
00056 void select ()
00057 {
00058 glColor3f (m_r, m_g, m_b);
00059 };
00060 };
00061
00063 static chart_color_t white_color (1, 1, 1);
00064 static chart_color_t red_color (1, 0, 0);
00065 static chart_color_t green_color (0, 1, 0);
00066 static chart_color_t blue_color (0, 0, 1);
00067 static chart_color_t black_color (0, 0, 0);
00068 static chart_color_t grey_color (0.3, 0.3, 0.3);
00069 static chart_color_t light_grey_color (0.5, 0.5, 0.5);
00070 static chart_color_t color011 (0, 1, 1);
00071 static chart_color_t color101 (1, 0, 1);
00072 static chart_color_t color110 (1, 1, 0);
00073
00074 static chart_color_t grid_line_color = blue_color;
00075 static chart_color_t chart_boundary_color = red_color;
00076 static chart_color_t road_color[2] =
00077 {
00078 chart_color_t (0.3, 0.3, 0.3),
00079 chart_color_t (0.6, 0.6, 0.6)
00080 };
00081
00082 void draw_axes (double length);
00083 void color_contour (double value, double max_value,
00084 double &r, double &g, double &b);
00085 void color_contour (double value, double max_value,
00086 unsigned char &r, unsigned char &g,
00087 unsigned char &b);
00088
00089 void color_gradient (double value, double max_value,
00090 double &r, double &g, double &b);
00091 void color_gradient (double value, double max_value,
00092 unsigned char &r, unsigned char &g,
00093 unsigned char &b);
00094 void color_gradient (double value, double max_value,
00095 unsigned short &r, unsigned short &g,
00096 unsigned short &b);
00097
00098
00099
00100
00101 void color_gradient (double value, double interval, double ref_r,
00102 unsigned short &r, unsigned short &g,
00103 unsigned short &b);
00104
00105 void split_filename (const char *filename,
00106 char* dirname, unsigned dirsize,
00107 char *filepart, unsigned fpartsize);
00108
00109 bool loadMilkshapeModelData ( Model *pModel, const char *filename);
00110 void load_ppm_p6 (char *fname, unsigned int *w, unsigned int *h,
00111 unsigned char **data, int mallocflag);
00112 void load_ppm_p3 (char *fname, unsigned int *w, unsigned int *h,
00113 unsigned char **data, int mallocflag);
00114 bool read_ppm_texture (const char *fname,
00115 unsigned char*& image_data_,
00116 unsigned &width_, unsigned &height_);
00117 GLuint setup_ppm_texture (const unsigned char *image_data_,
00118 unsigned width_, unsigned height_);
00119 GLuint setup_ppm_texture (const char *fname);
00120 void Normal_Plane (float v[3],float x[3],float y[3],float z[3]);
00121 void Render_Polygon (float v[4][3],float color[3],
00122 int texon, char *ppmname);
00123 void Render_Quadric (int type,float radius,float outerradius,
00124 float length,chart_color_t color,
00125 int texon, char *ppmname);
00126 void draw_cylinder (double radius, double height);
00127 void draw_sphere (double radius);
00128 void Render_box (float dimensions[3],float color[3],
00129 int texon, char *ppmname);
00130 void Render_Ground (float size,float color[3],int texon,char *ppmname);
00131 void Render_Sky (float size,float color[3],int texon,char *ppmname);
00132 void get_rotation_matrix (double rot[16],
00133 double heading, double pitch, double roll);
00134 void output_text (int posx,int posy,int posz, char const *str);
00135 void output_text (int posx, int posy, char const *str);
00136 void output_text (double posx, double posy, double posz, char const *str);
00137 void output_string_number (int posx, int posy, std::string num);
00138 void output_string_number (double posx, double posy, double posz,
00139 std::string num);
00140 void output_int_number (int posx,int posy, int posz, int num);
00141 void output_float_number (int posx,int posy,double num);
00142 void output_float_number (double posx, double posy, double posz,
00143 double num);
00144 void output_int_number (double posx, double posy, double posz, int num);
00145 void draw_cube (double dimensions[3]);
00146 void draw_square (double x, double y, double square_length);
00147 void draw_line (double x1, double y1, double z1, double x2, double y2,
00148 double z2 );
00149 void draw_rectangle (double x1, double y1, double x2, double y2,
00150 double height, cajun::chart_color_t color);
00151 void draw_filled_rectangle (double x1, double y1, double x2, double y2,
00152 double height, cajun::chart_color_t color);
00153 void draw_circle (double x, double y, double height, double radius,
00154 chart_color_t color);
00155 void draw_leg (float a1, float b1, float a2, float b2, float w);
00156 void draw_flag (double x, double y, double bot_z);
00157 bool IsGLExtensionSupported (const char* szTargetExtension);
00158 void calculate_normal (tri_ver_t &tri_ver_, float &x_,
00159 float &y_, float &z_);
00160
00161 extern char const *progname;
00162 };
00163 #endif