problem with WakeupOnCollisionEntry

i am willing to write a simple code with 2 Shape3D objects ( 2 Text3D signs in my case), added 2 Behavior classes, each one connected with one Text3D object respectively. One moves the text on mouse click and i want the other to react when moving text collides with it.

significant pieces of code :

1st Behavior class

publicclass SimpleBehaviorextends Behavior (the one that moves obj1)

{

private TransformGroup targetTG;

private WakeupCriterion wakeupNextFrame;

private Transform3D rotation =new Transform3D();

privatedouble angle = 0.0, x = 0.2, angle2;

SimpleBehavior(TransformGroup targetTG)

{

this.targetTG = targetTG;

wakeupNextFrame =new WakeupOnElapsedFrames(1);

}

publicvoid initialize()

{

//this.wakeupOn(new WakeupOnCollisionEntry(getBounds()));

this.wakeupOn(new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED));

angle = 0.0f;

angle2 = 10;

x = 0.2;

}

publicvoid processStimulus(Enumeration criteria)

{

if (angle < angle2)

{

x = x + 0.01;

angle += x;

rotation.setTranslation(new Vector3d(-angle, 0, 0));

targetTG.setTransform(rotation);

this.wakeupOn(wakeupNextFrame);

}

else

{

//angle = 0;

angle2 = angle2 + 10;

x = 0.2;

this.wakeupOn(new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED));

}

}

}

2nd Behavior class that would use wakeUpOnCollisionEntry criteria

publicclass SimpleBehavior2extends Behavior

{

private TransformGroup targetTG;

private WakeupCriterion wakeupNextFrame;

private Transform3D rotation =new Transform3D();

privatedouble angle = 0.0, x = 0.2, angle2;

SimpleBehavior2(TransformGroup targetTG)

{

this.targetTG = targetTG;

wakeupNextFrame =new WakeupOnElapsedFrames(5);

}

publicvoid initialize()

{

this.wakeupOn(new WakeupOnCollisionEntry(new BoundingSphere()));

angle = 0.0f;

angle2 = 10;

x = 0.2;

}

publicvoid processStimulus(Enumeration criteria)

{

if (angle < angle2)

{

x = x + 0.01;

angle += x;

rotation.setTranslation(new Vector3d(-angle, 0, 0));

targetTG.setTransform(rotation);

this.wakeupOn(wakeupNextFrame);

}

else

{

angle2 = angle2 + 10;

x = 0.2;

this.wakeupOn(new WakeupOnCollisionEntry(new BoundingSphere()));

}

}

}

how can i rewrite the second class to react the way i want to ?

really appreciate any help, can throw more code in if neccesary

Best regards, Lukasz

[4721 byte] By [Koniecznya] at [2007-10-3 11:35:52]
# 1

This code highlights a shape when another shape collides with it.

regards

class CollisionDetector extends Behavior {

private static final Color3f highlightColor = new Color3f(0.0f, 1.0f, 0.0f);

private static final ColoringAttributes highlight = new ColoringAttributes(

highlightColor, ColoringAttributes.SHADE_GOURAUD);

private boolean inCollision = false;

private Shape3D shape;

private ColoringAttributes shapeColoring;

private Appearance shapeAppearance;

private WakeupOnCollisionEntry wEnter;

private WakeupOnCollisionExit wExit;

public CollisionDetector(Shape3D s) {

shape = s;

shapeAppearance = shape.getAppearance();

shapeColoring = shapeAppearance.getColoringAttributes();

inCollision = false;

}

public void initialize() {

wEnter = new WakeupOnCollisionEntry(shape);

wExit = new WakeupOnCollisionExit(shape);

wakeupOn(wEnter);

}

public void processStimulus(Enumeration criteria) {

inCollision = !inCollision;

if (inCollision) {

shapeAppearance.setColoringAttributes(highlight);

wakeupOn(wExit);

} else {

shapeAppearance.setColoringAttributes(shapeColoring);

wakeupOn(wEnter);

}

}

}

messengersa at 2007-7-15 14:03:58 > top of Java-index,Security,Cryptography...
# 2

i copied that code, added :

textShape2.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);

textShape2.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);

textShape2.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);

textShape2.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);

where textShape2 is the object i want to higlight

but i am getting exceptions

Exception occurred during Behavior execution:

javax.media.j3d.CapabilityNotSetException: Appearance: no capability to set coloringAttributes

at javax.media.j3d.Appearance.setColoringAttributes(Appearance.java:362)

at Tlo3D$SimpleBehavior2.processStimulus(Tlo3D.java:298)

at javax.media.j3d.BehaviorScheduler.doWork(BehaviorScheduler.java:172)

at javax.media.j3d.J3dThread.run(J3dThread.java:250)

what causes such things ?

regards, Lukasz

Message was edited by:

Konieczny

null

Koniecznya at 2007-7-15 14:03:58 > top of Java-index,Security,Cryptography...