Debian Codegraph @

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

raw
1 // This file is unused!!!
2
3 #include "drawCoords.h"
4
5 #include <Inventor/nodes/SoCylinder.h>
6 #include <Inventor/nodes/SoNode.h>
7 #include <Inventor/nodes/SoTransform.h>
8 #include <Inventor/nodes/SoRotationXYZ.h>
9 #include <Inventor/nodes/SoMaterial.h>
10 #include <Inventor/nodes/SoCone.h>
11 #include <Inventor/SbLinear.h>
12 #include <Inventor/fields/SoField.h>
13
14 #include "gplaut04.h"
15
16 #define FONT_SIZE 24
17
18 //////////////////////////////////////////////////////////////////////
19 //
20 SoSeparator *
21 drawCoords(int where, float pos[], SbVec3f axisColors[], float height)
22 //
23 //////////////////////////////////////////////////////////////////////
24 {
25 float xGo=0, yGo=0, zGo = 0;
26
27 SoSeparator *myAxis= new SoSeparator;
28 SoSeparator *xGrp = new SoSeparator;
29 SoSeparator *yGrp = new SoSeparator;
30 SoSeparator *zGrp = new SoSeparator;
31
32 SoSeparator *redAxis = createAxis(axisColors[0][0], axisColors[0][1], axisColors[0][2], height, "X");
33 SoSeparator *blueAxis = createAxis(axisColors[1][0], axisColors[1][1],axisColors[1][2], height, "Y");
34 SoSeparator *greenAxis = createAxis(axisColors[2][0], axisColors[2][1],axisColors[2][2], height, "Z");
35
36 SoTransform *xXform = new SoTransform;
37 xXform->scaleFactor.setValue(1, 1, 1);
38 xXform->rotation.setValue(SbVec3f(0.0, 0.0, 1.0),-M_PI_2);
39 if(where == 2)
40 xXform->translation.setValue(1, 0, 0);
41 else
42 xXform->translation.setValue(xGo, 0, 0);
43
44 SoTransform *zXform = new SoTransform;
45 zXform->scaleFactor.setValue(1.0, 1.0, 1.0);
46 if(where == 2)
47 zXform->translation.setValue(0, 0, 1);
48 else
49 zXform->translation.setValue(0, 0, zGo);
50 zXform->rotation.setValue(SbVec3f(1.0, 0.0, 0.0),M_PI_2);
51
52 SoTransform *yXform = new SoTransform;
53 yXform->scaleFactor.setValue(1.0, 1.0, 1.0);
54 if(where == 2)
55 yXform->translation.setValue(0, 1, 0);
56 else
57 yXform->translation.setValue(0, yGo, 0);
58
59 // to draw the ticker of the X upward, we still need to
60 // rotate X for 180 degree.
61 SoRotationXYZ *rotX = new SoRotationXYZ;
62 rotX->axis = SoRotationXYZ::X;
63 rotX->angle = M_PI;
64
65 xGrp->addChild(rotX);
66 xGrp->addChild(xXform);
67 xGrp->addChild(redAxis);
68
69 yGrp->addChild(yXform);
70 yGrp->addChild(blueAxis);
71
72 zGrp->addChild(zXform);
73 zGrp->addChild(greenAxis);
74
75 SoSeparator *axs = new SoSeparator;
76 axs->addChild(xGrp);
77 axs->addChild(yGrp);
78 axs->addChild(zGrp);
79
80 SoTransform *axsXform = new SoTransform;
81 axsXform->translation.setValue(pos);
82 myAxis->addChild(axsXform);
83 myAxis->addChild(axs);
84
85 return myAxis;
86 }
87
88 SoSeparator * createAxis(float red, float green, float blue, float height, const char * label)
89 {
90 SoSeparator *axisSep = new SoSeparator;
91 SoMaterial *axisMtl = new SoMaterial;
92
93 //define materil
94 axisMtl->ambientColor.setValue(1.0,1.0,1.0);
95 axisMtl->diffuseColor.setValue(red, green, blue);
96 axisMtl->specularColor.setValue(1.0,1.0,1.0);
97 axisMtl->shininess = 0.9;
98 axisMtl->transparency = 0.0;
99
100 //define a cylindar for the axis
101 SoCylinder *cyl = new SoCylinder;
102 cyl->radius = height/350.0;
103 cyl->height = 1.1 * height;
104
105 //define arrow
106 SoSeparator *arrSep = new SoSeparator;
107 SoCone *arrow = new SoCone;
108 arrow->bottomRadius = height/150.0;
109 arrow->height = 5.0*height/100.0;
110 SoTransform *arrXform = new SoTransform;
111 float pst = (cyl->height.getValue())/2.0;
112 arrXform->translation.setValue(0.0, pst, 0.0);
113 arrSep->addChild(arrXform);
114 arrSep->addChild(arrow);
115
116 // define font for the axis
117 SoFont *axFont = new SoFont;
118 axFont->name.setValue("Helvetica");
119 axFont->size.setValue(FONT_SIZE);
120 SoText2 *axName = new SoText2;
121 axName->string.setValue(label);
122 arrSep->addChild(axFont);
123 arrSep->addChild(axName);
124
125 //add child to axisSep
126 axisSep->addChild(axisMtl);
127 axisSep->addChild(cyl);
128 axisSep->addChild(arrSep);
129 for(int i=0; i<=10; i++)
130 axisSep->addChild(drawTicker((float)(i/10.0-0.5)*height, height/100.0));
131
132 return axisSep;
133 }
134
135
136 SoSeparator * drawTicker(float pos, float height)
137 {
138 // define ticker
139 SoSeparator *tkSep = new SoSeparator;
140 SoCylinder *ticker = new SoCylinder;
141 ticker->radius = height/10.0;
142 ticker->height = height;
143
144 //define transform for the ticker
145 SoTransform *tkXform = new SoTransform;
146 tkXform->translation.setValue(0.00, pos, 0.00);
147 tkXform->rotation.setValue(SbVec3f(0.0,0.0,1.0),M_PI_2);
148 tkSep->addChild(tkXform);
149 tkSep->addChild(ticker);
150 return tkSep;
151 }