1 /******************************************************************************* 2 * Copyright 2011 See AUTHORS file. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 ******************************************************************************/ 16 /* 17 * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com) 18 * 19 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the 20 * License. You may obtain a copy of the License at 21 * 22 * http://www.apache.org/licenses/LICENSE-2.0 23 * 24 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" 25 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language 26 * governing permissions and limitations under the License. 27 */ 28 29 package com.badlogic.gdx.tests.box2d; 30 31 import com.badlogic.gdx.math.Vector2; 32 import com.badlogic.gdx.physics.box2d.Body; 33 import com.badlogic.gdx.physics.box2d.BodyDef; 34 import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; 35 import com.badlogic.gdx.physics.box2d.EdgeShape; 36 import com.badlogic.gdx.physics.box2d.PolygonShape; 37 import com.badlogic.gdx.physics.box2d.World; 38 39 public class ContinuousTest extends Box2DTest { 40 int m_stepCount = 0; 41 Body m_body; 42 float m_angularVelocity; 43 44 @Override createWorld(World world)45 protected void createWorld (World world) { 46 { 47 BodyDef bd = new BodyDef(); 48 bd.position.set(0, 0); 49 Body body = world.createBody(bd); 50 51 EdgeShape shape = new EdgeShape(); 52 shape.set(new Vector2(-10, 0), new Vector2(10, 0)); 53 body.createFixture(shape, 0); 54 shape.dispose(); 55 56 PolygonShape poly = new PolygonShape(); 57 poly.setAsBox(0.2f, 1.0f, new Vector2(0.5f, 1.0f), 0); 58 body.createFixture(poly, 0); 59 poly.dispose(); 60 } 61 62 { 63 BodyDef bd = new BodyDef(); 64 bd.type = BodyType.DynamicBody; 65 bd.position.set(0, 20); 66 67 PolygonShape shape = new PolygonShape(); 68 shape.setAsBox(2, 0.1f); 69 70 m_body = world.createBody(bd); 71 m_body.createFixture(shape, 1); 72 73 m_angularVelocity = 33.468121f; 74 m_body.setLinearVelocity(new Vector2(0, -100)); 75 m_body.setAngularVelocity(m_angularVelocity); 76 shape.dispose(); 77 } 78 } 79 launch()80 private void launch () { 81 m_body.setTransform(new Vector2(0, 20), 0); 82 m_angularVelocity = (float)Math.random() * 100 - 50; 83 m_body.setLinearVelocity(new Vector2(0, -100)); 84 m_body.setAngularVelocity(m_angularVelocity); 85 } 86 render()87 public void render () { 88 super.render(); 89 90 m_stepCount++; 91 if (m_stepCount % 60 == 0) launch(); 92 } 93 } 94