Get current viewpoint position in script 
Author Message
 Get current viewpoint position in script

I am sure someone must have already done this, and I see no need to
"reinvent the wheel" if someone is willing to share.

I am trying to get the user's current position. (Orientation would
be nice, too, but not as important, and if I can get position, I
can use the same technique to get the orientation.) I want to use
this to update a "You Are Here" pointer on a map of the world.

I think I understand the general idea of how to do this, but I am
having trouble with the details.

First, my plan is to have the map in a separate window from the
world, but I am having trouble getting Javascript to communicate
with another window from within the vrml browser. It works fine
when called from within an HTML window, but not from VRML. (At
least not using Cosmo Player.)

I could use a HUD within the world. That would eliminate the need
to communicate with another window. It would also make animating
the "You Are Here" pointer trivial. But I would rather keep the
user's view of the world as unobstructed as possible.

Either way, I still have a second question. My world has several
viewpoints defined. Is there an easy way to access the currently
bound viewpoint? Or do I need to route all of them to my script
and keep track of isbound events?

Chuck Linsley
linsley (at) best (dot) com
http://www.*-*-*.com/ ~linsley/photography/vrgallery/Gallery1.wrl
(very much under construction)



Tue, 07 Oct 2003 05:58:15 GMT  
 Get current viewpoint position in script


Quote:

> I am sure someone must have already done this, and I see no need to
> "reinvent the wheel" if someone is willing to share.

> I am trying to get the user's current position. (Orientation would
> be nice, too, but not as important, and if I can get position, I
> can use the same technique to get the orientation.) I want to use
> this to update a "You Are Here" pointer on a map of the world.

> I think I understand the general idea of how to do this, but I am
> having trouble with the details.

> First, my plan is to have the map in a separate window from the
> world, but I am having trouble getting Javascript to communicate
> with another window from within the VRML browser. It works fine
> when called from within an HTML window, but not from VRML. (At
> least not using Cosmo Player.)

> I could use a HUD within the world. That would eliminate the need
> to communicate with another window. It would also make animating
> the "You Are Here" pointer trivial. But I would rather keep the
> user's view of the world as unobstructed as possible.

Actually the HUD has the code you need namely the ProximitySensor. Simply
route the position_changed and orientation_changed events from the
ProximitySensor to a Script or object.

You could put the HUD on the side of the window which is less noticable. Ie
a kind of sidebar.

I have a special HUD which switches the scene for a second one. The actuall
HUD is invisable untill the pointer is over the icon.

Quote:
> Either way, I still have a second question. My world has several
> viewpoints defined. Is there an easy way to access the currently
> bound viewpoint? Or do I need to route all of them to my script
> and keep track of isbound events?

The method using ProximitySensors reads the user's current location. Works
reguardless of the viewpoint.

Quote:
> Chuck Linsley
> linsley (at) best (dot) com
> http://www.best.com/~linsley/photography/vrgallery/Gallery1.wrl
> (very much under construction)

Paul Aslin
http://members.nbci.com/vrmlworld/
tutorials includes HUD examples
http://members.nbci.com/vrmlworld/tutorials/


Wed, 08 Oct 2003 02:19:23 GMT  
 Get current viewpoint position in script

Quote:
> The method using ProximitySensors reads the user's current location. Works
> reguardless of the viewpoint.

just a note: the proxy dosn't generate events between the current location
and the viewpoint being bound. which means if the user binds a viewpoint
which is further away from their current location than the size of the
Proxy, they lose the HUD because it dosn't get updated. you would need to
put a bit of a 'hack' in, to send the Viewpoint.position_changed to the
Proxy.set_location (or position or whatever it is) whenever the viewpoint is
bound (repeat for all viewpoints).
db


Tue, 07 Oct 2003 18:57:50 GMT  
 Get current viewpoint position in script
In an article that never showed up on my ISP, and I had to go find at

Quote:
>Actually the HUD has the code you need namely the ProximitySensor.

Thanks. Where can I find this pre-existing HUD? Never mind; I found it.

Quote:
>I have a special HUD which switches the scene for a second one. The actuall
>HUD is invisable untill the pointer is over the icon.

This sounds good. Are you willing to share?


Quote:

>> The method using ProximitySensors reads the user's current location. Works
>> reguardless of the viewpoint.

>just a note: the proxy dosn't generate events between the current location
>and the viewpoint being bound. which means if the user binds a viewpoint
>which is further away from their current location than the size of the
>Proxy, they lose the HUD because it dosn't get updated. you would need to
>put a bit of a 'hack' in, to send the Viewpoint.position_changed to the
>Proxy.set_location (or position or whatever it is) whenever the viewpoint is
>bound (repeat for all viewpoints).

I was going to ask about just making the ProximitySensor big enough
to include all the viewpoints, but I read the ProximitySensor
section of the Annotated VRML 97 Reference, and that is exactly
what it recommends, unless you expect your world to be composited
into a larger world. Since my world defines a large outdoor area
as well as the interior of the gallery (the version currently online
doesn't, but the version under development does) I think it would
be difficult to incorporate into a larger world without modification,
so a large ProximitySensor is a minor issue.

BTW, that large outdoor area is the reason I am looking for this
navigation aid in the first place. It is 1km square, and hilly
enough that clear landmarks are not always visible. Even I get
lost in it. That will improve as I define textures for lawn,
hills, paths, etc., but right now it is just a checkerboard so I
can edit the mesh more easily. Still, I think it will be helpful
to the user to be able to see where he is with respect to the
"interesting" features.

It looks like the ProximitySensor example int the Annotated VRML
97 Reference has what I need to get started. Thanks, guys, for
pointing me in the right direction. I would not have thought about
the ProximityDetector without your help.

However, the Annotated VRML 97 Reference leaves me with one further
question. It states that the size of the browser's window must be
known to position the HUD, and that it is necessary to <EMBED> the
world in an HTML page to do this. I understand this. But is there a
way to do this without forcing the window to a fixed size? It would
be very desirable to use the viewer's current window, whether that
is modest window on a 640 x 480 screen, or 1600 x 1200 full-screen.

It is easy to find the window size in JavaScript from an HTML page,
but I do not see any way to pass this into the world. It seems as
though the assumed window size must be hard-coded into the world. I
could load the world through a CGI script that would patch the
appropriate values, but that seems kinda kludgy. Is there a better
way?

Chuck Linsley
linsley (at) best (dot) com
http://www.best.com/~linsley/photography/vrgallery/Gallery1.wrl
(very much under construction)



Wed, 08 Oct 2003 10:07:06 GMT  
 Get current viewpoint position in script

Quote:
> However, the Annotated VRML 97 Reference leaves me with one further
> question. It states that the size of the browser's window must be
> known to position the HUD, and that it is necessary to <EMBED> the
> world in an HTML page to do this. I understand this. But is there a
> way to do this without forcing the window to a fixed size? It would
> be very desirable to use the viewer's current window, whether that
> is modest window on a 640 x 480 screen, or 1600 x 1200 full-screen.

nah thats no fun. I created a more interesting system for positioning the
HUD so that its visible. basically the problem is that when the viewing area
of the scene has a different aspect ratio, some of the parts of the hud
might not be visible, in both cosmo and cortona the vertical aspect is
constant until the window has a rediculously low aspect ratio, but both of
them vary the hoizontal aspect more often. i created a small script that
scales the HUD components along the Y axis until they fit in the HUD. it
runs off continuous events from a timesensor, so when the scene loads the
hud appears to stretch or contract for a few seconds while it resizes, thats
the only efect the user sees. you can see it at:
ihug.com.au/~blaikie/tnakgame.wrl
load the world, watch it scale, then resize the window to give it a
different aspect ratio and refresh the window to rescale again (after the
initial scaling, the script is disabled so if the user changes the window
size after that, they will need to refresh the world to refit the HUD).
if you see this as usefull, i can provide the source in a simple example HUD
db


Wed, 08 Oct 2003 12:18:06 GMT  
 Get current viewpoint position in script

Quote:

>nah thats no fun. I created a more interesting system for positioning the
>HUD so that its visible. basically the problem is that when the viewing area
>of the scene has a different aspect ratio, some of the parts of the hud
>might not be visible, in both cosmo and cortona the vertical aspect is
>constant until the window has a rediculously low aspect ratio, but both of
>them vary the hoizontal aspect more often. i created a small script that
>scales the HUD components along the Y axis until they fit in the HUD. it
>runs off continuous events from a timesensor, so when the scene loads the
>hud appears to stretch or contract for a few seconds while it resizes, thats
>the only efect the user sees. you can see it at:
>ihug.com.au/~blaikie/tnakgame.wrl
>load the world, watch it scale, then resize the window to give it a
>different aspect ratio and refresh the window to rescale again (after the
>initial scaling, the script is disabled so if the user changes the window
>size after that, they will need to refresh the world to refit the HUD).
>if you see this as usefull, i can provide the source in a simple example HUD
>db

That sounds something like what I thought of while answering email
from Paul, except my proposed HUD is just a single TouchSensor
tucked away in one corner of the screen, so I would not need to
scale, just translate. Hmm, I might want to scale the pop-up when
the TouchSensor is activated, so it could be useful.  Also, my idea
could (if it works) detect changes in window size by means of
isActive events from a couple of tiny VisibilitySensors that are
attached to the HUD, and reposition itself without having to refresh
the world.

You guys are giving me good ideas, even before I see your code.
Thanks!

Chuck Linsley
linsley (at) best (dot) com
http://www.best.com/~linsley/photography/vrgallery/Gallery1.wrl
(very much under construction)



Wed, 08 Oct 2003 14:08:56 GMT  
 Get current viewpoint position in script

Quote:
> That sounds something like what I thought of while answering email
> from Paul, except my proposed HUD is just a single TouchSensor
> tucked away in one corner of the screen, so I would not need to
> scale, just translate. Hmm, I might want to scale the pop-up when
> the TouchSensor is activated, so it could be useful.  Also, my idea
> could (if it works) detect changes in window size by means of
> isActive events from a couple of tiny VisibilitySensors that are
> attached to the HUD, and reposition itself without having to refresh
> the world.

well i find scale is better in general.
my scaling system works via isActive events from a VisibilitySensor. but its
difficult to keep it active waiting for screen resizes, basically what
happens on itialization is the scaler is started on one mode (expand or
contract), if it then realises (via the isActive) that its going in the
wrong direction, it switches (so if it was on expand and it started of not
visible, it would need to switch and start contracting), it keeps doing this
(every time it receives a fraction_changed event from a TimeSensor, its a
bad way to do things, but its the only way to get an event with a new
timestamp) until the VisiSensor switches state, and then it stops. so lets
say the HUD was initially to large, so it scaled down, so after scaling the
VisiSensor sent a final isActive TRUE (to indicate it was visible). now what
happens if the user makes the window wider. the VisibilitySensor is still
visible, so it never generates a new isActive event. (obviously the inverse
case is also possible that the Visi finishes FALSE and the user makes the
screen less wide, so no event is produced). to fix this you would need 2
visibility sensors not very far apart and the screen would be scaled when
one was visible and the other wasn't, the code for, imho, requires to much
thought for the benefit.
also it would be easier for you just to scale the HUD along the Y initially,
rather than translating. because if u scale in the first place you don't
have to worry about your pop-up later. basically i just design my HUD for a
specific width, then i much around moving the VisibilitySensor so its just
wide enough to fit all my HUD bits and pieces. (or u can start with a
scaling HUD, and add elements and move the elements to fit the HUD)

db



Wed, 08 Oct 2003 14:28:48 GMT  
 Get current viewpoint position in script
Thanks to everyone who helped me with this problem, especially to
Sylvain Carette for sending me the sample HUD code. Using that as
a starting point, I now have a HUD that consists of a small map of
the world floating in the top left corner of the screen. A small,
green pointer shows the user's position and orientation. (If it is
red, you have managed to get yourself upside down. :-)

When the cursor is positioned over the small map, a larger map
appears, almost filling the window. Clicking on the small map
makes the large map remain visible until the small map is clicked
again. (Someday I may add the ability to click the big map to move
the user to the selected position, but not yet.)

The maps show more detail (and pointer movement changes correspondingly)
as the user moves into or out of a central region of greater interest.

The small map will reposition itself if the window size is changed.
(This is not perfect. Under some conditions, it can fail to converge,
and oscillate by a few pixels. But it seems to work correctly the
vast majority of the time.) The HUD hides itself until it is positioned.

You can see it at

http://www.best.com/~linsley/photography/vrgallery/hud.wrl

It loads fairly quickly (9K wrl, two jpgs, 23K and 50K), but it takes
a while for the HUD to find the corner of the screen. It is not too
bad with the HUD by itself, but it is outrageously slow when incorporated
into the rest of my world. (The rest of the world is rather bloated,
but that is a different topic.)

Again, thanks to all who helped.

Chuck Linsley
linsley (at) best (dot) com
http://www.best.com/~linsley/photography/vrgallery/Gallery1.wrl
(very much under development)



Sun, 12 Oct 2003 10:19:42 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. event to get current viewpoint position/orientation - how?

2. getting the position before a viewpoint was bound

3. Getting current position in TextPane

4. Getting current time within TCL script

5. How do I set the current Viewpoint? (EAI)

6. Current ViewPoint

7. moving current viewpoint

8. calculating position from viewpoint orientation with trig/jscript (?)

9. help on Camera Position & Viewpoints

10. Coverting Position, Target viewpoint

11. Guiding Viewpoint from Script: Help Please

12. Getting a current list of APF authorised libraries.

 

 
Powered by phpBB® Forum Software