[X3D-Public] X3DOM: Proximity Sensor

Joe D Williams joedwil at earthlink.net
Thu May 12 15:07:16 PDT 2011


If the keys and clicks are getting handled, then great.

how about?
since for every key:
var tmp = ((document.getElementById('vp'))...
then, for example, maybe in the cases:
tmp.position="' + 't_pos_x + ' ' + t_pos_y + ' ' + (t_pos_z-speed)'";
  break; ...

Otherwise, since this could get complicated with collision and all, I 
would still say to prototype this in X3D because it may be easier if 
you need to touch and connect stuff and when multiple changes need to 
occur. Since Instant is so close, I bet this would also work very well 
using all X3D nodes and events and the scripting is more simple.

Meanwhile, I am reading x3dom.js and wishing you very well for getting 
your example working with X3DOM.

After the scripts at the beginning, the xmlized x3d looks very 
friendly and if the DOM key events and onclicks are that easy to 
handle then all the more fun.

Best Regards,
Joe




----- Original Message ----- 
From: "Dark Before Dawn" <dark.before.dawn at gmail.com>
To: <x3d-public at web3d.org>
Sent: Tuesday, May 10, 2011 9:06 AM
Subject: [X3D-Public] X3DOM: Proximity Sensor


> Hello :)
> is there any way to read out camera position and orientation via
> JavaScript? It seems there is no ProximitySensor or equivalent in
> X3DOM.
>
> I tried to update the viewport node via JavaScript and keydown
> Events
> manualy. This kinda works, but there are also some disadvantages
> like
> manual collission detection.
>
> Thanks in advance :)
> Cheers
> Darky
>
> Code Snippet:
>
> <html>
> <head>
>     <script
> type='text/javascript'src='http://www.x3dom.org/x3dom/release/x3dom.js
> <view-source:http://www.x3dom.org/x3dom/release/x3dom.js>'></script>
>     <link
> rel="stylesheet"type="text/css"href="http://www.x3dom.org/x3dom/release/x3dom.css
> <view-source:http://www.x3dom.org/x3dom/release/x3dom.css>"/>
>
> <script  type='text/javascript'>
> document.onkeydown = handleKeys;
>
> function handleKeys(e)
> {
>    var key = (window.event) ? event.keyCode : e.keyCode;
>
> var tmp =
> ((document.getElementById('vp')).getAttribute('position')).split('
> ', 3);
> var t_pos_x = parseFloat(tmp[0]);
> var t_pos_y = parseFloat(tmp[1]);
> var t_pos_z = parseFloat(tmp[2]);
>
> var speed = 0.5;
>
>    switch(key) // custom movement :)
>    {
>       case 38:
>       document.getElementById('vp').setAttribute('position', '' +
> t_pos_x + ' ' + t_pos_y + ' ' + (t_pos_z-speed));
>       break;
>
>       case 40:
>       document.getElementById('vp').setAttribute('position', '' +
> t_pos_x + ' ' + t_pos_y + ' ' + (t_pos_z+speed));
>       break;
>
>       case 39:
>       document.getElementById('vp').setAttribute('position', '' +
> (t_pos_x+speed) + ' ' + t_pos_y + ' ' + t_pos_z);
>       break;
>
>       case 37:
>       document.getElementById('vp').setAttribute('position', '' +
> (t_pos_x-speed) + ' ' + t_pos_y + ' ' + t_pos_z);
>       break;
>    }
> updatePositionInfoLabel();
> }
> </script>
>
>         <script  type="text/javascript">
>
> var pos_x = 0.0;
>      var pos_y = 0.0;
>      var pos_z = 0.0;
>
>             function updatePositionInfoLabel()
>             {
> var tmp =
> ((document.getElementById('vp')).getAttribute('position')).split('', 
> 3);
> pos_x = tmp[0];
> pos_y = tmp[1];
> pos_z = tmp[2];
> document.getElementById('movement').innerHTML = 'Pos: ' + pos_x + '
> ' + pos_y + ' ' + pos_z;
>             }
>         </script>
> </head>
> <body>
>     <x3d  id='xdoc_1'width='400px'height='400px'>
>
>       <scene>
> <navigationInfo  type='"examine" "any"'></navigationInfo>
> <viewpoint  id='vp'position='0 0 5'></viewpoint>
> <transform  id='s_cone1'scale='0.2 0.2 0.2'center='0 0
> 0'onclick='updatePositionInfoLabel();'>
> <shape>
> <appearance  >
> <material  id='dc_yellow'diffuseColor='yellow'></material>
> </appearance  >
> <cone/>
>
> </shape>
> </transform>
>       </scene>
>     </x3d>
>     <label  id="movement">Movement</label>
> </body>
> </html>
>
>
>


--------------------------------------------------------------------------------


> _______________________________________________
> X3D-Public mailing list
> X3D-Public at web3d.org
> http://web3d.org/mailman/listinfo/x3d-public_web3d.org
>




More information about the X3D-Public mailing list