VRML position & orientation 2 transformation matrix 
Author Message
 VRML position & orientation 2 transformation matrix

Hi,
has anyone written a routine which converts the viewers vrml position &
orientation to a transformation matrix for the object in the center of
the scene?
Regards, Jan


Sat, 18 Aug 2001 03:00:00 GMT  
 VRML position & orientation 2 transformation matrix

Quote:

> has anyone written a routine which converts the viewers VRML position &
> orientation to a transformation matrix for the object in the center of
> the scene?

Hi Jan,

the following script will do this for you. You can send a rotation or a
translation
value to get the according 3x4 transformation matrix as a MFFloat with 12
values.
Vice versa it sends a translation ans a rotation event when a matrix is
sent.

regards
Martin

DEF MATROT Script {

  eventIn  SFVec3f    set_translation
  eventIn  SFRotation set_rotation
  eventIn  MFFloat    set_matrix
  eventOut SFVec3f    translation_changed
  eventOut SFRotation rotation_changed
  eventOut MFFloat    matrix_changed
  field    MFFloat    matrix [1,0,0,0,0,1,0,0,0,0,1,0]

  url "javascript:

  function set_translation(value) {
    matrix[ 3] = value[0];
    matrix[ 7] = value[1];
    matrix[11] = value[2];
    matrix_changed = matrix;
  }

  function set_rotation(value) {
    ct = Math.cos(value[3]);
    st = Math.sin(value[3]);
    vt = 1.0 - ct;
    kx = value[0];
    ky = value[1];
    kz = value[2];
    matrix[ 0] = kx*kx*vt + ct ;
    matrix[ 1] = kx*ky*vt - kz*st;
    matrix[ 2] = kx*kz*vt + ky*st;
    matrix[ 4] = kx*ky*vt + kz*st;
    matrix[ 5] = ky*ky*vt + ct;
    matrix[ 6] = ky*kz*vt - kx*st;
    matrix[ 8] = kx*kz*vt - ky*st;
    matrix[ 9] = ky*kz*vt + kx*st;
    matrix[10] = kz*kz*vt + ct;
    matrix_changed = matrix;
  }

  function set_matrix(value) {
    matrix = value;
    cos_t = (value[0]+value[5]+value[10]-1.0)/2.0;
    if (cos_t>=1.0) {
      rotation_changed = new SFRotation(1,0,0,0);
    }
    else if (Math.abs(cos_t+1.0)<1.0e-5) {
      r3 = Math.PI;
      s1 = (value[1]>=0) ? 1 : -1;
      s2 = (value[2]>=0) ? 1 : -1;
      r0 = Math.sqrt((value[0]+1.0)/2.0);
      r1 = s1*Math.sqrt((value[5]+1.0)/2.0);
      r2 = s2*Math.sqrt((value[10]+1.0)/2. );
      rotation_changed = new SFRotation(r0,r1,r2,r3);
    }
    else {
      r3 = Math.acos(cos_t);
      f = 1.0/(2.0*Math.sin(r3));
      r0 = f*(value[9]-value[6]);
      r1 = f*(value[2]-value[8]);
      r2 = f*(value[4]-value[1]);
      rotation_changed = new SFRotation(r0,r1,r2,r3);
    }
    translation_changed = new SFVec3f(value[3],value[7],value[11]);
  }
  "

Quote:
}



Sat, 18 Aug 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Creating a Transformation Matrix from a VRML 1.0 Camera

2. user position & orientation

3. A Question on Matrix Transformation Using J.

4. viewing matrix transformation with Live3D in Win3.1x

5. Wanted: 3x3 transformation matrix code

6. Matrix to Orientation

7. postdoc position--program transformation

8. vrml transformations

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

10. Getting the position and orientation of the avatar

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

12. keeping camera position/orientation on reentry ?

 

 
Powered by phpBB® Forum Software