本文整理汇总了Java中com.hackoeur.jglm.support.FastMath类的典型用法代码示例。如果您正苦于以下问题:Java FastMath类的具体用法?Java FastMath怎么用?Java FastMath使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FastMath类属于com.hackoeur.jglm.support包,在下文中一共展示了FastMath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: perspective
import com.hackoeur.jglm.support.FastMath; //导入依赖的package包/类
/**
* Creates a perspective projection matrix using field-of-view and
* aspect ratio to determine the left, right, top, bottom planes. This
* method is analogous to the now deprecated {@code gluPerspective} method.
*
* @param fovy field of view angle, in degrees, in the {@code y} direction
* @param aspect aspect ratio that determines the field of view in the x
* direction. The aspect ratio is the ratio of {@code x} (width) to
* {@code y} (height).
* @param zNear near plane distance from the viewer to the near clipping plane (always positive)
* @param zFar far plane distance from the viewer to the far clipping plane (always positive)
* @return
*/
public static final Mat4 perspective(final float fovy, final float aspect, final float zNear, final float zFar) {
final float halfFovyRadians = (float) FastMath.toRadians( (fovy / 2.0f) );
final float range = (float) FastMath.tan(halfFovyRadians) * zNear;
final float left = -range * aspect;
final float right = range * aspect;
final float bottom = -range;
final float top = range;
return new Mat4(
(2f * zNear) / (right - left), 0f, 0f, 0f,
0f, (2f * zNear) / (top - bottom), 0f, 0f,
0f, 0f, -(zFar + zNear) / (zFar - zNear), -1f,
0f, 0f, -(2f * zFar * zNear) / (zFar - zNear), 0f
);
}
示例2: update
import com.hackoeur.jglm.support.FastMath; //导入依赖的package包/类
@Override
public void update(float t, float dt)
{
List<SnapToTerrainNode> nodes = engine.getNodeList(SnapToTerrainNode.class);
HeightmapNode hnode = engine.getNodeList(HeightmapNode.class).get(0);
for (SnapToTerrainNode node : nodes)
{
float x = node.state.pos.getX();
float z = node.state.pos.getZ();
float y = getHeight(x, z, hnode.heightmap);
node.state.pos = new Vec3(x, y, z);
Vec3 tankNormal = getNormal(x, z, hnode.heightmap).multiply(0.5f);
Vec3 tankNX = new Vec3(tankNormal.getX(),tankNormal.getY(),0.0f).getUnitVector();
Vec3 tankNZ = new Vec3(0.0f,tankNormal.getY(),tankNormal.getZ()).getUnitVector();
float xRot = (float)FastMath.toDegrees(Math.asin(tankNZ.getZ()));
float zRot = -(float)FastMath.toDegrees(Math.asin(tankNX.getX()));
node.state.rot = new Vec4(xRot, node.state.rot.getY(), zRot, 0);
}
}
示例3: update
import com.hackoeur.jglm.support.FastMath; //导入依赖的package包/类
@Override
public void update(float t, float dt)
{
List<SpinnyCameraNode> nodes = engine.getNodeList(SpinnyCameraNode.class);
for (SpinnyCameraNode node : nodes)
{
final float angleRad = (float) FastMath.toRadians(node.spinny.angle);
final float pitchRad = (float) FastMath.toRadians(node.spinny.pitch);
node.spinny.angle += dt * node.spinny.angularVelocity;
node.camera.at = node.spinny.target;
node.camera.up = new Vec3(0, 1, 0);
float y = (float) FastMath.sin(pitchRad) * node.spinny.distance;
float r = (float) FastMath.cos(pitchRad) * node.spinny.distance;
float x = node.spinny.target.getX() + (float) FastMath.sin(angleRad) * r;
float z = node.spinny.target.getZ() + (float) FastMath.cos(angleRad) * r;
node.camera.eye = new Vec3(x, y, z);
}
}
示例4: getEntrancePointDistance
import com.hackoeur.jglm.support.FastMath; //导入依赖的package包/类
public float getEntrancePointDistance(Vec3 org, Vec3 ray)
{
List<Vec3> ps = getIntersectionPoints(org, ray);
if (ps.isEmpty())
{
return Float.POSITIVE_INFINITY;
}
float cdist = Float.POSITIVE_INFINITY;
for (int i = 0; i < ps.size(); i++)
{
float dist = ps.get(i).subtract(org).getLengthSquared();
if (dist < cdist)
{
cdist = dist;
}
}
return FastMath.sqrtFast(cdist);
}
示例5: rotate
import com.hackoeur.jglm.support.FastMath; //导入依赖的package包/类
/**
* Creates a rotation matrix for the given angle (in rad) around the given
* axis.
*
* @param phi The angle (in rad).
* @param axis The axis to rotate around. Must be a unit-axis.
* @return This matrix, rotated around the given axis.
*/
public static Mat4 rotate(final float phi, final Vec3 axis) {
double rcos = FastMath.cos(phi);
double rsin = FastMath.sin(phi);
float x = axis.x;
float y = axis.y;
float z = axis.z;
Vec4 v1 = new Vec4((float) (rcos + x * x * (1 - rcos)), (float) (z * rsin + y * x * (1 - rcos)), (float) (-y * rsin + z * x * (1 - rcos)), 0);
Vec4 v2 = new Vec4((float) (-z * rsin + x * y * (1 - rcos)), (float) (rcos + y * y * (1 - rcos)), (float) (x * rsin + z * y * (1 - rcos)), 0);
Vec4 v3 = new Vec4((float) (y * rsin + x * z * (1 - rcos)), (float) (-x * rsin + y * z * (1 - rcos)), (float) (rcos + z * z * (1 - rcos)), 0);
Vec4 v4 = new Vec4(0, 0, 0, 1);
return new Mat4(v1, v2, v3, v4);
}
示例6: getUnitVector
import com.hackoeur.jglm.support.FastMath; //导入依赖的package包/类
public Vec4 getUnitVector() {
final float sqLength = getLengthSquared();
final float invLength = FastMath.invSqrtFast(sqLength);
Vec4 normalVec = new Vec4(x * invLength, y * invLength, z * invLength, w * invLength);
return normalVec;
}
示例7: testRotate
import com.hackoeur.jglm.support.FastMath; //导入依赖的package包/类
@Test
public void testRotate() {
System.out.println("Rotate");
Mat4 got, expected;
got = Matrices.rotate((float) FastMath.PI, new Vec3(1, 0, 0));
expected = new Mat4(
+1.000000E+0f, +0.000000E+0f, +0.000000E+0f, +0.000000E+0f,
+0.000000E+0f, -1.000000E+0f, -8.742278E-8f, +0.000000E+0f,
+0.000000E+0f, +8.742278E-8f, -1.000000E+0f, +0.000000E+0f,
+0.000000E+0f, +0.000000E+0f, +0.000000E+0f, +1.000000E+0f
);
Assert.assertEquals(expected, got);
got = Matrices.rotate((float) FastMath.PI, new Vec3(0, 1, 0));
expected = new Mat4(
-1.000000E+0f, +0.000000E+0f, +8.742278E-8f, +0.000000E+0f,
+0.000000E+0f, +1.000000E+0f, +0.000000E+0f, +0.000000E+0f,
-8.742278E-8f, +0.000000E+0f, -1.000000E+0f, +0.000000E+0f,
+0.000000E+0f, +0.000000E+0f, +0.000000E+0f, +1.000000E+0f
);
Assert.assertEquals(expected, got);
got = Matrices.rotate((float) FastMath.PI, new Vec3(0, 0, 1));
expected = new Mat4(
-1.000000E+0f, -8.742278E-8f, +0.000000E+0f, +0.000000E+0f,
+8.742278E-8f, -1.000000E+0f, +0.000000E+0f, +0.000000E+0f,
+0.000000E+0f, +0.000000E+0f, +1.000000E+0f, +0.000000E+0f,
+0.000000E+0f, +0.000000E+0f, +0.000000E+0f, +1.000000E+0f
);
Assert.assertEquals(expected, got);
got = Matrices.rotate((float) FastMath.PI, new Vec3(1, 1, 1).getUnitVector());
expected = new Mat4(
-0.33333474f, +0.66666520f, +0.66666530f, +0.0000000E+0f,
+0.66666530f, -0.33333474f, +0.66666520f, +0.0000000E+0f,
+0.66666520f, +0.66666530f, -0.33333474f, +0.0000000E+0f,
+0.00000000f, +0.00000000f, +0.00000000f, +1.0000000E+0f
);
Assert.assertEquals(expected, got);
}
示例8: testFastInvSqrt
import com.hackoeur.jglm.support.FastMath; //导入依赖的package包/类
@Test
public void testFastInvSqrt() {
final float x = 133511f;
final float fastInvSqrt = FastMath.invSqrtFast(x);
final float computedInvSqrt = (float) (1 / StrictMath.sqrt(x));
Assert.assertEquals(fastInvSqrt, computedInvSqrt, 0.000000001f);
}
示例9: testFastSqrt
import com.hackoeur.jglm.support.FastMath; //导入依赖的package包/类
@Test
public void testFastSqrt() {
final float x = 133511f;
final float fastSqrt = FastMath.sqrtFast(x);
final float computedSqrt = (float) StrictMath.sqrt(x);
Assert.assertEquals(fastSqrt, computedSqrt, 0.0001f);
}
示例10: intersectionTesting
import com.hackoeur.jglm.support.FastMath; //导入依赖的package包/类
/**
* This function determines whether entity A will, and has crossed paths
* with entity B. We make use of the following formulas:
* <pre>
* A = a1 - b1
* B = (a2 - a1) - (b2 - b1)
* d^2 = A^2 - ((A · B)^2 / B^2)
* t = (-(A·B) - Sqr((A·B)^2 - B^2 (A^2 - (r(a) + r(b))^2))) / B^2
* </pre> if B^2 = 0, then either both a and b are: stationary or moving in
* the same direction at the same speed, and can thus not collide.
* <p>
* if d^2 > (r(a) + r(b))^2 - the sum of the entities radii squared. then
* the entities can never collide on there current trajectories.
* </p><p>
* if t is greater or equal to 0, and smaller than 1. Then entities a and b
* intersect in the current time step.
* </p>
*
* @param a
* @param b
* @return
*/
protected boolean intersectionTesting(State a, State b)
{
Vec3 B = (a.pos.subtract(a.prevPos)).subtract(b.pos.subtract(b.prevPos));
double bSqr = B.getLengthSquared();
if (Double.compare(bSqr, 0.0f) == 0)
{
return false;
}
Vec3 A = a.prevPos.subtract(b.prevPos);
double aSqr = A.getLengthSquared();
double rrSqr = ((a.scale.add(b.scale)).getLengthSquared()) / 2;
double aDotb = (A.dot(B));
double aDotbSqr = aDotb * aDotb;
double d2 = aSqr - (aDotbSqr / bSqr);
if (Double.compare(d2, rrSqr) > 0)
{
return false;
}
//find fastInv double implimentation
double t = (-(aDotb) - FastMath.sqrtFast((float) ((aDotbSqr) - bSqr * (aSqr - (rrSqr))))) / bSqr;
if (Double.compare(t, 0) < 0 || Double.compare(t, 1) >= 0)
{
return false;
}
return true;
}
示例11: getAngles
import com.hackoeur.jglm.support.FastMath; //导入依赖的package包/类
public static float[] getAngles(Vec3 v)
{
float bearing = (float) FastMath.atan2(v.getZ(), v.getX());
float elevation = (float) FastMath.atan2(v.getY(),
FastMath.sqrtFast(v.getX() * v.getX() + v.getZ() * v.getZ()));
return new float[]
{
bearing, elevation
};
}
示例12: createWorldMatrix
import com.hackoeur.jglm.support.FastMath; //导入依赖的package包/类
private Mat4 createWorldMatrix(AbstractCamera camera)
{
Mat4 world = new Mat4(1f);
world = Matrices.translate(world, getWorldPosition());
float x = camera.dir.getX();
float y = camera.dir.getY();
float z = camera.dir.getZ();
float roty, rotr;
if (z >= 0)
roty = -(float)FastMath.toDegrees(FastMath.atan2(z, x));
else
roty = (float)FastMath.toDegrees(FastMath.atan2(-z, x));
if (y >= 0)
rotr = -(float)FastMath.toDegrees(FastMath.atan2(-y, FastMath.sqrtFast(x*x+z*z)));
else
rotr = (float)FastMath.toDegrees(FastMath.atan2(y, FastMath.sqrtFast(x*x+z*z)));
// TODO: zRot must have an effect on the rotation of the billboard
if (spherical)
world = Matrices.rotate(
world,
rotr,
camera.right);
world = Matrices.rotate(
world,
roty,
new Vec3(0,1,0));
world = Matrices.scale(world, getWorldScale());
return world;
}
示例13:
import com.hackoeur.jglm.support.FastMath; //导入依赖的package包/类
public static final Mat4 rotate
(
final Mat4 m,
final float angle,
final Vec3 v
)
{
float a = (float)FastMath.toRadians(angle);
float c = (float)FastMath.cos(a);
float s = (float)FastMath.sin(a);
Vec3 axis = v.getUnitVector();
Vec3 temp = axis.scale(1f - c);
float
rot00 = c + temp.x * axis.x,
rot01 = 0 + temp.x * axis.y + s * axis.z,
rot02 = 0 + temp.x * axis.z - s * axis.y,
rot10 = 0 + temp.y * axis.x - s * axis.z,
rot11 = c + temp.y * axis.y,
rot12 = 0 + temp.y * axis.z + s * axis.x,
rot20 = 0 + temp.z * axis.x + s * axis.y,
rot21 = 0 + temp.z * axis.y - s * axis.x,
rot22 = c + temp.z * axis.z;
Mat4 Result = new Mat4(
m.<Vec4>getColumn(0) .scale( rot00 ) .add( m.<Vec4>getColumn(1) .scale( rot01 ) ) .add( m.<Vec4>getColumn(2) .scale( rot02 ) ),
m.<Vec4>getColumn(0) .scale( rot10 ) .add( m.<Vec4>getColumn(1) .scale( rot11 ) ) .add( m.<Vec4>getColumn(2) .scale( rot12 ) ),
m.<Vec4>getColumn(0) .scale( rot20 ) .add( m.<Vec4>getColumn(1) .scale( rot21 ) ) .add( m.<Vec4>getColumn(2) .scale( rot22 ) ),
m.<Vec4>getColumn(3)
);
return Result;
}
示例14: getLength
import com.hackoeur.jglm.support.FastMath; //导入依赖的package包/类
@Override
public final float getLength() {
return (float) FastMath.sqrtFast( getLengthSquared() );
}
示例15: getUnitVector
import com.hackoeur.jglm.support.FastMath; //导入依赖的package包/类
public Vec3 getUnitVector() {
final float sqLength = getLengthSquared();
final float invLength = FastMath.invSqrtFast(sqLength);
return new Vec3(x * invLength, y * invLength, z * invLength);
}