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

📄 transformgroupretained.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * $RCSfile: TransformGroupRetained.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.10 $ * $Date: 2007/04/23 18:44:29 $ * $State: Exp $ */package javax.media.j3d;import java.util.ArrayList;/** * Group node that contains a transform. */class TransformGroupRetained extends GroupRetained implements TargetsInterface{    /**     * The Transform value for the TransformGroup.     */    Transform3D transform = new Transform3D();    /**     * The inverse of the transform     */    Transform3D invTransform = null;    /**     * The transpose of the inverse of the transform     */    Transform3D normalTransform = null;    /**     * The Transform value currently being used internally     */    Transform3D currentTransform = new Transform3D();    /**     * localVworld values for children of this TG     */    Transform3D[][] childLocalToVworld = null;    int[][] 	    childLocalToVworldIndex = null;    // working variable for children transforms    Transform3D[][] childTrans = null;    int[][] 	    childTransIndex = null;    /**     * A bitmask of the types in targets     */    int localTargetThreads = 0;    // combined localTargetThreads and decendants' localTargetThreads    int targetThreads = 0;    /**     * A list of WakeupOnTransformChange conditions for this Transform     */    WakeupIndexedList transformChange = null;    // The current list of child transform group nodes or link nodes    // under a transform group    ArrayList childTransformLinks = new ArrayList(1);    // working area while compile    boolean needNormalsTransform = false; // true if normals transformation					  // is needed to push this					  // transform down to geometry        // key which identifies a unique path from a    // locale to this transform group    HashKey currentKey = new HashKey();    boolean aboveAViewPlatform = false;    // maximum transform level of all shared path    int maxTransformLevel = -1;    // List of transform level, one per shared path    int transformLevels[] = null;    // J3d copy.    CachedTargets[] j3dCTs = null;    // User copy.    CachedTargets[] cachedTargets = null;    // Contains per path data, XXXX: move to NodeRetained    TransformGroupData[] perPathData = null;    /**     * The constructor     */    TransformGroupRetained() {        this.nodeType = NodeRetained.TRANSFORMGROUP;    }  /**   * Sets the transform component of this TransformGroup to the value of   * the passed transform.   * @param t1 the transform to be copied   */  void setTransform(Transform3D t1) {      J3dMessage tchangeMessage = null;      int i, j;      Transform3D trans = null;          if (staticTransform != null) {	  // this writeable transformGroup has a static transform	  // merged into this node      	  trans = new Transform3D(staticTransform.transform);	  trans.mul(t1);      	  transform.setWithLock(trans);      } else {      	  trans = new Transform3D(t1);      	  transform.setWithLock(t1);      }      if (transformChange != null) {	  notifyConditions();      }      if (source.isLive()) {	  if (aboveAViewPlatform && !t1.isCongruent()) {	      throw new BadTransformException(J3dI18N.getString("ViewPlatformRetained0"));	  }	  tchangeMessage = new J3dMessage();	  tchangeMessage.type = J3dMessage.TRANSFORM_CHANGED;	  tchangeMessage.threads = targetThreads;	  tchangeMessage.args[1] = this;	  tchangeMessage.args[2] = trans;	  tchangeMessage.universe = universe;	  //System.err.println("TransformGroupRetained --- TRANSFORM_CHANGED " + this);	  VirtualUniverse.mc.processMessage(tchangeMessage);      }      dirtyBoundsCache();  }    /**     * Copies the transform component of this TransformGroup into     * the passed transform object.     * @param t1 the transform object to be copied into     */    void getTransform(Transform3D t1) {	transform.getWithLock(t1);        // if staticTransform exists for this node, need to        // redetermine the original user specified transform        if (staticTransform != null) {            Transform3D invTransform = staticTransform.getInvTransform();            t1.mul(invTransform, t1);        }    }    // get the inverse of the transform -- note: this method only    // supports static transform    Transform3D getInvTransform() {        if (invTransform == null) {            invTransform = new Transform3D(transform);            invTransform.invert();        }	return invTransform;    }    // get the inverse of the transpose -- note: this method only    // supports static transform, the translation component will     // not transform     Transform3D getNormalTransform() {	if (normalTransform == null) {            normalTransform = new Transform3D(transform);	    normalTransform.invert();	    normalTransform.transpose();        }	return normalTransform;    }    // synchronized with TransformStructure    synchronized void setNodeData(SetLiveState s) {	int i;        super.setNodeData(s);        childTrans = new Transform3D[s.currentTransforms.length][2];        childTransIndex = new int[s.currentTransforms.length][2];        for (i=0; i< s.currentTransforms.length; i++) {            childTrans[i][0] = new Transform3D();            childTrans[i][0].mul(s.currentTransforms[i]                                   [s.currentTransformsIndex[i]                                   [CURRENT_LOCAL_TO_VWORLD]], currentTransform);            childTrans[i][1] = new Transform3D(childTrans[i][0]);            childTransIndex[i][0] = 0;            childTransIndex[i][1] = 0;        }        if (!s.inSharedGroup) {            s.transformLevels[0] += 1;            maxTransformLevel = s.transformLevels[0];        } else {            for (i=0; i<s.keys.length; i++) {                s.transformLevels[i] += 1;                if (s.transformLevels[i] > maxTransformLevel) {                    maxTransformLevel = s.transformLevels[i];                }            }        }	if (!inSharedGroup) {	    if (childLocalToVworld == null) {		// If the node is a transformGroup then need to keep		// the child transforms as well		childLocalToVworld = new Transform3D[1][];		childLocalToVworldIndex = new int[1][];		transformLevels = new int[1];		// Use by TransformStructure                cachedTargets = new CachedTargets[1];                perPathData = new TransformGroupData[1];	    }	    childLocalToVworld[0] = childTrans[0];	    childLocalToVworldIndex[0] = childTransIndex[0];            transformLevels[0] = s.transformLevels[0];	    setAuxData(s, 0, 0);	} else {	    // For inSharedGroup case.	    int j, len;		    if (childLocalToVworld == null) {	        childLocalToVworld = new Transform3D[s.keys.length][];	        childLocalToVworldIndex = new int[s.keys.length][];                transformLevels = new int[s.keys.length];                cachedTargets = new CachedTargets[s.keys.length];                perPathData = new TransformGroupData[s.keys.length];	        len=0;	    } else {	        len = localToVworld.length - s.keys.length;	    	        int newLen = localToVworld.length;	    	    	        Transform3D newChildTList[][] = new Transform3D[newLen][];	        int newChildIndexList[][] = new int[newLen][]; 	        int newTransformLevels[] = new int[newLen];                CachedTargets newTargets[] = new CachedTargets[newLen];                TransformGroupData newPerPathData[] = new TransformGroupData[newLen];	    	        System.arraycopy(childLocalToVworld, 0,			     newChildTList, 0, childLocalToVworld.length);	        System.arraycopy(childLocalToVworldIndex, 0,			     newChildIndexList, 0, childLocalToVworldIndex.length);	        System.arraycopy(transformLevels, 0,			     newTransformLevels, 0, transformLevels.length);                System.arraycopy(cachedTargets, 0,                             newTargets, 0, cachedTargets.length);                System.arraycopy(perPathData, 0,                             newPerPathData, 0, perPathData.length);	    	        childLocalToVworld = newChildTList;	        childLocalToVworldIndex = newChildIndexList; 	        transformLevels = newTransformLevels;                cachedTargets = newTargets;		perPathData = newPerPathData;	    }	    int hkIndex;	    int hkIndexPlus1, blkSize;	    for(i=len, j=0; i<localToVworld.length; i++, j++) {	        hkIndex = s.keys[j].equals(localToVworldKeys, 0, 						localToVworldKeys.length);	    	        if(hkIndex < 0) {				    MasterControl.getCoreLogger().severe("Can't Find matching hashKey in setNodeData.");		    break;	        } else if(hkIndex >= i) { // Append to last.		    childLocalToVworld[i] = childTrans[j];		    childLocalToVworldIndex[i] = childTransIndex[j]; 		    transformLevels[i] = s.transformLevels[j];	        } else {		    hkIndexPlus1 = hkIndex + 1;		    blkSize = i - hkIndex;				    System.arraycopy(childLocalToVworld, hkIndex,				 childLocalToVworld, hkIndexPlus1, blkSize);				    System.arraycopy(childLocalToVworldIndex, hkIndex,				 childLocalToVworldIndex, hkIndexPlus1, blkSize);		    System.arraycopy(transformLevels, hkIndex,				 transformLevels, hkIndexPlus1, blkSize);                    System.arraycopy(cachedTargets, hkIndex,                                 cachedTargets, hkIndexPlus1, blkSize);                    System.arraycopy(perPathData, hkIndex,                                 perPathData, hkIndexPlus1, blkSize);		    childLocalToVworld[hkIndex] = childTrans[j];		    childLocalToVworldIndex[hkIndex] = childTransIndex[j]; 		    transformLevels[hkIndex] = s.transformLevels[j];	        }	    	        setAuxData(s, j, hkIndex);	    }	}        if (s.childTransformLinks != null) {            // do not duplicate shared nodes            synchronized(s.childTransformLinks) {                if(!inSharedGroup || !s.childTransformLinks.contains(this)) {                    s.childTransformLinks.add(this);                }            }        }	s.localToVworld = childLocalToVworld;	s.localToVworldIndex = childLocalToVworldIndex;        s.currentTransforms = childTrans;        s.currentTransformsIndex = childTransIndex;        s.childTransformLinks = childTransformLinks;        s.parentTransformLink = this;    }        void setAuxData(SetLiveState s, int index, int hkIndex) {        super.setAuxData(s, index, hkIndex);        perPathData[hkIndex] = new TransformGroupData();        perPathData[hkIndex].switchState =                                 (SwitchState)s.switchStates.get(hkIndex);    }    // Add a WakeupOnTransformChange to the list    void removeCondition(WakeupOnTransformChange wakeup) {	synchronized (transformChange) {	    transformChange.remove(wakeup);	}    }    // Add a WakeupOnTransformChange to the list    void addCondition(WakeupOnTransformChange wakeup) {	synchronized (transformChange) {	    transformChange.add(wakeup);	}    }    void notifyConditions() {	synchronized (transformChange) {	    WakeupOnTransformChange list[] = (WakeupOnTransformChange [])		transformChange.toArray(false);	    for (int i=transformChange.size()-1; i >=0; i--) {		list[i].setTriggered();	    }	}    }    boolean isStatic() {	if (!super.isStatic() ||	    source.getCapability(TransformGroup.ALLOW_TRANSFORM_READ) ||	    source.getCapability(TransformGroup.ALLOW_TRANSFORM_WRITE)) {	    return false;	} else {	    return true;	}    }    void mergeTransform(TransformGroupRetained xform) {	super.mergeTransform(xform);	transform.mul(xform.transform, transform);    }    void traverse(boolean sameLevel, int level) {	System.err.println();	for (int i = 0; i < level; i++) {	     System.err.print(".");	}	System.err.print(this);	if (isStatic()) {	    System.err.print(" (s)");	} else {	    System.err.print(" (w)");	}	System.err.println();	System.err.println(transform.toString());	super.traverse(true, level);    }    void compile(CompileState compState) {

⌨️ 快捷键说明

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