On my Scene, there is a Fountain animation which works, but I only want to add it to the scene once I detect a collision. My collision detection happens in KeyControl.java
Any idea how can I add this Child from another java class if the condition is met?
Main.java Main file with all objects
...
TransformGroup objSpin = new TransformGroup();
objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Transform3D tr21 = new Transform3D();
tr21.setTranslation(new Vector3f(0.75f, 0.35f, 0.2f));
tr21.setScale(0.2f);
TransformGroup tg21 = new TransformGroup(tr21);
tg21.addChild(objSpin);
root.addChild(tg21);
// a bounding sphere specifies a region a behavior is active
// create a sphere centered at the origin with radius of 1
BoundingSphere bounds = new BoundingSphere();
Fountain fountain = new Fountain();
objSpin.addChild(fountain);
Behavior waterBehavior = fountain.getWaterBehavior();
waterBehavior.setSchedulingBounds(bounds);
root.addChild(waterBehavior);
...
KeyControl.java Allows to move object and detect collision
...
} else if (wakeupCriterion instanceof WakeupOnCollisionEntry) {
collision = true;
System.out.println("WakeupOnCollisionEntry");
// Collision Detected
} else if (wakeupCriterion instanceof WakeupOnCollisionExit) {
collision = false;
System.out.println("WakeupOnCollisionExit");
}
...
