FloatSlider

This proto was posted by peter on 2007-08-17.

So far there are 3 comments. Feel free to add one.

Quick links

Description

A slider which outputs float values. It can be used horizontally or vertically and parameterized in value range and color. The slider does not contain a label or a textual representation of the current value.

Interface

Field name Value type Field type Default value
grooveLength SFFloat initializeOnly 1
The length of the slider groove.
initialValue SFFloat initializeOnly 0
The initial value of the slider.
maxVal SFFloat initializeOnly 1
The maximum value of the slider.
minVal SFFloat initializeOnly 0
The minimum value of the slider.
set_value SFFloat inputOnly
Sets the slider to the given value.
grooveColor SFColor inputOutput 0.5 0.5 0.5
The groove color.
handleColor SFColor inputOutput 0.2 0.2 0.2
The handle color.
value_changed SFFloat outputOnly
Outputs the current value whenever it has changed.

Proto code

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "http://www.web3d.org/specifications/x3d-3.0.dtd">
<X3D xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' profile='Full' version='3.0' xsd:noNamespaceSchemaLocation='http://www.web3d.org/specifications/x3d-3.0.xsd'>
  <Scene DEF='scene'>
    <ProtoDeclare name='FloatSlider' component='pyjax'
                  documentation='A slider which outputs float values. It can be used horizontally or vertically and parameterized in value range and color. The slider does not contain a label or a textual representation of the current value.'>
      <ProtoInterface>
        <field name='initialValue' accessType='initializeOnly' type='SFFloat' value='0'
               documentation='The initial value of the slider.' />
        <field name='set_value' accessType='inputOnly' type='SFFloat' 
               documentation='Sets the slider to the given value.'/>
        <field name='value_changed' accessType='outputOnly' type='SFFloat' 
               documentation='Outputs the current value whenever it has changed.' />
        <field name='minVal' accessType='initializeOnly' type='SFFloat' value='0'
               documentation='The minimum value of the slider.' />
        <field name='maxVal' accessType='initializeOnly' type='SFFloat' value='1'
               documentation='The maximum value of the slider.' />
        <field name='grooveLength' accessType='initializeOnly' type='SFFloat' value='1'
               documentation='The length of the slider groove.' />
        <field name='grooveColor' accessType='inputOutput' type='SFColor' value='0.5 0.5 0.5'
               documentation='The groove color.' />
        <field name='handleColor' accessType='inputOutput' type='SFColor' value='0.2 0.2 0.2'
               documentation='The handle color.' />                
      </ProtoInterface>
      <ProtoBody>
        <Group>            
          
          <Transform DEF='grooveTrans' translation='0.5 0 0'>
            <Shape>
              <Box  size='1 0.6 0.2' />
              <Appearance>
                <Material diffuseColor='.7 .7 .7'>
                  <IS><connect protoField='grooveColor' nodeField='emissiveColor' /></IS>
                </Material>
              </Appearance>
            </Shape>
          </Transform>                                  
          
          <Transform DEF='handleTrans'>
            <PlaneSensor DEF='planeSensor' autoOffset='true' />              
            <Shape>
              <Box size='0.2 1 0.4' />
              <Appearance>
                <Material diffuseColor='1 1 1'>
                  <IS><connect protoField='handleColor' nodeField='emissiveColor' /></IS>
                </Material>
              </Appearance>              
            </Shape>
          </Transform>
          
          <Script DEF='script'>
            <field name='planeSensor' accessType='inputOutput' type='SFNode'><PlaneSensor USE='planeSensor' /></field>
            <field name='grooveTrans' accessType='inputOutput' type='SFNode'><Transform USE='grooveTrans' /></field>
            <field name='handleTrans' accessType='inputOutput' type='SFNode'><Transform USE='handleTrans' /></field>
            <field accessType='initializeOnly' name='initialValue' type='SFFloat' value='0' />
            <field accessType='initializeOnly' name='minVal' type='SFFloat' value='0'/>
            <field accessType='initializeOnly' name='maxVal' type='SFFloat' value='1'/>
            <field accessType='initializeOnly' name='grooveLength' type='SFFloat' value='1'/>
            <field accessType='inputOnly' name='set_value' type='SFFloat' />
            <field accessType='outputOnly' name='value_changed' type='SFFloat' />
            <field accessType='inputOnly' name='on_handle_translation' type='SFVec3f' />            
            <IS>
              <connect protoField='initialValue' nodeField='initialValue' />
              <connect protoField='minVal' nodeField='minVal' />
              <connect protoField='maxVal' nodeField='maxVal' />
              <connect protoField='grooveLength' nodeField='grooveLength' />
              <connect protoField='value_changed' nodeField='value_changed' />
              <connect protoField='set_value' nodeField='set_value' />
            </IS>
            <![CDATA[javascript:
              function initialize(value,time)
              {    
                // planeSensor's minPosition is (0,0) by default 
                planeSensor.maxPosition.x = grooveLength;
                planeSensor.maxPosition.y = 0;
                planeSensor.offset.x = mapInterval(initialValue, minVal, maxVal, 0, grooveLength);;
                grooveTrans.scale.x = grooveLength;
                grooveTrans.translation.x = grooveLength/2.0;                   
                
                set_value(initialValue);                
              }
              
              function on_handle_translation(v) { 
                set_value(mapInterval(v[0], 0, grooveLength, minVal, maxVal)); 
              }    
              
              function set_value(v) {
                  value_changed = v;
                  handleTrans.translation.x = mapInterval(v, minVal, maxVal, 0, grooveLength);
              }
              
              function mapInterval(val, srcMin, srcMax, dstMin, dstMax) {
                return (val-srcMin) / 
                     ((srcMax-srcMin)/(dstMax-dstMin)) + dstMin;
              }
            ]]>
          </Script>
          
        </Group>
        
        <ROUTE fromNode='planeSensor' fromField='translation_changed' toNode='script' toField='on_handle_translation'/>
      </ProtoBody>
    </ProtoDeclare>

  </Scene>
</X3D>

Test code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "http://www.web3d.org/specifications/x3d-3.0.dtd">
<X3D xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' profile='Full' version='3.0' xsd:noNamespaceSchemaLocation='http://www.web3d.org/specifications/x3d-3.0.xsd'>

<Engine desiredFrameRate='60' > 
  <RenderJob>
    <WindowGroup>
      <Window size='960 440' />
    </WindowGroup>
  </RenderJob>
</Engine>

<Scene DEF='scene'> 
    <ExternProtoDeclare name='FloatSlider' url='FloatSlider_PROTO.x3d' />
    
    <DirectionalLight DEF='light' />
    <NavigationInfo type='none' headlight='false' />
    <OrthoViewpoint position='0 0 20' fieldOfView='-4.5 -4.5 4.5 4.5' />
    <GradientBackground color='0 0 0, 0.2 0.2 0.2 ' position='0.7 1'/>
                                
    <Transform translation='0 -1 0'>
      
      <Transform translation='-7.7 4 0' scale='0.8 0.8 0.8' >
        <Shape>
          <Text string='Float slider test'>
            <FontStyle family='"Arial" "SANS"' style='bold' />
          </Text>
        </Shape>
      </Transform>        
      
      <Transform DEF='textTrans' translation='-1.5 1.5 0' >
        <Shape>
          <Text DEF='loremText' solid='false' 
                string='"This tests demonstrates the usage of"
                        "the FloatSlider prototype." ""
                        "Using the two sliders on the left the"
                        "transparency and the scale of this text"
                        "can be manipulated."'>
            <FontStyle family='"Arial" "SANS"' style='plain' size='0.4' />
          </Text>
          <Appearance><Material DEF='loremMat' transparency='0.1' /></Appearance>
        </Shape>
      </Transform>
          
      <Anchor url='http://www.pyjax.net/'>
        <Transform DEF='pyjaxTrans' translation='3.2 4 0' >
          <Shape>
            <Text DEF='pyjaxText' solid='false' string='"Find more X3D tutorials on pyjax.net"'>
              <FontStyle family='"Arial" "SANS"' style='plain' size='0.3' />
            </Text>
            <Appearance><Material /></Appearance>
          </Shape>
        </Transform>
      </Anchor>
      
      <Transform translation='-7 1.5 0'>
        <FloatSlider DEF='slider1' minVal='0' maxVal='1' initialValue='0.5' grooveLength='5' />
      </Transform>        
      
      <Transform translation='-7 -0.5 0'>
        <FloatSlider DEF='slider2' minVal='0' maxVal='3' initialValue='1' grooveLength='5' />
      </Transform>       
    </Transform>
    
    <ScalarDamper DEF='transparencyDamper' tau='0.2' order='1' />
    <PositionInterpolator DEF='scaleInterpol' key='0, 3' keyValue='0 0 0, 3 3 3'/>
        
    <ROUTE fromNode='slider1' fromField='value_changed' toNode='transparencyDamper' toField='set_destination' />
    <ROUTE fromNode='transparencyDamper' fromField='value_changed' toNode='loremMat' toField='transparency' />
    
    <ROUTE fromNode='slider2' fromField='value_changed' toNode='scaleInterpol' toField='set_fraction'/>
    <ROUTE fromNode='scaleInterpol' fromField='value_changed' toNode='textTrans' toField='scale'/>
    
</Scene>
</X3D>
  

Comments

Dirk said on August 22, 2007

Cool!

Michael Luggen said on August 28, 2007

Did also something… :-)

A ProtoNode which takes a touchSensor as input to hide any objects with a transparency value.





















Juliann Garrison said on August 18, 2008

himyaritic pekoe lithesomeness preboding tannery metepencephalon unshapenly cagily
http://members.aol.com/benswordsowisdom/ >Ben’s Words Of Wisdom
http://www.hfn-pr.com/
http://www.glachbeg.org.uk/ >Glachbeg Croft Education Centre
http://callowaymarblerestoration.com
http://www.rbkc.gov.uk/ >Kensington and Chelsea Borough Council
http://www.snof.org/bd/bd.html
http://www.thomas.com/ >Thomas Brothers Maps
http://www.balloonsdirect.co.uk/

Add a comment