cylinder.java
来自「java 3d game jme 工程开发源代码」· Java 代码 · 共 460 行 · 第 1/2 页
JAVA
460 行
/*
* 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: Cylinder.java 4091 2009-01-21 19:01:20Z joshua.j.ellen $
package com.jme.scene.shape;
import static com.jme.util.geom.BufferUtils.*;
import java.io.IOException;
import com.jme.math.FastMath;
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.geom.BufferUtils;
/**
* A simple cylinder, defined by it's height and radius.
*
* @author Mark Powell
* @version $Revision: 4091 $, $Date: 2009-01-22 03:01:20 +0800 (星期四, 22 一月 2009) $
*/
public class Cylinder extends TriMesh {
private static final long serialVersionUID = 1L;
private int axisSamples;
private int radialSamples;
private float radius;
private float radius2;
private float height;
private boolean closed;
private boolean inverted;
public Cylinder() {
}
/**
* Creates a new Cylinder. By default its center is the origin. Usually, a
* higher sample number creates a better looking cylinder, but at the cost
* of more vertex information.
*
* @param name
* The name of this Cylinder.
* @param axisSamples
* Number of triangle samples along the axis.
* @param radialSamples
* Number of triangle samples along the radial.
* @param radius
* The radius of the cylinder.
* @param height
* The cylinder's height.
*/
public Cylinder(String name, int axisSamples, int radialSamples,
float radius, float height) {
this(name, axisSamples, radialSamples, radius, height, false);
}
/**
* Creates a new Cylinder. By default its center is the origin. Usually, a
* higher sample number creates a better looking cylinder, but at the cost
* of more vertex information. <br>
* If the cylinder is closed the texture is split into axisSamples parts:
* top most and bottom most part is used for top and bottom of the cylinder,
* rest of the texture for the cylinder wall. The middle of the top is
* mapped to texture coordinates (0.5, 1), bottom to (0.5, 0). Thus you need
* a suited distorted texture.
*
* @param name
* The name of this Cylinder.
* @param axisSamples
* Number of triangle samples along the axis.
* @param radialSamples
* Number of triangle samples along the radial.
* @param radius
* The radius of the cylinder.
* @param height
* The cylinder's height.
* @param closed
* true to create a cylinder with top and bottom surface
*/
public Cylinder(String name, int axisSamples, int radialSamples,
float radius, float height, boolean closed) {
this(name, axisSamples, radialSamples, radius, height, closed, false);
}
/**
* Creates a new Cylinder. By default its center is the origin. Usually, a
* higher sample number creates a better looking cylinder, but at the cost
* of more vertex information. <br>
* If the cylinder is closed the texture is split into axisSamples parts:
* top most and bottom most part is used for top and bottom of the cylinder,
* rest of the texture for the cylinder wall. The middle of the top is
* mapped to texture coordinates (0.5, 1), bottom to (0.5, 0). Thus you need
* a suited distorted texture.
*
* @param name
* The name of this Cylinder.
* @param axisSamples
* Number of triangle samples along the axis.
* @param radialSamples
* Number of triangle samples along the radial.
* @param radius
* The radius of the cylinder.
* @param height
* The cylinder's height.
* @param closed
* true to create a cylinder with top and bottom surface
* @param inverted
* true to create a cylinder that is meant to be viewed from the
* interior.
*/
public Cylinder(String name, int axisSamples, int radialSamples,
float radius, float height, boolean closed, boolean inverted) {
this(name, axisSamples, radialSamples, radius, radius, height, closed, inverted);
}
public Cylinder(String name, int axisSamples, int radialSamples,
float radius, float radius2, float height, boolean closed, boolean inverted) {
super(name);
updateGeometry(axisSamples, radialSamples, radius, radius2, height, closed, inverted);
}
/**
* @return the number of samples along the cylinder axis
*/
public int getAxisSamples() {
return axisSamples;
}
/**
* @return Returns the height.
*/
public float getHeight() {
return height;
}
/**
* @return number of samples around cylinder
*/
public int getRadialSamples() {
return radialSamples;
}
// /**
// * Set the height of the cylinder.
// * <p>
// * <strong>Note:</strong> this method causes the tri-mesh geometry data
// * to be recalculated, see <a href="package-summary.html#mutator-methods">
// * the package description</a> for more information about this.
// *
// * @param height the new height.
// */
// public void setHeight(float height) {
// this.height = height;
// allocateVertices();
// }
/**
* @return Returns the radius.
*/
public float getRadius() {
return radius;
}
public float getRadius2() {
return radius2;
}
/**
* @return true if end caps are used.
*/
public boolean isClosed() {
return closed;
}
/**
* @return true if normals and uvs are created for interior use
*/
public boolean isInverted() {
return inverted;
}
public void read(JMEImporter e) throws IOException {
super.read(e);
InputCapsule capsule = e.getCapsule(this);
axisSamples = capsule.readInt("axisSamples", 0);
radialSamples = capsule.readInt("radialSamples", 0);
radius = capsule.readFloat("radius", 0);
radius2 = capsule.readFloat("radius2", 0);
height = capsule.readFloat("height", 0);
closed = capsule.readBoolean("closed", false);
inverted = capsule.readBoolean("inverted", false);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?