<
head>
</
head>
<!--
Index for ProtoDeclare definition:
ProjectileSliderBar
Index for DEF nodes:
bar,
BarColor,
barTransform,
currentValue,
CurrentValueFinder,
currentValueFont,
currentValueText,
currentValueTransform,
HUDGroup,
HudProx,
HudTransform,
pointer,
PointerColor,
pointerTransform,
ShapeOrganizer,
SliderName,
sliderNameColor,
sliderNameTransform,
SliderShape,
SliderTransform,
SVPlaneSensor,
valueColor
Index for Viewpoint image:
Viewpoint_1
-->
<
Scene>
<
ProtoDeclare name='
ProjectileSliderBar'>
<
ProtoInterface>
<
field name='
name'
type='
MFString'
accessType='
initializeOnly'
appinfo='
Name of the Slider Bar. It appears on the left side of the bar.'/>
<
field name='
length'
type='
SFFloat'
value='
1'
accessType='
initializeOnly'
appinfo='
Length of the Slider bar. According to given value bar will arrange itself.'/>
<
field name='
width'
type='
SFFloat'
value='
1'
accessType='
initializeOnly'
appinfo='
Width of the Slider bar. According to given value bar will arrange itself.'/>
<
field name='
maxValue'
type='
SFFloat'
value='
1'
accessType='
initializeOnly'
appinfo='
Max. value of Slider Bar.It can be assigned a positive or a negative value.'/>
<
field name='
minValue'
type='
SFFloat'
value='
0'
accessType='
initializeOnly'
appinfo='
Min. value of Slider Bar. It can be assigned a positive or a negative value.'/>
<
field name='
barColor'
type='
SFColor'
value='
1 0 0'
accessType='
initializeOnly'
appinfo='
Color of Slider Bar.'/>
<
field name='
pointerColor'
type='
SFColor'
value='
1 1 0'
accessType='
initializeOnly'
appinfo='
Pointer Color of Slider Bar.'/>
<
field name='
nameColor'
type='
SFColor'
value='
1 0 1'
accessType='
initializeOnly'
appinfo='
Slider Bar Name Color.'/>
<
field name='
currentValueColor'
type='
SFColor'
value='
0.2 0.8 0.2'
accessType='
initializeOnly'
appinfo='
Color of Current Value text.'/>
<
field name='
currentValueInt'
type='
SFInt32'
accessType='
outputOnly'
appinfo='
If the precision is 0 current Value will be output in this eventOut field as Integer else in currentValueFloat eventOut field as Float.'/>
<
field name='
currentValueFloat'
type='
SFFloat'
accessType='
outputOnly'
appinfo='
If the precision is NOT 0 current Value will be output in this eventOut field as Float else in currentValueInt eventOut field as Integer.'/>
<
field name='
precision'
type='
SFInt32'
value='
2'
accessType='
initializeOnly'
appinfo='
Count of the numbers after Decimal Point. Example : If precision is 2 1.562777 -> 1.56'/>
<
field name='
translation'
type='
SFVec3f'
accessType='
initializeOnly'
appinfo='
Translation values of Slider Bar to define its location on the screen.'/>
</
ProtoInterface>
<
ProtoBody>
<
Group DEF='
HUDGroup'>
<
Collision enabled='
false'>
<!--
HudProx ROUTEs:
[
from position_changed to HudTransform.set_translation
]
[
from orientation_changed to HudTransform.set_rotation
]
[
self-route from position_changed to center
]
-->
<
ProximitySensor DEF='
HudProx'
size='
1000000 1000000 1000000'/>
<!--
HudTransform ROUTEs:
[
from HudProx.position_changed to set_translation
]
[
from HudProx.orientation_changed to set_rotation
]
-->
<
Transform DEF='
HudTransform'>
<
Transform translation='
0 0 -0.2'>
<
Transform DEF='
SliderTransform'>
<
IS>
<
connect nodeField='
translation'
protoField='
translation'/>
</
IS>
<
Group DEF='
SliderShape'>
<
Transform DEF='
barTransform'>
<
Shape>
<
Appearance>
<
Material DEF='
BarColor'
diffuseColor='
0 0 1'>
<
IS>
<
connect nodeField='
diffuseColor'
protoField='
barColor'/>
</
IS>
</
Material>
</
Appearance>
<
Box DEF='
bar'
size='
0.05 0.001 0.000001'/>
</
Shape>
</
Transform>
<!--
pointerTransform ROUTE:
[
from SVPlaneSensor.translation_changed to set_translation
]
-->
<
Transform DEF='
pointerTransform'>
</
Transform>
<
Transform DEF='
sliderNameTransform'>
<
Shape>
<
Text DEF='
SliderName'
solid='
true'>
<
IS>
<
connect nodeField='
string'
protoField='
name'/>
</
IS>
<
FontStyle family='
SERIF'
justify='
END'
size='
0.0085'
style='
BOLD'/>
</
Text>
<
Appearance>
<
Material DEF='
sliderNameColor'>
<
IS>
<
connect nodeField='
diffuseColor'
protoField='
nameColor'/>
</
IS>
</
Material>
</
Appearance>
</
Shape>
</
Transform>
<
Transform DEF='
currentValueTransform'>
<
Shape DEF='
currentValue'>
<
Text DEF='
currentValueText'
solid='
true'>
<
FontStyle DEF='
currentValueFont'
family='
SERIF'
justify='
BEGIN'
size='
0.0085'
style='
BOLD'/>
</
Text>
<
Appearance>
<
Material DEF='
valueColor'>
</
Material>
</
Appearance>
</
Shape>
</
Transform>
</
Group>
</
Transform>
</
Transform>
</
Transform>
</
Collision>
</
Group>
<
Script DEF='
ShapeOrganizer'
directOutput='
true'>
<
field name='
Length'
type='
SFFloat'
accessType='
initializeOnly'/>
<
field name='
Width'
type='
SFFloat'
accessType='
initializeOnly'/>
<
field name='
SliderNameTransformNode'
type='
SFNode'
accessType='
initializeOnly'>
</
field>
<
field name='
CurrentValueTransformNode'
type='
SFNode'
accessType='
initializeOnly'>
</
field>
<
field name='
BarTransformNode'
type='
SFNode'
accessType='
initializeOnly'>
</
field>
<
field name='
PointerTransformNode'
type='
SFNode'
accessType='
initializeOnly'>
</
field>
<
field name='
CurrentValueText'
type='
SFNode'
accessType='
initializeOnly'>
</
field>
<
field name='
SVPlaneSensorNode'
type='
SFNode'
accessType='
initializeOnly'>
</
field>
<
IS>
<
connect nodeField='
Length'
protoField='
length'/>
<
connect nodeField='
Width'
protoField='
width'/>
</
IS>
<![CDATA[
ecmascript:
function initialize() {
for(i = 0; i < 3; i++) {
BarTransformNode.scale[i] = 1;
if(i == 2) {
PointerTransformNode.scale[i] = 0.1;
}
else {
PointerTransformNode.scale[i] = 1;
}
}
setBarSize();
setPointerSize();
setCurrentValueTransform();
setNameTransform();
}
function setBarSize() {
BarTransformNode.scale[0] = Length * BarTransformNode.scale[0];
BarTransformNode.scale[1] = Width * BarTransformNode.scale[1];
}
function setPointerSize() {
PointerTransformNode.scale[0] = Width * PointerTransformNode.scale[0];
PointerTransformNode.scale[1] = Width * PointerTransformNode.scale[1];
SVPlaneSensorNode.minPosition[0] = Length * SVPlaneSensorNode.minPosition[0];
SVPlaneSensorNode.maxPosition[0] = Length * SVPlaneSensorNode.maxPosition[0];
}
function setCurrentValueTransform() {
CurrentValueTransformNode.translation[0] = (BarTransformNode.scale[0] * 0.05 / 2) + (BarTransformNode.scale[1] * 0.001 * 2);
}
function setNameTransform() {
SliderNameTransformNode.translation[0] = -((BarTransformNode.scale[0] * 0.05 / 2) + (BarTransformNode.scale[1] * 0.001 * 2));
}
]]>
</
Script>
<!--
CurrentValueFinder ROUTE:
[
from SVPlaneSensor.translation_changed to updateCurrentValue
]
-->
<
Script DEF='
CurrentValueFinder'
directOutput='
true'>
<
field name='
SVPlaneSensorNode'
type='
SFNode'
accessType='
initializeOnly'>
</
field>
<
field name='
MaxValue'
type='
SFFloat'
accessType='
initializeOnly'/>
<
field name='
MinValue'
type='
SFFloat'
accessType='
initializeOnly'/>
<
field name='
CurrentValueTextNode'
type='
SFNode'
accessType='
initializeOnly'>
</
field>
<
field name='
updateCurrentValue'
type='
SFVec3f'
accessType='
inputOnly'/>
<
field name='
CurrentValueInt'
type='
SFInt32'
accessType='
outputOnly'/>
<
field name='
CurrentValueFloat'
type='
SFFloat'
accessType='
outputOnly'/>
<
field name='
Precision'
type='
SFInt32'
accessType='
initializeOnly'/>
<
IS>
<
connect nodeField='
MaxValue'
protoField='
maxValue'/>
<
connect nodeField='
MinValue'
protoField='
minValue'/>
<
connect nodeField='
CurrentValueInt'
protoField='
currentValueInt'/>
<
connect nodeField='
CurrentValueFloat'
protoField='
currentValueFloat'/>
<
connect nodeField='
Precision'
protoField='
precision'/>
</
IS>
<![CDATA[
ecmascript:
var totalLength;
function initialize() {
realValue = (MaxValue + MinValue) / 2;
realValue = roundOff(realValue, Precision);
CurrentValueFloat = realValue;
CurrentValueInt = Math.round(realValue);
totalLength = SVPlaneSensorNode.maxPosition[0] - SVPlaneSensorNode.minPosition[0];
updateCurrentValueText(realValue.toString());
}
//Map pointer translation value to the real value
function updateCurrentValue(translation, timeEvent) {
var displayString;
var curPositionOnBar = translation[0] + totalLength / 2;
var x = (MaxValue - MinValue) * curPositionOnBar / totalLength;
var realValue = MinValue + x;
if(Precision == 0) { //If
CurrentValueInt = Math.round(realValue);
displayString = CurrentValueInt.toString();
}
else {
CurrentValueFloat = roundOff(realValue, Precision);
displayString = CurrentValueFloat.toString();
}
updateCurrentValueText(displayString);
}
function updateCurrentValueText(dispStr) {
CurrentValueTextNode.string[0] = dispStr;
}
//A function to round the values regarding to given precision.
function roundOff(value, precision) {
var result;
var isNegative = false;
var wholeInt = Math.round(value * Math.pow(10, precision));
//Negative numbers creates exceptional condition, therefor they are converted
//to positive values.
if(wholeInt < 0) {
wholeInt = -wholeInt;
isNegative = true;
}
var whole = wholeInt.toString();
var decPoint = whole.length - precision;
//Exception when precision is bigger than the string length
if(decPoint < 0) {
i = -decPoint;
for(i; i > 0; i--) {
whole ='0' + whole;
}
//Calculate decPoint according to new string expanded with 0s
decPoint = whole.length - precision;
}
if(whole !='0') {
//Put the decimal point on the appropriate place
result = whole.substring(0, decPoint);
result +='.';
result += whole.substring(decPoint, whole.length);
}
else { //If the string is'0', then result is'0'
result = whole;
}
//Negative numbers are altered.
if(isNegative) {
result ='-' + result;
}
//Convert the String value to Float.
resultFloat = parseFloat(result);
return resultFloat;
}
]]>
</
ProtoDeclare>
<
Viewpoint description='
Slider bar'
position='
0 0 5'/>
<!-- Scene graph nodes are added here -->
<
ProtoInstance name='
ProjectileSliderBar'
containerField='
children'>
<fieldValue name='name' value='AFAA'/>
<fieldValue name='length' value='1.5'/>
<fieldValue name='width' value='1'/>
<fieldValue name='maxValue' value='10'/>
<fieldValue name='minValue' value='-2'/>
</
ProtoInstance>
</
Scene>
</