本文整理汇总了Java中org.joml.Math类的典型用法代码示例。如果您正苦于以下问题:Java Math类的具体用法?Java Math怎么用?Java Math使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Math类属于org.joml包,在下文中一共展示了Math类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: gaussianKernel
import org.joml.Math; //导入依赖的package包/类
/**
* Generate a Gaussian convolution kernel with the given number of rows and columns, and store
* the factors in row-major order in <code>dest</code>.
*
* @param rows
* the number of rows (must be an odd number)
* @param cols
* the number of columns (must be an odd number)
* @param sigma
* determines how big the factors are at the center of distribution
* @param dest
* will hold the kernel factors in row-major order
*/
public static void gaussianKernel(int rows, int cols, float sigma, float[] dest) {
if ((rows & 1) == 0) {
throw new IllegalArgumentException("rows must be an odd number");
}
if ((cols & 1) == 0) {
throw new IllegalArgumentException("cols must be an odd number");
}
if (dest == null) {
throw new IllegalArgumentException("dest must not be null");
}
if (dest.length < rows * cols) {
throw new IllegalArgumentException("dest must have at least " + (rows * cols) + " remaining values");
}
float sum = 0.0f;
for (int i = 0, y = -(rows - 1) / 2; y <= (rows - 1) / 2; y++) {
for (int x = -(cols - 1) / 2; x <= (cols - 1) / 2; x++, i++) {
float k = (float) Math.exp(-(y * y + x * x) / (2.0 * sigma * sigma));
dest[i] = k;
sum += k;
}
}
for (int i = 0; i < rows * cols; i++) {
dest[i] = dest[i] / sum;
}
}
示例2: testBigCircle
import org.joml.Math; //导入依赖的package包/类
public static void testBigCircle() {
int polyN = 1024 * 256;
float[] verticesXY = new float[polyN * 2];
for (int i = 0; i < polyN; i++) {
float x = (float) Math.cos(2.0 * Math.PI * i / polyN);
float y = (float) Math.sin(2.0 * Math.PI * i / polyN);
verticesXY[2 * i + 0] = x;
verticesXY[2 * i + 1] = y;
}
PolygonsIntersection isect = new PolygonsIntersection(verticesXY, new int[0], polyN);
// Center
assertTrue(isect.testPoint(0, 0));
// Left outside
assertFalse(isect.testPoint(-1.1f, 0));
// Top right outside
assertFalse(isect.testPoint(0.8f, 0.8f));
// Top edge
assertTrue(isect.testPoint(1.0f, 0));
// Bottom edge <- algorithm only detects top edges as 'inside'
assertFalse(isect.testPoint(-1.0f, 0));
}
示例3: testProjectUnproject
import org.joml.Math; //导入依赖的package包/类
/**
* Test that project and unproject are each other's inverse operations.
*/
public static void testProjectUnproject() {
/* Build some arbitrary viewport. */
int[] viewport = {0, 0, 800, 800};
Vector3f expected = new Vector3f(1.0f, 2.0f, -3.0f);
Vector3f actual = new Vector3f();
/* Build a perspective projection and then project and unproject. */
Matrix4f m = new Matrix4f()
.perspective((float) Math.toRadians(45.0f), 1.0f, 0.01f, 100.0f);
m.project(expected, viewport, actual);
m.unproject(actual, viewport, actual);
/* Check for equality of the components */
assertEquals(expected.x, actual.x, TestUtil.MANY_OPS_AROUND_ZERO_PRECISION_FLOAT);
assertEquals(expected.y, actual.y, TestUtil.MANY_OPS_AROUND_ZERO_PRECISION_FLOAT);
assertEquals(expected.z, actual.z, TestUtil.MANY_OPS_AROUND_ZERO_PRECISION_FLOAT);
}
示例4: testFrustumRay
import org.joml.Math; //导入依赖的package包/类
public static void testFrustumRay() {
Vector3f dir = new Vector3f();
Matrix4f m = new Matrix4f()
.perspective((float) Math.toRadians(90), 1.0f, 0.1f, 100.0f)
.rotateY((float) Math.toRadians(90));
Vector3f expectedDir;
m.frustumRayDir(0, 0, dir);
expectedDir = new Vector3f(1, -1, -1).normalize();
TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f);
m.frustumRayDir(1, 0, dir);
expectedDir = new Vector3f(1, -1, 1).normalize();
TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f);
m.frustumRayDir(0, 1, dir);
expectedDir = new Vector3f(1, 1, -1).normalize();
TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f);
m.frustumRayDir(1, 1, dir);
expectedDir = new Vector3f(1, 1, 1).normalize();
TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f);
}
示例5: testFrustumRay2
import org.joml.Math; //导入依赖的package包/类
public static void testFrustumRay2() {
Vector3f dir = new Vector3f();
Matrix4f m = new Matrix4f()
.perspective((float) Math.toRadians(90), 1.0f, 0.1f, 100.0f)
.rotateZ((float) Math.toRadians(45));
Vector3f expectedDir;
m.frustumRayDir(0, 0, dir);
expectedDir = new Vector3f(-(float)Math.sqrt(2), 0, -1).normalize();
TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f);
m.frustumRayDir(1, 0, dir);
expectedDir = new Vector3f(0, -(float)Math.sqrt(2), -1).normalize();
TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f);
m.frustumRayDir(0, 1, dir);
expectedDir = new Vector3f(0, (float)Math.sqrt(2), -1).normalize();
TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f);
m.frustumRayDir(1, 1, dir);
expectedDir = new Vector3f((float)Math.sqrt(2), 0, -1).normalize();
TestUtil.assertVector3fEquals(expectedDir, dir, 1E-5f);
}
示例6: testOrthoCropWithPerspective
import org.joml.Math; //导入依赖的package包/类
public static void testOrthoCropWithPerspective() {
Matrix4f lightView = new Matrix4f()
.lookAt(0, 5, 0,
0, 0, 0,
0, 0, -1);
Matrix4f crop = new Matrix4f();
Matrix4f fin = new Matrix4f();
new Matrix4f().perspective((float) Math.toRadians(90), 1.0f, 5, 10).invertPerspective().orthoCrop(lightView, crop).mulOrthoAffine(lightView, fin);
Vector3f p = new Vector3f();
fin.transformProject(p.set(0, 0, -5));
assertEquals(+0.0f, p.x, 1E-6f);
assertEquals(-1.0f, p.y, 1E-6f);
assertEquals(+0.0f, p.z, 1E-6f);
fin.transformProject(p.set(0, 0, -10));
assertEquals(+0.0f, p.x, 1E-6f);
assertEquals(+1.0f, p.y, 1E-6f);
assertEquals(+0.0f, p.z, 1E-6f);
fin.transformProject(p.set(-10, 10, -10));
assertEquals(-1.0f, p.x, 1E-6f);
assertEquals(+1.0f, p.y, 1E-6f);
assertEquals(-1.0f, p.z, 1E-6f);
}
示例7: testObObTipToTip
import org.joml.Math; //导入依赖的package包/类
public static void testObObTipToTip() {
Vector3f c0 = new Vector3f();
float EPSILON = 1E-4f;
/* Position the second box so that they "almost" intersect */
float a = (float) Math.sqrt(1 + 1) + (float) Math.sqrt(1 + 1);
Vector3f c1 = new Vector3f(a + EPSILON, 0, 0);
Matrix3f m = new Matrix3f().rotateXYZ(0, (float) Math.toRadians(45.0), 0);
Vector3f ux0 = m.getColumn(0, new Vector3f());
Vector3f uy0 = m.getColumn(1, new Vector3f());
Vector3f uz0 = m.getColumn(2, new Vector3f());
Vector3f ux1 = m.getColumn(0, new Vector3f());
Vector3f uy1 = m.getColumn(1, new Vector3f());
Vector3f uz1 = m.getColumn(2, new Vector3f());
Vector3f hs = new Vector3f(1);
boolean intersects = Intersectionf.testObOb(c0, ux0, uy0, uz0, hs, c1, ux1, uy1, uz1, hs);
assertFalse(intersects); // <- they do not intersect
/* Position the second box so that they do intersect */
c1 = new Vector3f((float) Math.sqrt(2) * 2 - EPSILON, 0, 0);
intersects = Intersectionf.testObOb(c0, ux0, uy0, uz0, hs, c1, ux1, uy1, uz1, hs);
assertTrue(intersects); // <- they do intersect
}
示例8: testObOb
import org.joml.Math; //导入依赖的package包/类
public static void testObOb() {
float a = (float) (Math.sqrt(2.0*2.0 + 2.0*2.0) + Math.sqrt(0.5*0.5 + 0.5*0.5));
float EPSILON = 1E-4f;
Vector3f c0 = new Vector3f(0, 0, a - EPSILON);
Vector3f hs0 = new Vector3f(0.5f, 0.5f, 0.5f);
Vector3f c1 = new Vector3f(0, 0, 0);
Vector3f hs1 = new Vector3f(2, 0.5f, 2);
Matrix3f m = new Matrix3f().rotateY((float) Math.toRadians(45));
Vector3f ux0 = m.getColumn(0, new Vector3f());
Vector3f uy0 = m.getColumn(1, new Vector3f());
Vector3f uz0 = m.getColumn(2, new Vector3f());
Vector3f ux1 = m.getColumn(0, new Vector3f());
Vector3f uy1 = m.getColumn(1, new Vector3f());
Vector3f uz1 = m.getColumn(2, new Vector3f());
boolean intersects = Intersectionf.testObOb(c0, ux0, uy0, uz0, hs0, c1, ux1, uy1, uz1, hs1);
assertTrue(intersects); // <- they DO intersect
c0 = new Vector3f(0, 0, a + EPSILON);
intersects = Intersectionf.testObOb(c0, ux0, uy0, uz0, hs0, c1, ux1, uy1, uz1, hs1);
assertFalse(intersects); // <- they do not intersect
}
示例9: placeTile
import org.joml.Math; //导入依赖的package包/类
private void placeTile(int x, int y, Random random, Planet planet, float maxr, float fader) {
float randfl, distancesq;
// Tile coords
int tx = this.x * CHUNKSIZE_T + x;
int ty = this.y * CHUNKSIZE_T + y;
// World coords and world coords in the middle of the tile
float wx = tx * TileDefinition.TILE_SIZE;
float wy = ty * TileDefinition.TILE_SIZE;
float txwh = wx + TileDefinition.TILE_SIZE / 2;
float tywh = wy + TileDefinition.TILE_SIZE / 2;
if (txwh * txwh + tywh * tywh > maxr * maxr) {
return;
}
// get BiomeDefinition for this tile
BiomeDefinition biomedef = checkNeighbours(planet, tx, ty);
Tile tile = new Tile(biomedef.getTileDefinition(planet.getPlanetData(), tx, ty), biomedef);
// tile is to be faded?
if (txwh * txwh + tywh * tywh > fader * fader) {
// on this tile no decoration is allowed
tile.invalidate();
distancesq = 1 - ((float) Math.sqrt(txwh * txwh + tywh * tywh) - (fader)) / (maxr - fader);
randfl = random.nextFloat();
if (randfl * distancesq <= e(distancesq)) {
tile.getColor().set(1, 1, 1, randfl * distancesq * distancesq * distancesq);
} else {
tile.getColor().setAll(1);
}
}
tile.getTransform().setPosition(wx, wy);
array[x][y] = tile;
if (tile.getDefinition().isPrerenderable()) {
if (tiles.get(tile.getTexture()) == null) {
tiles.put(tile.getTexture(), new ArrayList<>());
}
tiles.get(tile.getTexture()).add(tile);
} else {
others.add(tile);
}
}
示例10: onMouseDown
import org.joml.Math; //导入依赖的package包/类
public void onMouseDown(int button) {
mouseDownX = mouseX;
mouseDownY = mouseY;
mouseDown[button] = true;
if (button == MOUSE_CENTER) {
/* Reset rotation with mouse position as center */
view.positiveX(v);
float ang = (float) Math.atan2(v.y, v.x);
Vector2f ndc = ndc(mouseDownX, mouseDownY);
view.translateLocal(-ndc.x, -ndc.y)
.rotateLocal(ang)
.translateLocal(ndc.x, ndc.y);
update();
}
}
示例11: onMouseMove
import org.joml.Math; //导入依赖的package包/类
/**
* @param winX
* the x coordinate in window coordinates/pixels
* @param winY
* the y coordinate in window coordinates/pixels
*/
public void onMouseMove(int winX, int winY) {
Vector2f ndc;
if (mouseDown[MOUSE_LEFT]) {
/* Move */
ndc = ndc(winX, winY);
float x0 = ndc.x, y0 = ndc.y;
ndc = ndc(mouseX, mouseY);
float x1 = ndc.x, y1 = ndc.y;
view.translateLocal(x0 - x1, y0 - y1);
update();
} else if (mouseDown[MOUSE_RIGHT]) {
/* Check if rotation is possible */
float dx = winX - mouseDownX;
float dy = winY - mouseDownY;
if (dx * dx + dy * dy > minRotateWinDistance2) {
/* Rotate */
float dx0 = winX - mouseDownX, dy0 = winY - mouseDownY;
float dx1 = mouseX - mouseDownX, dy1 = mouseY - mouseDownY;
float ang = (float) Math.atan2(dx1 * dy0 - dy1 * dx0, dx1 * dx0 + dy1 * dy0);
ndc = ndc(mouseDownX, mouseDownY);
view.translateLocal(-ndc.x, -ndc.y)
.rotateLocal(ang)
.translateLocal(ndc.x, ndc.y);
update();
}
}
mouseX = winX;
mouseY = winY;
}
示例12: testLookAt
import org.joml.Math; //导入依赖的package包/类
public static void testLookAt() {
Matrix4x3f m1, m2;
m1 = new Matrix4x3f().lookAt(0, 2, 3, 0, 0, 0, 0, 1, 0);
m2 = new Matrix4x3f().translate(0, 0, -(float) Math.sqrt(2 * 2 + 3 * 3)).rotateX(
(float) Math.atan2(2, 3));
TestUtil.assertMatrix4x3fEquals(m1, m2, 1E-5f);
m1 = new Matrix4x3f().lookAt(3, 2, 0, 0, 0, 0, 0, 1, 0);
m2 = new Matrix4x3f().translate(0, 0, -(float) Math.sqrt(2 * 2 + 3 * 3))
.rotateX((float) Math.atan2(2, 3)).rotateY((float) Math.toRadians(-90));
TestUtil.assertMatrix4x3fEquals(m1, m2, 1E-4f);
}
示例13: testPositiveXRotateY
import org.joml.Math; //导入依赖的package包/类
public static void testPositiveXRotateY() {
Vector3f dir = new Vector3f();
Matrix4x3f m = new Matrix4x3f()
.rotateY((float) Math.toRadians(90));
m.positiveX(dir);
TestUtil.assertVector3fEquals(new Vector3f(0, 0, 1), dir, 1E-7f);
}
示例14: testPositiveYRotateX
import org.joml.Math; //导入依赖的package包/类
public static void testPositiveYRotateX() {
Vector3f dir = new Vector3f();
Matrix4x3f m = new Matrix4x3f()
.rotateX((float) Math.toRadians(90));
m.positiveY(dir);
TestUtil.assertVector3fEquals(new Vector3f(0, 0, -1), dir, 1E-7f);
}
示例15: testPositiveZRotateX
import org.joml.Math; //导入依赖的package包/类
public static void testPositiveZRotateX() {
Vector3f dir = new Vector3f();
Matrix4x3f m = new Matrix4x3f()
.rotateX((float) Math.toRadians(90));
m.positiveZ(dir);
TestUtil.assertVector3fEquals(new Vector3f(0, 1, 0), dir, 1E-7f);
}