001: /*
002: * $RCSfile: OrientedShape3DRenderMethod.java,v $
003: *
004: * Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006: *
007: * This code is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License version 2 only, as
009: * published by the Free Software Foundation. Sun designates this
010: * particular file as subject to the "Classpath" exception as provided
011: * by Sun in the LICENSE file that accompanied this code.
012: *
013: * This code is distributed in the hope that it will be useful, but WITHOUT
014: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: * version 2 for more details (a copy is included in the LICENSE file that
017: * accompanied this code).
018: *
019: * You should have received a copy of the GNU General Public License version
020: * 2 along with this work; if not, write to the Free Software Foundation,
021: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022: *
023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024: * CA 95054 USA or visit www.sun.com if you need additional information or
025: * have any questions.
026: *
027: * $Revision: 1.7 $
028: * $Date: 2008/02/28 20:17:27 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: /**
035: * The OrientedShape3DRenderMethod provides a render method to render
036: * OrientedShape3D nodes.
037: * The RenderMethod interface is used to create various ways to render
038: * different geometries.
039: */
040:
041: class OrientedShape3DRenderMethod implements RenderMethod {
042:
043: public boolean render(RenderMolecule rm, Canvas3D cv,
044: RenderAtomListInfo ra, int dirtyBits) {
045: boolean useAlpha;
046: boolean isNonUniformScale;
047: Transform3D trans = null;
048:
049: useAlpha = rm.useAlpha;
050:
051: GeometryArrayRetained geo = (GeometryArrayRetained) ra
052: .geometry();
053: geo
054: .setVertexFormat(
055: (rm.useAlpha && ((geo.vertexFormat & GeometryArray.COLOR) != 0)),
056: rm.textureBin.attributeBin.ignoreVertexColors,
057: cv.ctx);
058:
059: if (rm.doInfinite) {
060: cv.updateState(dirtyBits);
061: while (ra != null) {
062: trans = ra.infLocalToVworld;
063: isNonUniformScale = !trans.isCongruent();
064:
065: cv.setModelViewMatrix(cv.ctx, cv.vworldToEc.mat, trans);
066: ra.geometry().execute(cv, ra.renderAtom,
067: isNonUniformScale,
068: (useAlpha && ra.geometry().noAlpha), rm.alpha,
069: cv.screen.screen,
070: rm.textureBin.attributeBin.ignoreVertexColors);
071: ra = ra.next;
072: }
073: return true;
074: }
075:
076: boolean isVisible = false; // True if any of the RAs is visible.
077: while (ra != null) {
078: if (cv.ra == ra.renderAtom) {
079: if (cv.raIsVisible) {
080: cv.updateState(dirtyBits);
081: trans = ra.localToVworld;
082: isNonUniformScale = !trans.isCongruent();
083:
084: cv.setModelViewMatrix(cv.ctx, cv.vworldToEc.mat,
085: trans);
086: ra
087: .geometry()
088: .execute(
089: cv,
090: ra.renderAtom,
091: isNonUniformScale,
092: (useAlpha && ra.geometry().noAlpha),
093: rm.alpha,
094: cv.screen.screen,
095: rm.textureBin.attributeBin.ignoreVertexColors);
096: isVisible = true;
097: }
098: } else {
099: if (!VirtualUniverse.mc.viewFrustumCulling
100: || ra.renderAtom.localeVwcBounds
101: .intersect(cv.viewFrustum)) {
102: cv.updateState(dirtyBits);
103: cv.raIsVisible = true;
104: trans = ra.localToVworld;
105: isNonUniformScale = !trans.isCongruent();
106:
107: cv.setModelViewMatrix(cv.ctx, cv.vworldToEc.mat,
108: trans);
109: ra
110: .geometry()
111: .execute(
112: cv,
113: ra.renderAtom,
114: isNonUniformScale,
115: (useAlpha && ra.geometry().noAlpha),
116: rm.alpha,
117: cv.screen.screen,
118: rm.textureBin.attributeBin.ignoreVertexColors);
119: isVisible = true;
120: } else {
121: cv.raIsVisible = false;
122: }
123: cv.ra = ra.renderAtom;
124:
125: }
126: ra = ra.next;
127:
128: }
129:
130: geo
131: .disableGlobalAlpha(
132: cv.ctx,
133: (rm.useAlpha && ((geo.vertexFormat & GeometryArray.COLOR) != 0)),
134: rm.textureBin.attributeBin.ignoreVertexColors);
135: return isVisible;
136: }
137: }
|