• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 package com.badlogic.gdx.tests.bullet;
3 
4 import com.badlogic.gdx.Gdx;
5 import com.badlogic.gdx.graphics.Color;
6 import com.badlogic.gdx.graphics.g3d.Model;
7 import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
8 import com.badlogic.gdx.math.Vector3;
9 import com.badlogic.gdx.physics.bullet.collision.btGImpactCollisionAlgorithm;
10 import com.badlogic.gdx.physics.bullet.collision.btGImpactMeshShape;
11 import com.badlogic.gdx.physics.bullet.collision.btTriangleIndexVertexArray;
12 
13 /** @author Xoppa */
14 public class GimpactTest extends BaseBulletTest {
15 	BulletEntity ground;
16 	btTriangleIndexVertexArray chassisVertexArray;
17 
18 	@Override
create()19 	public void create () {
20 		super.create();
21 
22 		final Model chassisModel = objLoader.loadModel(Gdx.files.internal("data/car.obj"));
23 		disposables.add(chassisModel);
24 		chassisModel.materials.get(0).clear();
25 		chassisModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.RED), ColorAttribute.createSpecular(Color.WHITE));
26 
27 		chassisVertexArray = new btTriangleIndexVertexArray(chassisModel.meshParts);
28 		btGImpactMeshShape chassisShape = new btGImpactMeshShape(chassisVertexArray);
29 		chassisShape.setLocalScaling(new Vector3(1f, 1f, 1f));
30 		chassisShape.setMargin(0f);
31 		chassisShape.updateBound();
32 
33 		world.addConstructor("chassis", new BulletConstructor(chassisModel, 1f, chassisShape));
34 
35 		(ground = world.add("ground", 0f, 0f, 0f)).setColor(0.25f + 0.5f * (float)Math.random(),
36 			0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
37 
38 		for (float y = 10f; y < 50f; y += 5f)
39 			world.add("chassis", -2f + (float)Math.random() * 4f, y, -2f + (float)Math.random() * 4f).setColor(
40 				0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
41 
42 		btGImpactCollisionAlgorithm.registerAlgorithm(world.dispatcher);
43 	}
44 
45 	@Override
tap(float x, float y, int count, int button)46 	public boolean tap (float x, float y, int count, int button) {
47 		shoot(x, y);
48 		return true;
49 	}
50 
51 	@Override
dispose()52 	public void dispose () {
53 		super.dispose();
54 		chassisVertexArray.dispose();
55 		chassisVertexArray = null;
56 		ground = null;
57 	}
58 }
59