use of com.badlogic.gdx.math.Vector2 in project commons-gdx by gemserk.
the class MovementSystem method processEntities.
@Override
protected void processEntities() {
RandomAccessMap<Entity, EntityComponents> allTheEntityComponents = componentsHolder.entityComponents;
int entitiesSize = allTheEntityComponents.size();
float delta = GlobalTime.getDelta();
for (int entityIndex = 0; entityIndex < entitiesSize; entityIndex++) {
EntityComponents entityComponents = allTheEntityComponents.get(entityIndex);
MovementComponent movementComponent = entityComponents.movementComponent;
Spatial spatial = entityComponents.spatialComponent.getSpatial();
Vector2 velocity = movementComponent.getVelocity();
tmpVelocity.set(velocity).mul(delta);
tmpPosition.set(spatial.getX(), spatial.getY()).add(tmpVelocity);
float newAngle = spatial.getAngle() + delta * movementComponent.getAngularVelocity();
spatial.setAngle(newAngle);
spatial.setPosition(tmpPosition.x, tmpPosition.y);
}
}
use of com.badlogic.gdx.math.Vector2 in project commons-gdx by gemserk.
the class ShapeUtils method calculateBounds.
public static void calculateBounds(Vector2[] vertices, Rectangle bounds) {
bounds.x = Float.MAX_VALUE;
bounds.y = Float.MAX_VALUE;
bounds.width = -Float.MAX_VALUE;
bounds.height = -Float.MAX_VALUE;
for (int i = 0; i < vertices.length; i++) {
Vector2 v = vertices[i];
if (v.x < bounds.x)
bounds.x = v.x;
if (v.y < bounds.y)
bounds.y = v.y;
if (v.x > bounds.x + bounds.width)
bounds.width = v.x - bounds.x;
if (v.y > bounds.y + bounds.height)
bounds.height = v.y - bounds.y;
}
}
use of com.badlogic.gdx.math.Vector2 in project commons-gdx by gemserk.
the class EfficientPolygonTriangulator method area.
static float area(Array<Vector2> contour) {
int n = contour.size;
float A = 0.0f;
for (int p = n - 1, q = 0; q < n; p = q++) {
Vector2 p0 = contour.get(p);
Vector2 p1 = contour.get(q);
A += p0.x * p1.y - p1.x * p0.y;
}
return A * 0.5f;
}
use of com.badlogic.gdx.math.Vector2 in project commons-gdx by gemserk.
the class ContactsTest method addingAContactReusesOneIfAvailable.
@Test
public void addingAContactReusesOneIfAvailable() {
mockery.checking(new Expectations() {
{
ignoring(fixtureA);
ignoring(fixtureB);
}
});
Contact reusedContact = new Contact();
contacts.contacts.add(reusedContact);
contacts.activeContacts = 0;
contacts.addContact(fixtureA, fixtureB, new Vector2());
assertTrue(contacts.isInContact());
assertThat(1, IsEqual.equalTo(contacts.getContactCount()));
Contact contact = contacts.contacts.get(0);
assertThat(true, IsEqual.equalTo(contact.inContact));
assertThat(contact.myFixture, same(fixtureA));
assertThat(contact.otherFixture, same(fixtureB));
}
use of com.badlogic.gdx.math.Vector2 in project commons-gdx by gemserk.
the class Libgdx2dCameraTransformImplTest method shouldReturnProjectedVectorWhenCameraMoved.
@Ignore
@Test
public void shouldReturnProjectedVectorWhenCameraMoved() {
Libgdx2dCameraTransformImpl camera = new Libgdx2dCameraTransformImpl();
camera.move(100, 0);
camera.zoom(32f);
Vector2 position = new Vector2(10f, 10f);
camera.project(position);
assertThat(position.x, IsEqual.equalTo(-2880f));
assertThat(position.y, IsEqual.equalTo(320f));
}
Aggregations