00001 #include "Utility.h"
00002
00003 void Utility::DrawQuad (const Point& p1, const Point& p2, const Point& p3, const Point& p4)
00004 {
00005 Point midpoint;
00006
00007
00008 midpoint.x = (p1.x + p2.x + p3.x + p4.x) / 4;
00009 midpoint.y = (p1.y + p2.y + p3.y + p4.y) / 4;
00010 midpoint.z = (p1.z + p2.z + p3.z + p4.z) / 4;
00011
00012
00013 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
00014
00015 glColor4fv (color);
00016
00017 glBegin (GL_QUADS);
00018
00019 glVertex3f (p1.x, p1.y, p1.z);
00020 glVertex3f (p2.x, p2.y, p2.z);
00021 glVertex3f (p3.x, p3.y, p3.z);
00022 glVertex3f (p4.x, p4.y, p4.z);
00023
00024 glEnd ();
00025
00026
00027 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
00028 }
00029
00030 void Utility::DrawBoundingBox (BoundingBox bounding_box)
00031 {
00032
00033 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
00034
00035 glColor4fv (color);
00036
00037 glBegin (GL_QUADS);
00038
00039
00040 glVertex3f (bounding_box.xmax, bounding_box.ymax, bounding_box.zmax);
00041 glVertex3f (bounding_box.xmax, bounding_box.ymin, bounding_box.zmax);
00042 glVertex3f (bounding_box.xmin, bounding_box.ymin, bounding_box.zmax);
00043 glVertex3f (bounding_box.xmin, bounding_box.ymax, bounding_box.zmax);
00044
00045
00046 glVertex3f (bounding_box.xmax, bounding_box.ymax, bounding_box.zmin);
00047 glVertex3f (bounding_box.xmax, bounding_box.ymin, bounding_box.zmin);
00048 glVertex3f (bounding_box.xmin, bounding_box.ymin, bounding_box.zmin);
00049 glVertex3f (bounding_box.xmin, bounding_box.ymax, bounding_box.zmin);
00050
00051
00052 glVertex3f (bounding_box.xmax, bounding_box.ymin, bounding_box.zmin);
00053 glVertex3f (bounding_box.xmax, bounding_box.ymin, bounding_box.zmax);
00054 glVertex3f (bounding_box.xmin, bounding_box.ymin, bounding_box.zmax);
00055 glVertex3f (bounding_box.xmin, bounding_box.ymin, bounding_box.zmin);
00056
00057
00058 glVertex3f (bounding_box.xmax, bounding_box.ymax, bounding_box.zmin);
00059 glVertex3f (bounding_box.xmax, bounding_box.ymax, bounding_box.zmax);
00060 glVertex3f (bounding_box.xmin, bounding_box.ymax, bounding_box.zmax);
00061 glVertex3f (bounding_box.xmin, bounding_box.ymax, bounding_box.zmin);
00062
00063
00064 glVertex3f (bounding_box.xmax, bounding_box.ymax, bounding_box.zmin);
00065 glVertex3f (bounding_box.xmax, bounding_box.ymax, bounding_box.zmax);
00066 glVertex3f (bounding_box.xmax, bounding_box.ymin, bounding_box.zmax);
00067 glVertex3f (bounding_box.xmax, bounding_box.ymin, bounding_box.zmin);
00068
00069
00070 glVertex3f (bounding_box.xmin, bounding_box.ymax, bounding_box.zmin);
00071 glVertex3f (bounding_box.xmin, bounding_box.ymax, bounding_box.zmax);
00072 glVertex3f (bounding_box.xmin, bounding_box.ymin, bounding_box.zmax);
00073 glVertex3f (bounding_box.xmin, bounding_box.ymin, bounding_box.zmin);
00074
00075 glEnd ();
00076
00077
00078 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
00079 }
00080
00081 void Utility::SetColor (float red, float green, float blue, float alpha)
00082 {
00083 color[0] = red;
00084 color[1] = green;
00085 color[2] = blue;
00086 color[3] = alpha;
00087 }
00088
00089 float Utility::color[4] = {1.0f, 1.0f, 1.0f, 0.0f};
00090
00091 Point Utility::GetPointFromBox (const BoundingBox & box, int index)
00092 {
00093 Point result;
00094 switch (index)
00095 {
00096 case 0: result.x = box.xmax;
00097 result.y = box.ymax;
00098 result.z = box.zmax;
00099 break;
00100 case 1: result.x = box.xmax;
00101 result.y = box.ymax;
00102 result.z = box.zmin;
00103 break;
00104 case 2: result.x = box.xmax;
00105 result.y = box.ymin;
00106 result.z = box.zmax;
00107 break;
00108 case 3: result.x = box.xmax;
00109 result.y = box.ymin;
00110 result.z = box.zmin;
00111 break;
00112 case 4: result.x = box.xmin;
00113 result.y = box.ymax;
00114 result.z = box.zmax;
00115 break;
00116 case 5: result.x = box.xmin;
00117 result.y = box.ymax;
00118 result.z = box.zmin;
00119 break;
00120 case 6: result.x = box.xmin;
00121 result.y = box.ymin;
00122 result.z = box.zmax;
00123 break;
00124 case 7: result.x = box.xmin;
00125 result.y = box.ymin;
00126 result.z = box.zmin;
00127 break;
00128 default: result.x = 0.0f;
00129 result.y = 0.0f;
00130 result.z = 0.0f;
00131 }
00132
00133 return result;
00134 }