List of usage examples for com.badlogic.gdx.math MathUtils degRad
float degRad
To view the source code for com.badlogic.gdx.math MathUtils degRad.
Click Source Link
From source file:CB_UI_Base.GL_UI.Controls.PopUps.PopUpMenu.java
License:Open Source License
private void addSegmentLine(float i) { float x1 = centerX + innerRadius * MathUtils.cos(i * MathUtils.degRad); float y1 = centerY + innerRadius * MathUtils.sin(i * MathUtils.degRad); float x2 = centerX + outerRadius * MathUtils.cos(i * MathUtils.degRad); float y2 = centerY + outerRadius * MathUtils.sin(i * MathUtils.degRad); Line l1 = new Line(x1, y1, x2, y2); Quadrangle q1 = new Quadrangle(l1, lineWidth); geomList.add(q1);//from w w w. j a v a2 s . com }
From source file:CB_UI_Base.graphics.Geometry.RingSegment.java
License:Open Source License
/** * Calculate the vertices of this circle with a minimum segment length of 10. <br> * OR a minimum segment count of 18. <br> * <br>// ww w. ja va 2 s .c om * For every segment are compute a triangle from the segment start, end and the center of this circle. */ @Override public void Compute() { if (!isDirty) return; // Nothing todo // calculate segment count double alpha = (360 * MIN_CIRCLE_SEGMENTH_LENGTH) / (MathUtils.PI2 * outerRadius); if (start > end) { alpha *= -1; } int segmente = (int) (((end - start) / alpha) + 1); // calculate theta step double thetaStep = alpha; // initialize arrays vertices = new float[(segmente + 1) * 4]; triangleIndices = new short[(segmente) * 6]; // float halfStrokeWidth = (PAINT.strokeWidth) / 2; int index = 0; int triangleIndex = 0; short verticeIdex = 0; boolean beginnTriangles = false; for (float i = start; index < ((segmente + 1) * 4); i += thetaStep) { if (i > end) i = end; vertices[index++] = centerX + innerRadius * MathUtils.cos(i * MathUtils.degRad); vertices[index++] = centerY + innerRadius * MathUtils.sin(i * MathUtils.degRad); vertices[index++] = centerX + outerRadius * MathUtils.cos(i * MathUtils.degRad); vertices[index++] = centerY + outerRadius * MathUtils.sin(i * MathUtils.degRad); if (!beginnTriangles) { if (index % 8 == 0) beginnTriangles = true; } if (beginnTriangles) { triangleIndices[triangleIndex++] = verticeIdex++; triangleIndices[triangleIndex++] = verticeIdex++; triangleIndices[triangleIndex++] = verticeIdex--; triangleIndices[triangleIndex++] = verticeIdex++; triangleIndices[triangleIndex++] = verticeIdex++; triangleIndices[triangleIndex++] = verticeIdex--; } } isDirty = false; }
From source file:com.agateau.pixelwheels.bonus.Missile.java
License:Open Source License
public static Missile create(Assets assets, GameWorld gameWorld, AudioManager audioManager, Racer shooter) { Missile object = sPool.obtain();/*from w ww . j a v a2 s. c o m*/ object.mAssets = assets; object.mGameWorld = gameWorld; object.mAudioManager = audioManager; object.setFinished(false); object.mRacerFinder.setIgnoredRacer(shooter); Vehicle vehicle = shooter.getVehicle(); object.mShooter = shooter; object.mBodyDef.position.set(vehicle.getX(), vehicle.getY()); object.mBodyDef.angle = vehicle.getAngle() * MathUtils.degRad; object.mBody = gameWorld.getBox2DWorld().createBody(object.mBodyDef); object.mBody.createFixture(object.mShape, WAITING_DENSITY); object.mBody.setUserData(object); Box2DUtils.setCollisionInfo(object.mBody, CollisionCategories.RACER_BULLET, CollisionCategories.WALL | CollisionCategories.RACER | CollisionCategories.EXPLOSABLE); object.mStatus = Status.WAITING; object.mNeedShootSound = false; object.mTarget = null; object.initJoint(); object.mGuidingSystem.init(object.mBody); gameWorld.addGameObject(object); DebugShapeMap.put(object, object.mDebugShape); return object; }
From source file:com.agateau.pixelwheels.racer.Vehicle.java
License:Open Source License
/** * Apply pilot commands to the wheels/*from www . j a v a2 s .co m*/ */ private void applyPilotCommands() { float speedDelta = 0; if (mGameWorld.getState() == GameWorld.State.RUNNING) { if (mAccelerating) { speedDelta = ACCELERATION_DELTA * mSpeedLimiter; } if (mBraking) { speedDelta -= BRAKING_DELTA; } } float steerAngle = computeSteerAngle() * MathUtils.degRad; for (WheelInfo info : mWheels) { float angle = info.steeringFactor * steerAngle; info.wheel.adjustSpeed(speedDelta); info.joint.setLimits(angle, angle); } }
From source file:com.esotericsoftware.spine.Box2DExample.java
License:Open Source License
public void create() { batch = new SpriteBatch(); renderer = new ShapeRenderer(); skeletonRenderer = new SkeletonRenderer(); skeletonRenderer.setPremultipliedAlpha(true); atlas = new TextureAtlas(Gdx.files.internal("spineboy/spineboy.atlas")); // This loader creates Box2dAttachments instead of RegionAttachments for an easy way to keep // track of the Box2D body for each attachment. AtlasAttachmentLoader atlasLoader = new AtlasAttachmentLoader(atlas) { public RegionAttachment newRegionAttachment(Skin skin, String name, String path) { Box2dAttachment attachment = new Box2dAttachment(name); AtlasRegion region = atlas.findRegion(attachment.getName()); if (region == null) throw new RuntimeException("Region not found in atlas: " + attachment); attachment.setRegion(region); return attachment; }//from w w w. ja v a 2 s . c om }; SkeletonJson json = new SkeletonJson(atlasLoader); json.setScale(0.6f * 0.05f); SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("spineboy/spineboy.json")); animation = skeletonData.findAnimation("walk"); skeleton = new Skeleton(skeletonData); skeleton.x = -32; skeleton.y = 1; skeleton.updateWorldTransform(); // See Box2DTest in libgdx for more detailed information about Box2D setup. camera = new OrthographicCamera(48, 32); camera.position.set(0, 16, 0); box2dRenderer = new Box2DDebugRenderer(); createWorld(); // Create a body for each attachment. Note it is probably better to create just a few bodies rather than one for each // region attachment, but this is just an example. for (Slot slot : skeleton.getSlots()) { if (!(slot.getAttachment() instanceof Box2dAttachment)) continue; Box2dAttachment attachment = (Box2dAttachment) slot.getAttachment(); PolygonShape boxPoly = new PolygonShape(); boxPoly.setAsBox(attachment.getWidth() / 2 * attachment.getScaleX(), attachment.getHeight() / 2 * attachment.getScaleY(), vector.set(attachment.getX(), attachment.getY()), attachment.getRotation() * MathUtils.degRad); BodyDef boxBodyDef = new BodyDef(); boxBodyDef.type = BodyType.StaticBody; attachment.body = world.createBody(boxBodyDef); attachment.body.createFixture(boxPoly, 1); boxPoly.dispose(); } }
From source file:com.esotericsoftware.spine.Box2DExample.java
License:Open Source License
public void render() { float delta = Gdx.graphics.getDeltaTime(); float remaining = delta; while (remaining > 0) { float d = Math.min(0.016f, remaining); world.step(d, 8, 3);//from ww w .j ava 2 s. co m time += d; remaining -= d; } camera.update(); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.setProjectionMatrix(camera.projection); batch.setTransformMatrix(camera.view); batch.begin(); animation.apply(skeleton, time, time, true, events); skeleton.x += 8 * delta; skeleton.updateWorldTransform(); skeletonRenderer.draw(batch, skeleton); batch.end(); // Position each attachment body. for (Slot slot : skeleton.getSlots()) { if (!(slot.getAttachment() instanceof Box2dAttachment)) continue; Box2dAttachment attachment = (Box2dAttachment) slot.getAttachment(); if (attachment.body == null) continue; float x = skeleton.x + slot.getBone().getWorldX(); float y = skeleton.y + slot.getBone().getWorldY(); float rotation = slot.getBone().getWorldRotation(); attachment.body.setTransform(x, y, rotation * MathUtils.degRad); } box2dRenderer.render(world, camera.combined); }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DMapObjectParser.java
License:Apache License
/** assigns the given {@link MapProperties properties} to the values of the given BodyDef * @param bodyDef the {@link BodyDef} which values to set according to the given {@link MapProperties} * @param properties the {@link MapProperties} to assign to the given {@link BodyDef} */ public void assignProperties(BodyDef bodyDef, MapProperties properties) { if (properties == null) return;/*from www .ja v a 2 s . c om*/ bodyDef.type = getProperty(properties, aliases.bodyType, "").equals(aliases.staticBody) ? BodyType.StaticBody : getProperty(properties, aliases.bodyType, "").equals(aliases.dynamicBody) ? BodyType.DynamicBody : getProperty(properties, aliases.bodyType, "").equals(aliases.kinematicBody) ? BodyType.KinematicBody : bodyDef.type; bodyDef.active = getProperty(properties, aliases.active, bodyDef.active); bodyDef.allowSleep = getProperty(properties, aliases.allowSleep, bodyDef.allowSleep); bodyDef.angle = getProperty(properties, aliases.angle, bodyDef.angle) * MathUtils.degRad; bodyDef.angularDamping = getProperty(properties, aliases.angularDamping, bodyDef.angularDamping); bodyDef.angularVelocity = getProperty(properties, aliases.angularVelocity, bodyDef.angularVelocity); bodyDef.awake = getProperty(properties, aliases.awake, bodyDef.awake); bodyDef.bullet = getProperty(properties, aliases.bullet, bodyDef.bullet); bodyDef.fixedRotation = getProperty(properties, aliases.fixedRotation, bodyDef.fixedRotation); bodyDef.gravityScale = getProperty(properties, aliases.gravityScale, bodyDef.gravityScale); bodyDef.linearDamping = getProperty(properties, aliases.linearDamping, bodyDef.linearDamping); bodyDef.linearVelocity.set(getProperty(properties, aliases.linearVelocityX, bodyDef.linearVelocity.x), getProperty(properties, aliases.linearVelocityY, bodyDef.linearVelocity.y)); bodyDef.position.set(getProperty(properties, aliases.x, bodyDef.position.x) * unitScale, getProperty(properties, aliases.y, bodyDef.position.y) * unitScale); }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DMapObjectParser.java
License:Apache License
/** assigns all properties unique to the given joint definition */ public void assignProperties(PrismaticJointDef prismaticJointDef, MapProperties properties) { if (properties == null) return;//ww w. j a v a2 s. c o m prismaticJointDef.enableLimit = getProperty(properties, aliases.enableLimit, prismaticJointDef.enableLimit); prismaticJointDef.enableMotor = getProperty(properties, aliases.enableMotor, prismaticJointDef.enableMotor); prismaticJointDef.localAnchorA.set( getProperty(properties, aliases.localAnchorAX, prismaticJointDef.localAnchorA.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorAY, prismaticJointDef.localAnchorA.y) * tileHeight * unitScale); prismaticJointDef.localAnchorB.set( getProperty(properties, aliases.localAnchorBX, prismaticJointDef.localAnchorB.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorBY, prismaticJointDef.localAnchorB.y) * tileHeight * unitScale); prismaticJointDef.localAxisA.set( getProperty(properties, aliases.localAxisAX, prismaticJointDef.localAxisA.x), getProperty(properties, aliases.localAxisAY, prismaticJointDef.localAxisA.y)); prismaticJointDef.lowerTranslation = getProperty(properties, aliases.lowerTranslation, prismaticJointDef.lowerTranslation) * (tileWidth + tileHeight) / 2 * unitScale; prismaticJointDef.maxMotorForce = getProperty(properties, aliases.maxMotorForce, prismaticJointDef.maxMotorForce); prismaticJointDef.motorSpeed = getProperty(properties, aliases.motorSpeed, prismaticJointDef.motorSpeed); prismaticJointDef.referenceAngle = getProperty(properties, aliases.referenceAngle, prismaticJointDef.referenceAngle) * MathUtils.degRad; prismaticJointDef.upperTranslation = getProperty(properties, aliases.upperTranslation, prismaticJointDef.upperTranslation) * (tileWidth + tileHeight) / 2 * unitScale; }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DMapObjectParser.java
License:Apache License
/** assigns all properties unique to the given joint definition */ public void assignProperties(RevoluteJointDef revoluteJointDef, MapProperties properties) { if (properties == null) return;/*w w w . j a v a 2 s . com*/ revoluteJointDef.enableLimit = getProperty(properties, aliases.enableLimit, revoluteJointDef.enableLimit); revoluteJointDef.enableMotor = getProperty(properties, aliases.enableMotor, revoluteJointDef.enableMotor); revoluteJointDef.localAnchorA.set( getProperty(properties, aliases.localAnchorAX, revoluteJointDef.localAnchorA.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorAY, revoluteJointDef.localAnchorA.y) * tileHeight * unitScale); revoluteJointDef.localAnchorB.set( getProperty(properties, aliases.localAnchorBX, revoluteJointDef.localAnchorB.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorBY, revoluteJointDef.localAnchorB.y) * tileHeight * unitScale); revoluteJointDef.lowerAngle = getProperty(properties, aliases.lowerAngle, revoluteJointDef.lowerAngle) * MathUtils.degRad; revoluteJointDef.maxMotorTorque = getProperty(properties, aliases.maxMotorTorque, revoluteJointDef.maxMotorTorque); revoluteJointDef.motorSpeed = getProperty(properties, aliases.motorSpeed, revoluteJointDef.motorSpeed); revoluteJointDef.referenceAngle = getProperty(properties, aliases.referenceAngle, revoluteJointDef.referenceAngle) * MathUtils.degRad; revoluteJointDef.upperAngle = getProperty(properties, aliases.upperAngle, revoluteJointDef.upperAngle) * MathUtils.degRad; }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DMapObjectParser.java
License:Apache License
/** assigns all properties unique to the given joint definition */ public void assignProperties(WeldJointDef weldJointDef, MapProperties properties) { if (properties == null) return;/*from w ww .ja va 2s.c o m*/ weldJointDef.localAnchorA.set( getProperty(properties, aliases.localAnchorAX, weldJointDef.localAnchorA.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorAY, weldJointDef.localAnchorA.y) * tileHeight * unitScale); weldJointDef.localAnchorB.set( getProperty(properties, aliases.localAnchorBX, weldJointDef.localAnchorB.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorBY, weldJointDef.localAnchorB.y) * tileHeight * unitScale); weldJointDef.referenceAngle = getProperty(properties, aliases.referenceAngle, weldJointDef.referenceAngle) * MathUtils.degRad; }