orientedbox.java
来自「java 3d game jme 工程开发源代码」· Java 代码 · 共 357 行 · 第 1/2 页
JAVA
357 行
/*
* Copyright (c) 2003-2009 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// $Id: OrientedBox.java 4091 2009-01-21 19:01:20Z joshua.j.ellen $
package com.jme.scene.shape;
import java.io.IOException;
import com.jme.math.Vector2f;
import com.jme.math.Vector3f;
import com.jme.scene.TexCoords;
import com.jme.scene.TriMesh;
import com.jme.util.export.InputCapsule;
import com.jme.util.export.JMEExporter;
import com.jme.util.export.JMEImporter;
import com.jme.util.export.OutputCapsule;
import com.jme.util.export.Savable;
import com.jme.util.geom.BufferUtils;
/**
* Started Date: Aug 22, 2004 <br>
* <br>
* This primitive represents a box that has options to orient it acording to its
* X/Y/Z axis. It is used to create an OrientedBoundingBox mostly.
*
* @author Jack Lindamood
* @version $Revision: 4091 $, $Date: 2009-01-22 03:01:20 +0800 (星期四, 22 一月 2009) $
*/
public class OrientedBox extends TriMesh {
private static final long serialVersionUID = 1L;
private static final Vector3f tempVa = new Vector3f();
private static final Vector3f tempVb = new Vector3f();
private static final Vector3f tempVc = new Vector3f();
/** Center of the Oriented Box. */
protected Vector3f center;
/**
* Have the corners of the box (as stored in the {@code #vectorStore} array)
* been set to correctly represent the box’s corners or not.
*/
public boolean correctCorners;
/** Extents of the box along the x,y,z axis. */
protected Vector3f extent = new Vector3f(0, 0, 0);
/** Texture coordintae values for the corners of the box. */
protected Vector2f texTopRight, texTopLeft, texBotRight, texBotLeft;
/** Vector array used to store the array of 8 corners the box has. */
public Vector3f[] vectorStore;
/** X axis of the Oriented Box. */
protected Vector3f xAxis = new Vector3f(1, 0, 0);
/** Y axis of the Oriented Box. */
protected Vector3f yAxis = new Vector3f(0, 1, 0);
/** Z axis of the Oriented Box. */
protected Vector3f zAxis = new Vector3f(0, 0, 1);
/**
* Creates a new OrientedBox with the given name.
*
* @param name
* The name of the new box.
*/
public OrientedBox(String name) {
this(name, new Vector3f(), new Vector2f(1, 1), new Vector2f(1, 0), new Vector2f(0, 1), new Vector2f(0, 0));
}
/**
* Create a new oriented box.
* <p>
* The box is initially configured based on the supplied texture co-ordinate points.
*
* @param name the name of the box.
* @param center point at the center of the box.
* @param topRight the top right hand corner of the box.
* @param topLeft the top left hand corner of the box.
* @param bottomRight the bottom right hand corner of the box.
* @param bottomLeft the bottom left hand corner of the box.
*/
public OrientedBox(String name, Vector3f center, Vector2f topRight, Vector2f topLeft, Vector2f bottomRight, Vector2f bottomLeft) {
super(name);
updateGeometry(center, topRight, topLeft, bottomRight, bottomLeft);
}
/**
* Sets the vectorStore information to the 8 corners of the box.
* @deprecated will be made private.
*/
public void computeCorners() {
correctCorners = true;
tempVa.set(xAxis).multLocal(extent.x);
tempVb.set(yAxis).multLocal(extent.y);
tempVc.set(zAxis).multLocal(extent.z);
vectorStore[0].set(center).addLocal(tempVa).addLocal(tempVb).addLocal(tempVc);
vectorStore[1].set(center).addLocal(tempVa).subtractLocal(tempVb).addLocal(tempVc);
vectorStore[2].set(center).addLocal(tempVa).addLocal(tempVb).subtractLocal(tempVc);
vectorStore[3].set(center).subtractLocal(tempVa).addLocal(tempVb).addLocal(tempVc);
vectorStore[4].set(center).addLocal(tempVa).subtractLocal(tempVb).subtractLocal(tempVc);
vectorStore[5].set(center).subtractLocal(tempVa).subtractLocal(tempVb).addLocal(tempVc);
vectorStore[6].set(center).subtractLocal(tempVa).addLocal(tempVb).subtractLocal(tempVc);
vectorStore[7].set(center).subtractLocal(tempVa).subtractLocal(tempVb).subtractLocal(tempVc);
}
/**
* Takes the plane and center information and creates the correct
* vertex,normal,color,texture,index information to represent the
* OrientedBox.
* @deprecated will be made private.
*/
public void computeInformation() {
updateGeometryVertices();
updateGeometryNormals();
updateGeometryTextures();
updateGeometryIndices();
}
/**
* Returns the center of the box.
*
* @return The box's center.
*/
public Vector3f getCenter() {
return center;
}
/**
* Returns the box's extent vector along the x,y,z.
*
* @return The box's extent vector.
*/
public Vector3f getExtent() {
return extent;
}
/** @deprecated Use {@link #getXAxis()} instead */
public Vector3f getxAxis() {
return getXAxis();
}
public Vector3f getXAxis() {
return xAxis;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?