This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > VRML > July 2005 > Identify wich object was clicked - x3d





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Identify wich object was clicked - x3d
nunomartins01

2005-07-03, 7:38 pm

Hello!

I'm triyng to diferenciate which object I have selecter in a x3d scene,

but not using buttons, simply click in the object.

I'm using 2 objects and 2 touch sensors.

I have a variable (sensor) thar I'm triyng to modify to identify if it
is selected
the object 1 (sensor=1), or the object 2 (sensor=2).

This is the problem, I don't know how to atribute the values to this
variable...

I have the code below...

Can anyone help me, this or other way ?

Thanks
Nuno

//-------------- TOUCH SENSOR 1 ---------------------

// Find the TouchSensor named TOUCH_SENSOR
X3DNode touch = mainScene.getNamedNode("TS");
if (touch == null) {
System.out.println("Couldn't find TouchSensor named: TS");
return;
}

SFTime ttime = (SFTime) touch.getField("touchTime");
// Listen for changes on the touchTime field
ttime.addX3DEventListener(this);



//-------------- TOUCH SENSOR 2 ---------------------

// Find the TouchSensor named TOUCH_SENSOR
X3DNode touch2 = mainScene.getNamedNode("TS2");
if (touch2 == null) {
System.out.println("Couldn't find TouchSensor named: TS2");
return;
}

SFTime ttime2 = (SFTime) touch2.getField("touchTime");

// Listen for changes on the touchTime field
ttime2.addX3DEventListener(this);

}

// -------------------------------------------------------

public void readableFieldChanged(X3DFieldEvent evt) {

if (sensor==1){
System.out.println("object 1 clicked");
}
else if (sensor==2){

System.out.println("Object 2 clicked");

}

}

Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews