Skip to content

Commit f3df56d

Browse files
committed
added value poti for UI, modified slider value text color
1 parent 5021590 commit f3df56d

5 files changed

Lines changed: 130 additions & 143 deletions

File tree

src/OpenCOVER/OpenVRUI/vsg/VSGVruiSlider.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ ref_ptr<Node> VSGVruiSlider::createText(float xPos)
285285
sliderTextLayout->position = vec3(0.0, 1.0, 0.0);
286286
sliderTextLayout->horizontal = vec3(1.0, 0.0, 0.0);
287287
sliderTextLayout->vertical = vec3(0.0, 1.0, 0.0);
288-
sliderTextLayout->color = vec4(1.0, 1.0, 1.0, 1.0);
288+
sliderTextLayout->color = vec4(0.85, 0.9, 0.8, 1.0);
289289
sliderTextLayout->outlineWidth = 0.1f;
290290
sliderTextLayout->billboard = false;
291291

@@ -393,7 +393,7 @@ ref_ptr<Node> VSGVruiSlider::createNode(const string& textureName, ref_ptr<vec3A
393393
{
394394
depthStencilState->depthWriteEnable = VK_FALSE;
395395
}
396-
396+
397397
depthStencilState->depthCompareOp = VK_COMPARE_OP_GREATER;
398398

399399
shaderSet->defaultGraphicsPipelineStates.push_back(colorBlendState);

src/OpenCOVER/OpenVRUI/vsg/VSGVruiValuePoti.cpp

Lines changed: 115 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include <vsg/nodes/MatrixTransform.h>
2121
#include <vsg/nodes/Switch.h>
22+
#include <vsg/text/GpuLayoutTechnique.h>
23+
#include <vsg/nodes/VertexIndexDraw.h>
2224
#include "mathUtils.h"
2325

2426
using namespace vsg;
@@ -49,21 +51,21 @@ void VSGVruiValuePoti::createGeometry()
4951
potiTransform = MatrixTransform::create();
5052
textTransform = MatrixTransform::create();
5153

52-
//potiTransform->setName("PotiTransform");
53-
//textTransform->setName("TextTransform");
54+
potiText = Text::create();
55+
potiTextLayout = StandardLayout::create();
56+
potiTextString = stringValue::create();
5457

55-
text = Text::create();
56-
//textNode->setName("TextNode");
58+
potiText->technique = GpuLayoutTechnique::create();
59+
60+
potiText->font = VSGVruiPresets::instance()->font2;
61+
potiText->text = potiTextString;
62+
potiText->layout = potiTextLayout;
5763

5864
ref_ptr<MatrixTransform> mainTransform = MatrixTransform::create();
5965
ref_ptr<MatrixTransform> panelTransform = MatrixTransform::create();
60-
//mainTransform->setName("MainTransform");
61-
//panelTransform->setName("PanelTransform");
6266

6367
ref_ptr<Group> icon = Group::create();
6468
ref_ptr<Group> iconDisabled = Group::create();
65-
//icon->setName("Icon");
66-
//iconDisabled->setName("IconDisabled");
6769

6870
VSGVruiNode *iconNode = dynamic_cast<VSGVruiNode *>(vruiRendererInterface::the()->getIcon("UI/poti2"));
6971

@@ -79,32 +81,30 @@ void VSGVruiValuePoti::createGeometry()
7981
iconDisabled->addChild(iconNode->node);
8082

8183
initText();
82-
text->text = vsg::stringValue::create(poti->getButtonText());
8384

8485
mainTransform->addChild(panelTransform);
8586
mainTransform->addChild(potiTransform);
8687

8788
mainTransform->addChild(textTransform);
8889

89-
textTransform->addChild(text);
90+
textTransform->addChild(potiText);
9091

9192
panelTransform->addChild(createPanelNode(poti->getBackgroundTexture()));
9293

9394
dmat4 panelMatrix;
9495
dmat4 s, hm, pm, rm;
9596
pm = rotate(0.0, 1.0, 0.0, 0.0);
9697
rm = rotate(0.0, 0.0, 1.0, 0.0);
97-
hm = rotate(0.0, 0.0, 0.0, 1.0);
98+
hm = rotate(vsg::radians(90.0), 0.0, 0.0, 1.0);
9899
s = scale(30.0, 30.0, 30.0);
99-
panelMatrix = s*hm*pm*rm;
100-
setTrans(panelMatrix,dvec3(0.0, 7.0, 1.0));
100+
panelMatrix = s * hm * pm * rm;
101+
setTrans(panelMatrix,dvec3(0.0, 7.0, 2.0));
101102
panelTransform->matrix = (panelMatrix);
102103

103104
stateSwitch = Switch::create();
104105
stateSwitch->addChild(true,icon);
105106
stateSwitch->addChild(false, iconDisabled);
106107
stateSwitch->setSingleChildOn(0);
107-
//stateSwitch->setName("StateSwitch");
108108

109109
potiTransform->addChild(stateSwitch);
110110

@@ -118,45 +118,23 @@ void VSGVruiValuePoti::createGeometry()
118118
/// Initialize text parameters.
119119
void VSGVruiValuePoti::initText()
120120
{
121-
122-
/*ref_ptr<Material> textMaterial = new Material();
123-
textMaterial->setColorMode(Material::AMBIENT_AND_DIFFUSE);
124-
textMaterial->setAmbient(Material::FRONT_AND_BACK, vsg::vec4(0.2, 0.2, 0.2, 1.0));
125-
textMaterial->setDiffuse(Material::FRONT_AND_BACK, vsg::vec4(0.9, 0.9, 0.9, 1.0));
126-
textMaterial->setSpecular(Material::FRONT_AND_BACK, vsg::vec4(0.9, 0.9, 0.9, 1.0));
127-
textMaterial->setEmission(Material::FRONT_AND_BACK, vsg::vec4(0.0, 0.0, 0.0, 1.0));
128-
textMaterial->setShininess(Material::FRONT_AND_BACK, 80.0f);
129-
130-
ref_ptr<StateSet> textStateSet = textNode->getOrCreateStateSet();
131-
132-
VSGVruiPresets::makeTransparent(textStateSet);
133-
textStateSet->setAttributeAndModes(textMaterial.get(), StateAttribute::ON | StateAttribute::PROTECTED);
134-
textStateSet->setMode(GL_LIGHTING, StateAttribute::ON | StateAttribute::PROTECTED);
135-
136-
text = new Text();
137-
text->setFont(VSGVruiPresets::getFontFile());
138-
text->setDrawMode(Text::TEXT);
139-
text->setAlignment(Text::LEFT_BASE_LINE);
140-
text->setColor(vsg::vec4(1.0, 1.0, 1.0, 1.0));
141-
text->setCharacterSize(10.0f);
142-
text->setText(poti->getButtonText(), String::ENCODING_UTF8);
143-
text->setLayout(Text::LEFT_TO_RIGHT);
144-
text->setAxisAlignment(Text::YZ_PLANE);
145-
146-
Matrix textMatrix;
147-
148-
Matrix s, hm, pm, rm;
149-
pm.makeRotate(vsg::inDegrees(0.0), 1.0, 0.0, 0.0);
150-
rm.makeRotate(vsg::inDegrees(-90.0), 0.0, 1.0, 0.0);
151-
hm.makeRotate(vsg::inDegrees(270.0), 0.0, 0.0, 1.0);
152-
s.makeScale(1.4, 1.4, 1.4);
153-
textMatrix = rm * pm * hm * s;
154-
155-
textMatrix.setTrans(-50.0 * 0.4 - 7.0, 50.0 * 0.4 + 7.0, 2.0);
156-
157-
textTransform->setMatrix(textMatrix);
158-
159-
textNode->addDrawable(text.get());*/
121+
potiTextLayout->horizontalAlignment = StandardLayout::CENTER_ALIGNMENT;
122+
potiTextLayout->position = vec3(0.0, 1.0, 0.0);
123+
potiTextLayout->horizontal = vec3(1.0, 0.0, 0.0);
124+
potiTextLayout->vertical = vec3(0.0, 1.0, 0.0);
125+
potiTextLayout->color = vec4(0.85, 0.9, 0.8, 1.0);
126+
potiTextLayout->outlineWidth = 0.3f;
127+
potiTextLayout->billboard = false;
128+
129+
potiTextString->value() = make_string(poti->getButtonText());
130+
potiText->setup(16, VSGVruiPresets::instance()->options);
131+
132+
dmat4 s, textMatrix;
133+
s = scale(12.5, 12.5, 1.);
134+
textMatrix = s;
135+
136+
setTrans(textMatrix, dvec3(-2.5, 14., 2.0));
137+
textTransform->matrix = textMatrix;
160138
}
161139

162140
void VSGVruiValuePoti::resizeGeometry()
@@ -166,29 +144,29 @@ void VSGVruiValuePoti::resizeGeometry()
166144
void VSGVruiValuePoti::update()
167145
{
168146

169-
/* if (poti->getValue() != oldValue)
147+
if (poti->getValue() != oldValue)
170148
{
171149

172150
//VRUILOG("VSGVruiValuePoti::update info: updating")
173151

174152
oldValue = poti->getValue();
175153

176-
Matrix rot1, rot2, trans, result;
154+
dmat4 rot1, rot2, trans, result;
177155

178156
float frac;
179157

180-
trans.makeTranslate(0.0, 0.0, 5.0);
158+
setTrans(trans, dvec3(0.0, 0.0, 5.0));
181159

182-
Matrix s, hm, pm, rm;
183-
pm.makeRotate(vsg::inDegrees(270.0), 1.0, 0.0, 0.0);
184-
rm.makeRotate(vsg::inDegrees(0.0), 0.0, 1.0, 0.0);
185-
hm.makeRotate(vsg::inDegrees(0.0), 0.0, 0.0, 1.0);
186-
rot1 = rm * pm * hm;
160+
dmat4 s, hm, pm, rm;
161+
pm = rotate(vsg::radians(270.0), 1.0, 0.0, 0.0);
162+
rm = rotate(vsg::radians(0.0), 0.0, 1.0, 0.0);
163+
hm = rotate(vsg::radians(0.0), 0.0, 0.0, 1.0);
164+
rot1 = hm * pm * rm;
187165

188166
coSlopePoti *sPoti = dynamic_cast<coSlopePoti *>(poti);
189167
if (sPoti)
190168
{
191-
pm.makeRotate(vsg::inDegrees((1.0 - sPoti->convertSlopeToLinear(poti->getValue())) * 360), 0.0, 0.0, 1.0);
169+
pm = rotate(vsg::radians((1.0 - sPoti->convertSlopeToLinear(poti->getValue())) * 360), 0.0, 0.0, 1.0);
192170
//pm.makeRotate(sPoti->convertSlopeToLinear(-sPoti->getValue())*2*M_PI, 0.0, 0.0, 1.0);
193171
}
194172
else
@@ -209,28 +187,27 @@ void VSGVruiValuePoti::update()
209187
frac = (poti->getValue() - poti->getMin()) / (poti->getMax() - poti->getMin());
210188
}
211189

212-
pm.makeRotate(vsg::inDegrees((0.5 - frac) * RANGE), 0.0, 0.0, 1.0);
190+
pm = rotate(vsg::radians((0.5 - frac) * RANGE), 0.0, 0.0, 1.0);
213191
}
214192

215-
s.makeScale(1.2, 1.2, 1.2);
216-
//rm.makeRotate(vsg::inDegrees(0.0), 0.0, 1.0, 0.0);
193+
s = scale(1.2, 1.2, 1.2);
217194

218-
rot2 = rm * pm * hm * s;
195+
rot2 = s * hm * pm * rm;
219196

220-
result = rot1 * rot2 * trans;
197+
result = trans * rot2 * rot1;
221198

222-
potiTransform->setMatrix(result);
199+
potiTransform->matrix = (result);
223200
}
224201

225202
if (poti->getButtonText() != oldButtonText)
226203
{
227204
oldButtonText = poti->getButtonText();
228205
//VRUILOG("VSGVruiValuePoti::update info: setting text " << oldButtonText)
229-
text->setText(oldButtonText, String::ENCODING_UTF8);
206+
//text->setText(oldButtonText, String::ENCODING_UTF8);
207+
potiTextString->value() = make_string(oldButtonText);
208+
potiText->setup(16, VSGVruiPresets::instance()->options);
230209
}
231210

232-
textNode->setNodeMask((poti->isLabelVisible()) ? (~1) : 0);
233-
234211
if (poti->isEnabled() != oldEnabled)
235212
{
236213
if (poti->isEnabled())
@@ -241,7 +218,7 @@ void VSGVruiValuePoti::update()
241218
{
242219
stateSwitch->setSingleChildOn(1);
243220
}
244-
}*/
221+
}
245222
}
246223

247224
/** Create a node for the poti background texture.
@@ -250,86 +227,84 @@ void VSGVruiValuePoti::update()
250227
*/
251228
ref_ptr<Node> VSGVruiValuePoti::createPanelNode(const string &textureName)
252229
{
253-
/* ref_ptr<vec3Array> coord = new vec3Array(4);
254-
ref_ptr<vsg::vec4Array> color = new vsg::vec4Array(1);
255-
ref_ptr<vec3Array> normal = new vec3Array(1);
256-
ref_ptr<vec2Array> texCoord = new vec2Array(4);
230+
ref_ptr<vec3Array> coord = vec3Array::create(4);
231+
ref_ptr<vec4Array> color = vec4Array::create(1);
232+
ref_ptr<vec3Array> normal = vec3Array::create(1);
233+
ref_ptr<vec2Array> texCoord = vec2Array::create(4);
234+
ref_ptr<uintArray> coordIndices = uintArray::create(6);
257235

258-
(*coord)[0].set(-1.0, 1.0, 0.0f);
259-
(*coord)[1].set(-1.0, -1.0, 0.0f);
260-
(*coord)[2].set(1.0, -1.0, 0.0f);
261-
(*coord)[3].set(1.0, 1.0, 0.0f);
236+
(*coord)[0].set(-1.0f, 1.0f, 0.0f);
237+
(*coord)[1].set(-1.0f, -1.0f, 0.0f);
238+
(*coord)[2].set(1.0f, -1.0f, 0.0f);
239+
(*coord)[3].set(1.0f, 1.0f, 0.0f);
262240

263-
(*color)[0].set(1.0, 1.0, 1.0, 1.0);
241+
(*color)[0].set(1.0f, 1.0f, 1.0f, 1.0f);
264242

265243
(*normal)[0].set(0.0, 0.0, 1.0);
266244

267-
(*texCoord)[0].set(0.0, 0.0);
268-
(*texCoord)[1].set(1.0, 0.0);
269-
(*texCoord)[2].set(1.0, 1.0);
270-
(*texCoord)[3].set(0.0, 1.0);
271-
272-
// Define a material:
273-
ref_ptr<Material> material = new Material();
274-
material->setColorMode(Material::AMBIENT_AND_DIFFUSE);
275-
material->setAmbient(Material::FRONT_AND_BACK, vsg::vec4(0.2, 0.2, 0.2, 1.0));
276-
material->setDiffuse(Material::FRONT_AND_BACK, vsg::vec4(1.0, 1.0, 1.0, 1.0));
277-
material->setSpecular(Material::FRONT_AND_BACK, vsg::vec4(1.0, 1.0, 1.0, 1.0));
278-
material->setEmission(Material::FRONT_AND_BACK, vsg::vec4(0.0, 0.0, 0.0, 1.0));
279-
material->setShininess(Material::FRONT_AND_BACK, 80.0f);
245+
(*texCoord)[0].set(0.0, 1.0);
246+
(*texCoord)[1].set(1.0, 1.0);
247+
(*texCoord)[2].set(1.0, 0.0);
248+
(*texCoord)[3].set(0.0, 0.0);
280249

281-
ref_ptr<StateSet> stateSet = new StateSet();
282-
283-
stateSet->setAttributeAndModes(material.get(), StateAttribute::ON | StateAttribute::PROTECTED);
284-
285-
//VRUILOG("VSGVruiValuePoti::createPanelNode info: loading texture image " << textureName)
286-
287-
auto texture = VSGVruiRendererInterface::the()->getVsgTexture(textureName);
288-
289-
if (texture && texture->data)
290-
{
291-
texture->setFilter(Texture::MIN_FILTER, Texture::LINEAR);
292-
texture->setWrap(Texture::WRAP_S, Texture::CLAMP);
293-
texture->setWrap(Texture::WRAP_T, Texture::CLAMP);
294-
}
250+
coordIndices = uintArray::create(
251+
{
252+
0,1,2 , 0,2,3
253+
}
254+
);
255+
256+
ref_ptr<ShaderSet> shaderSet;
257+
shaderSet = createFlatShadedShaderSet();
258+
259+
auto colorBlendState = vsg::ColorBlendState::create();
260+
colorBlendState->attachments[0].blendEnable = VK_TRUE;
261+
colorBlendState->attachments[0].srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
262+
colorBlendState->attachments[0].dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
263+
colorBlendState->attachments[0].colorBlendOp = VK_BLEND_OP_ADD;
264+
colorBlendState->attachments[0].srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
265+
colorBlendState->attachments[0].dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
266+
colorBlendState->attachments[0].alphaBlendOp = VK_BLEND_OP_ADD;
267+
colorBlendState->attachments[0].colorWriteMask = VK_COLOR_COMPONENT_R_BIT |
268+
VK_COLOR_COMPONENT_G_BIT |
269+
VK_COLOR_COMPONENT_B_BIT |
270+
VK_COLOR_COMPONENT_A_BIT;
271+
colorBlendState->logicOpEnable = VK_FALSE;
272+
273+
auto depthStencilState = vsg::DepthStencilState::create();
274+
depthStencilState->depthTestEnable = VK_TRUE;
275+
depthStencilState->depthWriteEnable = VK_FALSE;
276+
277+
shaderSet->defaultGraphicsPipelineStates.push_back(colorBlendState);
278+
shaderSet->defaultGraphicsPipelineStates.push_back(depthStencilState);
279+
280+
DataList vertexArrays;
281+
282+
ref_ptr<GraphicsPipelineConfigurator> gpConfigurator = GraphicsPipelineConfigurator::create(shaderSet);
283+
284+
auto image = VSGVruiRendererInterface::the()->createVsgTexture(textureName);
285+
if (image && image->data)
286+
gpConfigurator->assignTexture("diffuseMap", image->data);
295287
else
296-
{
297-
VRUILOG("VSGVruiValuePoti::createPanelNode err: texture image " << textureName << " not found")
298-
}
299-
300-
ref_ptr<TexEnv> texEnv = VSGVruiPresets::getTexEnvModulate();
301-
ref_ptr<CullFace> cullFace = VSGVruiPresets::getCullFaceBack();
302-
ref_ptr<PolygonMode> polyMode = VSGVruiPresets::getPolyModeFill();
303-
304-
ref_ptr<Geode> geometryNode = new Geode();
305-
//geometryNode->setName("GeometryNode");
306-
ref_ptr<Geometry> geometry = new Geometry();
307-
308-
geometry->setVertexArray(coord.get());
309-
geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::QUADS, 0, 4));
310-
geometry->setColorArray(color.get());
311-
geometry->setColorBinding(Geometry::BIND_OVERALL);
312-
geometry->setNormalArray(normal.get());
313-
geometry->setNormalBinding(Geometry::BIND_OVERALL);
314-
geometry->setTexCoordArray(0, texCoord.get());
288+
cerr << "No texture could be loaded for poti panel!" << endl;
315289

316-
VSGVruiPresets::makeTransparent(stateSet);
317-
stateSet->setMode(GL_BLEND, StateAttribute::ON | StateAttribute::PROTECTED);
318-
stateSet->setMode(GL_LIGHTING, StateAttribute::ON | StateAttribute::PROTECTED);
319-
stateSet->setAttributeAndModes(cullFace.get(), StateAttribute::ON | StateAttribute::PROTECTED);
320-
stateSet->setAttributeAndModes(polyMode.get(), StateAttribute::ON | StateAttribute::PROTECTED);
290+
gpConfigurator->assignArray(vertexArrays, "vsg_Vertex", VK_VERTEX_INPUT_RATE_VERTEX, coord);
291+
gpConfigurator->assignArray(vertexArrays, "vsg_Normal", VK_VERTEX_INPUT_RATE_INSTANCE, normal);
292+
gpConfigurator->assignArray(vertexArrays, "vsg_TexCoord0", VK_VERTEX_INPUT_RATE_VERTEX, texCoord);
293+
gpConfigurator->assignArray(vertexArrays, "vsg_Color", VK_VERTEX_INPUT_RATE_INSTANCE, color);
321294

322-
stateSet->setTextureAttribute(0, texEnv.get());
323-
stateSet->setTextureAttributeAndModes(0, texture.get(), StateAttribute::ON | StateAttribute::PROTECTED);
295+
gpConfigurator->init();
324296

325-
geometryNode->setName(textureName);
297+
ref_ptr<StateGroup> stateGroup = StateGroup::create();
298+
gpConfigurator->copyTo(stateGroup);
326299

327-
geometryNode->setStateSet(stateSet.get());
328-
geometryNode->addDrawable(geometry.get());
300+
ref_ptr<VertexIndexDraw> vid = VertexIndexDraw::create();
301+
vid->assignArrays(vertexArrays);
302+
vid->assignIndices(coordIndices);
303+
vid->indexCount = static_cast<uint32_t>(coordIndices->size());
304+
vid->instanceCount = 1;
329305

330-
return geometryNode;*/
306+
stateGroup->addChild(vid);
331307

332-
vsg::ref_ptr<vsg::MatrixTransform> node = MatrixTransform::create();
333-
return node;
308+
return stateGroup;
334309
}
335310
}

0 commit comments

Comments
 (0)