Skip to content

Instantly share code, notes, and snippets.

@cecilemuller
Created May 18, 2013 05:52
Show Gist options
  • Save cecilemuller/5603388 to your computer and use it in GitHub Desktop.
Save cecilemuller/5603388 to your computer and use it in GitHub Desktop.
Combine two SFRotation
#VRML V2.0 utf8
# (because I always forget the link to my post: http://comp.lang.vrml.narkive.com/RS6A2W0P/add-two-sfrotation-in-js)
Viewpoint{description "A"}
DEF tr1 Transform{
rotation 0.5 0.4 0.1 2
children Transform{
rotation 0.1 0.6 0.3 -0.8
children DEF obj Shape{
appearance Appearance{material Material{diffuseColor 0 0 1 emissiveColor 0.3 0 0}}
geometry Box{size 4 1 2}
}
}
}
DEF tr2 Transform{
children Shape{
appearance Appearance{material Material{diffuseColor 0 0 1 emissiveColor 0.3 0 0 transparency 0.5}}
geometry Box{size 5 2 3}
}
}
Script{
field SFNode tr1 USE tr1
field SFNode tr2 USE tr2
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(){
tr2.rotation = add_rotations( tr1.rotation, tr1.children[0].rotation );
}
"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment