本文整理汇总了Java中com.jme3.math.FastMath类的典型用法代码示例。如果您正苦于以下问题:Java FastMath类的具体用法?Java FastMath怎么用?Java FastMath使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FastMath类属于com.jme3.math包,在下文中一共展示了FastMath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateAngle
import com.jme3.math.FastMath; //导入依赖的package包/类
private void updateAngle() {
Vector3f temp, higher, lower;
if (point2.y > point1.y) {
temp = point2;
higher = point2;
lower = point1;
} else {
temp = point1;
higher = point1;
lower = point2;
}
temp = temp.clone().setY(lower.y);
float angle = ((FastMath.asin(temp.distance(higher) / lower.distance(higher))) * FastMath.RAD_TO_DEG);
angleText.setText(angle + " degrees");
angleText.setLocalTranslation(new Vector3f().interpolateLocal(point1, point2, 0.5f));
if (line.getParent() == null) {
parent.attachChild(line);
parent.attachChild(angleText);
}
((Line) line.getMesh()).updatePoints(point1, point2);
}
示例2: zoomCamera
import com.jme3.math.FastMath; //导入依赖的package包/类
protected void zoomCamera(float value){
// derive fovY value
float h = cam.getFrustumTop();
float w = cam.getFrustumRight();
float aspect = w / h;
float near = cam.getFrustumNear();
float fovY = FastMath.atan(h / near)
/ (FastMath.DEG_TO_RAD * .5f);
fovY += value * 0.1f;
h = FastMath.tan( fovY * FastMath.DEG_TO_RAD * .5f) * near;
w = h * aspect;
cam.setFrustumTop(h);
cam.setFrustumBottom(-h);
cam.setFrustumLeft(-w);
cam.setFrustumRight(w);
}
示例3: doAnimUpdate
import com.jme3.math.FastMath; //导入依赖的package包/类
@Override
protected void doAnimUpdate(float interpolation) {
TempVars tv = TempVars.get();
Vector3f scale = tv.vect1;
FastMath.extrapolateLinear(interpolation, startScale, endScale, scale);
target.setLocalScale(scale);
// 位置偏移,当设置了缩放偏移时需要处理缩放过程中的目标对象位置
if (localScaleOffset != null) {
FastMath.extrapolateLinear(interpolation, scaleStartPos, scaleEndPos, tv.vect2);
target.setLocalTranslation(tv.vect2);
}
tv.release();
}
示例4: checkSlope
import com.jme3.math.FastMath; //导入依赖的package包/类
protected void checkSlope() {
if (this.getWalkDirection().length() > 0) {
List<PhysicsRayTestResult> results = space.rayTest(
rigidBody.getPhysicsLocation().add(0, 0.01f, 0),
rigidBody.getPhysicsLocation().add(
walkDirection.setY(0).normalize().mult(getFinalRadius())).add(0, 0.01f, 0));
for (PhysicsRayTestResult physicsRayTestResult : results) {
float angle = physicsRayTestResult
.getHitNormalLocal()
.normalize()
.angleBetween(
physicsRayTestResult.getHitNormalLocal()
.setY(0).normalize());
if (Math.abs(angle * FastMath.RAD_TO_DEG - 90) > maxSlope && !physicsRayTestResult.getCollisionObject().equals(rigidBody)) {
tooSteep = true;
return;
}
}
}
tooSteep = false;
}
示例5: doZoomCamera
import com.jme3.math.FastMath; //导入依赖的package包/类
public void doZoomCamera(float amount) {
amount = amount * 0.1f;
amount = cam.getLocation().distance(focus) * amount;
float dist = cam.getLocation().distance(focus);
amount = dist - Math.max(0f, dist - amount);
// 一个最小距离用于防止拉到0距离后缩放不回来的BUG
if (amount >= dist) {
amount -= minDistance;
}
Vector3f loc = cam.getLocation().clone();
loc.scaleAdd(amount, cam.getDirection(), loc);
cam.setLocation(loc);
if (cam.isParallelProjection()) {
float aspect = (float) cam.getWidth() / cam.getHeight();
float h = FastMath.tan(45f * FastMath.DEG_TO_RAD * .5f) * dist;
float w = h * aspect;
cam.setFrustum(orthoNear, orthoFar, -w, w, h, -h);
}
// LOG.log(Level.INFO, "doZoomCamera, Camera location={0}", cam.getLocation());
}
示例6: dropRandomBlock
import com.jme3.math.FastMath; //导入依赖的package包/类
public void dropRandomBlock() {
final ColorRGBA[] colors = new ColorRGBA[] { ColorRGBA.Red,
ColorRGBA.Blue, ColorRGBA.Yellow, ColorRGBA.Green,
ColorRGBA.Brown, ColorRGBA.Cyan, ColorRGBA.Magenta,
ColorRGBA.Orange };
Spatial s = factory.makeBlock(getUniqueId("largeblock"), 1.5f, 1.5f, 1.5f,
colors[random.nextInt(colors.length)]);
s.setLocalTranslation(
(random.nextFloat() * 2 - 1) * (tableWidth / 2),
10,
(random.nextFloat() * 2 - 1) * (tableDepth / 2));
s.setLocalRotation(new Quaternion().fromAngleAxis(
FastMath.HALF_PI * random.nextFloat(),
Vector3f.UNIT_XYZ));
inventory.addItem(s, 1);
}
示例7: tryDetour
import com.jme3.math.FastMath; //导入依赖的package包/类
@Override
protected void tryDetour(int count) {
if (count == 0) {
direction = MathUtils.randomPON();
}
TempVars tv = TempVars.get();
float angle = 30 * (count + 1) * FastMath.DEG_TO_RAD * direction;
tv.vect1.set(actorService.getWalkDirection(actor));
MathUtils.rotate(tv.vect1.normalizeLocal(), angle, Vector3f.UNIT_Y, tv.vect2);
detour(tv.vect2);
tv.release();
float lockTime = count * 0.25f + 0.25f;
action.lock(lockTime);
}
示例8: jSpinner1StateChanged
import com.jme3.math.FastMath; //导入依赖的package包/类
private void jSpinner1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinner1StateChanged
// This is called, when the spinner of the near plane has been changed.
float near = ((float)jSlider1.getValue() / 1000f);
float spin = (Float)jSpinner1.getValue();
// Prevent an endless loop of state changes and don't change the slider when the spinner
// has gone out of range, since this would lead to the slider's StateChanged overwriting the spinner again.
// but we want the spinner to be a free-form field
if (spin <= 2000f && spin >= 100f && !FastMath.approximateEquals((Float)(jSpinner1.getValue()), near)) {
jSlider1.setValue((int)((Float)(jSpinner1.getValue()) * 1000f));
}
final Camera cam = SceneApplication.getApplication().getCamera();
cam.setFrustumPerspective(45f, (float)cam.getWidth() / cam.getHeight(), spin, cam.getFrustumFar());
}
示例9: doToggleOrthoPerspMode
import com.jme3.math.FastMath; //导入依赖的package包/类
protected boolean doToggleOrthoPerspMode() {
float aspect = (float) cam.getWidth() / cam.getHeight();
if (!cam.isParallelProjection()) {
cam.setParallelProjection(true);
float h = cam.getFrustumTop();
float w;
float dist = cam.getLocation().distance(focus);
float fovY = FastMath.atan(h) / (FastMath.DEG_TO_RAD * .5f);
h = FastMath.tan(fovY * FastMath.DEG_TO_RAD * .5f) * dist;
w = h * aspect;
cam.setFrustum(-1000, 1000, -w, w, h, -h);
return true;
} else {
cam.setParallelProjection(false);
cam.setFrustumPerspective(45f, aspect, 1, 1000);
return false;
}
}
示例10: 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();
}
示例11: setMeshes
import com.jme3.math.FastMath; //导入依赖的package包/类
@Override
public void setMeshes(List<Mesh> meshes) {
this.vertices = new ArrayList<List<Vector3f>>(meshes.size());
this.normals = new ArrayList<List<Vector3f>>(meshes.size());
for (Mesh mesh : meshes) {
Vector3f[] vertexTable = BufferUtils.getVector3Array(mesh.getFloatBuffer(Type.Position));
int[] indices = new int[3];
List<Vector3f> vertices = new ArrayList<Vector3f>(mesh.getTriangleCount() * 3);
List<Vector3f> normals = new ArrayList<Vector3f>(mesh.getTriangleCount());
for (int i = 0; i < mesh.getTriangleCount(); ++i) {
mesh.getTriangle(i, indices);
vertices.add(vertexTable[indices[0]]);
vertices.add(vertexTable[indices[1]]);
vertices.add(vertexTable[indices[2]]);
normals.add(FastMath.computeNormal(vertexTable[indices[0]], vertexTable[indices[1]], vertexTable[indices[2]]));
}
this.vertices.add(vertices);
this.normals.add(normals);
}
}
示例12: completeWrap
import com.jme3.math.FastMath; //导入依赖的package包/类
protected void completeWrap(int i) {
lineWidth = Math.max(lnWidth, lineWidth);
updateLineForAlignment(0, i, lineWidth);
updateForAlign();
Vector2f rotSize = rotation == 0 ? dimensions
: MathUtil.rotatedBounds(dimensions, rotation * FastMath.RAD_TO_DEG);
setOrigin(rotSize.x / 2, rotSize.y / 2);
setOrigin(0, 0);
mesh.update(0);
mesh.updateBound();
lineDisplay.update(0);
if (textVAlign != null) {
alignToBoundsV();
}
}
示例13: getLowestRoot
import com.jme3.math.FastMath; //导入依赖的package包/类
private static float getLowestRoot(float a, float b, float c, float maxR) {
float determinant = b * b - 4f * a * c;
if (determinant < 0){
return Float.NaN;
}
float sqrtd = FastMath.sqrt(determinant);
float r1 = (-b - sqrtd) / (2f * a);
float r2 = (-b + sqrtd) / (2f * a);
if (r1 > r2){
float temp = r2;
r2 = r1;
r1 = temp;
}
if (r1 > 0 && r1 < maxR){
return r1;
}
if (r2 > 0 && r2 < maxR){
return r2;
}
return Float.NaN;
}
示例14: getTriangleAtPoint
import com.jme3.math.FastMath; //导入依赖的package包/类
/**
* Get the triangle that the point is on.
*
* @param x coordinate in local space to the geomap
* @param z coordinate in local space to the geomap
* @return triangle in local space to the geomap
*/
protected Triangle getTriangleAtPoint(float x, float z) {
Triangle[] triangles = getGridTrianglesAtPoint(x, z);
if (triangles == null) {
System.out.println("x,z: " + x + "," + z);
return null;
}
Vector2f point = new Vector2f(x, z);
Vector2f t1 = new Vector2f(triangles[0].get1().x, triangles[0].get1().z);
Vector2f t2 = new Vector2f(triangles[0].get2().x, triangles[0].get2().z);
Vector2f t3 = new Vector2f(triangles[0].get3().x, triangles[0].get3().z);
if (0 != FastMath.pointInsideTriangle(t1, t2, t3, point)) {
return triangles[0];
}
t1.set(triangles[1].get1().x, triangles[1].get1().z);
t1.set(triangles[1].get2().x, triangles[1].get2().z);
t1.set(triangles[1].get3().x, triangles[1].get3().z);
if (0 != FastMath.pointInsideTriangle(t1, t2, t3, point)) {
return triangles[1];
}
return null;
}
示例15: processGuestBondPointElement
import com.jme3.math.FastMath; //导入依赖的package包/类
private Spatial processGuestBondPointElement(Element elm) {
String id = elm.getAttribute("id");
id = getUniqueId(id);
// Non-empty string; two parts must have the same type before they can be put together
String type = elm.getAttribute("type");
Vector3f location = parseVector3(elm.getAttribute("location"));
Vector3f rotation = parseVector3(elm.getAttribute("rotation"));
// The host bond point that this object (guest) is fastened to; ignored if is host
String hostId = elm.getAttribute("initBondHostId");
int hostTightness = Integer.parseInt(elm.getAttribute("initBondTightness"));
Node node = new Node(id);
node.setLocalTranslation(location);
node.setLocalRotation(new Quaternion().fromAngles(
rotation.x * FastMath.DEG_TO_RAD,
rotation.y * FastMath.DEG_TO_RAD,
rotation.z * FastMath.DEG_TO_RAD));
node.setUserData("bondPoint", "guest");
node.setUserData("bondType", type);
if (!hostId.isEmpty()) {
node.setUserData("initBondHostId", hostId);
node.setUserData("initBondTightness", hostTightness);
}
return node;
}