At 15:03 07/06/99 -0400, you wrote:
>
>All--
>
> I've noticed that there's a lot of trouble out there with collision
>detection and the 3D API and have gone through several different
>possibilities trying to figure this out. I've had significant trouble
>with this myself for anything but the simplest 3D shapes. Initially, I
>had a 3D object composed of Primitive subclasses (Cylinder, Cone, etc...)
>and couldn't ever get collision detection working on those shapes (whether
>as standalone shapes or composed together in some more complex object).
>
I've had similar problems Edward - though I haven't tried complex shapes
yet. The trouble with collision detection is it is ****ed hard to do.
Just llok at some of the algorithms out there for it. I suspect that if we
want decent CD then we'll need to look at V-Clip, I-Collide, RAPID etc and
none of those have been ported to Java yet (though I just might do it for
V-Clip). The J3D collision detection just doesn't provide enough info to
be really useful except in the VRML collision detection sense (which is
probably where it came from).
As far as collision detection with primitives goes, it is do-able, 'cos
I've done it although only between a sphere as a Primitive and a Box cast
into Shape3D (the sphere wasn't). It did need a couple of changes from the
example collider:
The ball was a snookerBall class, extending TransformGroup:
public snookerBall(double xpos, double ypos, double zpos, double rad){
t.set(1, new Vector3d(xpos, ypos, zpos));
setTransform(t);
setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
M.setCapability(Material.ALLOW_COMPONENT_WRITE);
app.setMaterial(M);
// alt to shape3D for ch1 - 1 line but needs collider changed too & setCap
type change
Primitive ch1 = new Sphere((float)rad, Sphere.GENERATE_NORMALS |
Sphere.GENERATE_TEXTURE_COORDS, 20, app);
ch1.setCapability(Primitive.ALLOW_COLLISION_BOUNDS_READ);
ch1.setCapability(Primitive.ALLOW_COLLISION_BOUNDS_WRITE);
BoundingSphere bs = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), rad*2);
ch1.setCollisionBounds(bs);
addChild(ch1);
//collision detection
collider cd = new collider(ch1, this);
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
100.0);
cd.setSchedulingBounds(bounds);
addChild(cd);
// now for the physics values; velocity already set to zero;
radius = rad;
height = ypos;
}
and the collider behaviour:
public class collider extends Behavior {
private boolean inCollision = false;
private WakeupOnCollisionEntry wEnter;
private WakeupOnCollisionExit wExit;
private WakeupOnElapsedTime wElapsed;
private WakeupCriterion[] wInTime;
private WakeupCriterion[] wOutTime;
private snookerBall p;
private Node shape;
public collider (Node s, snookerBall daddy) {
p = daddy;
shape = s;
inCollision = false;
System.out.print("Collider Created ... ");
}
public void initialize() {
wEnter = new WakeupOnCollisionEntry(shape);
wExit = new WakeupOnCollisionExit(shape);
wElapsed = new WakeupOnElapsedTime(5);
wInTime = new WakeupCriterion[2];
wInTime[0] = wEnter;
wInTime[1] = wElapsed;
wOutTime = new WakeupCriterion[2];
wOutTime[0] = wExit;
wOutTime[1] = wElapsed;
wakeupOn(new WakeupOr(wInTime));
System.out.println("Initialized");
}
etc...
Hope this is of some use. I've got the complete files if you want them,
and refs to some collision detection systems.
Tony
=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/