use of com.badlogic.gdx.math.Vector3 in project libgdx by libgdx.
the class MatrixJNITest method create.
@Override
public void create() {
Matrix4 mat1 = new Matrix4();
Matrix4 mat2 = new Matrix4();
Matrix4 mat3 = new Matrix4();
Vector3 vec = new Vector3(1, 2, 3);
float[] fvec = { 1, 2, 3 };
float[] fvecs = { 1, 2, 3, 0, 0, 1, 2, 3, 0, 0, 1, 2, 3, 0, 0 };
mat1.setToRotation(0, 1, 0, 45);
mat2.setToRotation(1, 0, 0, 45);
vec.mul(mat1);
Matrix4.mulVec(mat1.val, fvec);
Matrix4.mulVec(mat1.val, fvecs, 0, 3, 5);
check(vec, fvec);
check(vec, fvecs, 3, 5);
vec.prj(mat1);
Matrix4.prj(mat1.val, fvec);
Matrix4.prj(mat1.val, fvecs, 0, 3, 5);
check(vec, fvec);
check(vec, fvecs, 3, 5);
vec.rot(mat1);
Matrix4.rot(mat1.val, fvec);
Matrix4.rot(mat1.val, fvecs, 0, 3, 5);
check(vec, fvec);
check(vec, fvecs, 3, 5);
if (mat1.det() != Matrix4.det(mat1.val))
throw new GdxRuntimeException("det doesn't work");
mat2.set(mat1);
mat1.inv();
Matrix4.inv(mat2.val);
check(mat1, mat2);
mat3.set(mat1);
mat1.mul(mat2);
Matrix4.mul(mat3.val, mat2.val);
check(mat1, mat3);
bench();
System.out.println("All tests passed.");
}
use of com.badlogic.gdx.math.Vector3 in project libgdx by libgdx.
the class Mesh method transform.
/** Method to transform the positions in the float array. Normals will be kept as is. This is a potentially slow operation, use
* with care.
* @param matrix the transformation matrix
* @param vertices the float array
* @param vertexSize the number of floats in each vertex
* @param offset the offset within a vertex to the position
* @param dimensions the size of the position
* @param start the vertex to start with
* @param count the amount of vertices to transform */
public static void transform(final Matrix4 matrix, final float[] vertices, int vertexSize, int offset, int dimensions, int start, int count) {
if (offset < 0 || dimensions < 1 || (offset + dimensions) > vertexSize)
throw new IndexOutOfBoundsException();
if (start < 0 || count < 1 || ((start + count) * vertexSize) > vertices.length)
throw new IndexOutOfBoundsException("start = " + start + ", count = " + count + ", vertexSize = " + vertexSize + ", length = " + vertices.length);
final Vector3 tmp = new Vector3();
int idx = offset + (start * vertexSize);
switch(dimensions) {
case 1:
for (int i = 0; i < count; i++) {
tmp.set(vertices[idx], 0, 0).mul(matrix);
vertices[idx] = tmp.x;
idx += vertexSize;
}
break;
case 2:
for (int i = 0; i < count; i++) {
tmp.set(vertices[idx], vertices[idx + 1], 0).mul(matrix);
vertices[idx] = tmp.x;
vertices[idx + 1] = tmp.y;
idx += vertexSize;
}
break;
case 3:
for (int i = 0; i < count; i++) {
tmp.set(vertices[idx], vertices[idx + 1], vertices[idx + 2]).mul(matrix);
vertices[idx] = tmp.x;
vertices[idx + 1] = tmp.y;
vertices[idx + 2] = tmp.z;
idx += vertexSize;
}
break;
}
}
use of com.badlogic.gdx.math.Vector3 in project libgdx by libgdx.
the class FloatTextureTest method createScreenQuad.
private void createScreenQuad() {
if (screenQuad != null)
return;
screenQuad = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.ColorUnpacked, 4, "a_color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));
Vector3 vec0 = new Vector3(0, 0, 0);
screenCamera.unproject(vec0);
Vector3 vec1 = new Vector3(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 0);
screenCamera.unproject(vec1);
screenQuad.setVertices(new float[] { vec0.x, vec0.y, 0, 1, 1, 1, 1, 0, 1, vec1.x, vec0.y, 0, 1, 1, 1, 1, 1, 1, vec1.x, vec1.y, 0, 1, 1, 1, 1, 1, 0, vec0.x, vec1.y, 0, 1, 1, 1, 1, 0, 0 });
screenQuad.setIndices(new short[] { 0, 1, 2, 2, 3, 0 });
}
use of com.badlogic.gdx.math.Vector3 in project libgdx by libgdx.
the class CharacterTest method createWorld.
@Override
public BulletWorld createWorld() {
// We create the world using an axis sweep broadphase for this test
btDefaultCollisionConfiguration collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher dispatcher = new btCollisionDispatcher(collisionConfiguration);
btAxisSweep3 sweep = new btAxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000));
btSequentialImpulseConstraintSolver solver = new btSequentialImpulseConstraintSolver();
btDiscreteDynamicsWorld collisionWorld = new btDiscreteDynamicsWorld(dispatcher, sweep, solver, collisionConfiguration);
ghostPairCallback = new btGhostPairCallback();
sweep.getOverlappingPairCache().setInternalGhostPairCallback(ghostPairCallback);
return new BulletWorld(collisionConfiguration, dispatcher, sweep, solver, collisionWorld);
}
use of com.badlogic.gdx.math.Vector3 in project libgdx by libgdx.
the class BulletConstructor method create.
private void create(final Model model, final float mass, final btCollisionShape shape) {
this.model = model;
this.shape = shape;
if (shape != null && mass >= 0) {
// Calculate the local inertia, bodies with no mass are static
Vector3 localInertia;
if (mass == 0)
localInertia = Vector3.Zero;
else {
shape.calculateLocalInertia(mass, tmpV);
localInertia = tmpV;
}
// For now just pass null as the motionstate, we'll add that to the body in the entity itself
bodyInfo = new btRigidBodyConstructionInfo(mass, null, shape, localInertia);
}
}
Aggregations