use of com.badlogic.gdx.math.Vector3 in project libgdx by libgdx.
the class BaseAnimationController method getTranslationAtTime.
private static final Vector3 getTranslationAtTime(final NodeAnimation nodeAnim, final float time, final Vector3 out) {
if (nodeAnim.translation == null)
return out.set(nodeAnim.node.translation);
if (nodeAnim.translation.size == 1)
return out.set(nodeAnim.translation.get(0).value);
int index = getFirstKeyframeIndexAtTime(nodeAnim.translation, time);
final NodeKeyframe firstKeyframe = nodeAnim.translation.get(index);
out.set((Vector3) firstKeyframe.value);
if (++index < nodeAnim.translation.size) {
final NodeKeyframe<Vector3> secondKeyframe = nodeAnim.translation.get(index);
final float t = (time - firstKeyframe.keytime) / (secondKeyframe.keytime - firstKeyframe.keytime);
out.lerp(secondKeyframe.value, t);
}
return out;
}
use of com.badlogic.gdx.math.Vector3 in project libgdx by libgdx.
the class CollisionTest method testBoundingBox.
@Test
public void testBoundingBox() {
BoundingBox b1 = new BoundingBox(Vector3.Zero, new Vector3(1, 1, 1));
BoundingBox b2 = new BoundingBox(new Vector3(1, 1, 1), new Vector3(2, 2, 2));
assertTrue(b1.contains(Vector3.Zero));
assertTrue(b1.contains(b1));
assertFalse(b1.contains(b2));
// Note, in stage the bottom and left sides are inclusive while the right and top sides are exclusive.
}
use of com.badlogic.gdx.math.Vector3 in project libgdx by libgdx.
the class FrustumShapeBuilder method build.
/** Build Camera with custom colors
* @param builder
* @param camera
* @param frustumColor
* @param coneColor
* @param upColor
* @param targetColor
* @param crossColor */
public static void build(MeshPartBuilder builder, Camera camera, Color frustumColor, Color coneColor, Color upColor, Color targetColor, Color crossColor) {
Vector3[] planePoints = camera.frustum.planePoints;
// Frustum
build(builder, camera.frustum, frustumColor, crossColor);
// Cones (camera position to near plane)
builder.line(planePoints[0], coneColor, camera.position, coneColor);
builder.line(planePoints[1], coneColor, camera.position, coneColor);
builder.line(planePoints[2], coneColor, camera.position, coneColor);
builder.line(planePoints[3], coneColor, camera.position, coneColor);
// Target line
builder.line(camera.position, targetColor, centerPoint(planePoints[4], planePoints[5], planePoints[6]), targetColor);
// Up triangle
float halfNearSize = tmpV0.set(planePoints[1]).sub(planePoints[0]).scl(0.5f).len();
Vector3 centerNear = centerPoint(planePoints[0], planePoints[1], planePoints[2]);
tmpV0.set(camera.up).scl(halfNearSize * 2);
centerNear.add(tmpV0);
builder.line(centerNear, upColor, planePoints[2], upColor);
builder.line(planePoints[2], upColor, planePoints[3], upColor);
builder.line(planePoints[3], upColor, centerNear, upColor);
}
use of com.badlogic.gdx.math.Vector3 in project libgdx by libgdx.
the class EllipseShapeBuilder method build.
/** Build an ellipse */
public static void build(MeshPartBuilder builder, float width, float height, float innerWidth, float innerHeight, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ, float angleFrom, float angleTo) {
if (innerWidth <= 0 || innerHeight <= 0) {
builder.ensureVertices(divisions + 2);
builder.ensureTriangleIndices(divisions);
} else if (innerWidth == width && innerHeight == height) {
builder.ensureVertices(divisions + 1);
builder.ensureIndices(divisions + 1);
if (builder.getPrimitiveType() != GL20.GL_LINES)
throw new GdxRuntimeException("Incorrect primitive type : expect GL_LINES because innerWidth == width && innerHeight == height");
} else {
builder.ensureVertices((divisions + 1) * 2);
builder.ensureRectangleIndices(divisions + 1);
}
final float ao = MathUtils.degreesToRadians * angleFrom;
final float step = (MathUtils.degreesToRadians * (angleTo - angleFrom)) / divisions;
final Vector3 sxEx = tmpV1.set(tangentX, tangentY, tangentZ).scl(width * 0.5f);
final Vector3 syEx = tmpV2.set(binormalX, binormalY, binormalZ).scl(height * 0.5f);
final Vector3 sxIn = tmpV3.set(tangentX, tangentY, tangentZ).scl(innerWidth * 0.5f);
final Vector3 syIn = tmpV4.set(binormalX, binormalY, binormalZ).scl(innerHeight * 0.5f);
VertexInfo currIn = vertTmp3.set(null, null, null, null);
currIn.hasUV = currIn.hasPosition = currIn.hasNormal = true;
currIn.uv.set(.5f, .5f);
currIn.position.set(centerX, centerY, centerZ);
currIn.normal.set(normalX, normalY, normalZ);
VertexInfo currEx = vertTmp4.set(null, null, null, null);
currEx.hasUV = currEx.hasPosition = currEx.hasNormal = true;
currEx.uv.set(.5f, .5f);
currEx.position.set(centerX, centerY, centerZ);
currEx.normal.set(normalX, normalY, normalZ);
final short center = builder.vertex(currEx);
float angle = 0f;
final float us = 0.5f * (innerWidth / width);
final float vs = 0.5f * (innerHeight / height);
short i1, i2 = 0, i3 = 0, i4 = 0;
for (int i = 0; i <= divisions; i++) {
angle = ao + step * i;
final float x = MathUtils.cos(angle);
final float y = MathUtils.sin(angle);
currEx.position.set(centerX, centerY, centerZ).add(sxEx.x * x + syEx.x * y, sxEx.y * x + syEx.y * y, sxEx.z * x + syEx.z * y);
currEx.uv.set(.5f + .5f * x, .5f + .5f * y);
i1 = builder.vertex(currEx);
if (innerWidth <= 0f || innerHeight <= 0f) {
if (i != 0)
builder.triangle(i1, i2, center);
i2 = i1;
} else if (innerWidth == width && innerHeight == height) {
if (i != 0)
builder.line(i1, i2);
i2 = i1;
} else {
currIn.position.set(centerX, centerY, centerZ).add(sxIn.x * x + syIn.x * y, sxIn.y * x + syIn.y * y, sxIn.z * x + syIn.z * y);
currIn.uv.set(.5f + us * x, .5f + vs * y);
i2 = i1;
i1 = builder.vertex(currIn);
if (i != 0)
builder.rect(i1, i2, i4, i3);
i4 = i2;
i3 = i1;
}
}
}
use of com.badlogic.gdx.math.Vector3 in project libgdx by libgdx.
the class MatrixJNITest method bench.
private void bench() {
Matrix4 mata = new Matrix4();
Matrix4 matb = new Matrix4();
long start = TimeUtils.nanoTime();
for (int i = 0; i < 1000000; i++) {
mata.mul(matb);
}
Gdx.app.log("MatrixJNITest", "java matrix * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
start = TimeUtils.nanoTime();
for (int i = 0; i < 1000000; i++) {
Matrix4.mul(mata.val, matb.val);
}
Gdx.app.log("MatrixJNITest", "jni matrix * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
Vector3 vec = new Vector3();
start = TimeUtils.nanoTime();
for (int i = 0; i < 500000; i++) {
vec.mul(mata);
}
Gdx.app.log("MatrixJNITest", "java vecs * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
float[] fvec = new float[3];
start = TimeUtils.nanoTime();
for (int i = 0; i < 500000; i++) {
Matrix4.mulVec(mata.val, fvec);
}
Gdx.app.log("MatrixJNITest", "jni vecs * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
float[] fvecs = new float[3 * 500000];
start = TimeUtils.nanoTime();
Matrix4.mulVec(mata.val, fvecs, 0, 500000, 3);
Gdx.app.log("MatrixJNITest", "jni bulk vecs * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
start = TimeUtils.nanoTime();
for (int i = 0; i < 1000000; i++) {
mata.inv();
}
Gdx.app.log("MatrixJNITest", "java inv(matrix): " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
start = TimeUtils.nanoTime();
for (int i = 0; i < 1000000; i++) {
Matrix4.inv(mata.val);
}
Gdx.app.log("MatrixJNITest", "jni inv(matrix): " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
}
Aggregations