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

📄 canvasviewcache.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * $RCSfile: CanvasViewCache.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.8 $ * $Date: 2007/04/12 17:34:04 $ * $State: Exp $ */package javax.media.j3d;import java.awt.Point;import java.awt.Dimension;import java.awt.Rectangle;import java.awt.IllegalComponentStateException;import javax.vecmath.*;/** * The CanvasViewCache class is used to cache all data, both API data * and derived data, that is dependent on the Canvas3D or Screen3D. * The final view and projection matrices are stored here. */class CanvasViewCache extends Object {    // Used for debugging only    private static Object debugLock = new Object();    // The canvas associated with this canvas view cache    private Canvas3D canvas;    // Mask that indicates this CanvasViewCache view dependence info. has changed,    // and CanvasViewCache may need to recompute the final view matries.    int cvcDirtyMask = 0;    // The screen view cache associated with this canvas view cache    private ScreenViewCache screenViewCache;    // The view cache associated with this canvas view cache    private ViewCache viewCache;    // *************    // API/INPUT DATA    // *************    // The position and size of the canvas (in pixels)    private int awtCanvasX;    private int awtCanvasY;    private int awtCanvasWidth;    private int awtCanvasHeight;    // The current RenderBin used for rendering during the frame    // associated with this snapshot.    private RenderBin renderBin;    // Flag indicating whether or not stereo will be used.  Computed by    // Canvas3D as: useStereo = stereoEnable && stereoAvailable    private boolean useStereo;    // Current monoscopic view policy from canvas    private int monoscopicViewPolicy;    // The manual positions of the left and right eyes in image-plate    // coordinates.    // Note that these values are only used in non-head-tracked mode    // when the view's window eyepoint policy is one of RELATIVE_TO_SCREEN    // or RELATIVE_TO_WINDOW.    private Point3d leftManualEyeInImagePlate = new Point3d();    private Point3d rightManualEyeInImagePlate = new Point3d();    // *************    // DERIVED DATA    // *************    // The width and height of the screen in meters (from ScreenViewCache)    double physicalScreenWidth;    double physicalScreenHeight;    // The width and height of the screen in pixels (from ScreenViewCache)    int screenWidth;    int screenHeight;    // Meters per pixel in the X and Y dimension (from ScreenViewCache)    double metersPerPixelX;    double metersPerPixelY;    // The position and size of the canvas (in pixels)    private int canvasX;    private int canvasY;    private int canvasWidth;    private int canvasHeight;    // Either the Canvas' or the View's monoscopicViewPolicy    private int effectiveMonoscopicViewPolicy;    // The current cached projection transforms.    private Transform3D leftProjection = new Transform3D();    private Transform3D rightProjection = new Transform3D();    private Transform3D infLeftProjection = new Transform3D();    private Transform3D infRightProjection = new Transform3D();    // The current cached viewing transforms.    private Transform3D leftVpcToEc = new Transform3D();    private Transform3D rightVpcToEc = new Transform3D();    private Transform3D infLeftVpcToEc = new Transform3D();    private Transform3D infRightVpcToEc = new Transform3D();    // The current cached inverse viewing transforms.    private Transform3D leftEcToVpc = new Transform3D();    private Transform3D rightEcToVpc = new Transform3D();    private Transform3D infLeftEcToVpc = new Transform3D();    private Transform3D infRightEcToVpc = new Transform3D();    // Arrays of Vector4d objects that represent the plane equations for    // the 6 planes in the viewing frustum in ViewPlatform coordinates.    private Vector4d[] leftFrustumPlanes = new Vector4d[6];    private Vector4d[] rightFrustumPlanes = new Vector4d[6];    // Arrays of Vector4d objects that represent the volume of viewing frustum    private Point4d leftFrustumPoints[] = new Point4d[8];    private Point4d rightFrustumPoints[] = new Point4d[8];    // Calibration matrix from Screen object for HMD mode using    // non-field-sequential stereo    private Transform3D headTrackerToLeftImagePlate = new Transform3D();    private Transform3D headTrackerToRightImagePlate = new Transform3D();    // Head tracked version of eye in imageplate    private Point3d leftTrackedEyeInImagePlate = new Point3d();    private Point3d rightTrackedEyeInImagePlate = new Point3d();    // Derived version of eye in image plate coordinates    private Point3d leftEyeInImagePlate = new Point3d();    private Point3d rightEyeInImagePlate = new Point3d();    private Point3d centerEyeInImagePlate = new Point3d();    // Derived version of nominalEyeOffsetFromNominalScreen    private double nominalEyeOffset;    // Physical window position,size and center (in image plate coordinates)    private double physicalWindowXLeft;    private double physicalWindowYBottom;    private double physicalWindowXRight;    private double physicalWindowYTop;    private double physicalWindowWidth;    private double physicalWindowHeight;    private Point3d physicalWindowCenter = new Point3d();    // Screen scale value from viewCache or from screen size.    private double screenScale;    // Window scale value that compensates for window size if    // the window resize policy is PHYSICAL_WORLD.    private double windowScale;    // ViewPlatform scale that takes coordinates from view platform    // coordinates and scales them to physical coordinates    private double viewPlatformScale;    // Various derived transforms    private Transform3D leftCcToVworld = new Transform3D();    private Transform3D rightCcToVworld = new Transform3D();    private Transform3D coexistenceToLeftPlate = new Transform3D();    private Transform3D coexistenceToRightPlate = new Transform3D();    private Transform3D vpcToCoexistence = new Transform3D();    private Transform3D vpcToLeftPlate = new Transform3D();    private Transform3D vpcToRightPlate = new Transform3D();    private Transform3D leftPlateToVpc = new Transform3D();    private Transform3D rightPlateToVpc = new Transform3D();    private Transform3D vworldToLeftPlate = new Transform3D();    private Transform3D lastVworldToLeftPlate = new Transform3D();    private Transform3D vworldToRightPlate = new Transform3D();    private Transform3D leftPlateToVworld = new Transform3D();    private Transform3D rightPlateToVworld = new Transform3D();    private Transform3D headToLeftImagePlate = new Transform3D();    private Transform3D headToRightImagePlate = new Transform3D();    private Transform3D vworldToTrackerBase = new Transform3D();    private Transform3D tempTrans = new Transform3D();    private Transform3D headToVworld = new Transform3D();    private Vector3d coexistenceCenter = new Vector3d();    // scale for transformimg clip and fog distances    private double vworldToCoexistenceScale;    private double infVworldToCoexistenceScale;    //    // Temporary matrices and vectors, so we dont generate garbage    //    private Transform3D tMat1 = new Transform3D();    private Transform3D tMat2 = new Transform3D();    private Vector3d tVec1 = new Vector3d();    private Vector3d tVec2 = new Vector3d();    private Vector3d tVec3 = new Vector3d();    private Point3d tPnt1 = new Point3d();    private Point3d tPnt2 = new Point3d();    private Matrix4d tMatrix = new Matrix4d();    /**     * The view platform transforms.     */    private Transform3D vworldToVpc = new Transform3D();    private Transform3D vpcToVworld = new Transform3D();    private Transform3D infVworldToVpc = new Transform3D();    // This flag is used to remember the last time doInfinite flag    // is true or not.    // If this cache is updated twice, the first time in RenderBin    // updateViewCache() and the second time in Renderer with    // geometryBackground. The first time will reset the vcDirtyMask    // to 0 so that geometry background will not get updated the    // second time doComputeDerivedData() is invoked when view change.    private boolean lastDoInfinite = false;    private boolean updateLastTime = false;    void getCanvasPositionAndSize() {	if(J3dDebug.canvasViewCache >= J3dDebug.LEVEL_2) {	    System.err.println("Get canvas position and size");	    System.err.println("Before");	    System.err.println("Canvas pos = (" + awtCanvasX + ", " +			       awtCanvasY + "), size = " + awtCanvasWidth +			       "x" + awtCanvasHeight);	    System.err.println("After");	}	awtCanvasX = canvas.newPosition.x;	awtCanvasY = canvas.newPosition.y;	awtCanvasWidth = canvas.newSize.width;	awtCanvasHeight = canvas.newSize.height;	// The following works around problem when awt creates 0-size	// window at startup	if ((awtCanvasWidth <= 0) || (awtCanvasHeight <= 0)) {	    awtCanvasWidth = 1;	    awtCanvasHeight = 1;	}	if (J3dDebug.canvasViewCache >= J3dDebug.LEVEL_1) {	    System.err.println("Canvas pos = (" + awtCanvasX + ", " +			       awtCanvasY + "), size = " + awtCanvasWidth +			       "x" + awtCanvasHeight);	}    }    void computefrustumBBox(BoundingBox frustumBBox) {	int i;	for(i = 0; i < leftFrustumPoints.length; i++) {	    if(frustumBBox.lower.x > leftFrustumPoints[i].x)		frustumBBox.lower.x = leftFrustumPoints[i].x;	    if(frustumBBox.lower.y > leftFrustumPoints[i].y)		frustumBBox.lower.y = leftFrustumPoints[i].y;	    if(frustumBBox.lower.z > leftFrustumPoints[i].z)		frustumBBox.lower.z = leftFrustumPoints[i].z;	    if(frustumBBox.upper.x < leftFrustumPoints[i].x)		frustumBBox.upper.x = leftFrustumPoints[i].x;	    if(frustumBBox.upper.y < leftFrustumPoints[i].y)		frustumBBox.upper.y = leftFrustumPoints[i].y;	    if(frustumBBox.upper.z < leftFrustumPoints[i].z)		frustumBBox.upper.z = leftFrustumPoints[i].z;	}	if(useStereo) {	    for(i = 0; i< rightFrustumPoints.length; i++) {		if(frustumBBox.lower.x > rightFrustumPoints[i].x)		    frustumBBox.lower.x = rightFrustumPoints[i].x;		if(frustumBBox.lower.y > rightFrustumPoints[i].y)		    frustumBBox.lower.y = rightFrustumPoints[i].y;		if(frustumBBox.lower.z > rightFrustumPoints[i].z)		    frustumBBox.lower.z = rightFrustumPoints[i].z;		if(frustumBBox.upper.x < rightFrustumPoints[i].x)		    frustumBBox.upper.x = rightFrustumPoints[i].x;		if(frustumBBox.upper.y < rightFrustumPoints[i].y)		    frustumBBox.upper.y = rightFrustumPoints[i].y;		if(frustumBBox.upper.z < rightFrustumPoints[i].z)		    frustumBBox.upper.z = rightFrustumPoints[i].z;	    }	}    }    void copyComputedCanvasViewCache(CanvasViewCache cvc, boolean doInfinite) {	// For performance reason, only data needed by renderer are copied.	// useStereo,	// canvasWidth,	// canvasHeight,	// leftProjection,	// rightProjection,	// leftVpcToEc,	// rightVpcToEc,	// leftFrustumPlanes,	// rightFrustumPlanes,	// vpcToVworld,	// vworldToVpc.	cvc.useStereo = useStereo;	cvc.canvasWidth = canvasWidth;	cvc.canvasHeight = canvasHeight;	cvc.leftProjection.set(leftProjection);	cvc.rightProjection.set(rightProjection);	cvc.leftVpcToEc.set(leftVpcToEc) ;	cvc.rightVpcToEc.set(rightVpcToEc) ;	cvc.vpcToVworld = vpcToVworld;	cvc.vworldToVpc.set(vworldToVpc);        if (doInfinite) {            cvc.infLeftProjection.set(infLeftProjection);            cvc.infRightProjection.set(infRightProjection);            cvc.infLeftVpcToEc.set(infLeftVpcToEc) ;            cvc.infRightVpcToEc.set(infRightVpcToEc) ;            cvc.infVworldToVpc.set(infVworldToVpc);        }	for (int i = 0; i < leftFrustumPlanes.length; i++) {	    cvc.leftFrustumPlanes[i].x = leftFrustumPlanes[i].x;	    cvc.leftFrustumPlanes[i].y = leftFrustumPlanes[i].y;	    cvc.leftFrustumPlanes[i].z = leftFrustumPlanes[i].z;	    cvc.leftFrustumPlanes[i].w = leftFrustumPlanes[i].w;	    cvc.rightFrustumPlanes[i].x = rightFrustumPlanes[i].x;	    cvc.rightFrustumPlanes[i].y = rightFrustumPlanes[i].y;	    cvc.rightFrustumPlanes[i].z = rightFrustumPlanes[i].z;	    cvc.rightFrustumPlanes[i].w = rightFrustumPlanes[i].w;	}    }    /**     * Take snapshot of all per-canvas API parameters and input values.     * NOTE: This is probably not needed, but we'll do it for symmetry     * with the ScreenViewCache and ViewCache objects.     */    synchronized void snapshot(boolean computeFrustum) {        // Issue 109 : determine the the correct index to use -- either the        // Renderer or RenderBin        int dirtyIndex = computeFrustum ?            Canvas3D.RENDER_BIN_DIRTY_IDX : Canvas3D.RENDERER_DIRTY_IDX;        synchronized (canvas.dirtyMaskLock) {            // Issue 109 : read/clear the dirty bits for the correct index            cvcDirtyMask = canvas.cvDirtyMask[dirtyIndex];            canvas.cvDirtyMask[dirtyIndex] = 0;        }        useStereo = canvas.useStereo;	monoscopicViewPolicy = canvas.monoscopicViewPolicy;	leftManualEyeInImagePlate.set(canvas.leftManualEyeInImagePlate);	rightManualEyeInImagePlate.set(canvas.rightManualEyeInImagePlate);	if(( cvcDirtyMask & Canvas3D.MOVED_OR_RESIZED_DIRTY) != 0) {	    getCanvasPositionAndSize();	}	renderBin = canvas.view.renderBin;    }    /**     * Compute derived data using the snapshot of the per-canvas,     * per-screen and per-view data.     */    synchronized void computeDerivedData(boolean currentFlag,	CanvasViewCache cvc, BoundingBox frustumBBox, boolean doInfinite) {	if((J3dDebug.devPhase) && (J3dDebug.canvasViewCache >= J3dDebug.LEVEL_1)) {	    synchronized(debugLock) {		System.err.println("------------------------------");		doComputeDerivedData(currentFlag,cvc,frustumBBox,doInfinite);	    }	}	else {	    doComputeDerivedData(currentFlag,cvc,frustumBBox,doInfinite);	}    }    /**     * Compute derived data using the snapshot of the per-canvas,     * per-screen and per-view data.  Caller must synchronize before     * calling this method.     */    private void doComputeDerivedData(boolean currentFlag,	CanvasViewCache cvc, BoundingBox frustumBBox, boolean doInfinite) {        // Issue 109 : determine the the correct index to use -- either the        // Renderer or RenderBin        int dirtyIndex = (frustumBBox != null) ?            Canvas3D.RENDER_BIN_DIRTY_IDX : Canvas3D.RENDERER_DIRTY_IDX;        int scrvcDirtyMask;                // Issue 109 : read/clear the dirty bits for the correct index        synchronized (screenViewCache) {            scrvcDirtyMask = screenViewCache.scrvcDirtyMask[dirtyIndex];            // reset screen view dirty mask if canvas is offScreen. Note:            // there is only one canvas per offscreen, so it is ok to

⌨️ 快捷键说明

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