test_nomap_vr.html 9.09 KB
Newer Older
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
1 2 3 4 5
<!DOCTYPE HTML>
<html lang="en">
  <head>
    <meta charset="utf-8"/>
    <title>Scene (NoMap)</title>
Rurik Bugdanov's avatar
Rurik Bugdanov committed
6

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
7 8 9 10 11 12
    <script type='text/javascript' src='js/jquery/jquery-3.1.1.js'></script>
    <script type='text/javascript' src='js/x3dom/x3dom-full.debug.js'></script>

<!--     <script type='text/javascript' src='js/nomap_vr_init.js'></script> -->

    <link rel='stylesheet' type='text/css' href='js/x3dom/x3dom.css'></link>
Rurik Bugdanov's avatar
Rurik Bugdanov committed
13

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
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
    <style type='text/css'>
        body {margin:0; padding:0; background-color:#04344c; background-color:#ddeeff; }
        .stereo-view {float:left; }
        .stereo-view x3d {float:left; }
    </style>
    <script>
        // Get display size
        var deviceOrientation = 'portrait';
        notFirstTime = false;
        //alert ('Checking device orientation and display size');
        while (deviceOrientation == 'portrait') {
            insideWidth = window.innerWidth;
            insideHeight = window.innerHeight;
            if (insideWidth > insideHeight) {deviceOrientation = 'landscape';}
            if (notFirstTime) {alert ("Please oriention device to landscape and press 'OK'");}
            notFirstTime = true;
        }
        x3dWidth = Math.floor((insideWidth-12)/2);
        x3dHeight = insideHeight;
        //x3dHeight = x3dHeight/2;
        x3dHeight = x3dHeight - 2;
    </script>
  </head>
  <body>
    <div class='stereo-view-1'>
        <!--view-source:http://realism.com/sample/model/stereo/VAM_246-1-1870/model-ig0b75.x3d?=&headlight=true&ipd=30&%20=-->
        <!--view-source:http://realism.com/x3d-examples/HTML5-Fall2014/stereo/kelpie.sgl.html -->
Rurik Bugdanov's avatar
Rurik Bugdanov committed
41

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
42
        <script>
43
            document.writeln ("<x3d id='all_view' showStat='false' showLog='false' disableDoubleClick='true' keysEnabled='true' x='0px' y='0px' width='"+(2*x3dWidth)+"px' height='"+x3dHeight+"px'>");
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
44 45
            var x3dDimStr = x3dWidth + ' ' + x3dHeight + ' 4';
        </script>
Rurik Bugdanov's avatar
Rurik Bugdanov committed
46

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
47 48 49
        <scene>
            <navigationInfo type='"EXAMINE" "WALK"'></navigationInfo>
	
Rurik Bugdanov's avatar
Rurik Bugdanov committed
50 51 52
            <background DEF='bgnd'
                backUrl=  "js/images/background_side.jpeg"
                bottomUrl="js/images/background_floor.jpeg"
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
53
                frontUrl= "models/1488240695_710844/V0/1488240695_710844-texture-bgnd-ext.jpeg"
Rurik Bugdanov's avatar
Rurik Bugdanov committed
54 55
                leftUrl=  "js/images/background_side.jpeg"
                rightUrl= "js/images/background_side.jpeg"
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
56 57
                topUrl=   "js/images/background_sky.jpeg">
            </background>
Rurik Bugdanov's avatar
Rurik Bugdanov committed
58

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
59 60 61
            <transform translation='0 0 0' rotation='0 1 0 0'>
                <viewpoint DEF='viewpoint' id='x3d_viewpoint' position='0 0 0' orientation='0 1 0 0' zNear='0.001' zFar='2000'></viewpoint>
            </transform>
Rurik Bugdanov's avatar
Rurik Bugdanov committed
62

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
            <group id='unrendered_scene' render='false'>
                <group DEF='scene'>
                    <transform DEF='Viewpoint-Left'  id='x3d_viewpoint'       translation='0 0 0' rotation='0 1 0 0'>
                    <transform DEF='Viewpoint-gamma' id='x3d_viewpoint_gamma' translation='0 0 0'  rotation='0 1 0 0'>
                    <transform DEF='Viewpoint-beta'  id='x3d_viewpoint_beta'  translation='0 0 0'  rotation='1 0 0 0'>
                    <transform DEF='Viewpoint-alpha' id='x3d_viewpoint_alpha' translation='0 0 0'  rotation='0 0 1 0'>
                    <transform translation='0 0 0'>	<!-- account for model center != center-of-mass -->
                        <inline url='models/1488240695_710844/V0/1488240695_710844.x3d'></inline>
                    </transform>
                    </transform>
                    </transform>
                    </transform>
                    </transform>
                </group>
            </group>
Rurik Bugdanov's avatar
Rurik Bugdanov committed
78

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
79 80 81 82 83 84 85
            <group DEF='left' render='true'>
                <shape>
                    <appearance>
                        <!-- The dimensions is the size of each display side -->
                        <script>
                            document.writeln ("<renderedTexture interpupillaryDistance='0.3' id='rtLeft' stereoMode='LEFT_EYE' update='ALWAYS' dimensions='"+x3dDimStr+"' repeatS='false' repeatT='false'>");
                        </script>
Rurik Bugdanov's avatar
Rurik Bugdanov committed
86

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
87
                        <viewpoint USE='viewpoint' containerField='viewpoint'></viewpoint>
Rurik Bugdanov's avatar
Rurik Bugdanov committed
88

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
89
                        <background USE='bgnd' containerField='background'></background>
Rurik Bugdanov's avatar
Rurik Bugdanov committed
90

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
91
                        <group USE='scene' containerField="scene"></group>
Rurik Bugdanov's avatar
Rurik Bugdanov committed
92

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
93
                    </renderedTexture>
Rurik Bugdanov's avatar
Rurik Bugdanov committed
94

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108
                    <composedShader>
                        <field name='tex' type='SFInt32' value='0'></field>
                        <field name='leftEye' type='SFFloat' value='1'></field>
                        <shaderPart type='VERTEX'>
                            attribute vec3 position;
                            attribute vec2 texcoord;

                            uniform mat4 modelViewProjectionMatrix;
                            varying vec2 fragTexCoord;

                            void main()
                            {
                                vec2 pos = sign(position.xy);
                                fragTexCoord = texcoord;
Rurik Bugdanov's avatar
Rurik Bugdanov committed
109
                                gl_Position = vec4((pos.x/2.0)-0.5, pos.y, 0.0, 1.0);
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
                            }
                        </shaderPart>
                        <!-- The division of pos.x relates to the fraction of the window that is used -->
                        <shaderPart DEF="frag" type='FRAGMENT'>
                            #ifdef GL_ES
                            precision highp float;
                            #endif

                            uniform sampler2D tex;
                            uniform float leftEye;
                            varying vec2 fragTexCoord;

                            void main()
                            {
                                gl_FragColor = texture2D(tex, fragTexCoord);
                            }
                        </shaderPart>
                    </composedShader>
                    </appearance>
                    <plane solid="false"></plane>
                </shape>
            </group>		<!-- End of tag for left window -->

            <group DEF='right'>
                <shape>
                    <appearance>
                        <script>
                            document.writeln ("<renderedTexture interpupillaryDistance='0.3' id='rtRight' stereoMode='RIGHT_EYE' update='ALWAYS' dimensions='"+x3dDimStr+"' repeatS='false' repeatT='false'>");
                        </script>
Rurik Bugdanov's avatar
Rurik Bugdanov committed
139

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
140
                        <viewpoint USE='viewpoint' containerField='viewpoint'></viewpoint>
Rurik Bugdanov's avatar
Rurik Bugdanov committed
141

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
142
                        <background USE='bgnd' containerField='background'></background>
Rurik Bugdanov's avatar
Rurik Bugdanov committed
143

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
144
                        <group USE='scene' containerField="scene"></group>
Rurik Bugdanov's avatar
Rurik Bugdanov committed
145

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
146
                    </renderedTexture>
Rurik Bugdanov's avatar
Rurik Bugdanov committed
147

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
                    <composedShader>
                        <field name='tex' type='SFInt32' value='0'></field>
                        <field name='leftEye' type='SFFloat' value='0'></field>
                        <shaderPart type='VERTEX'>
                            attribute vec3 position;
                            attribute vec2 texcoord;

                            uniform mat4 modelViewProjectionMatrix;
                            varying vec2 fragTexCoord;

                            void main()
                            {
                                vec2 pos = sign(position.xy);
                                fragTexCoord = texcoord;
                                gl_Position = vec4((pos.x + 1.0)/2.0, pos.y, 0.0, 1.0);
                            }
                        </shaderPart>
                        <shaderPart USE="frag" type='FRAGMENT'>
                        </shaderPart>
                    </composedShader>
                    </appearance>
                    <plane solid="false"></plane>
                </shape>
            </group>
        </scene>
        </x3d>
    </div>
Rurik Bugdanov's avatar
Rurik Bugdanov committed
175

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189
    <script language='JavaScript'>
        // --> Check to see if there are DeviceOrientation events in the DOM

        var previousAngles = {'alpha':0, 'beta':0, 'gamma':0};
        var vectors = {'alpha':"0 1 0 ", 'beta':"1 0 0 ", 'gamma':"0 0 1 "};
        var deg2rad = Math.PI / 180;

        if (window.DeviceOrientationEvent) {
            window.addEventListener('deviceorientation', function(eventData) {
                gamma = eventData.gamma;
		beta = eventData.beta;
		alpha = 360-eventData.alpha;
		rotate (alpha, 'alpha');
		rotate (beta,  'beta');
Rurik Bugdanov's avatar
Rurik Bugdanov committed
190
		rotate (gamma, 'gamma');
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
191 192 193 194 195 196 197 198 199
            }, false);
        }else{
            alert ('No Device Motion Sensor');
        }

        function rotate (angle, label) {
            intAngle = Math.floor(angle + 0.5);
            if (intAngle == previousAngles[label]) {return; }
            previousAngles[label] = intAngle;
Rurik Bugdanov's avatar
Rurik Bugdanov committed
200

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
201 202 203 204 205 206
            if (label == 'alpha') {
		rotateView ("x3d_viewpoint_"+label, vectors[label]+" "+intAngle*deg2rad);
//              rotateView ("x3d_viewpointR_"+label, vectors[label]+" "+intAngle*deg2rad);
//              rotateView ("x3d_viewpointL_"+label, vectors[label]+" "+intAngle*deg2rad);
            }
        }
Rurik Bugdanov's avatar
Rurik Bugdanov committed
207

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
208 209 210 211 212 213 214
        function rotateView (label, vector) {
            view = document.getElementById(label);
            view.setAttribute('set_rotation',vector);
        }
    </script>
  </body>
</html>