• 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 package com.badlogic.gdx.tests.bullet;
18 
19 import com.badlogic.gdx.Gdx;
20 import com.badlogic.gdx.graphics.Color;
21 import com.badlogic.gdx.graphics.VertexAttribute;
22 import com.badlogic.gdx.graphics.VertexAttributes;
23 import com.badlogic.gdx.graphics.VertexAttributes.Usage;
24 import com.badlogic.gdx.graphics.g3d.Material;
25 import com.badlogic.gdx.graphics.g3d.Model;
26 import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
27 import com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute;
28 import com.badlogic.gdx.graphics.glutils.ShaderProgram;
29 import com.badlogic.gdx.math.Matrix4;
30 import com.badlogic.gdx.math.Vector3;
31 import com.badlogic.gdx.math.collision.BoundingBox;
32 import com.badlogic.gdx.physics.bullet.collision.btBvhTriangleMeshShape;
33 import com.badlogic.gdx.physics.bullet.collision.btSphereShape;
34 
35 /** @author xoppa */
36 public class MeshShapeTest extends BaseBulletTest {
37 
38 	@Override
create()39 	public void create () {
40 		super.create();
41 
42 		final Model sphereModel = modelBuilder.createSphere(0.5f, 0.5f, 0.5f, 8, 8,
43 			new Material(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE)), Usage.Position
44 				| Usage.Normal);
45 		disposables.add(sphereModel);
46 		final BulletConstructor sphereConstructor = new BulletConstructor(sphereModel, 0.25f, new btSphereShape(0.25f));
47 		sphereConstructor.bodyInfo.setRestitution(1f);
48 		world.addConstructor("sphere", sphereConstructor);
49 
50 		final Model sceneModel = objLoader.loadModel(Gdx.files.internal("data/scene.obj"));
51 		disposables.add(sceneModel);
52 		final BulletConstructor sceneConstructor = new BulletConstructor(sceneModel, 0f, new btBvhTriangleMeshShape(
53 			sceneModel.meshParts));
54 		sceneConstructor.bodyInfo.setRestitution(0.25f);
55 		world.addConstructor("scene", sceneConstructor);
56 
57 		world.add("scene", (new Matrix4()).setToTranslation(0f, 2f, 0f).rotate(Vector3.Y, -90)).setColor(
58 			0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
59 
60 		world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(),
61 			0.25f + 0.5f * (float)Math.random(), 1f);
62 
63 		for (float x = -3; x < 7; x++) {
64 			for (float z = -5; z < 5; z++) {
65 				world.add("sphere", x, 10f + (float)Math.random() * 0.1f, z).setColor(0.5f + 0.5f * (float)Math.random(),
66 					0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
67 			}
68 		}
69 	}
70 
71 	@Override
tap(float x, float y, int count, int button)72 	public boolean tap (float x, float y, int count, int button) {
73 		shoot(x, y);
74 		return true;
75 	}
76 }
77