00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <cstdio>
00012 #include "GLee.h"
00013 #include "BoundBox.h"
00014 #include "Point.h"
00015
00016 BoundBox::BoundBox() {
00017 m_b1 = NULL;
00018 m_b2 = NULL;
00019 m_b3 = NULL;
00020 m_b4 = NULL;
00021
00022 m_t1 = NULL;
00023 m_t2 = NULL;
00024 m_t3 = NULL;
00025 m_t4 = NULL;
00026 }
00027
00028 BoundBox::BoundBox(float minX, float maxX, float minY, float maxY, float minZ, float maxZ) {
00029 m_b1 = new Point(minX, minY, minZ);
00030 m_b2 = new Point(maxX, minY, minZ);
00031 m_b3 = new Point(minX, minY, maxZ);
00032 m_b4 = new Point(maxX, minY, maxZ);
00033
00034 m_t1 = new Point(minX, maxY, minZ);
00035 m_t2 = new Point(maxX, maxY, minZ);
00036 m_t3 = new Point(minX, maxY, maxZ);
00037 m_t4 = new Point(maxX, maxY, maxZ);
00038 }
00039
00040 BoundBox::~BoundBox() {
00041 delete m_b1;
00042 delete m_b2;
00043 delete m_b3;
00044 delete m_b4;
00045
00046 delete m_t1;
00047 delete m_t2;
00048 delete m_t3;
00049 delete m_t4;
00050 }
00051
00052 void BoundBox::SetHeight(float low, float high) {
00053 if ((m_b1 == NULL) || (m_b2 == NULL) || (m_b3 == NULL) || (m_b4 == NULL)) {
00054 printf("NULL!\n");
00055 }
00056 m_b1->m_y = low;
00057 m_b2->m_y = low;
00058 m_b3->m_y = low;
00059 m_b4->m_y = low;
00060
00061 delete m_t1;
00062 delete m_t2;
00063 delete m_t3;
00064 delete m_t4;
00065
00066 m_t1 = new Point(m_b1->m_x, high, m_b1->m_z);
00067 m_t2 = new Point(m_b2->m_x, high, m_b2->m_z);
00068 m_t3 = new Point(m_b3->m_x, high, m_b3->m_z);
00069 m_t4 = new Point(m_b4->m_x, high, m_b4->m_z);
00070 }
00071
00072 void BoundBox::Draw() {
00073 glBegin(GL_LINES);
00074 glNormal3f(0, 1, 0);
00075 m_b1->Draw();
00076 m_b2->Draw();
00077
00078 m_b2->Draw();
00079 m_b4->Draw();
00080
00081 m_b4->Draw();
00082 m_b3->Draw();
00083
00084 m_b3->Draw();
00085 m_b1->Draw();
00086
00087 m_b1->Draw();
00088 m_t1->Draw();
00089
00090 m_b2->Draw();
00091 m_t2->Draw();
00092
00093 m_b3->Draw();
00094 m_t3->Draw();
00095
00096 m_b4->Draw();
00097 m_t4->Draw();
00098
00099 m_t1->Draw();
00100 m_t2->Draw();
00101
00102 m_t2->Draw();
00103 m_t4->Draw();
00104
00105 m_t4->Draw();
00106 m_t3->Draw();
00107
00108 m_t3->Draw();
00109 m_t1->Draw();
00110 glEnd();
00111 }
00112
00113 void BoundBox::Dump() {
00114 m_b1->Dump();
00115 m_b2->Dump();
00116 m_b3->Dump();
00117 m_b4->Dump();
00118
00119 m_t1->Dump();
00120 m_t2->Dump();
00121 m_t3->Dump();
00122 m_t4->Dump();
00123 }