Debian Codegraph @

07p/plaut04/src/createBoundingBox.c++

raw
1 #include "createBoundingBox.h"
2
3 #include <Inventor/So.h>
4 ///////////////////////////////////////////////////////////////////////////////
5 //
6 SoSeparator *
7 drawLine(SbVec3f pointS, SbVec3f pointE, SbVec3f color, float thickness, bool ticker, bool text, int dir)
8 //
9 ///////////////////////////////////////////////////////////////////////////////
10 {
11
12 SoSeparator * aSep = new SoSeparator;
13
14 SoCylinder * aCylinder = new SoCylinder;
15 aCylinder->radius = thickness;
16 aCylinder->height = (pointS-pointE).length();
17
18 SoMaterial *aMtl = new SoMaterial;
19 aMtl->ambientColor.setValue(0.8,0.8,0.8);
20 aMtl->diffuseColor.setValue(0.8,0.8,0.8);
21 aMtl->specularColor.setValue(0.5,0.5,0.5);
22 aMtl->shininess = 0.9;
23 aMtl->transparency = 0.0;
24
25 SoTransform * xTrans = new SoTransform;
26 if(dir==1)
27 xTrans->rotation.setValue(SbVec3f(0, 0, 1), M_PI_2);
28 else if(dir == 2)
29 xTrans->rotation.setValue(SbVec3f(0, 1, 0), M_PI_2);
30 else if(dir == 3)
31 xTrans->rotation.setValue(SbVec3f(1, 0, 0), M_PI_2);
32
33 xTrans->translation.setValue((pointE+pointS)/2);
34
35 aSep->addChild(xTrans);
36 aSep->addChild(aMtl);
37 aSep->addChild(aCylinder);
38
39 return aSep;
40 }
41
42
43 ///////////////////////////////////////////////////////////////////////////////
44 //
45 SoSeparator *
46 createBoundingBox()
47 //
48 ///////////////////////////////////////////////////////////////////////////////
49 {
50 SbVec3f pointS, pointE, color;
51 float thickness = 0.003;
52 float xMin, yMin, zMin, xMax, yMax, zMax;
53 xMin = yMin = zMin = -1;
54 xMax = yMax = zMax = 1;
55
56 SoSeparator *bdBoxSep = new SoSeparator;
57 bdBoxSep->setName("bdBox");
58 color.setValue(1,1,1);
59
60 pointS.setValue(xMin,yMin,zMin);
61 pointE.setValue(xMax, yMin, zMin);
62 bdBoxSep->addChild(drawLine(pointS, pointE, color, thickness, false, false, 1));
63
64 pointS.setValue(xMin, yMax, zMin);
65 pointE.setValue(xMax, yMax, zMin);
66 bdBoxSep->addChild(drawLine(pointS, pointE, color, thickness, false, false, 1));
67
68 pointS.setValue(xMin, yMax, zMax);
69 pointE.setValue(xMax, yMax, zMax);
70 bdBoxSep->addChild(drawLine(pointS, pointE, color, thickness, false, false, 1));
71
72 pointS.setValue(xMin, yMin, zMax);
73 pointE.setValue(xMax, yMin, zMax);
74 bdBoxSep->addChild(drawLine(pointS, pointE, color, thickness, false, false, 1));
75
76 pointS.setValue(xMin, yMin, zMin);
77 pointE.setValue(xMin, yMin, zMax);
78 bdBoxSep->addChild(drawLine(pointS, pointE, color, thickness, false, false, 3));
79
80 pointS.setValue(xMax, yMin, zMin);
81 pointE.setValue(xMax, yMin, zMax);
82 bdBoxSep->addChild(drawLine(pointS, pointE, color, thickness, false, false, 3));
83
84 pointS.setValue(xMax, yMax, zMin);
85 pointE.setValue(xMax, yMax, zMax);
86 bdBoxSep->addChild(drawLine(pointS, pointE, color, thickness, false, false, 3));
87
88 pointS.setValue(xMin, yMax, zMin);
89 pointE.setValue(xMin, yMax, zMax);
90 bdBoxSep->addChild(drawLine(pointS, pointE, color, thickness, false, false, 3));
91
92 pointS.setValue(xMin, yMin, zMin);
93 pointE.setValue(xMin, yMax, zMin);
94 bdBoxSep->addChild(drawLine(pointS, pointE, color, thickness, false, false, 2));
95
96 pointS.setValue(xMax, yMin, zMin);
97 pointE.setValue(xMax, yMax, zMin);
98 bdBoxSep->addChild(drawLine(pointS, pointE, color, thickness, false, false, 2));
99
100 pointS.setValue(xMax, yMin, zMax);
101 pointE.setValue(xMax, yMax, zMax);
102 bdBoxSep->addChild(drawLine(pointS, pointE, color, thickness, false, false, 2));
103
104 pointS.setValue(xMin, yMin, zMax);
105 pointE.setValue(xMin, yMax, zMax);
106 bdBoxSep->addChild(drawLine(pointS, pointE, color, thickness, false, false, 2));
107 return bdBoxSep;
108 }