use of com.badlogic.gdx.math.Vector2 in project libgdx by libgdx.
the class BodyTypes method render.
@Override
public void render() {
if (m_platform.getType() == BodyType.KinematicBody) {
Vector2 p = m_platform.getTransform().getPosition();
Vector2 v = m_platform.getLinearVelocity();
if ((p.x < -10 && v.x < 0) || (p.x > 10 && v.x > 0)) {
v.x = -v.x;
m_platform.setLinearVelocity(v);
}
}
super.render();
// if (renderer.batch != null) {
// renderer.batch.begin();
// // renderer.batch.drawText(renderer.font, "Keys: (d) dynamic, (s) static, (k) kinematic", 0, Gdx.app.getGraphics()
// // .getHeight(), Color.WHITE);
// renderer.batch.end();
// }
}
use of com.badlogic.gdx.math.Vector2 in project libgdx by libgdx.
the class Box2DTest method create.
@Override
public void create() {
// setup the camera. In Box2D we operate on a
// meter scale, pixels won't do it. So we use
// an orthographic camera with a viewport of
// 48 meters in width and 32 meters in height.
// We also position the camera so that it
// looks at (0,16) (that's where the middle of the
// screen will be located).
camera = new OrthographicCamera(48, 32);
camera.position.set(0, 15, 0);
// create the debug renderer
renderer = new Box2DDebugRenderer();
// create the world
world = new World(new Vector2(0, -10), true);
// we also need an invisible zero size ground body
// to which we can connect the mouse joint
BodyDef bodyDef = new BodyDef();
groundBody = world.createBody(bodyDef);
// call abstract method to populate the world
createWorld(world);
batch = new SpriteBatch();
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
}
use of com.badlogic.gdx.math.Vector2 in project libgdx by libgdx.
the class ConveyorBelt method createWorld.
@Override
protected void createWorld(World world) {
world.setContactListener(this);
// Ground
{
BodyDef bodyDef = new BodyDef();
groundBody = world.createBody(bodyDef);
EdgeShape shape = new EdgeShape();
shape.set(new Vector2(-20.0f, 0.0f), new Vector2(20.0f, 0.0f));
groundBody.createFixture(shape, 0.0f);
}
// Platform
{
BodyDef bd = new BodyDef();
bd.position.set(-5.0f, 5.0f);
Body body = world.createBody(bd);
PolygonShape shape = new PolygonShape();
shape.setAsBox(10.0f, 0.5f);
FixtureDef fd = new FixtureDef();
fd.shape = shape;
fd.friction = 0.8f;
m_platform = body.createFixture(fd);
}
// Boxes
for (int i = 0; i < 5; ++i) {
BodyDef bd = new BodyDef();
bd.type = BodyType.DynamicBody;
bd.position.set(-10.0f + 2.0f * i, 7.0f);
Body body = world.createBody(bd);
PolygonShape shape = new PolygonShape();
shape.setAsBox(0.5f, 0.5f);
body.createFixture(shape, 20.0f);
}
}
use of com.badlogic.gdx.math.Vector2 in project libgdx by libgdx.
the class GwtTest method create.
@Override
public void create() {
Preferences pref = Gdx.app.getPreferences("test");
boolean resultb = pref.getBoolean("test");
int resulti = pref.getInteger("test");
shader = new ShaderProgram(Gdx.files.internal("data/shaders/shader-vs.glsl"), Gdx.files.internal("data/shaders/shader-fs.glsl"));
if (!shader.isCompiled())
throw new GdxRuntimeException(shader.getLog());
mesh = new Mesh(VertexDataType.VertexBufferObject, true, 6, 0, VertexAttribute.Position(), VertexAttribute.TexCoords(0));
mesh.setVertices(new float[] { -0.5f, -0.5f, 0, 0, 1, 0.5f, -0.5f, 0, 1, 1, 0.5f, 0.5f, 0, 1, 0, 0.5f, 0.5f, 0, 1, 0, -0.5f, 0.5f, 0, 0, 0, -0.5f, -0.5f, 0, 0, 1 });
texture = new Texture(new Pixmap(Gdx.files.internal("data/badlogic.jpg")), true);
texture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
String params = Gdx.files.internal("data/gwttestparams.txt").readString();
numSprites = Integer.parseInt(params);
batch = new SpriteBatch();
positions = new ArrayList<Vector2>();
for (int i = 0; i < numSprites; i++) {
positions.add(new Vector2(MathUtils.random() * Gdx.graphics.getWidth(), MathUtils.random() * Gdx.graphics.getHeight()));
}
sprite = new Sprite(texture);
sprite.setSize(64, 64);
sprite.setOrigin(32, 32);
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
cache = font.newFontCache();
cache.setColor(Color.RED);
cache.setText("This is a Test", 0, 0);
atlas = new TextureAtlas(Gdx.files.internal("data/pack"));
}
use of com.badlogic.gdx.math.Vector2 in project commons-gdx by gemserk.
the class LimitLinearVelocitySystem method process.
@Override
protected void process(Entity e) {
PhysicsComponent physicsComponent = Components.getPhysicsComponent(e);
Body body = physicsComponent.getPhysics().getBody();
LinearVelocityLimitComponent limitComponent = e.getComponent(LinearVelocityLimitComponent.class);
Vector2 linearVelocity = body.getLinearVelocity();
float speed = linearVelocity.len();
float maxSpeed = limitComponent.getLimit();
if (speed > maxSpeed) {
float factor = maxSpeed / speed;
linearVelocity.mul(factor);
body.setLinearVelocity(linearVelocity);
}
}
Aggregations