/
BulletTestCollection.java
213 lines (180 loc) · 6.99 KB
/
BulletTestCollection.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package com.badlogic.gdx.tests;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g3d.utils.CameraInputController;
import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.input.GestureDetector.GestureListener;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.tests.bullet.*;
import com.badlogic.gdx.tests.utils.GdxTest;
import com.badlogic.gdx.utils.Align;
/** @author xoppa */
public class BulletTestCollection extends GdxTest implements InputProcessor, GestureListener {
protected final BulletTest[] tests = {new BasicBulletTest(), new ShootTest(), new BasicShapesTest(), new KinematicTest(),
new ConstraintsTest(), new MeshShapeTest(), new GimpactTest(), new ConvexHullTest(), new ConvexHullDistanceTest(),
new RayCastTest(), new RayPickRagdollTest(), new InternalTickTest(), new CollisionWorldTest(), new CollisionTest(),
new FrustumCullingTest(), new CollisionDispatcherTest(), new ContactCallbackTest(), new ContactCallbackTest2(),
new ContactCacheTest(), new SoftBodyTest(), new SoftMeshTest(), new VehicleTest(), new VehicleFilterTest(),
new CharacterTest(), new ImportTest(), new TriangleRaycastTest(), new OcclusionCullingTest(), new PairCacheTest()};
protected int testIndex = 0;
private Application app = null;
private BitmapFont font;
private Stage hud;
private Label fpsLabel;
private Label titleLabel;
private Label instructLabel;
private int loading = 0;
private CameraInputController cameraController;
@Override
public void render () {
if ((loading > 0) && (++loading > 2)) loadnext();
tests[testIndex].render();
fpsLabel.setText(tests[testIndex].performance);
hud.draw();
}
@Override
public void create () {
if (app == null) {
app = Gdx.app;
tests[testIndex].create();
}
cameraController = new CameraInputController(tests[testIndex].camera);
cameraController.activateKey = Keys.CONTROL_LEFT;
cameraController.autoUpdate = false;
cameraController.forwardTarget = false;
cameraController.translateTarget = false;
Gdx.input.setInputProcessor(new InputMultiplexer(cameraController, this, new GestureDetector(this)));
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
hud = new Stage();
hud.addActor(fpsLabel = new Label(" ", new Label.LabelStyle(font, Color.WHITE)));
fpsLabel.setPosition(0, 0);
hud.addActor(titleLabel = new Label(tests[testIndex].getClass().getSimpleName(), new Label.LabelStyle(font, Color.WHITE)));
titleLabel.setY(hud.getHeight() - titleLabel.getHeight());
hud.addActor(instructLabel = new Label("A\nB\nC\nD\nE\nF", new Label.LabelStyle(font, Color.WHITE)));
instructLabel.setY(titleLabel.getY() - instructLabel.getHeight());
instructLabel.setAlignment(Align.top | Align.left);
instructLabel.setText(tests[testIndex].instructions);
}
@Override
public void resize (int width, int height) {
hud.getViewport().update(width, height, true);
}
@Override
public void dispose () {
tests[testIndex].dispose();
app = null;
}
public void next () {
titleLabel.setText("Loading...");
loading = 1;
}
public void loadnext () {
app.log("TestCollection", "disposing test '" + tests[testIndex].getClass().getName() + "'");
tests[testIndex].dispose();
// This would be a good time for GC to kick in.
System.gc();
testIndex++;
if (testIndex >= tests.length) testIndex = 0;
tests[testIndex].create();
cameraController.camera = tests[testIndex].camera;
app.log("TestCollection", "created test '" + tests[testIndex].getClass().getName() + "'");
titleLabel.setText(tests[testIndex].getClass().getSimpleName());
instructLabel.setText(tests[testIndex].instructions);
loading = 0;
}
@Override
public boolean keyDown (int keycode) {
return tests[testIndex].keyDown(keycode);
}
@Override
public boolean keyTyped (char character) {
return tests[testIndex].keyTyped(character);
}
@Override
public boolean keyUp (int keycode) {
boolean result = tests[testIndex].keyUp(keycode);
if ((result == false) && (keycode == Keys.SPACE || keycode == Keys.MENU)) {
next();
result = true;
}
return result;
}
@Override
public boolean touchDown (int x, int y, int pointer, int button) {
return tests[testIndex].touchDown(x, y, pointer, button);
}
@Override
public boolean touchDragged (int x, int y, int pointer) {
return tests[testIndex].touchDragged(x, y, pointer);
}
@Override
public boolean touchUp (int x, int y, int pointer, int button) {
return tests[testIndex].touchUp(x, y, pointer, button);
}
@Override
public boolean mouseMoved (int x, int y) {
return tests[testIndex].mouseMoved(x, y);
}
@Override
public boolean scrolled (float amountX, float amountY) {
return tests[testIndex].scrolled(amountX,amountY);
}
@Override
public boolean touchDown (float x, float y, int pointer, int button) {
return tests[testIndex].touchDown(x, y, pointer, button);
}
@Override
public boolean tap (float x, float y, int count, int button) {
return tests[testIndex].tap(x, y, count, button);
}
@Override
public boolean longPress (float x, float y) {
return tests[testIndex].longPress(x, y);
}
@Override
public boolean fling (float velocityX, float velocityY, int button) {
if (tests[testIndex].fling(velocityX, velocityY, button) == false) next();
return true;
}
@Override
public boolean pan (float x, float y, float deltaX, float deltaY) {
return tests[testIndex].pan(x, y, deltaX, deltaY);
}
@Override
public boolean panStop (float x, float y, int pointer, int button) {
return tests[testIndex].panStop(x, y, pointer, button);
}
@Override
public boolean zoom (float originalDistance, float currentDistance) {
return tests[testIndex].zoom(originalDistance, currentDistance);
}
@Override
public boolean pinch (Vector2 initialFirstPointer, Vector2 initialSecondPointer, Vector2 firstPointer, Vector2 secondPointer) {
return tests[testIndex].pinch(initialFirstPointer, initialSecondPointer, firstPointer, secondPointer);
}
@Override
public void pinchStop () {
}
}