13.1.4 Inverse getLocalToVworld
Situations can arise where you need the Vworld-to-local transform, instead of the
local-to-Vworld transform returned by a node. In such case, you can use the
inverse method of Transform3D to convert the transform. Because this situation
comes up fairly often when performing in-scene manipulation and the pseudo-overlay
visualization techniques, it is worth exploring this subject in more detail.
For example, using world-relative mapping (WRM) control you may want to slide
a desk in a room toward a window, which is north of the desk. Normally, the world-relative
output from the WRM technique would be used to manipulate the desk's
"actuator" transform group directly. If, however, the desk is a member of a group, such
as in a suite of furniture, then the group itself is likely to have an actuator transform
allowing the group as a whole to slide and rotate. Because the desk's actuator is not in
the world space but in the local space of the group, you can't simply apply the world-relative
movement from WRM to the desk's actuator. Instead, you have to first convert
the world-relative movement, a vector pointing north, into a group-relative movement.
This requires getting the desk actuator's local-to-Vworld transform, inverting it
into a Vworld-to-local transform, and transforming the north-pointing vector with it.
The result is a north-pointing vector expressed in terms of the desk actuator's local
space, which is defined by the group's actuator. Because the coordinate space of the
vector and the desk's actuator now match, they can be multiplied together to update
the desk actuator's transform state while leaving the rest of the group alone.
The following code fragment illustrates the salient points of this example:
// build a desk and group with actuators
/// create the desk object
MyDesk desk = new MyDesk();
/// create a desk actuator and add the desk to it
TransformGroup deskAct = new TransformGroup();
deskAct.addChild(desk);
/// create a group actuator and add the desk actuator to it
TransformGroup groupAct = new TransformGroup();
groupAct.addChild(deskAct);
/// add the desk to the world's root node
root.addChild(groupAct);
// arbitrarily manipulate the group and desk
...
// move the desk north in the world by 10 meters
Vector3d northward = new Vector3d(0, 0, -10);
/// get the desk actuator's local transform
Transform3D xform = new Transform3D();
deskAct.getLocalToVworld(xform);
/// transform the northward vector from world to local space
xform.invert();
xform.transform(northward);
/// get the current desk actuator state
Transform3D current = new Transform3D();
deskAct.getTransform(current);
/// apply the change vector to the desk actuator state
Transform3D change = new Transform3D();
change.set(northward);
current.mul(change);
/// don't forget to set the new transform
deskAct.setTransform(current);
13.1.5 Local-to-local
The most general case of coordinate-space transformation, conversion is needed to
go from one local space to another. A simple example would be DRM control of a
target object in a group, where display-relative local space inputs are translated into
their world-relative equivalents, which are then converted for use in the local space of
the target object actuator. To perform this two-legged coordinate-space transformation,
imagine combining the two previous coding examples into one, with the first
half going from local to world space, and the second half going from world to local
space. Generalized versions of local-to-local transformation— from a source space to
a target space— are provided by the j3dui.control.mappers.Mapper.
toTargetSpace methods in the UI framework. One method is for point transformation
and the other is for vectors.
Stop by in one week for the next installment!
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|