use of com.jme3.bullet.BulletAppState in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestCollision method simpleInitApp.
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
stateManager.attach(bulletAppState);
setupKeys();
matRock = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");
matRock.setTexture("Alpha", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
grass.setWrap(WrapMode.Repeat);
matRock.setTexture("Tex1", grass);
matRock.setFloat("Tex1Scale", 64f);
Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
dirt.setWrap(WrapMode.Repeat);
matRock.setTexture("Tex2", dirt);
matRock.setFloat("Tex2Scale", 32f);
Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
rock.setWrap(WrapMode.Repeat);
matRock.setTexture("Tex3", rock);
matRock.setFloat("Tex3Scale", 128f);
matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matWire.getAdditionalRenderState().setWireframe(true);
matWire.setColor("Color", ColorRGBA.Green);
AbstractHeightMap heightmap = null;
try {
heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f);
heightmap.load();
} catch (Exception e) {
}
terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
// patch size, and a multiplier
control.setLodCalculator(new DistanceLodCalculator(65, 2.7f));
terrain.addControl(control);
terrain.setMaterial(matRock);
terrain.setLocalScale(new Vector3f(2, 2, 2));
// unlock it so we can edit the height
terrain.setLocked(false);
rootNode.attachChild(terrain);
/**
* Create PhysicsRigidBodyControl for collision
*/
terrain.addControl(new RigidBodyControl(0));
bulletAppState.getPhysicsSpace().addAll(terrain);
// let them drop from the sky
for (int i = 0; i < 5; i++) {
float r = (float) (8 * Math.random());
Geometry sphere = new Geometry("cannonball", new Sphere(10, 10, r));
sphere.setMaterial(matWire);
// random position
float x = (float) (20 * Math.random()) - 40;
// random position
float y = (float) (20 * Math.random()) - 40;
// random position
float z = (float) (20 * Math.random()) - 40;
sphere.setLocalTranslation(new Vector3f(x, 100 + y, z));
sphere.addControl(new RigidBodyControl(new SphereCollisionShape(r), 2));
rootNode.attachChild(sphere);
bulletAppState.getPhysicsSpace().add(sphere);
}
collisionBox = new Geometry("collisionBox", new Box(2, 2, 2));
collisionBox.setModelBound(new BoundingBox());
collisionBox.setLocalTranslation(new Vector3f(20, 95, 30));
collisionBox.setMaterial(matWire);
rootNode.attachChild(collisionBox);
selectedCollisionObject = collisionBox;
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(1, -0.5f, -0.1f).normalizeLocal());
dl.setColor(new ColorRGBA(0.50f, 0.40f, 0.50f, 1.0f));
rootNode.addLight(dl);
cam.setLocation(new Vector3f(0, 25, -10));
cam.lookAtDirection(new Vector3f(0, -1, 0).normalizeLocal(), Vector3f.UNIT_Y);
}
use of com.jme3.bullet.BulletAppState in project jmonkeyengine by jMonkeyEngine.
the class TestBatchNodeTower method simpleInitApp.
@Override
public void simpleInitApp() {
timer = new NanoTimer();
bulletAppState = new BulletAppState();
bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
// bulletAppState.setEnabled(false);
stateManager.attach(bulletAppState);
bullet = new Sphere(32, 32, 0.4f, true, false);
bullet.setTextureMode(TextureMode.Projected);
bulletCollisionShape = new SphereCollisionShape(0.4f);
brick = new Box(brickWidth, brickHeight, brickDepth);
brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
//bulletAppState.getPhysicsSpace().enableDebug(assetManager);
initMaterial();
initTower();
initFloor();
initCrossHairs();
this.cam.setLocation(new Vector3f(0, 25f, 8f));
cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
cam.setFrustumFar(80);
inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addListener(actionListener, "shoot");
rootNode.setShadowMode(ShadowMode.Off);
batchNode.batch();
batchNode.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(batchNode);
shadowRenderer = new DirectionalLightShadowFilter(assetManager, 1024, 2);
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
shadowRenderer.setLight(dl);
shadowRenderer.setLambda(0.55f);
shadowRenderer.setShadowIntensity(0.6f);
shadowRenderer.setShadowCompareMode(CompareMode.Hardware);
shadowRenderer.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
fpp.addFilter(shadowRenderer);
viewPort.addProcessor(fpp);
}
use of com.jme3.bullet.BulletAppState in project jmonkeyengine by jMonkeyEngine.
the class TestAttachDriver method simpleInitApp.
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
setupKeys();
setupFloor();
buildPlayer();
}
use of com.jme3.bullet.BulletAppState in project jmonkeyengine by jMonkeyEngine.
the class TestAttachGhostObject method simpleInitApp.
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
setupKeys();
setupJoint();
}
use of com.jme3.bullet.BulletAppState in project jmonkeyengine by jMonkeyEngine.
the class TestBetterCharacter method simpleInitApp.
@Override
public void simpleInitApp() {
//setup keyboard mapping
setupKeys();
// activate physics
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
// init a physics test scene
PhysicsTestHelper.createPhysicsTestWorldSoccer(rootNode, assetManager, bulletAppState.getPhysicsSpace());
PhysicsTestHelper.createBallShooter(this, rootNode, bulletAppState.getPhysicsSpace());
setupPlanet();
// Create a node for the character model
characterNode = new Node("character node");
characterNode.setLocalTranslation(new Vector3f(4, 5, 2));
// Add a character control to the node so we can add other things and
// control the model rotation
physicsCharacter = new BetterCharacterControl(0.3f, 2.5f, 8f);
characterNode.addControl(physicsCharacter);
getPhysicsSpace().add(physicsCharacter);
// Load model, attach to character node
Node model = (Node) assetManager.loadModel("Models/Jaime/Jaime.j3o");
model.setLocalScale(1.50f);
characterNode.attachChild(model);
// Add character node to the rootNode
rootNode.attachChild(characterNode);
// Set forward camera node that follows the character, only used when
// view is "locked"
camNode = new CameraNode("CamNode", cam);
camNode.setControlDir(ControlDirection.SpatialToCamera);
camNode.setLocalTranslation(new Vector3f(0, 2, -6));
Quaternion quat = new Quaternion();
// These coordinates are local, the camNode is attached to the character node!
quat.lookAt(Vector3f.UNIT_Z, Vector3f.UNIT_Y);
camNode.setLocalRotation(quat);
characterNode.attachChild(camNode);
// Disable by default, can be enabled via keyboard shortcut
camNode.setEnabled(false);
}
Aggregations