23
#include "PreCompiled.h"
30
# include <OpenGL/gl.h>
35
# include <Inventor/actions/SoGetBoundingBoxAction.h>
36
# include <Inventor/actions/SoGLRenderAction.h>
37
# include <Inventor/bundles/SoMaterialBundle.h>
38
# include <Inventor/bundles/SoTextureCoordinateBundle.h>
39
# include <Inventor/elements/SoLazyElement.h>
40
# include <Inventor/elements/SoModelMatrixElement.h>
41
# include <Inventor/elements/SoViewportRegionElement.h>
42
# include <Inventor/elements/SoViewVolumeElement.h>
43
# include <Inventor/nodekits/SoShapeKit.h>
44
# include <Inventor/nodes/SoBaseColor.h>
45
# include <Inventor/nodes/SoCone.h>
46
# include <Inventor/nodes/SoCoordinate3.h>
47
# include <Inventor/nodes/SoCube.h>
48
# include <Inventor/nodes/SoFontStyle.h>
49
# include <Inventor/nodes/SoLineSet.h>
50
# include <Inventor/nodes/SoScale.h>
51
# include <Inventor/nodes/SoSeparator.h>
52
# include <Inventor/nodes/SoText2.h>
53
# include <Inventor/nodes/SoTranslation.h>
56
#include "SoAxisCrossKit.h"
62
SO_KIT_SOURCE(SoShapeScale)
65
SoShapeScale::SoShapeScale()
67
SO_KIT_CONSTRUCTOR(SoShapeScale);
69
SO_KIT_ADD_FIELD(active, (true));
70
SO_KIT_ADD_FIELD(scaleFactor, (1.0f));
72
SO_KIT_ADD_CATALOG_ENTRY(topSeparator, SoSeparator, false, this, "", false);
73
SO_KIT_ADD_CATALOG_ABSTRACT_ENTRY(shape, SoNode, SoCube, true, topSeparator, "", true);
74
SO_KIT_ADD_CATALOG_ENTRY(scale, SoScale, false, topSeparator, shape, false);
76
SO_KIT_INIT_INSTANCE();
80
SoShapeScale::~SoShapeScale() = default;
83
SoShapeScale::initClass()
85
SO_KIT_INIT_CLASS(SoShapeScale, SoBaseKit, "BaseKit");
89
SoShapeScale::GLRender(SoGLRenderAction * action)
91
SoState * state = action->getState();
93
SoScale * scale = static_cast<SoScale*>(this->getAnyPart(SbName("scale"), true));
94
if (!this->active.getValue()) {
95
SbVec3f v(1.0f, 1.0f, 1.0f);
96
if (scale->scaleFactor.getValue() != v)
97
scale->scaleFactor = v;
100
const SbViewportRegion & vp = SoViewportRegionElement::get(state);
101
const SbViewVolume & vv = SoViewVolumeElement::get(state);
102
SbVec3f center(0.0f, 0.0f, 0.0f);
103
float nsize = this->scaleFactor.getValue() / float(vp.getViewportSizePixels()[1]);
104
SoModelMatrixElement::get(state).multVecMatrix(center, center);
105
float sf = vv.getWorldToScreenScale(center, nsize);
106
SbVec3f v(sf, sf, sf);
107
if (scale->scaleFactor.getValue() != v)
108
scale->scaleFactor = v;
111
inherited::GLRender(action);
116
SO_KIT_SOURCE(SoAxisCrossKit)
119
SoAxisCrossKit::initClass()
121
SO_KIT_INIT_CLASS(SoAxisCrossKit,SoBaseKit, "BaseKit");
124
SoAxisCrossKit::SoAxisCrossKit()
126
SO_KIT_CONSTRUCTOR(SoAxisCrossKit);
129
SO_KIT_ADD_CATALOG_ENTRY(xAxis, SoShapeKit,
130
true, this,"", true);
131
SO_KIT_ADD_CATALOG_ENTRY(xHead, SoShapeKit,
132
true, this,"", true);
133
SO_KIT_ADD_CATALOG_ENTRY(yAxis, SoShapeKit,
134
true, this,"", true);
135
SO_KIT_ADD_CATALOG_ENTRY(yHead, SoShapeKit,
136
true, this,"", true);
137
SO_KIT_ADD_CATALOG_ENTRY(zAxis, SoShapeKit,
138
true, this,"", true);
139
SO_KIT_ADD_CATALOG_ENTRY(zHead, SoShapeKit,
140
true, this,"", true);
142
SO_KIT_INIT_INSTANCE();
147
SoAxisCrossKit::~SoAxisCrossKit() = default;
152
SoAxisCrossKit::affectsState() const
157
void SoAxisCrossKit::addWriteReference(SoOutput * , SbBool )
162
void SoAxisCrossKit::getBoundingBox(SoGetBoundingBoxAction * action)
164
inherited::getBoundingBox(action);
165
action->resetCenter();
166
action->setCenter(SbVec3f(0,0,0), false);
171
SoAxisCrossKit::createAxes()
174
auto head = new SoCone;
175
head->bottomRadius.setValue(5);
176
head->height.setValue(10);
177
setPart("xHead.shape", head);
178
setPart("yHead.shape", head);
179
setPart("zHead.shape", head);
182
auto coords = new SoCoordinate3;
183
coords->point.set1Value(0, SbVec3f(0,0,0));
184
coords->point.set1Value(1, SbVec3f(90,0,0));
185
setPart("xAxis.coordinate3", coords);
186
setPart("yAxis.coordinate3", coords);
187
setPart("zAxis.coordinate3", coords);
189
auto shape = new SoLineSet;
190
setPart("xAxis.shape", shape);
191
setPart("yAxis.shape", shape);
192
setPart("zAxis.shape", shape);
195
set("yAxis.transform", "rotation 0 0 1 1.5707999");
196
set("zAxis.transform", "rotation 0 1 0 -1.5707999");
198
set("xHead.transform", "translation 95 0 0");
199
set("xHead.transform", "scaleFactor 0.5 1.5 0.5");
200
set("xHead.transform", "rotation 0 0 -1 1.5707999");
202
set("yHead.transform", "translation 0 95 0");
203
set("yHead.transform", "scaleFactor 0.5 1.5 0.5");
204
set("yHead.transform", "rotation 0 0 1 0");
206
set("zHead.transform", "translation 0 0 95");
207
set("zHead.transform", "scaleFactor 0.5 1.5 0.5");
208
set("zHead.transform", "rotation 1 0 0 1.5707999");
211
set("xAxis.appearance.lightModel", "model BASE_COLOR");
212
set("xHead.appearance.lightModel", "model BASE_COLOR");
213
set("yAxis.appearance.lightModel", "model BASE_COLOR");
214
set("yHead.appearance.lightModel", "model BASE_COLOR");
215
set("zAxis.appearance.lightModel", "model BASE_COLOR");
216
set("zHead.appearance.lightModel", "model BASE_COLOR");
217
set("xAxis.appearance.drawStyle", "lineWidth 1");
218
set("yAxis.appearance.drawStyle", "lineWidth 1");
219
set("zAxis.appearance.drawStyle", "lineWidth 1");
220
set("xAxis.appearance.material", "diffuseColor 0.5 0.125 0.125");
221
set("xHead.appearance.material", "diffuseColor 0.5 0.125 0.125");
222
set("yAxis.appearance.material", "diffuseColor 0.125 0.5 0.125");
223
set("yHead.appearance.material", "diffuseColor 0.125 0.5 0.125");
224
set("zAxis.appearance.material", "diffuseColor 0.125 0.125 0.5");
225
set("zHead.appearance.material", "diffuseColor 0.125 0.125 0.5");
228
set("xAxis.pickStyle", "style UNPICKABLE");
229
set("xHead.pickStyle", "style UNPICKABLE");
230
set("yAxis.pickStyle", "style UNPICKABLE");
231
set("yHead.pickStyle", "style UNPICKABLE");
232
set("zAxis.pickStyle", "style UNPICKABLE");
233
set("zHead.pickStyle", "style UNPICKABLE");
238
SO_NODE_SOURCE(SoRegPoint)
240
void SoRegPoint::initClass()
242
SO_NODE_INIT_CLASS(SoRegPoint, SoShape, "Shape");
245
SoRegPoint::SoRegPoint()
247
SO_NODE_CONSTRUCTOR(SoRegPoint);
249
SO_NODE_ADD_FIELD(base, (SbVec3f(0,0,0)));
250
SO_NODE_ADD_FIELD(normal, (SbVec3f(1,1,1)));
251
SO_NODE_ADD_FIELD(length, (3.0));
252
SO_NODE_ADD_FIELD(color, (1.0f, 0.447059f, 0.337255f));
253
SO_NODE_ADD_FIELD(text, (""));
255
root = new SoSeparator();
259
auto move = new SoTranslation();
260
move->translation.setValue(base.getValue() + normal.getValue() * length.getValue());
261
root->addChild(move);
264
auto col = new SoBaseColor();
265
col->rgb.setValue(this->color.getValue());
267
auto font = new SoFontStyle;
270
auto sub = new SoSeparator();
273
sub->addChild(new SoText2());
277
SoRegPoint::~SoRegPoint()
285
void SoRegPoint::GLRender(SoGLRenderAction *action)
287
if (shouldGLRender(action))
289
SoState* state = action->getState();
291
SoMaterialBundle mb(action);
292
SoTextureCoordinateBundle tb(action, true, false);
293
SoLazyElement::setLightModel(state, SoLazyElement::BASE_COLOR);
296
SbVec3f p1 = base.getValue();
297
SbVec3f p2 = p1 + normal.getValue() * length.getValue();
300
glColor3fv(color.getValue().getValue());
301
glBegin(GL_LINE_STRIP);
302
glVertex3d(p1[0], p1[1], p1[2]);
303
glVertex3d(p2[0], p2[1], p2[2]);
307
glVertex3fv(p1.getValue());
311
glVertex3fv(p2.getValue());
314
root->GLRender(action);
319
void SoRegPoint::generatePrimitives(SoAction* )
326
void SoRegPoint::computeBBox(SoAction *action, SbBox3f &box, SbVec3f ¢er)
328
root->doAction(action);
329
if (action->getTypeId().isDerivedFrom(SoGetBoundingBoxAction::getClassTypeId()))
330
static_cast<SoGetBoundingBoxAction*>(action)->resetCenter();
332
SbVec3f p1 = base.getValue();
333
SbVec3f p2 = p1 + normal.getValue() * length.getValue();
338
center = box.getCenter();
341
void SoRegPoint::notify(SoNotList * node)
343
SoField * f = node->getLastField();
344
if (f == &this->base || f == &this->normal || f == &this->length) {
345
auto move = static_cast<SoTranslation*>(root->getChild(0));
346
move->translation.setValue(base.getValue() + normal.getValue() * length.getValue());
348
else if (f == &this->color) {
349
auto sub = static_cast<SoSeparator*>(root->getChild(1));
350
auto col = static_cast<SoBaseColor*>(sub->getChild(0));
351
col->rgb = this->color.getValue();
353
else if (f == &this->text) {
354
auto sub = static_cast<SoSeparator*>(root->getChild(1));
355
auto label = static_cast<SoText2*>(sub->getChild(2));
356
label->string = this->text.getValue();
359
SoShape::notify(node);