00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <stdlib.h>
00042 #include <stdio.h>
00043
00044 #include "OSGConfig.h"
00045
00046 #include <OSGGL.h>
00047
00048 #include <OSGLog.h>
00049 #include <OSGBoxVolume.h>
00050 #include <OSGSphereVolume.h>
00051 #include <OSGFrustumVolume.h>
00052 #include <OSGCylinderVolume.h>
00053 #include <OSGSimpleGeometry.h>
00054 #include <OSGRenderAction.h>
00055
00056 #include "OSGVolumeDraw.h"
00057
00058 OSG_USING_NAMESPACE
00059
00060
00064 OSG_SYSTEMLIB_DLLMAPPING
00065 void OSG::drawVolume(const DynamicVolume &volume)
00066 {
00067 const Volume *v = &volume.getInstance();
00068 const BoxVolume *bv;
00069 const SphereVolume *sv;
00070 const CylinderVolume *cv;
00071 const FrustumVolume *fv;
00072
00073 if((bv = dynamic_cast<const BoxVolume*>(v)))
00074 {
00075 drawVolume(*bv);
00076 }
00077 else if((sv = dynamic_cast<const SphereVolume*>(v)))
00078 {
00079 drawVolume(*sv);
00080 }
00081 else if((cv = dynamic_cast<const CylinderVolume*>(v)))
00082 {
00083 drawVolume(*cv);
00084 }
00085 else if((fv = dynamic_cast<const FrustumVolume*>(v)))
00086 {
00087 drawVolume(*fv);
00088 }
00089 }
00090
00094 OSG_SYSTEMLIB_DLLMAPPING
00095 void OSG::drawVolume(const BoxVolume &volume)
00096 {
00097 Pnt3f min,max;
00098 volume.getBounds(min, max);
00099
00100 glBegin(GL_LINE_LOOP);
00101 glVertex3f(min[0], min[1], min[2]);
00102 glVertex3f(max[0], min[1], min[2]);
00103 glVertex3f(max[0], max[1], min[2]);
00104 glVertex3f(min[0], max[1], min[2]);
00105 glVertex3f(min[0], min[1], min[2]);
00106 glVertex3f(min[0], min[1], max[2]);
00107 glVertex3f(max[0], min[1], max[2]);
00108 glVertex3f(max[0], max[1], max[2]);
00109 glVertex3f(min[0], max[1], max[2]);
00110 glVertex3f(min[0], min[1], max[2]);
00111 glEnd();
00112
00113 glBegin(GL_LINES);
00114 glVertex3f(min[0], max[1], min[2]);
00115 glVertex3f(min[0], max[1], max[2]);
00116 glVertex3f(max[0], max[1], min[2]);
00117 glVertex3f(max[0], max[1], max[2]);
00118 glVertex3f(max[0], min[1], min[2]);
00119 glVertex3f(max[0], min[1], max[2]);
00120 glEnd();
00121
00122 return;
00123 }
00124
00130 OSG_SYSTEMLIB_DLLMAPPING
00131 void OSG::drawVolume(const SphereVolume &OSG_CHECK_ARG(volume))
00132 {
00133 FWARNING(("drawVolume(SphereVolume): not implemented yet!\n"));
00134 return;
00135 }
00136
00141 OSG_SYSTEMLIB_DLLMAPPING
00142 void OSG::drawVolume(const FrustumVolume &volume)
00143 {
00144 Line lines[4];
00145
00146
00147 if(volume.getLeft().intersect(volume.getTop(), lines[0]) == false)
00148 {
00149 FWARNING(("drawVolume(Frustum): left & top parallel ?!?\n"));
00150 return;
00151 }
00152
00153 if(volume.getLeft().intersect(volume.getBottom(), lines[1]) == false)
00154 {
00155 FWARNING(("drawVolume(Frustum): left & bottom parallel ?!?\n"));
00156 return;
00157 }
00158
00159 if(volume.getRight().intersect(volume.getTop(), lines[2]) == false)
00160 {
00161 FWARNING(("drawVolume(Frustum): right & top parallel ?!?\n"));
00162 return;
00163 }
00164
00165 if(volume.getRight().intersect(volume.getBottom(), lines[3]) == false)
00166 {
00167 FWARNING(("drawVolume(Frustum): right & bottom parallel ?!?\n"));
00168 return;
00169 }
00170
00171
00172 Pnt3f pnts[8];
00173
00174 if(volume.getNear().intersectInfinite(lines[0], pnts[0]) == false)
00175 {
00176 FWARNING(("drawVolume(Frustum): near & left/top parallel ?!?\n"));
00177 return;
00178 }
00179
00180 if(volume.getFar().intersectInfinite(lines[0], pnts[1]) == false)
00181 {
00182 FWARNING(("drawVolume(Frustum): far & left/top parallel ?!?\n"));
00183 return;
00184 }
00185
00186 if(volume.getNear().intersectInfinite(lines[1], pnts[2]) == false)
00187 {
00188 FWARNING(("drawVolume(Frustum): near & left/bottom parallel ?!?\n"));
00189 return;
00190 }
00191
00192 if(volume.getFar().intersectInfinite(lines[1], pnts[3]) == false)
00193 {
00194 FWARNING(("drawVolume(Frustum): far & left/bottom parallel ?!?\n"));
00195 return;
00196 }
00197
00198 if(volume.getNear().intersectInfinite(lines[2], pnts[4]) == false)
00199 {
00200 FWARNING(("drawVolume(Frustum): near & right/top parallel ?!?\n"));
00201 return;
00202 }
00203
00204 if(volume.getFar().intersectInfinite(lines[2], pnts[5]) == false)
00205 {
00206 FWARNING(("drawVolume(Frustum): far & right/top parallel ?!?\n"));
00207 return;
00208 }
00209
00210 if(volume.getNear().intersectInfinite(lines[3], pnts[6]) == false)
00211 {
00212 FWARNING(("drawVolume(Frustum): near & right/bottom parallel ?!?\n"));
00213 return;
00214 }
00215
00216 if(volume.getFar().intersectInfinite(lines[3], pnts[7]) == false)
00217 {
00218 FWARNING(("drawVolume(Frustum): far & right/bottom parallel ?!?\n"));
00219 return;
00220 }
00221
00222
00223
00224 glBegin(GL_LINE_LOOP);
00225 glVertex3fv(pnts[0].getValues());
00226 glVertex3fv(pnts[1].getValues());
00227 glVertex3fv(pnts[3].getValues());
00228 glVertex3fv(pnts[2].getValues());
00229 glVertex3fv(pnts[6].getValues());
00230 glVertex3fv(pnts[7].getValues());
00231 glVertex3fv(pnts[5].getValues());
00232 glVertex3fv(pnts[4].getValues());
00233 glEnd();
00234
00235 glBegin(GL_LINES);
00236 glVertex3fv(pnts[0].getValues());
00237 glVertex3fv(pnts[2].getValues());
00238 glVertex3fv(pnts[1].getValues());
00239 glVertex3fv(pnts[5].getValues());
00240 glVertex3fv(pnts[2].getValues());
00241 glVertex3fv(pnts[6].getValues());
00242 glVertex3fv(pnts[4].getValues());
00243 glVertex3fv(pnts[6].getValues());
00244 glEnd();
00245
00246 return;
00247 }
00248
00254 OSG_SYSTEMLIB_DLLMAPPING
00255 void OSG::drawVolume(const CylinderVolume &OSG_CHECK_ARG(volume))
00256 {
00257 FWARNING(("drawVolume(CylinderVolume): not implemented yet!\n"));
00258 return;
00259 }
00260
00265 class VolumeDrawWrapper
00266 {
00267 public:
00268
00269 VolumeDrawWrapper(const DynamicVolume &vol, Color3f col) :
00270 _vol(vol), _col(col)
00271 {}
00272
00273 ~VolumeDrawWrapper()
00274 {}
00275
00276 static void drop(DrawActionBase *action, NodePtr node, Color3f col)
00277 {
00278 node->updateVolume();
00279
00280 drop(action, node->getVolume(), col);
00281 }
00282
00283 static void drop(DrawActionBase *action, const DynamicVolume &volume, Color3f col)
00284 {
00285 VolumeDrawWrapper * vdw = new VolumeDrawWrapper(volume, col);
00286
00287 Material::DrawFunctor func;
00288 func = osgTypedMethodFunctor1ObjPtr(vdw, &VolumeDrawWrapper::draw);
00289
00290 RenderAction *ra = dynamic_cast<RenderAction*>(action);
00291
00292 ra->dropFunctor(func, getDefaultUnlitMaterial().getCPtr());
00293 }
00294
00295 private:
00296
00297 Action::ResultE draw(DrawActionBase *)
00298 {
00299 glColor3fv(_col.getValuesRGB());
00300 drawVolume(_vol);
00301
00302
00303 delete this;
00304
00305 return Action::Continue;
00306 }
00307
00308 DynamicVolume _vol;
00309 Color3f _col;
00310 };
00311
00315 OSG_SYSTEMLIB_DLLMAPPING
00316 void OSG::dropVolume(DrawActionBase *action, NodePtr node, Color3f col)
00317 {
00318 VolumeDrawWrapper::drop(action, node, col);
00319 return;
00320 }
00321
00325 OSG_SYSTEMLIB_DLLMAPPING
00326 void OSG::dropVolume(DrawActionBase *action, const DynamicVolume &volume, Color3f col)
00327 {
00328 VolumeDrawWrapper::drop(action, volume, col);
00329 return;
00330 }