Hi everyone:
Recently, I tried to draw Bezier curves in Java3D. I got many problems. Since I have
no experimence coding in Java3D, it's very difficult for me to find the solution. Can
anyone help me?
Problem 1: I want to draw a new point on the cursor position when I click left mouse
button. The code I wrote are like this:
public class PickDragBehavior extends Behavior {
....
public void processStimulus (Enumeration criteria) {
...
if (id == MouseEvent.MOUSE_PRESSED) {
x=((MouseEvent)event[i]).getX(); y=((MouseEvent)event[i]).getY();
Point3d mousePos = new Point3d();
canvas3D.getPixelLocationInImagePlate(x, y, mousePos);
Sphere point = new Sphere(0.02f);
Transform3D pointPos = new Transform3D();
pointPos.setTranslation(new Vector3f((float)mousePos.x, (float)mousePos.y,
(float)mousePos.z));
TransformGroup pointGroup = new TransformGroup(pointPos);
pointGroup.addChild(point);
tg.addChild(pointGroup);//tg is the tranform group passed in
...}
I got this error message:
"Exception occurred during Behavior execution:
javax.media.j3d.RestrictedAccessException: Group : only a BranchGroup node may be
added".
Problem 2: I displyed a curve with 4 control points on the screen. Then I want to move
one point with right mouse button, and display the curve again. The code I wrote are
like this:
public class MyBehavior extends Behavior {
...
public void processStimulus (Enumeration criteria) {
...
if (id == MouseEvent.MOUSE_DRAGGED && !((MouseEvent)event[i]).isAltDown() &&
((MouseEvent)event[i]).isMetaDown()) {
x=((MouseEvent)event[i]).getX();y=((MouseEvent)event[i]).getY();
...//get current eye&mouse position to define a pick ray...
pickRay.set(mousePos, mouseVec);
sceneGraphPath = branchGroup.pickAllSorted(pickRay);
if (sceneGraphPath != null) {
for (int j=0; j<sceneGraphPath.length; j++) {
if (sceneGraphPath[j] != null) {
Node node = sceneGraphPath[j].getObject();
if (node instanceof Shape3D) { myPoint p= (myPoint)node;
p.setPosition(mousePos);//change the point position
myCurve.updateGeometry(points);//redraw the curve
...}
There are no error messages this time, but the point I picked doesn't move, and the
curve disappears.
I know there are lots of errors in my code. Can anyone give me some advise to solve
the problems? or some example codes would be very helpful.
Thanks
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".