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

📄 orientedshape3dretained.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $RCSfile: OrientedShape3DRetained.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.5 $ * $Date: 2007/02/09 17:18:13 $ * $State: Exp $ */package javax.media.j3d;import javax.vecmath.*;import java.util.ArrayList;class OrientedShape3DRetained extends Shape3DRetained {    static final int ALIGNMENT_CHANGED          = LAST_DEFINED_BIT << 1;    static final int AXIS_CHANGED               = LAST_DEFINED_BIT << 2;    static final int ROTATION_CHANGED           = LAST_DEFINED_BIT << 3;    static final int CONSTANT_SCALE_CHANGED     = LAST_DEFINED_BIT << 4;    static final int SCALE_FACTOR_CHANGED       = LAST_DEFINED_BIT << 5;    int mode = OrientedShape3D.ROTATE_ABOUT_AXIS;    // Axis about which to rotate.    Vector3f axis = new Vector3f(0.0f, 1.0f, 0.0f);    Point3f rotationPoint = new Point3f(0.0f, 0.0f, 1.0f);    private Vector3d nAxis = new Vector3d(0.0, 1.0, 0.0); // normalized axis    // reused temporaries    private Point3d viewPosition = new Point3d();    private Point3d yUpPoint = new Point3d();    private Vector3d eyeVec = new Vector3d();    private Vector3d yUp = new Vector3d();    private Vector3d zAxis  = new Vector3d();    private Vector3d yAxis  = new Vector3d();    private Vector3d vector = new Vector3d();    private AxisAngle4d aa = new AxisAngle4d();    private Transform3D xform = new Transform3D(); // used several times    private Transform3D zRotate = new Transform3D();    // For scale invariant mode    boolean constantScale = false;    double scaleFactor = 1.0;    // Frequently used variables for scale invariant computation    // Left and right Vworld to Clip coordinates transforms    private Transform3D left_xform = new Transform3D();     private Transform3D right_xform = new Transform3D();     // Transform for scaling the OrientedShape3D to correct for     // perspective foreshortening    Transform3D scaleXform = new Transform3D();    // Variables for converting between clip to local world coords    private Vector4d im_vec[] = {new Vector4d(), new Vector4d()};    private Vector4d lvec = new Vector4d();    boolean orientedTransformDirty = true;    Transform3D[] orientedTransforms = new Transform3D[1];    static final double EPSILON = 1.0e-6;    /**     * Constructs a OrientedShape3D node with default parameters.     * The default values are as follows:     * <ul>     * alignment mode : ROTATE_ABOUT_AXIS<br>     * alignment axis : Y-axis (0,1,0)<br>     * rotation point : (0,0,1)<br>     *</ul>     */    public OrientedShape3DRetained() {	super();        this.nodeType = NodeRetained.ORIENTEDSHAPE3D;    }    // initializes alignment mode    void initAlignmentMode(int mode) {	this.mode = mode;    }    /**     * Sets the alignment mode.     * @param mode one of: ROTATE_ABOUT_AXIS or ROTATE_ABOUT_POINT     */    void setAlignmentMode(int mode) {	if (this.mode != mode) {	    initAlignmentMode(mode);	    sendChangedMessage(ALIGNMENT_CHANGED, new Integer(mode));	}    }    /**     * Retrieves the alignment mode.     * @return one of: ROTATE_ABOUT_AXIS or ROTATE_ABOUT_POINT     */    int getAlignmentMode() {	return(mode);    }    // initializes alignment axis    void initAlignmentAxis(Vector3f axis) {	initAlignmentAxis(axis.x, axis.y, axis.z);    }    // initializes alignment axis    void initAlignmentAxis(float x, float y, float z) {        this.axis.set(x,y,z);        double invMag;        invMag =  1.0/Math.sqrt(axis.x*axis.x + axis.y*axis.y + axis.z*axis.z);        nAxis.x = (double)axis.x*invMag;        nAxis.y = (double)axis.y*invMag;        nAxis.z = (double)axis.z*invMag;    }    /**     * Sets the new alignment axis.  This is the ray about which this     * OrientedShape3D rotates when the mode is ROTATE_ABOUT_AXIS.     * @param axis the new alignment axis     */    void setAlignmentAxis(Vector3f axis) {        setAlignmentAxis(axis.x, axis.y, axis.z);    }    /**     * Sets the new alignment axis.  This is the ray about which this     * OrientedShape3D rotates when the mode is ROTATE_ABOUT_AXIS.     * @param x the x component of the alignment axis     * @param y the y component of the alignment axis     * @param z the z component of the alignment axis     */    void setAlignmentAxis(float x, float y, float z) {        initAlignmentAxis(x,y,z);	if (mode == OrientedShape3D.ROTATE_ABOUT_AXIS) {	    sendChangedMessage(AXIS_CHANGED, new Vector3f(x,y,z));	}    }    /**     * Retrieves the alignment axis of this OrientedShape3D node,     * and copies it into the specified vector.     * @param axis the vector that will contain the alignment axis     */    void getAlignmentAxis(Vector3f axis)  {        axis.set(this.axis);    }    // initializes rotation point    void initRotationPoint(Point3f point) {	rotationPoint.set(point);    }    // initializes rotation point    void initRotationPoint(float x, float y, float z) {	rotationPoint.set(x,y,z);    }    /**     * Sets the new rotation point.  This is the point about which the     * OrientedShape3D rotates when the mode is ROTATE_ABOUT_POINT.     * @param point the new rotation point     */    void setRotationPoint(Point3f point) {	setRotationPoint(point.x, point.y, point.z);    }    /**     * Sets the new rotation point.  This is the point about which the     * OrientedShape3D rotates when the mode is ROTATE_ABOUT_POINT.     * @param x the x component of the rotation point     * @param y the y component of the rotation point     * @param z the z component of the rotation point     */    void setRotationPoint(float x, float y, float z) {	initRotationPoint(x,y,z);	if (mode == OrientedShape3D.ROTATE_ABOUT_POINT) {	    sendChangedMessage(ROTATION_CHANGED, new Point3f(x,y,z));	}    }    /**     * Retrieves the rotation point of this OrientedShape3D node,     * and copies it into the specified vector.     * @param axis the point that will contain the rotation point     */    void getRotationPoint(Point3f point)  {        point.set(rotationPoint);    }    void setConstantScaleEnable(boolean enable) {	if(constantScale != enable) {	    initConstantScaleEnable(enable);	    sendChangedMessage(CONSTANT_SCALE_CHANGED, new Boolean(enable));	}    }    boolean getConstantScaleEnable() {	return constantScale;    }    void initConstantScaleEnable(boolean cons_scale) {	constantScale = cons_scale;    }    void setScale(double scale) {	initScale(scale);	if(constantScale)	    sendChangedMessage(SCALE_FACTOR_CHANGED, new Double(scale));    }    void initScale(double scale) {	scaleFactor = scale;    }    double getScale() {	return scaleFactor;    }    void sendChangedMessage(int component, Object attr) {        J3dMessage changeMessage = new J3dMessage();        changeMessage.type = J3dMessage.ORIENTEDSHAPE3D_CHANGED;        changeMessage.threads = targetThreads ;        changeMessage.universe = universe;        changeMessage.args[0] = getGeomAtomsArray(mirrorShape3D);	changeMessage.args[1] = new Integer(component);	changeMessage.args[2] = attr;	OrientedShape3DRetained[] o3dArr = 	    new OrientedShape3DRetained[mirrorShape3D.size()];	mirrorShape3D.toArray(o3dArr);	changeMessage.args[3] = o3dArr;	changeMessage.args[4] = this;        VirtualUniverse.mc.processMessage(changeMessage);    }    void updateImmediateMirrorObject(Object[] args) {	int component = ((Integer)args[1]).intValue();	if ((component & (ALIGNMENT_CHANGED      | 			  AXIS_CHANGED           |			  ROTATION_CHANGED       |			  CONSTANT_SCALE_CHANGED |			  SCALE_FACTOR_CHANGED)) != 0) {	    OrientedShape3DRetained[] msArr = (OrientedShape3DRetained[])args[3];	    Object obj = args[2];	    if ((component & ALIGNMENT_CHANGED) != 0) {		int mode = ((Integer)obj).intValue();		for (int i=0; i< msArr.length; i++) {		    msArr[i].initAlignmentMode(mode);		}	    }	    else if ((component & AXIS_CHANGED) != 0) {		Vector3f axis =(Vector3f) obj;		for (int i=0; i< msArr.length; i++) {		     msArr[i].initAlignmentAxis(axis);		}	    }	    else if ((component & ROTATION_CHANGED) != 0) {		Point3f point =(Point3f) obj;		for (int i=0; i< msArr.length; i++) {		    msArr[i].initRotationPoint(point);		}	    }	    else if((component & CONSTANT_SCALE_CHANGED) != 0) {		boolean bool = ((Boolean)obj).booleanValue();		for (int i=0; i< msArr.length; i++) {		    msArr[i].initConstantScaleEnable(bool);		}	    }	    else if((component & SCALE_FACTOR_CHANGED) != 0) {		double scale = ((Double)obj).doubleValue();		for (int i=0; i< msArr.length; i++) {		    msArr[i].initScale(scale);		}	    }	}	else {	    super.updateImmediateMirrorObject(args);	}    }    Transform3D getOrientedTransform(int viewIndex) {	synchronized(orientedTransforms) {	    if (viewIndex >= orientedTransforms.length) {		Transform3D xform = new Transform3D();		Transform3D[] newList = new Transform3D[viewIndex+1];		for (int i = 0; i < orientedTransforms.length; i++) {

⌨️ 快捷键说明

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