本文整理匯總了Java中com.jme3.math.FastMath.cos方法的典型用法代碼示例。如果您正苦於以下問題:Java FastMath.cos方法的具體用法?Java FastMath.cos怎麽用?Java FastMath.cos使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.jme3.math.FastMath
的用法示例。
在下文中一共展示了FastMath.cos方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateGeometry
import com.jme3.math.FastMath; //導入方法依賴的package包/類
protected void updateGeometry() {
FloatBuffer positions = BufferUtils.createFloatBuffer(samples * 3);
FloatBuffer normals = BufferUtils.createFloatBuffer(samples * 3);
short[] indices = new short[samples * 2];
float rate = FastMath.TWO_PI / samples;
float angle = 0;
int idc = 0;
for (int i = 0; i < samples; i++) {
float x = FastMath.cos(angle) * radius.x + center.x;
float z = FastMath.sin(angle) * radius.y + center.y;
positions.put(x).put(z).put(0);
normals.put(new float[]{0, 1, 0});
indices[idc++] = (short) i;
if (i < samples - 1) {
indices[idc++] = (short) (i + 1);
} else {
indices[idc++] = 0;
}
angle += rate;
}
setBuffer(VertexBuffer.Type.Position, 3, positions);
setBuffer(VertexBuffer.Type.Normal, 3, normals);
setBuffer(VertexBuffer.Type.Index, 2, indices);
setBuffer(VertexBuffer.Type.TexCoord, 2, new float[]{0, 0, 1, 1});
updateBound();
}
示例2: onLayout
import com.jme3.math.FastMath; //導入方法依賴的package包/類
@Override
protected void onLayout(ElementContainer<?,?> parent) {
for (BaseElement el : parent.getElements()) {
float cx = parent.getWidth() / 2f;
float cy = parent.getHeight() / 2f;
Vector2f elpref = el.calcPreferredSize();
RadialLayoutInfo con = constraints.get(el);
String layoutData = el.getLayoutData();
if(layoutData != null && layoutData.length() > 0) {
con = parseConstraints(layoutData);
}
float inset = this.inset;
if (con != null) {
if(con.getInset() != Float.MIN_VALUE)
inset = con.getInset();
cx += FastMath.sin(con.getAngle()) * (cx - inset);
cy -= FastMath.cos(con.getAngle()) * (cy - inset);
el.setBounds(Math.round(cx - (elpref.x / 2f)), Math.round(cy - (elpref.y / 2f)), elpref.x, elpref.y);
}
}
}
示例3: updateGeometry
import com.jme3.math.FastMath; //導入方法依賴的package包/類
protected void updateGeometry() {
FloatBuffer positions = BufferUtils.createFloatBuffer(samples * 3);
FloatBuffer normals = BufferUtils.createFloatBuffer(samples * 3);
short[] indices = new short[samples * 2];
float rate = FastMath.TWO_PI / samples;
float angle = 0;
for (int i = 0; i < samples; i++) {
float x = FastMath.cos(angle) + center.x;
float y = FastMath.sin(angle) + center.y;
positions.put(x * radius).put(y * radius).put(center.z);
normals.put(new float[] { 0, 1, 0 });
indices[i * 2] = (short) i;
indices[i * 2 + 1] = (short) ((i + 1) % samples);
angle += rate;
}
setBuffer(Type.Position, 3, positions);
setBuffer(Type.Normal, 3, normals);
setBuffer(Type.Index, 2, indices);
setBuffer(Type.TexCoord, 2, new float[] { 0, 0, 1, 1 });
updateBound();
}
示例4: simpleUpdate
import com.jme3.math.FastMath; //導入方法依賴的package包/類
@Override
public void simpleUpdate(float tpf){
angle += tpf;
angle %= FastMath.TWO_PI;
float x = FastMath.cos(angle) * 2;
float y = FastMath.sin(angle) * 2;
emit.setLocalTranslation(x, 0, y);
}
示例5: setToleranceAngle
import com.jme3.math.FastMath; //導入方法依賴的package包/類
public static void setToleranceAngle(float angle) {
if (angle < 0 || angle > 179) {
throw new IllegalArgumentException(
"The angle must be between 0 and 179 degrees.");
}
toleranceDot = FastMath.cos(angle*FastMath.DEG_TO_RAD);
toleranceAngle = angle;
}
示例6: rotatedBoundsLocal
import com.jme3.math.FastMath; //導入方法依賴的package包/類
public static Vector2f rotatedBoundsLocal(Vector2f rect, float rad) {
float s = FastMath.sin(rad);
float c = FastMath.cos(rad);
float rx = rect.y * FastMath.abs(s) + rect.x * FastMath.abs(c);
float ry = rect.y * FastMath.abs(c) + rect.x * FastMath.abs(s);
rect.set(rx, ry);
return rect;
}
示例7: rot
import com.jme3.math.FastMath; //導入方法依賴的package包/類
public Vector2f rot(Vector2f p, float angle) {
cos = FastMath.cos(angle * FastMath.DEG_TO_RAD);
sin = FastMath.sin(angle * FastMath.DEG_TO_RAD);
x = p.x * cos - p.y * sin;
y = p.x * sin + p.y * cos;
return p.set(x, y);
}
示例8: getRandomPositionInXZPlane
import com.jme3.math.FastMath; //導入方法依賴的package包/類
/**
* 以原點為中心,在半徑為radius的xz平麵範圍內取一個點
* @param maxRadius
* @param store
* @return
*/
public static Vector3f getRandomPositionInXZPlane(float maxRadius, Vector3f store) {
if (store == null) {
store = new Vector3f();
}
TempVars tv = TempVars.get();
float radius = FastMath.nextRandomFloat() * maxRadius;
float angleInRadian = FastMath.nextRandomFloat() * FastMath.TWO_PI;
float x = FastMath.cos(angleInRadian) * radius;
float y = FastMath.sin(angleInRadian) * radius;
store.set(x, 0, y); // xz平麵
tv.release();
return store;
}
示例9: setGeometryData
import com.jme3.math.FastMath; //導入方法依賴的package包/類
private void setGeometryData() {
// allocate vertices
int vertCount = (circleSamples + 1) * (radialSamples + 1);
FloatBuffer fpb = BufferUtils.createVector3Buffer(vertCount);
setBuffer(Type.Position, 3, fpb);
// allocate normals if requested
FloatBuffer fnb = BufferUtils.createVector3Buffer(vertCount);
setBuffer(Type.Normal, 3, fnb);
// allocate texture coordinates
FloatBuffer ftb = BufferUtils.createVector2Buffer(vertCount);
setBuffer(Type.TexCoord, 2, ftb);
// generate geometry
float inverseCircleSamples = 1.0f / circleSamples;
float inverseRadialSamples = 1.0f / radialSamples;
int i = 0;
// generate the cylinder itself
Vector3f radialAxis = new Vector3f(), torusMiddle = new Vector3f(), tempNormal = new Vector3f();
for (int circleCount = 0; circleCount < circleSamples; circleCount++) {
// compute center point on torus circle at specified angle
float circleFraction = circleCount * inverseCircleSamples;
float theta = FastMath.TWO_PI * circleFraction;
float cosTheta = FastMath.cos(theta);
float sinTheta = FastMath.sin(theta);
radialAxis.set(cosTheta, sinTheta, 0);
radialAxis.mult(outerRadius, torusMiddle);
// compute slice vertices with duplication at end point
int iSave = i;
for (int radialCount = 0; radialCount < radialSamples; radialCount++) {
float radialFraction = radialCount * inverseRadialSamples;
// in [0,1)
float phi = FastMath.TWO_PI * radialFraction;
float cosPhi = FastMath.cos(phi);
float sinPhi = FastMath.sin(phi);
tempNormal.set(radialAxis).multLocal(cosPhi);
tempNormal.z += sinPhi;
fnb.put(tempNormal.x).put(tempNormal.y).put(
tempNormal.z);
tempNormal.multLocal(innerRadius).addLocal(torusMiddle);
fpb.put(tempNormal.x).put(tempNormal.y).put(
tempNormal.z);
ftb.put(radialFraction).put(circleFraction);
i++;
}
BufferUtils.copyInternalVector3(fpb, iSave, i);
BufferUtils.copyInternalVector3(fnb, iSave, i);
ftb.put(1.0f).put(circleFraction);
i++;
}
// duplicate the cylinder ends to form a torus
for (int iR = 0; iR <= radialSamples; iR++, i++) {
BufferUtils.copyInternalVector3(fpb, iR, i);
BufferUtils.copyInternalVector3(fnb, iR, i);
BufferUtils.copyInternalVector2(ftb, iR, i);
ftb.put(i * 2 + 1, 1.0f);
}
}
示例10: rotatedBounds
import com.jme3.math.FastMath; //導入方法依賴的package包/類
public static Vector2f rotatedBounds(Vector2f rect, float rad) {
float s = FastMath.sin(rad);
float c = FastMath.cos(rad);
return new Vector2f(rect.y * FastMath.abs(s) + rect.x * FastMath.abs(c),
rect.y * FastMath.abs(c) + rect.x * FastMath.abs(s));
}
示例11: apply
import com.jme3.math.FastMath; //導入方法依賴的package包/類
@Override
public float apply (float a) {
return (1 - FastMath.cos(a * FastMath.PI)) / 2;
}
示例12: createCone
import com.jme3.math.FastMath; //導入方法依賴的package包/類
private static Mesh createCone(int radialSamples, float radius, float height) {
Mesh cone = new Mesh();
float fInvRS = 1.0f / radialSamples;
// Generate points on the unit circle to be used in computing the mesh
// points on a dome slice.
float[] afSin = new float[radialSamples];
float[] afCos = new float[radialSamples];
for (int i = 0; i < radialSamples; i++) {
float fAngle = FastMath.TWO_PI * fInvRS * i;
afCos[i] = FastMath.cos(fAngle);
afSin[i] = FastMath.sin(fAngle);
}
FloatBuffer vb = BufferUtils.createVector3Buffer(radialSamples + 2);
cone.setBuffer(Type.Position, 3, vb);
TempVars vars = TempVars.get();
Vector3f tempVa = vars.vect1;
for (int i = 0; i < radialSamples; i++) {
Vector3f kRadial = tempVa.set(afCos[i], 0, afSin[i]);
kRadial.mult(radius, tempVa);
vb.put(tempVa.x).put(tempVa.y).put(tempVa.z);
BufferUtils.populateFromBuffer(tempVa, vb, i);
}
vars.release();
// top of the cone
vb.put(0).put(height).put(0);
// base of the cone
vb.put(0).put(0).put(0);
ShortBuffer ib = BufferUtils.createShortBuffer(3 * (radialSamples) * 2);
cone.setBuffer(Type.Index, 3, ib);
short top = (short) radialSamples;
short bot = (short) (radialSamples + 1);
for (int i = 0; i < radialSamples; i++) {
short a = (short) i;
short b = (short) ((i + 1) % radialSamples);
ib.put(top);
ib.put(b);
ib.put(a);
ib.put(a);
ib.put(b);
ib.put(bot);
}
cone.updateBound();
return cone;
}
示例13: setGeometryData
import com.jme3.math.FastMath; //導入方法依賴的package包/類
/**
* builds the vertices based on the radius
*/
private void setGeometryData() {
setMode(Mode.Lines);
FloatBuffer posBuf = BufferUtils.createVector3Buffer((radialSamples + 1));
FloatBuffer colBuf = BufferUtils.createFloatBuffer((radialSamples + 1) * 4);
FloatBuffer texBuf = BufferUtils.createVector2Buffer(radialSamples + 1);
setBuffer(Type.Position, 3, posBuf);
setBuffer(Type.Color, 4, colBuf);
setBuffer(Type.TexCoord, 2, texBuf);
// generate geometry
float fInvRS = 1.0f / radialSamples;
// Generate points on the unit circle to be used in computing the mesh
// points on a sphere slice.
float[] afSin = new float[(radialSamples + 1)];
float[] afCos = new float[(radialSamples + 1)];
for (int iR = 0; iR < radialSamples; iR++) {
float fAngle = FastMath.TWO_PI * fInvRS * iR;
afCos[iR] = FastMath.cos(fAngle);
afSin[iR] = FastMath.sin(fAngle);
}
afSin[radialSamples] = afSin[0];
afCos[radialSamples] = afCos[0];
for (int iR = 0; iR <= radialSamples; iR++) {
posBuf.put(afCos[iR])
.put(afSin[iR])
.put(0);
colBuf.put(ColorRGBA.Orange.r)
.put(ColorRGBA.Orange.g)
.put(ColorRGBA.Orange.b)
.put(ColorRGBA.Orange.a);
texBuf.put(iR % 2f)
.put(iR % 2f);
}
updateBound();
setStatic();
}
示例14: setGeometryData
import com.jme3.math.FastMath; //導入方法依賴的package包/類
/**
* builds the vertices based on the radius
*/
private void setGeometryData() {
setMode(Mode.Lines);
FloatBuffer posBuf = BufferUtils.createVector3Buffer((radialSamples + 1));
FloatBuffer colBuf = BufferUtils.createFloatBuffer((radialSamples + 1) * 4);
FloatBuffer texBuf = BufferUtils.createVector2Buffer(radialSamples + 1);
setBuffer(Type.Position, 3, posBuf);
setBuffer(Type.Color, 4, colBuf);
setBuffer(Type.TexCoord, 2, texBuf);
// generate geometry
float fInvRS = 1.0f / radialSamples;
// Generate points on the unit circle to be used in computing the mesh
// points on a sphere slice.
float[] afSin = new float[(radialSamples + 1)];
float[] afCos = new float[(radialSamples + 1)];
for (int iR = 0; iR < radialSamples; iR++) {
float fAngle = FastMath.TWO_PI * fInvRS * iR;
afCos[iR] = FastMath.cos(fAngle);
afSin[iR] = FastMath.sin(fAngle);
}
afSin[radialSamples] = afSin[0];
afCos[radialSamples] = afCos[0];
for (int iR = 0; iR <= radialSamples; iR++) {
posBuf.put(afCos[iR])
.put(afSin[iR])
.put(0);
colBuf.put(ColorRGBA.Orange.r)
.put(ColorRGBA.Orange.g)
.put(ColorRGBA.Orange.b)
.put(ColorRGBA.Orange.a);
texBuf.put(iR % 2f)
.put(iR % 2f);
}
updateBound();
setStatic();
}
示例15: processToggleSwitchElement
import com.jme3.math.FastMath; //導入方法依賴的package包/類
private Spatial processToggleSwitchElement(Element elm, boolean isWhole) {
String id = getUniqueId(elm.getAttribute("id"));
boolean pointable = Boolean.parseBoolean(elm.getAttribute("pointable"));
Vector3f location = parseVector3(elm.getAttribute("location"));
Vector3f rotation = parseVector3(elm.getAttribute("rotation"));
float xspan = Float.parseFloat(elm.getAttribute("xspan"));
float zspan = Float.parseFloat(elm.getAttribute("yspan"));
float yspan = Float.parseFloat(elm.getAttribute("zspan"));
float angle = Float.parseFloat(elm.getAttribute("angle")) * FastMath.DEG_TO_RAD;
ColorRGBA color = parseColor(elm.getAttribute("color"));
boolean leftPressed = Boolean.parseBoolean(elm.getAttribute("leftPressed"));
int numStates = Integer.parseInt(elm.getAttribute("numStates"));
int initState = Integer.parseInt(elm.getAttribute("initState"));
if (initState < 0) {
initState = 0;
} else if (initState >= numStates) {
initState = numStates - 1;
}
float btxspan = xspan / (1.0f + FastMath.cos(angle));
Node s = new Node(id);
s.setLocalTranslation(location);
s.setLocalRotation(new Quaternion().fromAngles(
rotation.x * FastMath.DEG_TO_RAD,
rotation.y * FastMath.DEG_TO_RAD,
rotation.z * FastMath.DEG_TO_RAD));
// button 1
Spatial b1 = factory.makeBlock(id + "-b1", btxspan, yspan, zspan, color);
b1.setLocalTranslation(-btxspan / 2, yspan / 2, 0);
s.attachChild(b1);
// button 2
Spatial b2 = factory.makeBlock(id + "-b2", btxspan, yspan, zspan, color);
b2.setLocalRotation(new Quaternion().fromAngles(0, 0, angle));
float hypoLen = FastMath.sqr(btxspan * btxspan + yspan * yspan); // hypotenues
float cosine = (btxspan / hypoLen) * FastMath.cos(angle) - (yspan / hypoLen) * FastMath.sin(angle);
float sine = (yspan / hypoLen) * FastMath.cos(angle) + (btxspan / hypoLen) * FastMath.sin(angle);
b2.setLocalTranslation(hypoLen / 2f * cosine, hypoLen / 2f * sine, 0);
s.attachChild(b2);
// get <downstream> and <state> elements
LinkedList<String> dsIds = new LinkedList<>();
for (org.w3c.dom.Node child = elm.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE
&& child.getNodeName().equals("downstream")) {
dsIds.add(((Element) child).getAttribute("id"));
}
}
ToggleSwitchControl c = new ToggleSwitchControl(inventory, s, angle, leftPressed, numStates, initState);
for (String dsId : dsIds) {
c.addDownstreamId(dsId);
}
inventory.registerControl(s, c);
if (isWhole) {
float mass = Float.parseFloat(elm.getAttribute("mass"));
inventory.addItem(s, mass);
processDescriptionElements(elm, s, "toggleSwitch");
}
if (pointable) {
s.setUserData("pointable", "" + pointable);
}
return s;
}