1
- package com .exampleGamePad ;
1
+ package com .myGame ;
2
2
3
3
import android .graphics .Color ;
4
4
import android .view .View ;
16
16
import com .jme3 .input .ChaseCamera ;
17
17
import com .jme3 .light .AmbientLight ;
18
18
import com .jme3 .material .Material ;
19
+ import com .jme3 .material .RenderState ;
19
20
import com .jme3 .math .ColorRGBA ;
20
21
import com .jme3 .math .FastMath ;
21
22
import com .jme3 .math .Plane ;
26
27
import com .jme3 .scene .shape .Box ;
27
28
import com .jme3 .scene .shape .Cylinder ;
28
29
import com .jme3 .scene .shape .Sphere ;
30
+ import com .jme3 .texture .Texture ;
31
+ import com .jme3 .util .SkyFactory ;
29
32
import com .scrappers .jmeGamePad .GamePadView ;
30
33
31
34
public class JmeGame extends SimpleApplication {
32
35
33
36
private BulletAppState bulletAppState ;
34
37
private VehicleControl vehicle ;
35
- private final float accelerationForce = FastMath .pow (5 , 3.5f );
36
38
private final float brakeForce = 300f ;
37
- private float steeringValue = 0 ;
38
- private float accelerationValue = 0 ;
39
- private final Vector3f jumpForce = new Vector3f (0 , 3000 , 0 );
39
+ private final Vector3f jumpForce = new Vector3f (0 , 2000 , 0 );
40
40
41
41
42
42
@ Override
43
43
public void simpleInitApp () {
44
44
bulletAppState = new BulletAppState ();
45
45
stateManager .attach (bulletAppState );
46
46
bulletAppState .setDebugEnabled (false );
47
+ addSky ();
47
48
createPhysicsTestWorld (rootNode , getAssetManager (), bulletAppState .getPhysicsSpace ());
48
49
buildPlayer ();
49
50
50
-
51
+ /*LIBRARY CODE*/
51
52
/*run the gamePad Attachments & listeners from the android activity UI thread */
52
53
JmeHarness .jmeHarness .runOnUiThread (new Runnable () {
53
54
@ Override
@@ -59,7 +60,7 @@ public void run() {
59
60
/* create a gamePadView instance of cardView/FrameLayout to display gamePad Component */
60
61
GamePadView gamePadView =new GamePadView ( JmeHarness .jmeHarness ,gameStick );
61
62
/* Initialize GamePad Parts*/
62
- gamePadView .initializeGamePad (R .drawable .gamepad_domain ,GamePadView .HALF_SCREEN )
63
+ gamePadView .initializeGamePad (R .drawable .gamepad_domain ,GamePadView .ONE_THIRD_SCREEN )
63
64
.initializeGameStickHolder (R .drawable .moving_stick_domain )
64
65
.initializeGameStick (GamePadView .CRYSTAL_BUTTONS ,R .drawable .ic_baseline_gamepad_24 ,200 );
65
66
/*initialize the gameStick track */
@@ -70,13 +71,13 @@ public void run() {
70
71
gamePadView .addControlButton ("BUTTON A" ,GamePadView .GAMEPAD_BUTTON_A ,GamePadView .CRYSTAL_BUTTONS , R .drawable .ic_baseline_gamepad_24 ,new View .OnClickListener () {
71
72
@ Override
72
73
public void onClick (View view ) {
73
- vehicle .accelerate ( accelerationForce );
74
+ vehicle .applyCentralImpulse ( jumpForce );
74
75
}
75
76
},null );
76
77
gamePadView .addControlButton ("BUTTON B" ,GamePadView .GAMEPAD_BUTTON_B , GamePadView .CRYSTAL_BUTTONS , R .drawable .ic_baseline_gamepad_24 ,new View .OnClickListener () {
77
78
@ Override
78
79
public void onClick (View view ) {
79
- vehicle . brake ( brakeForce );
80
+
80
81
}
81
82
},null );
82
83
gamePadView .addControlButton ("BUTTON X" ,GamePadView .GAMEPAD_BUTTON_X , GamePadView .CRYSTAL_BUTTONS , R .drawable .ic_baseline_gamepad_24 ,new View .OnClickListener () {
@@ -96,6 +97,12 @@ public void onClick(View view) {
96
97
});
97
98
}
98
99
100
+ private void addSky () {
101
+ Geometry sky = (Geometry ) SkyFactory .createSky (assetManager ,assetManager .loadTexture ("RocketLeauge/assets/Textures/sky.jpg" ),Vector3f .UNIT_XYZ , SkyFactory .EnvMapType .EquirectMap );
102
+ sky .getMaterial ().getAdditionalRenderState ().setDepthFunc (RenderState .TestFunction .LessOrEqual );
103
+ getRootNode ().attachChild (sky );
104
+ }
105
+
99
106
private PhysicsSpace getPhysicsSpace (){
100
107
return bulletAppState .getPhysicsSpace ();
101
108
}
@@ -109,12 +116,12 @@ private PhysicsSpace getPhysicsSpace(){
109
116
*/
110
117
public static void createPhysicsTestWorld (Node rootNode , AssetManager assetManager , PhysicsSpace space ) {
111
118
AmbientLight light = new AmbientLight ();
112
- light .setColor (ColorRGBA .LightGray );
119
+ light .setColor (ColorRGBA .White );
113
120
rootNode .addLight (light );
114
121
115
122
116
123
Material material = new Material (assetManager , "Common/MatDefs/Misc/Unshaded.j3md" );
117
- material .setTexture ("ColorMap" , assetManager .loadTexture ("mars.jpg" ));
124
+ material .setTexture ("ColorMap" , assetManager .loadTexture ("RocketLeauge/assets/Textures/ mars.jpg" ));
118
125
119
126
Box floorBox = new Box (200f , 0.5f , 200f );
120
127
Geometry floorGeometry = new Geometry ("Floor" , floorBox );
@@ -160,20 +167,25 @@ private void buildPlayer() {
160
167
//create a compound shape and attach the BoxCollisionShape for the car body at 0,1,0
161
168
//this shifts the effective center of mass of the BoxCollisionShape to 0,-1,0
162
169
CompoundCollisionShape compoundShape = new CompoundCollisionShape ();
163
- BoxCollisionShape box = new BoxCollisionShape (new Vector3f (2f , 0.5f , 2.5f ));
170
+ BoxCollisionShape box = new BoxCollisionShape (new Vector3f (2. 2f , 0.5f , 2.5f ));
164
171
165
172
compoundShape .addChildShape (box , new Vector3f (0 , 1.5f , 0 ));
166
173
167
- Spatial spatial =assetManager .loadModel ("Mars.j3o" );
168
- spatial .setLocalScale (0.01f ,0.01f ,0.01f );
169
- spatial .setLocalTranslation (new Vector3f (0 , 1.5f , 0 ));
174
+ Spatial spatial =assetManager .loadModel ("RocketLeauge/assets/Models/car22221/car22221.j3o" );
175
+ spatial .setLocalScale (2.2f ,2.2f ,2.2f );
176
+ spatial .setLocalTranslation (new Vector3f (0 , 1.2f , 0 ));
177
+ //colors
178
+ ((Node )spatial ).getChild ("glass" ).setMaterial (createMat (ColorRGBA .BlackNoAlpha ,"" ));
179
+ ((Node )spatial ).getChild ("chassis" ).setMaterial (createMat (new ColorRGBA (0f ,1f ,3f ,1f ),"RocketLeauge/assets/Textures/TexturesCom_MetalBare0201_6_M.jpg" ));
180
+ ((Node )spatial ).getChild ("addOns" ).setMaterial (createMat (ColorRGBA .White ,"" ));
181
+ ((Node )spatial ).getChild ("nitros" ).setMaterial (createMat (new ColorRGBA (0f ,0f ,5f ,1f ),"RocketLeauge/assets/Textures/TexturesCom_MetalBare0201_6_M.jpg" ));
182
+ ((Node )spatial ).getChild ("light" ).setMaterial (createMat (ColorRGBA .Yellow ,"" ));
170
183
171
184
//create vehicle node
172
- Node vehicleNode =new Node ("vehicleNfode " );
185
+ Node vehicleNode =new Node ("vehicleNode " );
173
186
vehicleNode .attachChild (spatial );
174
187
175
188
// chassis.setMaterial(mat);
176
- // vehicleNode.attachChild(chassis);
177
189
vehicle = new VehicleControl (compoundShape , 600f );
178
190
vehicleNode .addControl (vehicle );
179
191
//add a chaseCam tomove the cam with the object
@@ -186,7 +198,7 @@ private void buildPlayer() {
186
198
//setting suspension values for wheels, this can be a bit tricky
187
199
//see also https://docs.google.com/Doc?docid=0AXVUZ5xw6XpKZGNuZG56a3FfMzU0Z2NyZnF4Zmo&hl=en
188
200
float stiffness =30.0f ;//200=f1 car
189
- float compValue = 0.3f ; //(should be lower than damp)
201
+ float compValue = 0.5f ; //(should be lower than damp)
190
202
float dampValue = 2f ;
191
203
//compression force of spring(Shock Producer)
192
204
vehicle .setSuspensionCompression (compValue * 2.0f * FastMath .sqrt (stiffness ));
@@ -201,7 +213,7 @@ private void buildPlayer() {
201
213
float radius = 0.5f ;
202
214
float restLength = 0.1f ;
203
215
float yOff = radius ;
204
- float xOff = 2 *radius ;
216
+ float xOff = 3 *radius ;
205
217
float zOff = 4 *radius ;
206
218
207
219
Cylinder wheelMesh = new Cylinder (16 , 16 , radius , radius * 0.5f , true );
@@ -244,13 +256,33 @@ private void buildPlayer() {
244
256
vehicleNode .attachChild (node4 );
245
257
rootNode .attachChild (vehicleNode );
246
258
259
+ setWheelFrictionSlip (20f );
260
+
247
261
getPhysicsSpace ().add (vehicle );
248
262
}
249
263
264
+ private void setWheelFrictionSlip (float frictionSlip ) {
265
+ for (int nOfWheel =0 ;nOfWheel <vehicle .getNumWheels ();nOfWheel ++) {
266
+ vehicle .getWheel (nOfWheel ).setFrictionSlip (frictionSlip );
267
+ }
268
+ }
269
+
270
+ public Material createMat (ColorRGBA colorRGBA ,String Tex ){
271
+ Material material =new Material (assetManager ,"Common/MatDefs/Misc/Unshaded.j3md" );
272
+ if (colorRGBA !=null ){
273
+ material .setColor ("Color" , colorRGBA );
274
+ }
275
+ if (Tex .length () >1 ){
276
+ Texture texture =assetManager .loadTexture (Tex );
277
+ material .setTexture ("ColorMap" ,texture );
278
+ }
279
+ material .setReceivesShadows (true );
280
+
281
+ return material ;
282
+ }
283
+
250
284
@ Override
251
285
public void simpleUpdate (float tpf ) {
252
- cam .lookAt (vehicle .getPhysicsLocation (), Vector3f .UNIT_Y );
253
- System .out .println ();
254
286
}
255
287
256
288
}
0 commit comments