aboutsummaryrefslogtreecommitdiffstats
path: root/src/javax/media/j3d/ScreenViewCache.java
blob: bc4cdd121f506ded57fbb7261eaf4276b77876f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Sun designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Sun in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 *
 */

package javax.media.j3d;


/**
 * The ScreenViewCache class is used to cache all API data
 * from the Screen3D object.
 */
class ScreenViewCache extends Object {
    // The screen associated with this screen view cache
    Screen3D screen;

    //
    // API/INPUT DATA
    //

    // The width and height of the screen in meters.
    double physicalScreenWidth;
    double physicalScreenHeight;

    // The width and height of the screen in pixels.
    int screenWidth;
    int screenHeight;

    // Mask that indicates Screen3D view dependence info. has changed,
    // and CanvasViewCache may need to recompute the final view matries.
    // Issue 163: Array of dirty bits is used because the Renderer and
    // RenderBin run asynchronously. Now that they each have a separate
    // instance of CanvasViewCache (due to the fix for Issue 109), they
    // need separate dirty bits. Array element 0 is used for the Renderer and
    // element 1 is used for the RenderBin.
    int[] scrvcDirtyMask = new int[2];

    //
    // Tracker-base coordinate system to image-plate coordinate
    // system transform.  If head tracking is enabled, this transform
    // is a calibration constant.  If head tracking is not enabled,
    // this transform is not used.
    // This is used only in SCREEN_VIEW mode.
    //
    Transform3D trackerBaseToImagePlate = new Transform3D();

    //
    // Head-tracker coordinate system to left and right image-plate coordinate
    // system transforms.  If head tracking is enabled, these transforms
    // are calibration constants.  If head tracking is not enabled,
    // these transforms are not used.
    // These are used only in HMD_VIEW mode.
    //
    Transform3D headTrackerToLeftImagePlate = new Transform3D();
    Transform3D headTrackerToRightImagePlate = new Transform3D();


    //
    // DERIVED DATA
    //

    // Meters per pixel in the X and Y dimension
    double metersPerPixelX;
    double metersPerPixelY;


    /**
     * Take snapshot of all per-screen API parameters.
     */
    synchronized void snapshot() {

        // accumulate the dirty bits for offscreen because
        // the dirty bits will not be processed until renderOffScreen
        // or triggered by RenderBin at some little time
        if (screen.offScreen) {
            scrvcDirtyMask[0] |= screen.scrDirtyMask;
            scrvcDirtyMask[1] |= screen.scrDirtyMask;
        } else {
            scrvcDirtyMask[0] = screen.scrDirtyMask;
            scrvcDirtyMask[1] = screen.scrDirtyMask;
        }
        screen.scrDirtyMask = 0;

        physicalScreenWidth = screen.physicalScreenWidth;
	physicalScreenHeight = screen.physicalScreenHeight;
	screenWidth = screen.screenSize.width;
	screenHeight = screen.screenSize.height;

	screen.trackerBaseToImagePlate.getWithLock(trackerBaseToImagePlate);

	screen.headTrackerToLeftImagePlate.getWithLock
	    (headTrackerToLeftImagePlate);
	screen.headTrackerToRightImagePlate.getWithLock
	    (headTrackerToRightImagePlate);

	// This isn't really API data, but since we have no other derived
	// data, and it's a simple calculation, it's easier if we just do
	// it here.
	metersPerPixelX = physicalScreenWidth / (double) screenWidth;
	metersPerPixelY = physicalScreenHeight / (double) screenHeight;
    }


    /**
     * Constructs and initializes a ScreenViewCache object.
     */
    ScreenViewCache(Screen3D screen) {
	this.screen = screen;

	if (false)
	    System.err.println("Constructed a ScreenViewCache");
    }
}