00001
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00019
00020
00021 #include <vpcutplane.h>
00022
00023
00025
00026
00027
00028
00029 VPCutPlane::VPCutPlane() {
00030
00031 }
00032
00033
00035
00036
00037
00038
00039
00040 VPCutPlane::VPCutPlane(VPBoundingBox b) {
00041 boundingBox = b;
00042 vpPlaneComputation();
00043 }
00044
00045
00047
00048
00049
00050
00051 void VPCutPlane::vpSetBoundingBox(VPBoundingBox b) {
00052 boundingBox = b;
00053 vpPlaneComputation();
00054 }
00055
00056
00058
00059
00060
00061
00062
00063 VPVector3D VPCutPlane::vpGetNormal(void) {
00064 return normal;
00065 }
00066
00067
00069
00070
00071
00072
00073 void VPCutPlane::vpPlaneComputation(void) {
00074 float maiorX,maiorY,maiorZ,menorX,menorY,menorZ,aux;
00075 float cx,cy,cz;
00076
00077 cx = boundingBox.vpGetCenter()->vpGetX();
00078 cy = boundingBox.vpGetCenter()->vpGetY();
00079 cz = boundingBox.vpGetCenter()->vpGetZ();
00080
00081 maiorX = boundingBox.vpGetGreaterX();
00082 maiorY = boundingBox.vpGetGreaterY();
00083 maiorZ = boundingBox.vpGetGreaterZ();
00084 menorX = boundingBox.vpGetSmallerX();
00085 menorY = boundingBox.vpGetSmallerY();
00086 menorZ = boundingBox.vpGetSmallerZ();
00087
00088 if((maiorX)>(maiorY))
00089 {
00090 if((maiorX)>(maiorZ))
00091 aux = maiorX - cx;
00092 else
00093 aux = maiorZ - cz;
00094 }
00095 else
00096 {
00097 if((maiorY)>(maiorZ))
00098 aux = maiorY - cy;
00099 else
00100 aux = maiorZ - cz;
00101 }
00102
00103 plane[0] = VPPoint3D(cx-aux,cy,cz-aux);
00104 plane[1] = VPPoint3D(cx+aux,cy,cz-aux);
00105 plane[2] = VPPoint3D(cx+aux,cy+(aux/2),cz+aux);
00106 plane[3] = VPPoint3D(cx-aux,cy+(aux/2),cz+aux);
00107
00108 vpNormalComputation
00109 (plane[0].vpGetX(),plane[0].vpGetY(),plane[0].vpGetZ(),
00110 plane[1].vpGetX(),plane[1].vpGetY(),plane[1].vpGetZ(),
00111 plane[2].vpGetX(),plane[2].vpGetY(),plane[2].vpGetZ());
00112 }
00113
00114
00116
00117
00118
00119
00120
00121 void VPCutPlane::vpNormalComputation(float x1,float y1,float z1,
00122 float x2,float y2,float z2,
00123 float x3,float y3,float z3){
00124
00125 float vax, vay, vaz, vbx, vby, vbz, nx, ny, nz;
00126 float modulo;
00127
00128
00129
00130 vax = x2-x1;
00131 vay = y2-y1;
00132 vaz = z2-z1;
00133
00134 vbx = x3-x1;
00135 vby = y3-y1;
00136 vbz = z3-z1;
00137
00138 nx = (vay*vbz) - (vaz*vby);
00139 ny = (vaz*vbx) - (vax*vbz);
00140 nz = (vax*vby) - (vay*vbx);
00141
00142 modulo = (float) sqrt(nx*nx + ny*ny + nz*nz);
00143
00144 nx = nx / modulo;
00145 ny = ny / modulo;
00146 nz = nz / modulo;
00147
00148 normal.vpSetVector3D(nx,ny,nz);
00149 }
00150
00151
00153
00154
00155
00156
00157 VPRotation* VPCutPlane::vpGetRotation(void){
00158 return &rotation;
00159 }
00160
00161
00163
00164
00165
00166
00167 VPTranslation* VPCutPlane::vpGetTranslation(void){
00168 return &translation;
00169 }
00170
00171
00173
00174
00175
00176 void VPCutPlane::vpRender(void){
00177
00178 glPushMatrix();
00179 glTranslatef(translation.vpGetPositionX(),0.0,0.0);
00180 glTranslatef(0.0,-translation.vpGetPositionY(),0.0);
00181
00182 glPushMatrix();
00183 glRotatef(rotation.vpGetAngleX(),0.0,1.0,0.0);
00184 glRotatef(rotation.vpGetAngleY(),1.0,0.0,0.0);
00185
00186 glPushMatrix();
00187 glBegin(GL_QUADS);
00188 glColor3ub(150,200,200);
00189 glNormal3f(normal.vpGetVector3DX(),normal.vpGetVector3DY(),normal.vpGetVector3DZ());
00190 glVertex3f(plane[0].vpGetX(),plane[0].vpGetY(),plane[0].vpGetZ());
00191 glVertex3f(plane[1].vpGetX(),plane[1].vpGetY(),plane[1].vpGetZ());
00192 glVertex3f(plane[2].vpGetX(),plane[2].vpGetY(),plane[2].vpGetZ());
00193 glVertex3f(plane[3].vpGetX(),plane[3].vpGetY(),plane[3].vpGetZ());
00194 glEnd();
00195 glPopMatrix();
00196 glPopMatrix();
00197 glPopMatrix();
00198
00199 }
00200
00201
00203
00204
00205
00206
00207 void VPCutPlane::vpDComputation(void){
00208 float nx,ny,nz;
00209
00210 nx = normal.vpGetVector3DX();
00211 ny = normal.vpGetVector3DY();
00212 nz = normal.vpGetVector3DZ();
00213
00214 nD = -(nx*plane[0].vpGetX() + ny*plane[0].vpGetY() + nz*plane[0].vpGetZ());
00215 }
00216
00217
00219
00220
00221
00222
00223 float VPCutPlane::vpGetD(){
00224 return nD;
00225 }
00226