• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.CircleShape;
36 import com.badlogic.gdx.physics.box2d.EdgeShape;
37 import com.badlogic.gdx.physics.box2d.FixtureDef;
38 import com.badlogic.gdx.physics.box2d.World;
39 
40 public class VaryingRestitution extends Box2DTest {
41 	@Override
createWorld(World world)42 	protected void createWorld (World world) {
43 		{
44 			BodyDef bd = new BodyDef();
45 			Body ground = world.createBody(bd);
46 
47 			EdgeShape shape = new EdgeShape();
48 			shape.set(new Vector2(-40, 0), new Vector2(40, 0));
49 			ground.createFixture(shape, 0.0f);
50 			shape.dispose();
51 		}
52 
53 		{
54 			CircleShape shape = new CircleShape();
55 			shape.setRadius(1);
56 
57 			FixtureDef fd = new FixtureDef();
58 			fd.shape = shape;
59 			fd.density = 1.0f;
60 
61 			float restitution[] = {0, 0.1f, 0.3f, 0.5f, 0.75f, 0.9f, 1.0f};
62 
63 			for (int i = 0; i < restitution.length; i++) {
64 				BodyDef bd = new BodyDef();
65 				bd.type = BodyType.DynamicBody;
66 				bd.position.set(-10.0f + 3.0f * i, 20.0f);
67 
68 				Body body = world.createBody(bd);
69 				fd.restitution = restitution[i];
70 				body.createFixture(fd);
71 			}
72 
73 			shape.dispose();
74 		}
75 	}
76 }
77