Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Combine two SFRotation into a single SFRotation using VRMLScript
#VRML V2.0 utf8
Viewpoint{
position 0 0 10
}
#
# Box 1: encapsulated transforms.
#
DEF box1_outer Transform {
rotation 0.5 0.4 0.1 2
children DEF box1_inner Transform {
rotation 0.1 0.6 0.3 -0.8
children DEF obj Shape {
appearance Appearance {
material Material {
diffuseColor 0 0 0
emissiveColor 1 0 0
}
}
geometry Box{size 4 1 2}
}
}
}
#
# Box 2: larger box with only one transform (that combines the transformation of the box with two transforms).
#
DEF box2 Transform {
children Shape {
appearance Appearance {
material Material {
diffuseColor 0 0 0
emissiveColor 0 1 0
transparency 0.5
}
}
geometry Box{size 6 2 4}
}
}
Script {
field SFNode box1_outer USE box1_outer
field SFNode box1_inner USE box1_inner
field SFNode box2 USE box2
directOutput TRUE
url "javascript:
function add_rotations(outer_rotation, inner_rotation) {
var result = new SFRotation();
var p = new SFVec3f(0, 0, 0);
var outer = new VrmlMatrix();
var inner = new VrmlMatrix();
outer.setTransform(p, outer_rotation);
inner.setTransform(p, inner_rotation);
outer.multLeft(inner).getTransform(null, result, null);
return result;
}
function initialize(){
box2.rotation = add_rotations (
box1_outer.rotation,
box1_inner.rotation
);
}
"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.