All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javax.media.j3d.DistanceLOD Maven / Gradle / Ivy

The newest version!
/*
 * 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;

import java.util.Enumeration;

import javax.vecmath.Point3f;

/**
 * This class defines a distance-based LOD behavior node that operates on
 * a Switch group node to select one of the children of that Switch node
 * based on the distance of this LOD node from the viewer.
 * An array of n monotonically increasing distance values is
 * specified, such that distances[0] is associated with the highest level of
 * detail and distances[n-1] is associated with the lowest level of
 * detail.  Based on the actual distance from the viewer to
 * this DistanceLOD node, these n
 * distance values [0, n-1] select from among n+1
 * levels of detail [0, n].  If d is the distance from
 * the viewer to the LOD node, then the equation for determining
 * which level of detail (child of the Switch node) is selected is:
 * 

*

    * 0, if d <= distances[0] *
    * i, if distances[i-1] < d <= distances[i] *
    * n, if d > distances[n-1] *
*

* Note that both the position and the array of distances are * specified in the local coordinate system of this node. */ public class DistanceLOD extends LOD { private double distances[]; private Point3f position = new Point3f(0.0f, 0.0f, 0.0f); // variables for processStimulus private Point3f center = new Point3f(); private Point3f viewPosition = new Point3f(); /** * Constructs and initializes a DistanceLOD node with default values. * Note that the default constructor creates a DistanceLOD object with * a single distance value set to 0.0 and is, therefore, not useful. */ public DistanceLOD() { distances = new double[1]; distances[0] = 0.0; } /** * Constructs and initializes a DistanceLOD node with the specified * array of distances and a default position of (0,0,0). * @param distances an array of values representing LOD cutoff distances */ public DistanceLOD(float[] distances) { this.distances = new double[distances.length]; for(int i=0;i distances[n-1] if( viewDistance <= distances[0] ) { index = 0; } else { for (i=1; i < distances.length; i++) { if ((viewDistance > distances[i-1]) && (viewDistance <= distances[i])) { index = i; break; } } } for(i=nSwitches-1; i>=0; i--) { Switch sw = getSwitch(i); // Optimize, this behavior is passive // Note that we skip the capability check for getWhichChild() if (((SwitchRetained) sw.retained).getWhichChild() != index) { sw.setWhichChild(index); } } // Insert wakeup condition into queue wakeupOn(wakeupFrame); } /** * Used to create a new instance of the node. This routine is called * by cloneTree to duplicate the current node. * @param forceDuplicate when set to true, causes the * duplicateOnCloneTree flag to be ignored. When * false, the value of each node's * duplicateOnCloneTree variable determines whether * NodeComponent data is duplicated or copied. * * @see Node#cloneTree * @see Node#cloneNode * @see Node#duplicateNode * @see NodeComponent#setDuplicateOnCloneTree */ @Override public Node cloneNode(boolean forceDuplicate) { DistanceLOD d = new DistanceLOD(); d.duplicateNode(this, forceDuplicate); return d; } /** * Copies all DistanceLOD information from * originalNode into * the current node. This method is called from the * cloneNode method which is, in turn, called by the * cloneTree method.

* * @param originalNode the original node to duplicate. * @param forceDuplicate when set to true, causes the * duplicateOnCloneTree flag to be ignored. When * false, the value of each node's * duplicateOnCloneTree variable determines whether * NodeComponent data is duplicated or copied. * * @exception RestrictedAccessException if this object is part of a live * or compiled scenegraph. * * @see Node#duplicateNode * @see Node#cloneTree * @see NodeComponent#setDuplicateOnCloneTree */ @Override void duplicateAttributes(Node originalNode, boolean forceDuplicate) { super.duplicateAttributes(originalNode, forceDuplicate); DistanceLOD lod = (DistanceLOD) originalNode; int numD = lod.numDistances(); // No API available to set the size of this array after initialize this.distances = new double[numD]; for (int i = 0; i < numD; i++) setDistance(i, lod.getDistance(i)); Point3f p = new Point3f(); lod.getPosition(p); setPosition(p); } void mergeTransform(TransformGroupRetained xform) { xform.transform.transform(position, position); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy