use of com.badlogic.gdx.math.Vector3 in project libgdx-inGameConsole by StrongJoshua.
the class Box2DTest method render.
@Override
public void render() {
if (Gdx.input.isTouched()) {
float x = Gdx.input.getX();
float y = Gdx.input.getY();
if (!console.hitsConsole(x, y)) {
Vector3 worldVector = c.unproject(new Vector3(x, y, 0));
createExplosion(worldVector.x, worldVector.y, 2000);
console.log(String.format("Created touch explosion at %.2f, %.2f!", worldVector.x, worldVector.y), LogLevel.SUCCESS);
}
}
if (Gdx.input.isKeyPressed(Input.Keys.ESCAPE))
Gdx.app.exit();
world.step(1 / 60f, 6, 2);
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
for (int i = 0; i < bodies.length; i++) {
Vector2 pos = bodies[i].getPosition();
sprites[i].setPosition(pos.x - sprites[i].getWidth() / 2, pos.y - sprites[i].getHeight() / 2);
sprites[i].setRotation(MathUtils.radiansToDegrees * bodies[i].getAngle());
sprites[i].draw(batch);
}
batch.end();
debugRenderer.render(world, c.combined);
console.draw();
}
use of com.badlogic.gdx.math.Vector3 in project libgdx-inGameConsole by StrongJoshua.
the class Box2DTest method createExplosion.
/**
* Creates an explosion that applies forces to the bodies relative to their
* position and the given x and y values.
*
* @param maxForce
* The maximum force to be applied to the bodies (diminishes as
* distance from touch increases).
*/
private void createExplosion(float x, float y, float maxForce) {
float force;
Vector2 touch = new Vector2(x, y);
for (int i = 0; i < bodies.length; i++) {
Body b = bodies[i];
Vector2 v = b.getPosition();
float dist = v.dst2(touch);
if (dist == 0)
force = maxForce;
else
force = MathUtils.clamp(maxForce / dist, 0, maxForce);
float angle = v.cpy().sub(touch).angle();
float xForce = force * MathUtils.cosDeg(angle);
float yForce = force * MathUtils.sinDeg(angle);
Vector3 touch3, v3, boundMin, boundMax, intersection;
touch3 = new Vector3(touch.x, touch.y, 0);
v3 = new Vector3(v.x, v.y, 0);
boundMin = new Vector3(v.x - 1, v.y - 1, 0);
boundMax = new Vector3(v.x + 1, v.y + 1, 0);
intersection = Vector3.Zero;
Intersector.intersectRayBounds(new Ray(touch3, v3), new BoundingBox(boundMin, boundMax), intersection);
b.applyForce(new Vector2(xForce, yForce), new Vector2(intersection.x, intersection.y), true);
}
}
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);
}
Aggregations