At 01:24 AM 5/3/99 PDT, you wrote:
>Hello folks,
>
>I have to pick all objects in a canvas3D with a single mouse click or an
>argument like that follows
>
>Can anybody help me?
>
>Regrads,
>
>Yadav.
>
>
>______________________________________________________
>Get Your Private, Free Email at http://www.hotmail.com
>=====================================================================
>To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
>Java 3D Home Page: http://java.sun.com/products/java-media/3D/
>
Try using the BoundingPolytope to create a viewing volume and based on the
dimensions
of your Canvas3D and pick using that BoundingObject. Here is a method that
that creates a BoundingPolytope (It is in a class that inherits from
Canvas3D). I can't remember if the
Perspective projection works.
protected BoundingPolytope getFrustrum(int upLeftPixX, int upLeftPixY, int
downRightPixX, int downRightPixY){
boolean perspective;
if (getView().getProjectionPolicy() == View.PERSPECTIVE_PROJECTION){
perspective = true;
}
else{ // Orthographic_projection
perspective = false;
}
Point3d centerEye = new Point3d();
Point3d centerImage = new Point3d();
Point3d upLeft = new Point3d();
Point3d upRight = new Point3d();
Point3d downLeft = new Point3d();
Point3d downRight = new Point3d();
Transform3D t = new Transform3D();
Vector3d v1 = new Vector3d();
Vector3d v2 = new Vector3d();
Vector3d normal = new Vector3d();
Vector4d[] planes = new Vector4d[6];
getCenterEyeInImagePlate(centerEye);
getImageCenterInImagePlate(centerImage);
//getPixelLocationInImagePlate(getWidth()/2, getHeight()/2,
centerImage);
getPixelLocationInImagePlate(upLeftPixX, upLeftPixY, upLeft);
getPixelLocationInImagePlate(downRightPixX, upLeftPixY, upRight);
getPixelLocationInImagePlate(upLeftPixX, downRightPixY, downLeft);
getPixelLocationInImagePlate(downRightPixX, downRightPixY, downRight);
getImagePlateToVworld(t);
t.transform(centerEye);
t.transform(centerImage);
t.transform(upLeft);
t.transform(upRight);
t.transform(downLeft);
t.transform(downRight);
// System.out.println("pickbox upLeft "+upLeft);
// System.out.println("pickbox upRight "+upRight);
// System.out.println("pickbox downLeft "+downLeft);
// System.out.println("pickbox downRight "+downRight);
// top plane
if (perspective){
v1.sub(upRight,centerEye);
v2.sub(upLeft,centerEye);
normal.cross(v1,v2);
planes[0] = new Vector4d(normal.x, normal.y, normal.z,
-(normal.x *
upRight.x + normal.y * upRight.y + normal.z * upRight.z));
}
else{
v1.sub(centerImage,centerEye);
v2.sub(upRight, upLeft);
normal.cross(v2,v1);
planes[0] = new Vector4d(normal.x, normal.y, normal.z,
-(normal.x *
upRight.x + normal.y * upRight.y + normal.z * upRight.z));
}
// left plane
if (perspective){
v1.sub(upLeft,centerEye);
v2.sub(downLeft,centerEye);
normal.cross(v1,v2);
planes[1] = new Vector4d(normal.x, normal.y, normal.z,
-(normal.x *
upLeft.x + normal.y * upLeft.y + normal.z * upLeft.z));
}
else{
v1.sub(centerImage,centerEye);
v2.sub(upLeft, downLeft);
normal.cross(v2,v1);
planes[1] = new Vector4d(normal.x, normal.y, normal.z,
-(normal.x *
upLeft.x + normal.y * upLeft.y + normal.z * upLeft.z));
}
// right plane
if (perspective){
v1.sub(downRight,centerEye);
v2.sub(upRight,centerEye);
normal.cross(v1,v2);
planes[2] = new Vector4d(normal.x, normal.y, normal.z,
-(normal.x *
downRight.x + normal.y * downRight.y + normal.z * downRight.z));
}
else{
v1.sub(centerImage,centerEye);
v2.sub(downRight, upRight);
normal.cross(v2,v1);
planes[2] = new Vector4d(normal.x, normal.y, normal.z,
-(normal.x *
downRight.x + normal.y * downRight.y + normal.z * downRight.z));
}
// bottom plane
if (perspective){
v1.sub(downLeft,centerEye);
v2.sub(downRight,centerEye);
normal.cross(v1,v2);
planes[3] = new Vector4d(normal.x, normal.y, normal.z,
-(normal.x *
downLeft.x + normal.y * downLeft.y + normal.z * downLeft.z));
}
else{
v1.sub(centerImage,centerEye);
v2.sub(downLeft, downRight);
normal.cross(v2,v1);
planes[3] = new Vector4d(normal.x, normal.y, normal.z,
-(normal.x *
downLeft.x + normal.y * downLeft.y + normal.z * downLeft.z));
}
// front
v1.sub(upRight, downRight);
v2.sub(upLeft, downRight);
normal.cross(v1,v2);
planes[4] = new Vector4d(normal.x, normal.y, normal.z, -(normal.x *
centerEye.x + normal.y * centerEye.y + normal.z * centerEye.z));
// back
normal.negate();
v1.sub(centerImage, centerEye);
v1.normalize();
v1.scale(SceneDimensions.WORLD_SPHERE_DIAMETER*2.0);
planes[5] = new Vector4d(normal.x, normal.y, normal.z, -(normal.x *
v1.x
+ normal.y * v1.y + normal.z * v1.z));
return new BoundingPolytope(planes);
}
=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/