This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > VRML > December 2003 > 3d rotational vector to 4-float VRML rotation node





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 3d rotational vector to 4-float VRML rotation node
Dave Coventry

2003-12-04, 1:00 pm

Hi,

I need help in translating a vector rotation element into the
four-float rotation node in VRML.

The vector is a one-unit vector indicating a 3d point one unit from
the origin.

The four-float rotation node gives an axis (a 3d vector) followed by
an angle of rotation around that vector.

Thanks,

Dave Coventry
Herbert Stocker

2003-12-04, 1:00 pm



Dave Coventry wrote:
quote:

> Hi,
>
> I need help in translating a vector rotation element into the
> four-float rotation node in VRML.
>
> The vector is a one-unit vector indicating a 3d point one unit from
> the origin.



Please tell me how this vector describes a rotation, then i can
(probably) tell you how to calculate the SFRotation.

But let me guess: Does the vector describe where the user should
look at?

In this case try
ori= new SFRotation(new SFVec3f(0, 0, -1), yourVector);

In general, the constructor new SFRotation(vectorA, vectorB)
calculates an SFRotation that rotates vectorA into vectorB,
and 0 0 -1 is the direction a user looks into by default.
(Excatly this constructor calculates the shortest rotation
from A to B.)
quote:

>
> The four-float rotation node gives an axis (a 3d vector) followed by
> an angle of rotation around that vector.
>
> Thanks,
>
> Dave Coventry




--
Herbert Stocker (aka hersto)
http://www.hersto.de
www.bitmanagement.de

Dave Coventry

2003-12-04, 1:00 pm

Herbert,

Thanks very much for your reply,
quote:

> Please tell me how this vector describes a rotation, then i can
> (probably) tell you how to calculate the SFRotation.
>
> But let me guess: Does the vector describe where the user should
> look at?


Yes the vector describes the direction vector from the origin.
quote:

> In this case try
> ori= new SFRotation(new SFVec3f(0, 0, -1), yourVector);



How would this be used? Could you use it like so:
Transform{
rotation new SFRotation(new SFVec3f(0, 0, -1), (-0.99863,
-0.052336, 1.67112e-005))
children[....]
}

quote:

> In general, the constructor new SFRotation(vectorA, vectorB)
> calculates an SFRotation that rotates vectorA into vectorB,
> and 0 0 -1 is the direction a user looks into by default.
> (Excatly this constructor calculates the shortest rotation
> from A to B.)
>


Herbert Stocker

2003-12-04, 1:00 pm



Dave Coventry wrote:
quote:

> Herbert,
>
> Thanks very much for your reply,
>
>
>
> Yes the vector describes the direction vector from the origin.
>
>
>
>
> How would this be used? Could you use it like so:
> Transform{
> rotation new SFRotation(new SFVec3f(0, 0, -1), (-0.99863,
> -0.052336, 1.67112e-005))
> children[....]
> }
>



Would be too easy. ;-)

You need to use a Script node, that calculates the rotation and
sends it to the Transform.

DEF Trans Transform
{
}

DEF Scr Script
{
field SFVec3f dir 0 1 0
eventIn SFVec3f set_dir

eventOut SFRotation ori_changed

field SFVec3f negZ 0 0 -1

url "vrmlscript:

function initialize()
{
ori_changed= new SFRotation(negZ, dir);
}

function set_dir(d)
{
dir= d;
ori_changed= new SFRotation(negZ, dir);
}

"
}

ROUTE Scr.ori_changed TO Trans.rotation
ROUTE Something.dir_changed TO Scr.set_dir # if required.

If the direction vector doesn't change dynamically, you
can omit
eventIn SFVec3f set_dir
and
function set_dir(d)


Herbert


--
Herbert Stocker (aka hersto)
http://www.hersto.de
www.bitmanagement.de

Herbert Stocker

2003-12-04, 1:00 pm



I wrote:
quote:

> function set_dir(d)
> {
> dir= d;
> ori_changed= new SFRotation(negZ, dir);
> }
>



This calculates the shortest rotation from negZ to dir.
It might be not sufficient if you want to adjust the
Viewpoint or an avatar. The Viewpoint will be tilted
sidewards if you have a Y component in dir.

Better to combine two rotations, a horizontal one and
then a vertical one for the elevation:

DEF Trans Transform
{
}

DEF Scr Script
{
field SFVec3f dir 0 1 0
eventIn SFVec3f set_dir

eventOut SFRotation ori_changed

field SFVec3f negZ 0 0 -1

url "vrmlscript:

function initialize()
{
set_dir(dir);
}

function set_dir(d)
{
dir= d;
var dirH= new SFVec3f(dir.x, 0, dir.z);
var oriH= new SFRotation(negZ, dirH);
var oriV= new SFRotation(dirH, dir);

ori_changed= oriH.multiply(oriV);
// For Cortona you need to swap both operands.
// use Browser.getName() for deciding whether
// it runs in Cortona or not.
}

"
}

ROUTE Scr.ori_changed TO Trans.rotation
ROUTE Something.dir_changed TO Scr.set_dir

This is not tested, because i don't have a test case.
So maybe R. Russel needs to give me back the cigar. :-)

Herbert

P.S.: dir need not be of length 1.



--
Herbert Stocker (aka hersto)
http://www.hersto.de
www.bitmanagement.de

Dave Coventry

2003-12-04, 1:00 pm

Herbert,

My problem is that I'm trying extract extruded circles out of an
AutoCAD drawing using lisp (Autolisp).

The circle is decribed by a centre point and a radius which is on a
plane which is described by it's normal (the direction vector).

There is also a value called thickness which, if it exists, describes
the extruded height of the circle.

I'm trying to convert these into a 'Cylinder' primitive, rotated as
described by the direction vector.

The problem with using the technique you advocate is that if there are
a thousand (or more!) such circles, there would need to be a
corresponding number of scripts to rotate each cylinder.

Dave
Joerg Scheurich aka MUFTI

2003-12-04, 1:00 pm

> The problem with using the technique you advocate is that if there are
quote:

> a thousand (or more!) such circles, there would need to be a
> corresponding number of scripts to rotate each cylinder.



You can define a PROTO, that includes both the shape and the script
and reuse this PROTO thousands times.

so long
MUFTI
--
Unbekannter Fehler. Der Fehler 999 wurde erkannt.
Legen Sie den Datentraeger "C:\" ein, um den Fehler zu beheben.
Fortfahren/Fortfahren
Dave Coventry

2003-12-04, 1:00 pm

Herbert,

I though that if I take the dot product of the direction vector and
the (0,0,-1) I would get the vector of the normal of the plane formed
by the direction vector and the default VRML vector.

Then I need the angle between the two vectors which would give me the
fourth float. However, this does not give the expected result....

Dave Coventry
Sponsored Links


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