This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > VRML > December 2003 > Detecting user view velocity





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Detecting user view velocity
John Öström

2003-12-04, 1:00 pm

Hello!

Is there a way to detect the velocity of the user view by using
ProximitySensor ? Or maybe some other way ? How should this be implemented ?
I'm using it for my HUD, which has a user position display.

Thanks,

John


Cecile Muller

2003-12-04, 1:00 pm

Try this (the "Math.round(velocity*100)/100" is just there to make it
more humanly readable in the trace by removing the smallest decimals).

-------
#VRML V2.0 utf8

Viewpoint{position 0 0 10}
DEF proxy ProximitySensor{size 10e20 10e20 10e20}
DEF timer TimeSensor{loop TRUE}
DEF brain Script{
field SFBool wasInit FALSE
field SFTime lastTime 0
field SFVec3f lastPos 0 0 10 #put the default position
field SFNode proxy USE proxy
eventIn SFTime time_in
directOutput TRUE
url "javascript:
function time_in(t){
if (wasInit) {
velocity = (((proxy.position_changed).subtract(lastPos)).length()) /
(t - lastTime);
lastPos = proxy.position_changed;
} else {
velocity = 0;
wasInit = true;
}
lastTime = t;
trace('velocity: ' + (Math.round(velocity*100)/100) + ' m/s');
}
"
}
ROUTE timer.time TO brain.time_in
------
John Öström

2003-12-04, 1:00 pm

Thanks a lot Cecile, that works !!

John

"Cecile Muller" <spam@wildpeaks.com> wrote in message
news:aff31ac6.0311260620.71a486cc@posting.google.com...
quote:

> Try this (the "Math.round(velocity*100)/100" is just there to make it
> more humanly readable in the trace by removing the smallest decimals).
>
> -------
> #VRML V2.0 utf8
>
> Viewpoint{position 0 0 10}
> DEF proxy ProximitySensor{size 10e20 10e20 10e20}
> DEF timer TimeSensor{loop TRUE}
> DEF brain Script{
> field SFBool wasInit FALSE
> field SFTime lastTime 0
> field SFVec3f lastPos 0 0 10 #put the default position
> field SFNode proxy USE proxy
> eventIn SFTime time_in
> directOutput TRUE
> url "java script:
> function time_in(t){
> if (wasInit) {
> velocity = (((proxy.position_changed).subtract(lastPos)).length()) /
> (t - lastTime);
> lastPos = proxy.position_changed;
> } else {
> velocity = 0;
> wasInit = true;
> }
> lastTime = t;
> trace('velocity: ' + (Math.round(velocity*100)/100) + ' m/s');
> }
> "
> }
> ROUTE timer.time TO brain.time_in
> ------




John Öström

2003-12-04, 1:00 pm

Now I have a new question in this. I'm trying to use the same kind of code
to detect the velocity components of a certain object (in this case defined
as Plane). Then I calculate the velocity (Ve), angle of attack (a) and
sideslip angle (b) from the components u, v, w. The code is as follows:

DEF timer TimeSensor{loop TRUE}

DEF HUDScript Script {

field SFBool wasInit FALSE
field SFTime lastTime 0
field SFFloat u 0
field SFFloat v 0
field SFFloat w 0
field SFFloat Ve 0
field SFVec3f lastPos 0 0 10
field SFNode Plane USE Plane

eventIn SFTime time_in
eventOut MFString HUDString

url "java script:
function time_in(t){
if (wasInit) {
u = ((Plane.translation[0] - lastPos[0]) / (t - lastTime));
v = ((Plane.translation[2] - lastPos[2]) / (t - lastTime));
w = ((Plane.translation[1] - lastPos[1]) / (t - lastTime));
Ve = Math.sqrt(u*u+v*v+w*w);}
else {u = 0;v = 0;w = 0;Ve=0;wasInit = TRUE;}
lastTime = t;
lastPos = Plane.translation;
HUDString = new MFString('Airspeed: ' +Math.round(Ve) + ' m/s',
'Alt: '+Math.round(Plane.translation[1]) + ' m',
'a: ' +Math.round(Math.atan(w/u*-1)*10)/10 +' deg',
'b: ' +Math.round(Math.asin(v/Ve)*10)/10+' deg');
}
"
}

ROUTE HUDScript.HUDString TO HUDText.string
ROUTE timer.time TO HUDScript.time_in

Of course it has DEF's for plane and HUDText, I removed them to cut some
lines in this post. The Plane translation is run externally from Simulink
Virtual Reality toolbox. The problem is that (Plane.translation[0] -
lastPos[0]) seems to be zero all the time. So I can't get any velocity
components... The altitude indication(Alt=Plane.translation[1]) is working
fine. Do you guys have any idea what might be wrong ?

Thanks,
John


Joerg Scheurich aka MUFTI

2003-12-04, 1:00 pm

> Of course it has DEF's for plane and HUDText, I removed them to cut some
quote:

> lines in this post.



Can you give a few lines, how "plane" is defined ?
quote:

> The Plane translation is run externally from Simulink
> Virtual Reality toolbox.



Do externally mean it is a Transform node in a Inline or EXTERNPROTO ?
In this case, i would wonder, if Plane.translation[0] would work if
translation is not a field of the EXTERNPROTO
quote:

> The problem is that (Plane.translation[0] -
> lastPos[0]) seems to be zero all the time. So I can't get any velocity
> components... The altitude indication(Alt=Plane.translation[1]) is working
> fine.



If Plane is a PROTO/EXTERNPROTO, what is the PROTO header. Did you tested,
if routing the information from/to the PROTO/EXTERNPROTO would work ?

so long
MUFTI
--
Unbekannter Fehler. Der Fehler 999 wurde erkannt.
Legen Sie den Datentraeger "C:\" ein, um den Fehler zu beheben.
Fortfahren/Fortfahren
John Öström

2003-12-04, 1:01 pm

Hello!

The Plane is just a transform node that includes the aircraft 3D-model. I
have to say I don't quite know how VR toolbox drives the model but you just
define what you want to control (like translation, rotation, center and so
on)

"Joerg Scheurich aka MUFTI" <rusmufti@helpdesk.rus.uni-stuttgart.de> wrote
in message news:bqf61v$k5b$1@news.uni-stuttgart.de...
quote:

some[QUOTE][color=darkred]
>
> Can you give a few lines, how "plane" is defined ?
>
>
> Do externally mean it is a Transform node in a Inline or EXTERNPROTO ?
> In this case, i would wonder, if Plane.translation[0] would work if
> translation is not a field of the EXTERNPROTO
>
working[QUOTE][color=darkred]
>
> If Plane is a PROTO/EXTERNPROTO, what is the PROTO header. Did you tested,
> if routing the information from/to the PROTO/EXTERNPROTO would work ?



I posted a question to the comp.soft-sys.matlab -group as well. I included
the code into that question as well. Here's the post I sent:

I have developed a small HUD view into my VRML world using a simple
javascript. It calculates the airspeed, angle of attack and sideslip angle
according to aircraft velocities. It works fine when used in a standalone
VRML-world where the plane (DEF Plane) is driven by position and orientation
interpolators. But when I try to use the same script when the plane is
driven from VRSink-block (translation and rotation), all I get is zeros in
the calculated values. The altitude calculation only shows the initial value
but does not refresh.

The VRML world and the script I'm using:

**********************************************************************
#VRML V2.0 utf8
DEF User ProximitySensor {size 10e20 10e20 10e20}
DEF timer TimeSensor {}
DEF Plane Transform { *** aircraft 3d model here ***}
DEF UserPos Transform { translation 5 0 0 children [ Transform { translation
0.3 -0.1 -1 children [
Shape { appearance Appearance { material Material { diffuseColor 0.178062
0.8 0.0662137 } }
geometry DEF HUDText Text { string "Position" fontStyle FontStyle { size
0.04 } } } ] } ] }
DEF HUDScript Script{
field SFBool wasInit FALSE
field SFTime lastTime 0
field SFVec3f lastPos 0 0 0
field SFFloat t 0
field SFFloat Ve 0
field SFFloat a 0
field SFFloat b 0
field SFNode timer USE timer
eventIn SFVec3f transxyz
eventIn SFRotation rot
eventOut MFString HUDString
url "java script:
function transxyz(transxyz){
if(wasInit) {
t = timer.cycleInterval*timer.fraction_changed;
uNED = ((transxyz[0] - lastPos[0]) / (t - lastTime));
vNED = ((transxyz[2] - lastPos[2]) / (t - lastTime));
wNED = -((transxyz[1] - lastPos[1]) / (t - lastTime));
q0 = Math.cos(rot[3]/2);
q1 = rot[0]*Math.sin(rot[3]/2);
q2 = rot[2]*Math.sin(rot[3]/2);
q3 = rot[1]*Math.sin(rot[3]/2)*-1;
uABC =
uNED*q0*q0+uNED*q1*q1-uNED*q2*q2-uNED*q3*q3+2*vNED*q1*q2+2*vNED*q0*q3+2*wNED
*q1*q3-2*wNED*q0*q2;
vABC =
2*uNED*q1*q2-2*uNED*q0*q3+vNED*q0*q0-vNED*q1*q1+vNED*q2*q2-vNED*q3*q3+2*wNED
*q2*q3+2*wNED*q0*q1;
wABC =
2*uNED*q1*q3+2*uNED*q0*q2+2*vNED*q2*q3-2*vNED*q0*q1+wNED*q0*q0-wNED*q1*q1-wN
ED*q2*q2+wNED*q3*q3;
Ve = Math.sqrt(uABC*uABC+vABC*vABC+wABC*wABC);
a = Math.atan(wABC/uABC)*57.2958;
b = Math.asin(vABC/Ve)*57.2958;
lastTime = t;
lastPos = transxyz;}
else {VE = 0; a = 0; b = 0;wasInit = TRUE;}
HUDString = new MFString('Airspeed: ' +Math.round(Ve) + ' m/s',
'Alt: '+Math.round(transxyz[1]) + ' m',
'a: ' +Math.round(a*10)/10 +' deg',
'b: ' +Math.round(b*10)/10 +' deg');}"}

ROUTE User.position_changed TO UserPos.set_translation
ROUTE User.orientation_changed TO UserPos.set_rotation
ROUTE HUDScript.HUDString TO HUDText.string
ROUTE Plane.translation TO HUDScript.transxyz
ROUTE Plane.rotation TO HUDScript.rot

**********************************************************************

It seems that the problem is in the timer, because the following script
(that does not need timer) works just fine:

**********************************************************************
DEF HUDScript Script {
eventIn SFVec3f transxyz
eventOut MFString HUDString
url ["java script:
function rndr(v) { return Math.round(v * 1) / 1; }
function transxyz(value) {
HUDString = new
MFString('pNorth='+rndr(value[0]),'pEast='+rndr(value[2]*-1),'Alt='+rndr(val
ue[1]));
}"]
}
**********************************************************************


Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews