Skip to main content

Help in Java 3D

1 reply [Last post]
Raicho
Offline
Joined: 2006-02-17

I'm having a lot of trouble trying to change the appearance every time I try to touch a cone here's the code =\
/**
* addCones
* Adds cones to the scene.
* The position, orientation and appearance of the cones are hardcoded
* here.
*/

private void addCones(BranchGroup objRoot) {
cones_ = new Vector();
for (int i = 0; i < 4; i++) {
Cones cone = new Cones(i);
switch (i) {
case 0:
cone.setPosition(new Vector3d(3d, 0, -3d));
cone.setAppearance(new Appearances(Appearances.red));
break;
case 1:
cone.setPosition(new Vector3d(-3d, 0, -3d));
cone.setAppearance(new Appearances(Appearances.yellow));
break;
case 2:
cone.setPosition(new Vector3d(-3d, 0, 3d));
cone.setAppearance(new Appearances(Appearances.aqua));
break;
case 3:
cone.setPosition(new Vector3d(3d, 0, 3d));
cone.setAppearance(new Appearances(Appearances.purple));
break;
}
cones_.add(cone);
objRoot.addChild(cone);
}
}
/**
* Handles events sent by the KeyboardBehavior.
*/
public void keyPressed(KeyPressedEvent keyPressedEvent) {
switch(keyPressedEvent.getKey()) {
case KeyPressedEvent.LEFT:
car_.turnLeft();
break;
case KeyPressedEvent.RIGHT:
car_.turnRight();
break;
case KeyPressedEvent.UP:
car_.goForward();
break;
case KeyPressedEvent.DOWN:
car_.goBack();
break;
}
vpTrans_.setTransform(car_);
getVectors(car_.getPos()); // Here's where I send the cubes position to check if it collides a cone to then change it's appearance
}

/**
* Get cone Vectors
*/
private void getVectors(Vector3d vec) {
Enumeration e = cones_.elements();
while (e.hasMoreElements()) {
Cones c = (Cones)e.nextElement();
if (c != null) {
Point3d p1 = new Point3d(c.getPosition());
Point3d p2 = new Point3d(vec);
if(p1.distance(p2) <= 1) {
if (c != null)
c.setAppearance(new Appearances(Appearances.white));
}
}
}

however every time I run it I get this ....

C:\Documents and Settings\Admin.FROZEN-THRONE\Desktop\TinyNetVE\TinyNetVEv.5>cd
src

C:\Documents and Settings\Admin\Desktop\TinyNetVE\TinyNetVEv.5\src
>java scene3D/SharedCubes 0
User: 0
Exception occurred during Behavior execution:
javax.media.j3d.CapabilityNotSetException: Shape3D: no capability to set appeara
nce
at javax.media.j3d.Shape3D.setAppearance(Shape3D.java:472)
at scene3D.Cones.setAppearance(Cones.java:65)
at scene3D.SharedCubes.getVectors(SharedCubes.java:329)
at scene3D.SharedCubes.keyPressed(SharedCubes.java:197)
at devices.KeyboardBehavior.fireKeyPressedEvent(KeyboardBehavior.java:94
)
at devices.KeyboardBehavior.processStimulus(KeyboardBehavior.java:54)
at javax.media.j3d.BehaviorScheduler.doWork(BehaviorScheduler.java:172)
at javax.media.j3d.J3dThread.run(J3dThread.java:250)

I uploaded the program here http://www.freewebs.com/cubitrix/TinyNetVEv.zip

Any help appreciated.. or more like please help me =(

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Mike Pilone

Hello,

As the exception states, you need to set the capability to allow the
appearance to be changed once the object is in the scene.

Something like:
ConeShape.setCapability(Cone.ALLOW_APPEARANCE_WRITE).

Hope that helps,
-mike

-----Original Message-----
From: java3d-interest@javadesktop.org
[mailto:java3d-interest@javadesktop.org]
Sent: Thursday, October 28, 2004 6:24 PM
To: interest@java3d.dev.java.net
Subject: [JAVA3D-INTEREST] Help in Java 3D

I'm having a lot of trouble trying to change the appearance every time I try
to touch a cone here's the code =\
/**
* addCones
* Adds cones to the scene.
* The position, orientation and appearance of the cones are hardcoded
* here.
*/

private void addCones(BranchGroup objRoot) {
cones_ = new Vector();
for (int i = 0; i < 4; i++) {
Cones cone = new Cones(i);
switch (i) {
case 0:
cone.setPosition(new Vector3d(3d, 0, -3d));
cone.setAppearance(new
Appearances(Appearances.red));
break;
case 1:
cone.setPosition(new Vector3d(-3d, 0, -3d));
cone.setAppearance(new
Appearances(Appearances.yellow));
break;
case 2:
cone.setPosition(new Vector3d(-3d, 0, 3d));
cone.setAppearance(new
Appearances(Appearances.aqua));
break;
case 3:
cone.setPosition(new Vector3d(3d, 0, 3d));
cone.setAppearance(new
Appearances(Appearances.purple));
break;
}
cones_.add(cone);
objRoot.addChild(cone);
}
}
/**
* Handles events sent by the KeyboardBehavior.
*/
public void keyPressed(KeyPressedEvent keyPressedEvent) {
switch(keyPressedEvent.getKey()) {
case KeyPressedEvent.LEFT:
car_.turnLeft();
break;
case KeyPressedEvent.RIGHT:
car_.turnRight();
break;
case KeyPressedEvent.UP:
car_.goForward();
break;
case KeyPressedEvent.DOWN:
car_.goBack();
break;
}
vpTrans_.setTransform(car_);
getVectors(car_.getPos()); // Here's where I send the cubes position
to check if it collides a cone to then change it's appearance
}

/**
* Get cone Vectors
*/
private void getVectors(Vector3d vec) {
Enumeration e = cones_.elements();
while (e.hasMoreElements()) {
Cones c = (Cones)e.nextElement();
if (c != null) {
Point3d p1 = new Point3d(c.getPosition());
Point3d p2 = new Point3d(vec);
if(p1.distance(p2) <= 1) {
if (c != null)
c.setAppearance(new Appearances(Appearances.white));

}
}
}

however every time I run it I get this ....

C:\Documents and
Settings\Admin.FROZEN-THRONE\Desktop\TinyNetVE\TinyNetVEv.5>cd
src

C:\Documents and Settings\Admin\Desktop\TinyNetVE\TinyNetVEv.5\src
>java scene3D/SharedCubes 0
User: 0
Exception occurred during Behavior execution:
javax.media.j3d.CapabilityNotSetException: Shape3D: no capability to set
appeara
nce
at javax.media.j3d.Shape3D.setAppearance(Shape3D.java:472)
at scene3D.Cones.setAppearance(Cones.java:65)
at scene3D.SharedCubes.getVectors(SharedCubes.java:329)
at scene3D.SharedCubes.keyPressed(SharedCubes.java:197)
at
devices.KeyboardBehavior.fireKeyPressedEvent(KeyboardBehavior.java:94
)
at
devices.KeyboardBehavior.processStimulus(KeyboardBehavior.java:54)
at
javax.media.j3d.BehaviorScheduler.doWork(BehaviorScheduler.java:172)
at javax.media.j3d.J3dThread.run(J3dThread.java:250)

I uploaded the program here http://www.freewebs.com/cubitrix/TinyNetVEv.zip

Any help appreciated.. or more like please help me =(
---
[Message sent by forum member 'Raicho' (Raicho)]

http://www.javadesktop.org/forums/thread.jspa?messageID=35657&#35657

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net