Hallo,
I've written one vrml file which provide user with the possibility to
move object using mouse. The problem is that I can just move the
object in the xy layer. Can someone help me to check the vrml file and
tell me, where I made a mistake?
Thanks a lot
Lucia
Here is the source code:
#VRML V2.0 utf8
PROTO SpaceSensor [
eventOut SFVec3f translation_changed
eventOut SFRotation rotation_changed
eventOut SFVec3f scale_changed
eventIn MFNode addChildren
eventIn MFNode removeChildren
exposedField MFNode children []
field SFVec3f bboxCenter 0 0 0
field SFVec3f bboxSize 2 2 2
]
{
DEF SPACE Transform {
children [
DEF TOUCH TouchSensor {
}
DEF T Transform {
addChildren IS addChildren
removeChildren IS removeChildren
children IS children
bboxCenter IS bboxCenter
bboxSize IS bboxSize
}
DEF SWITCH_ALL Switch {
choice[
DEF MODE_MOVE Group {
children[
DEF Axis_X Transform{
children[
Shape {
appearance Appearance {
material Material {
diffuseColor 1.0 1.0 1.0
}
}
geometry IndexedLineSet {
coord Coordinate {
point [
0.0 0.0 0.0, 1.0 0.0 0.0, 0.0 1.0 0.0,
0.0 0.0 1.0
]
}
coordIndex [
0, 1, -1
]
}
}
Transform{
children[
DEF X_Axis_Sensor PlaneSensor {}
Transform{
translation 1.0 0.0 0.0
rotation 0.0 0.0 -1.0 1.57
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 1.0 0.0 0.0
}
}
geometry Cone{
height 0.15
bottomRadius 0.05
}
}
]
}
]
}
]
}
DEF Axis_Y Transform{
children[
Shape {
appearance Appearance {
material Material {
diffuseColor 1.0 1.0 1.0
}
}
geometry IndexedLineSet {
coord Coordinate {
point [
0.0 0.0 0.0, 1.0 0.0 0.0, 0.0 1.0 0.0,
0.0 0.0 1.0
]
}
coordIndex [
0, 2, -1
]
}
}
Transform{
children[
DEF Y_Axis_Sensor PlaneSensor {}
Transform{
translation 0.0 1.0 0.0
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 0.0 1.0 0.0
}
}
geometry Cone{
height 0.15
bottomRadius 0.05
}
}
]
}
]
}
]
}
DEF Axis_Z Transform{
children[
Shape {
appearance Appearance {
material Material {
diffuseColor 1.0 1.0 1.0
}
}
geometry IndexedLineSet {
coord Coordinate {
point [
0.0 0.0 0.0, 1.0 0.0 0.0, 0.0 1.0 0.0,
0.0 0.0 1.0
]
}
coordIndex [
0, 3, -1
]
}
}
Transform{
children[
DEF Z_Axis_Sensor PlaneSensor {}
Transform{
translation 0.0 0.0 1.0
rotation 1.0 0.0 0.0 1.57
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 0.0 0.0 1.0
}
}
geometry Cone{
height 0.15
bottomRadius 0.05
}
}
]
}
]
}
]
}
]
}
]
}
]
}
DEF OUT_MOVE Script {
eventIn SFVec3f translation_X_in
eventIn SFVec3f translation_Y_in
eventIn SFVec3f translation_Z_in
eventOut SFVec3f translation_changed IS translation_changed
field SFVec3f trans 0 0 0
field SFInt32 i 0
url "vrmlscript:
function out() {
Browser.setDescription('INFO: ' + trans[0]+ ' ' + trans[1]+ ' '+
trans[2]);
translation_changed[0]=trans[0];
translation_changed[1]=trans[1];
translation_changed[2]=trans[2];
}
function translation_X_in(val) {
trans[0]=val[0];
out();
}
function translation_Y_in(val) {
trans[1]=val[1];
out();
}
function translation_Z_in(val) {
trans[2]=val[2];
out();
}
"
}
DEF ACTIVATE Script {
eventIn SFBool bool_in
eventOut SFInt32 choice_out
field SFInt32 choice_status -1
url "vrmlscript:
function initialize() {
choice_out=-1;
}
function bool_in(val) {
if (val) {
if (choice_out==1) choice_out=-1;
else choice_out=choice_out+1;
}
}
"
}
# Detect translation
ROUTE X_Axis_Sensor.translation_changed TO
OUT_MOVE.translation_X_in
ROUTE Y_Axis_Sensor.translation_changed TO
OUT_MOVE.translation_Y_in
ROUTE Z_Axis_Sensor.translation_changed TO
OUT_MOVE.translation_Z_in
# give back translation
ROUTE OUT_MOVE.translation_changed TO SPACE.translation
# activate and deactivate Sensor
ROUTE TOUCH.isActive TO ACTIVATE.bool_in
ROUTE ACTIVATE.choice_out TO SWITCH_ALL.whichChoice
}
SpaceSensor {
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 1 0 1
transparency 0.5
}
}
geometry Sphere {
radius 0.5
}
}
]
bboxSize 3 3 3
}
|