Moving Worlds Java API

Why Sony proposes the extended JAVA API?

It is known that the primitives defined in the current Moving Worlds (Draft #1) are not enough to easily realize complex manipulations of 3D objects. Sony has a proposal to provide higher level API set for common operations to let ordinal users make charming models with less effort.


Sony's Proposal

To: www-vrml@wired.com
Subject: [Proposal to VRML2.0] 'Transform' and 'Shape' java class
Date: Tue, 23 Apr 1996 14:09:51 +0900
From: Kouichi Matsuda 

Hi!

Proposal: 'Transform' and 'Shape' java class

We propose the the 'Transform' and 'Shape' Java classes to access the
VRML nodes easily in Java script. These classes act as a kind of high level
APIs.

In the current Moving Worlds(MW), if user wants to change the current
transformation of an object with a script, it needs many
script-programmings to do that(See "Advantage of SONY's proposal").
These increase the script file size and network traffics. Also
browser can not optimize the script execusion.

So, we propose the follwoing java classes.
If browser supports the methods of these classes as native methods,
it can execute them efficiently.

- - ----------------------------------------------------------------
1. Full specification of 'Transform' and 'Shape' class:

public class Transform implements Node {

    // *** GET information ***
    public float[3] getTranslation(); // x,y,z. local coordinate
    public float[4] getRotation();    // SFRotation local coordinate

    // *** SET information ***
    public void translate(float T[3], // SFVec3
                          int mode);             // relative or absolate

    // rotateAroundLine() with P = (0,0,0)
    public void rotate(float R[4],  // SFRotation
                       int mode);

    // rotate around the line which is defined by R and P
    public void rotateAroundLine(float R[4], // SFRotation
                                 float P[3], //
                                 int mode);

    // rotateAroundLine() with P = (0,0,0)
    public void rotateDegree(float R[4],  //SFRotation    R[3] = degree.
                             int mode);

    // rotate around the line which is defined by R and P
    public void rotateAroundLineDegree(float R[4], // SFRotation  R[3] = degree.
                                       float P[3], //
                                       int mode);
    }

public class Shape implements Node {
    // *** Material access ***
    public float[] getColor (int whichcolor); // whichcolor = diffuse, emissive, specular
    public float getAmbientIntensity ();
    public float getShininess ();
    public float getTransparency ();

    public void setColor (int whichcolor, float[] color); // whichcolor = diffuse, emissive, specular
    public void setAmbientIntensity (float intensity);
    public void setShininess (float shininess);
    public void setTransparency (float transparency);

    // *** Texture access ***
    public String[] getTextureFilename ();
    public float getTextureFraction ();

    public void setTextureFilename (String filename[]);
    public float getTextureFraction (float fraction);

    // *** TextureTransform access methods may be necessary.
}

public class MwMath {
    puvlic float[] degreeToRad(float[] degree) ; // returning rad from degree.
}

- - --------------------------------------------------------------------
2. Advantage of SONY's proposal.

Let me show you how to realize the following 'natural' behavior of an
object using (1) native MovingWorlds events, and (2) SONY-proposed
high-level Java APIs.

- - - A cone is located as default.
        it is centered at (0, 0, 0).
        its bottom radius is 1m.
        its height is 2m.
        its apex is at (0, 1, 0).
        its bottom center is at (0, -1, 0).

- - - Whenever you click the cone, the cone is rotated by 0.1 radian around a
  line which passes the cone's apex (0, 1, 0) and has a direction vector
  (1, 0, 0).

- - - The key point is that the center of rotation is not the origin of the
  local coordinate system of the cone.

************************
* Current MovingWorlds *
************************

The following is mathematical explanation behind the MovingWorlds
implementation.

Let 'a' be an arbitrary point on the surface of the cone located at the
initial position. Let 'b' be the position of 'a' after the above rotating.

P:      3 x 3 matrix which rotates an arbitrary point around the x-axis by
        r radian. This matrix is easy to get since the rotation axle passes
        the origin.

u:      a vector (0, 1, 0)

R:      3 x 3 matrix which represents the rotation field of a Moving Worlds'
        Transform node.

t:      a vector which represents the translation field of a Moving Worlds'
        Transform node.

Equivalence:            b = P(a - u) + u = Ra + t

That means:             R = P
                        t = -Pu + u

You can rotate the cone around the line by writing the 'R' and 'b' to
Transform's rotation and translation fields.

        ------- move.wrl ---------

#VRML V2.0 utf8
DEF CONE_TRANSFORM Transform{
        translation 0 0 0      # initial position
        rotation 1 0 0 0       # initial orientation
        children[
                Shape{
                        geometry Cone{}
                }
                DEF TOUCH_SENSOR TouchSensor{}
        ]
}

DEF SCRIPT Script{
        behavior "move.class"
        scriptType "JAVABC"
        eventIn SFBool clicked
        eventOut SFVec3f setConeTranslation
        eventOut SFRotation setConeRotation
        field SFFloat rad 0.0
}

ROUTE TOUCH_SENSOR.isActive TO SCRIPT.clicked
ROUTE SCRIPT.setConeTranslation TO CONE_TRANSFORM.set_translation
ROUTE SCRIPT.setConeRotation TO CONE_TRANSFORM.set_rotation

        ------- move.java --------

import vrml.*;

class move extends Script{
        SFVec3f setConeTranslation = (SFVec3f)getEventOut("setConeTranslation");
        SFRotation setConeRotation = (SFVec3f)getEventOut("setConeRotation");
        SFFloat rad = (SFFloat)getField("rad");

        public void clicked(SFBool arg, SFTime ts){
                // for internal calc.
                float[][] P;
                float[]   u = new float[3];

                // for eventOuts.
                float[]   t;
                float[]   R = new float[4];

                if(arg.getValue() == true){
                        // the button is pressed.
                        // do nothing.
                        return;
                }

                // the button is released.

                // calculate a 3 x 3 matrix for rotation by 'rad' around
                // the vector (1, 0, 0).
                P = MwMath.generateRotMatrix(1, 0, 0, rad.getValue());

                // VsVec3f
                u[0] = 0; u[1] = 1; u[2] = 0;
                t = -MwMath.multMatrixVec(P, u) + u;

                // VsRotation
                R[0] = 1; R[1] = 0; R[2] = 0; R[3] = rad;

                // set the new position of the Cone.
                setConeTranslation.setValue(t);
                setConeRotation(R);

                // update the radian.
                rad.setValue(rad.getValue() + 0.1);
        }
}


************
* SONY API *
************

On the other hand, SONY API library supports common rotation cases such as

- - - rotate a Transform around an arbitrary line.
- - - rotate a Transform around the center of its contents.
- - - rotate a Transform around its origin.

In this case, the first one is applicable.

        ------- move.wrl ---------

#VRML V2.0 utf8
DEF CONE_TRANSFORM Transform{
        children[
                Shape{
                        geometry Cone{}
                }
                DEF CLICK_SENSOR ClickSensor{}
        ]
}

DEF SCRIPT Script{
        behavior "move.class"
        scriptType "JAVA"
        eventIn SFBool clicked
        field SFNode coneTransform USE CONE_TRANSFORM
}

ROUTE CLICK_SENSOR.isActive TO SCRIPT.clicked

        ------- move.java --------

import vrml.*;

class move extends Script{
        SFNode coneTransform = (SFNode)getField("coneTransform");

        float point[] = new float[3];
        float direction[] = new float[4];

        // constructor
        move(void){
                // parameters to describe rotation around a line (x, 1, 0)
                // by 0.1 radian.
                point[0] = 0;  point[1] = 1;  point[2] = 0;
                direction[0] = 1; direction[1] = 0; direction[2] = 0;
                direction[3] = 0.1;
        }

        public void clicked(SFBool arg, SFTime ts){
                if(arg.getValue() == true){
                        // the button is pressed.
             

Sony's high level Java API

  • Browser
  • Kinemation
  • Shape
  • Transform

    Current Implementation