1
0
mirror of https://github.com/Dejvino/roadtrip synced 2024-12-22 03:48:48 +00:00

Added a car model for the weak car type.

This commit is contained in:
Dejvino 2017-01-06 08:35:57 +01:00
parent 2a723f6eff
commit 8d1da0c00e
6 changed files with 28 additions and 6 deletions

View File

@ -6,6 +6,7 @@ A game about a journey involving vehicles and obstacles.
## Status
### DONE
* Physics-based vehicles
* One car model
* Driving controls (WASDX)
* Enter / Exit a car (Enter)
* Camera following the player

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,3 @@
#
#Fri Jan 06 07:21:19 CET 2017
ORIGINAL_PATH=Models/rivercrossing.scene

Binary file not shown.

Before

Width:  |  Height:  |  Size: 907 KiB

After

Width:  |  Height:  |  Size: 773 KiB

View File

@ -11,6 +11,7 @@ import com.jme3.bullet.collision.shapes.HeightfieldCollisionShape;
import com.jme3.bullet.control.BetterCharacterControl;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.control.VehicleControl;
import com.jme3.input.ChaseCamera;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
@ -20,9 +21,11 @@ import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.CameraNode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.CameraControl.ControlDirection;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Cylinder;
import com.jme3.terrain.geomipmap.TerrainGrid;
@ -59,6 +62,8 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
public static boolean DEBUG = false;//true;
private BulletAppState bulletAppState;
private ChaseCamera chaseCam;
// START Terrain
private Material mat_terrain;
@ -122,6 +127,9 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
addPerson();
addPlayer();
chaseCam = new ChaseCamera(cam, playerNode, inputManager);
chaseCam.setSmoothMotion(true);
}
private void setupKeys() {
@ -163,15 +171,25 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
float xOff = 1.6f;
float zOff = 2f;
Geometry carBody = new Geometry("car body", new Box(new Vector3f(0.0f, 1f, 0.0f), 1.4f, 0.5f, 3.6f));
Material matBody = new Material(getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
matBody.setFloat("Shininess", 32f);
matBody.setBoolean("UseMaterialColors", true);
matBody.setColor("Ambient", ColorRGBA.Black);
matBody.setColor("Diffuse", ColorRGBA.Red);
matBody.setColor("Specular", ColorRGBA.White);
carBody.setMaterial(matBody);
vehicleModel.attachChild(carBody);
if (vehicleInstance.carType == VehicleInstance.WEAK) {
Spatial carBody = getAssetManager().loadModel("Models/rivercrossing.j3o");
carBody.setLocalScale(1.1f, 0.8f, 0.8f);
carBody.setLocalTranslation(0f, -1f, 0f);
carBody.rotate(0f, 3.1415f, 0f);
vehicleModel.attachChild(carBody);
} else {
Geometry carBody = new Geometry("car body", new Box(new Vector3f(0.0f, 1f, 0.0f), 1.4f, 0.5f, 3.6f));
carBody.setMaterial(matBody);
vehicleModel.attachChild(carBody);
}
//create a compound shape and attach the BoxCollisionShape for the car body at 0,1,0
//this shifts the effective center of mass of the BoxCollisionShape to 0,-1,0
@ -462,8 +480,8 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
public void simpleUpdate(float tpf) {
Vector3f playerLocation = playerNode.getWorldTranslation();
Vector3f newLocation = new Vector3f(playerLocation).add(new Vector3f(-1f, 1.5f, 2.4f).mult(20f));
cam.setLocation(new Vector3f(cam.getLocation()).interpolate(newLocation, Math.min(tpf, 1f)));
cam.lookAt(playerLocation, Vector3f.UNIT_Y);
/*cam.setLocation(new Vector3f(cam.getLocation()).interpolate(newLocation, Math.min(tpf, 1f)));
cam.lookAt(playerLocation, Vector3f.UNIT_Y);*/
for (VehicleNode vehicle : vehicles) {
vehicle.vehicleInstance.accelerationSmooth = (vehicle.vehicleInstance.accelerationSmooth + vehicle.vehicleInstance.accelerationValue * (tpf * 10f)) / (1 + tpf * 10f);
@ -546,7 +564,7 @@ public class RoadTrip extends SimpleApplication implements ActionListener {
if (dist < 5f) {
playerVehicleNode = vehicle;
playerNode.removeFromParent();
playerNode.setLocalTranslation(0f, 0f, 0f);
playerNode.setLocalTranslation(0f, 0f, -1f);
playerNode.setLocalRotation(Quaternion.DIRECTION_Z);
playerNode.removeControl(playerPersonControl);
playerVehicleNode.attachChild(playerNode);