⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pickinfo.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * $RCSfile: PickInfo.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.11 $ * $Date: 2007/04/12 17:34:05 $ * $State: Exp $ */package javax.media.j3d;import javax.vecmath.*;import java.util.*;/** * The PickInfo object contains the computed information about a pick hit.   * The detailed information about each intersection of the PickShape  * with the picked Node can be inquired.  The PickInfo object is constructed with * basic information and more detailed information can be generated by setting the * appropriate mask to the flag argument in the pick methods of BranchGroup and  * Locale. * <p> * * @see Locale * @see BranchGroup  * * @since Java 3D 1.4 */public class PickInfo extends Object {        static final int PICK_ALL = 1;    static final int PICK_ANY = 2;    /* The SceneGraphPath of the intersected pickable item */    private SceneGraphPath sgp;    /* The intersected pickable node object */    private  Node node;        /* A copy of LocalToVworld transform of the pickable node */    private Transform3D l2vw;    /* The closest intersection point */    private Point3d closestIntersectionPoint;     /* Distance between start point of pickShape and closest intersection point */    private double  closestDistance;    /* An array to store intersection results */    private IntersectionInfo[] intersectionInfoArr;        /* The following references are for internal geometry computation use only */    private ArrayList intersectionInfoList = new ArrayList();    private boolean intersectionInfoListSorted = false;    private Transform3D l2vwRef;    private Node nodeRef;        /**     * Specifies a Pick using the bounds of the pickable nodes.     */    public static final int PICK_BOUNDS = 1;        /**     * Specifies a Pick using the geometry of the pickable nodes.     */    public static final int PICK_GEOMETRY = 2;        /**   * Specifies that this PickInfo returns the computed SceneGraphPath object.   */    public static final int SCENEGRAPHPATH  = 0x01;        /**     * Specifies that this PickInfo returns the computed intersected Node object.     */    public static final int NODE = 0x02;        /**     * Specifies that this PickInfo returns the computed local to vworld transform.     */    public static final int LOCAL_TO_VWORLD = 0x04;        /**     * Specifies that this PickInfo returns the closest intersection point.     */    public static final int CLOSEST_INTERSECTION_POINT = 0x08;    /**     * Specifies that this PickInfo returns the closest intersection distance.     */    public static final int CLOSEST_DISTANCE = 0x10;    /**     * Specifies that this PickInfo returns only the closest intersection      * geometry information.     */    public static final int CLOSEST_GEOM_INFO = 0x20;    /**     * Specifies that this PickInfo returns all the closest intersection      * geometry informations.     */    public static final int ALL_GEOM_INFO = 0x40;    /** PickInfo Constructor */    PickInfo() {    }        void setSceneGraphPath(SceneGraphPath sgp) {        this.sgp = sgp;    }        void setNode(Node node) {        this.node = node;    }        void setLocalToVWorld(Transform3D l2vw) {        this.l2vw = l2vw;    }        void setClosestIntersectionPoint(Point3d cIPt) {        this.closestIntersectionPoint = cIPt;    }        void setClosestDistance(double cDist) {        this.closestDistance = cDist;    }        void setLocalToVWorldRef(Transform3D l2vwRef) {        this.l2vwRef = l2vwRef;    }        void setNodeRef(Node nodeRef) {        this.nodeRef = nodeRef;    }        IntersectionInfo createIntersectionInfo() {        return new IntersectionInfo();    }        void insertIntersectionInfo(IntersectionInfo iInfo) {        intersectionInfoList.add(iInfo);        intersectionInfoListSorted = false;    }        void sortIntersectionInfoArray(IntersectionInfo[] iInfoArr) {        class Sort {	    	    IntersectionInfo iInfoArr[];	    Sort(IntersectionInfo[] iInfoArr) {                // System.err.println("Sort IntersectionInfo ...");		this.iInfoArr = iInfoArr;	    }	    void sorting() {		if (iInfoArr.length < 7) {                    // System.err.println(" -- insertSort.");		    insertSort();	    	} else {                    // System.err.println(" -- quicksort.");                    		    quicksort(0, iInfoArr.length-1);    		}	    }	    // Insertion sort on smallest arrays	    final void insertSort() {		for (int i=0; i<iInfoArr.length; i++) {		    for (int j=i; j>0 &&                              (iInfoArr[j-1].distance > iInfoArr[j].distance); j--) {			IntersectionInfo iInfo = iInfoArr[j];			iInfoArr[j] = iInfoArr[j-1];			iInfoArr[j-1] = iInfo;		    }		}	    }            final void quicksort( int l, int r ) {		int i = l;		int j = r;		double k = iInfoArr[(l+r) / 2].distance;		do {		    while (iInfoArr[i].distance<k) i++;		    while (k<iInfoArr[j].distance) j--;		    if (i<=j) {						IntersectionInfo iInfo = iInfoArr[i];			iInfoArr[i] = iInfoArr[j];			iInfoArr[j] = iInfo;			i++;			j--;		    }		} while (i<=j);				if (l<j) quicksort(l,j);		if (l<r) quicksort(i,r);	    }	}	(new Sort(iInfoArr)).sorting();                    intersectionInfoListSorted = true;    }    static void sortPickInfoArray(PickInfo[] pickInfoArr) {            class Sort {	    	    PickInfo pIArr[];	    Sort(PickInfo[] pIArr) {                // System.err.println("Sort PickInfo ...");		this.pIArr = pIArr;	    }	    void sorting() {		if (pIArr.length < 7) {                    // System.err.println(" -- insertSort.");		    insertSort();	    	} else {                    // System.err.println(" -- quicksort.");                    		    quicksort(0, pIArr.length-1);    		}	    }	    // Insertion sort on smallest arrays	    final void insertSort() {		for (int i=0; i<pIArr.length; i++) {		    for (int j=i; j>0 &&                              (pIArr[j-1].closestDistance > pIArr[j].closestDistance); j--) {			PickInfo pI = pIArr[j];			pIArr[j] = pIArr[j-1];			pIArr[j-1] = pI;		    }		}	    }            final void quicksort( int l, int r ) {		int i = l;		int j = r;		double k = pIArr[(l+r) / 2].closestDistance;		do {		    while (pIArr[i].closestDistance<k) i++;		    while (k<pIArr[j].closestDistance) j--;		    if (i<=j) {						PickInfo pI = pIArr[i];			pIArr[i] = pIArr[j];			pIArr[j] = pI;			i++;			j--;		    }		} while (i<=j);				if (l<j) quicksort(l,j);		if (l<r) quicksort(i,r);	    }	}	(new Sort(pickInfoArr)).sorting();                    }        /**     * Retrieves the reference to the SceneGraphPath in this PickInfo object.     * @return the SceneGraphPath object, or null if  flag is not set with SCENEGRAPHPATH.     * @see Locale     * @see BranchGroup     */    public SceneGraphPath getSceneGraphPath() {	return sgp;    }    /**     * Retrieves the reference to the picked node, either a Shape3D or a Morph, in this PickInfo object.     * @return the picked leaf node object, or null if  flag is not set with NODE.     * @see Locale     * @see BranchGroup     */    public Node getNode() {	return node;    }    /**     * Retrieves the reference to the LocalToVworld transform of the picked node in this PickInfo object.     * @return the local to vworld transform, or null if  flag is not set with LOCAL_TO_VWORLD.     * @see Locale     * @see BranchGroup     */    public Transform3D getLocalToVWorld() {	return l2vw;    }	    /**     * Retrieves the reference to the closest intersection point in this PickInfo object.     * @return the closest intersection point, or null if  flag is not set with CLOSEST_INTERSECTION_POINT.     * @see Locale     * @see BranchGroup     */    public Point3d getClosestIntersectionPoint() {	return closestIntersectionPoint;    }    /**     * Retrieves the distance between the start point of the pickShape and the closest intersection point.     * @return the closest distance in double, or NaN if  flag is not set with CLOSEST_INTERSECTION_POINT.     * Note : If this PickInfo object is returned by either pickClosest or pickAllSorted method, the return     * value is the closest distance in double even if flag is not set with CLOSET_INTERSECTION_POINT.     * @see Locale     * @see BranchGroup     */    public double getClosestDistance() {	return closestDistance;    }    Transform3D getLocalToVWorldRef() {        return l2vwRef;    }        Node getNodeRef() {        return nodeRef;    }        /**     * Retrieves the reference to the array of intersection results in this PickInfo object.     * @return an array of 1 IntersectionInfo object if flag is to set  CLOSEST_GEOM_INFO,     * or an array of <i>N</i> IntersectionInfo objects containing all intersections of      * the picked node in sorted order if flag is to set ALL_GEOM_INFO, or null if neither      * bit is set.     * @see Locale     * @see BranchGroup     */    public IntersectionInfo[] getIntersectionInfos() {        if (intersectionInfoListSorted == false) {            intersectionInfoArr = new IntersectionInfo[intersectionInfoList.size()];            intersectionInfoArr =                    (IntersectionInfo []) intersectionInfoList.toArray(intersectionInfoArr);                        sortIntersectionInfoArray(intersectionInfoArr);                             }                return intersectionInfoArr;    }         /**     * Search the path from nodeR up to Locale.     * Return the search path as ArrayList if found.     * Note that the locale will not insert into path.     */    static ArrayList initSceneGraphPath(NodeRetained nodeR) { 	ArrayList path = new ArrayList(5);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -