use of com.jme3.bullet.control.RigidBodyControl in project jmonkeyengine by jMonkeyEngine.
the class TestRagdollCharacter method initWall.
public void initWall(float bLength, float bWidth, float bHeight) {
Box brick = new Box(bLength, bHeight, bWidth);
brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
key.setGenerateMips(true);
Texture tex = assetManager.loadTexture(key);
mat2.setTexture("ColorMap", tex);
float startpt = bLength / 4;
float height = -5;
for (int j = 0; j < 15; j++) {
for (int i = 0; i < 4; i++) {
Vector3f ori = new Vector3f(i * bLength * 2 + startpt, bHeight + height, -10);
Geometry reBoxg = new Geometry("brick", brick);
reBoxg.setMaterial(mat2);
reBoxg.setLocalTranslation(ori);
//for geometry with sphere mesh the physics system automatically uses a sphere collision shape
reBoxg.addControl(new RigidBodyControl(1.5f));
reBoxg.setShadowMode(ShadowMode.CastAndReceive);
reBoxg.getControl(RigidBodyControl.class).setFriction(0.6f);
this.rootNode.attachChild(reBoxg);
this.getPhysicsSpace().add(reBoxg);
}
startpt = -startpt;
height += 2 * bHeight;
}
}
use of com.jme3.bullet.control.RigidBodyControl in project jmonkeyengine by jMonkeyEngine.
the class TestSweepTest method simpleInitApp.
@Override
public void simpleInitApp() {
obstacleCollisionShape = new CapsuleCollisionShape(0.3f, 0.5f);
capsuleCollisionShape = new CapsuleCollisionShape(1f, 1f);
stateManager.attach(bulletAppState);
capsule = new Node("capsule");
capsule.move(-2, 0, 0);
capsule.addControl(new RigidBodyControl(capsuleCollisionShape, 1));
capsule.getControl(RigidBodyControl.class).setKinematic(true);
bulletAppState.getPhysicsSpace().add(capsule);
rootNode.attachChild(capsule);
obstacle = new Node("obstacle");
obstacle.move(2, 0, 0);
RigidBodyControl bodyControl = new RigidBodyControl(obstacleCollisionShape, 0);
obstacle.addControl(bodyControl);
bulletAppState.getPhysicsSpace().add(obstacle);
rootNode.attachChild(obstacle);
bulletAppState.setDebugEnabled(true);
}
use of com.jme3.bullet.control.RigidBodyControl in project jmonkeyengine by jMonkeyEngine.
the class TestPhysicsRayCast method simpleInitApp.
@Override
public void simpleInitApp() {
stateManager.attach(bulletAppState);
initCrossHair();
Spatial s = assetManager.loadModel("Models/Elephant/Elephant.mesh.xml");
s.setLocalScale(0.1f);
CollisionShape collisionShape = CollisionShapeFactory.createMeshShape(s);
Node n = new Node("elephant");
n.addControl(new RigidBodyControl(collisionShape, 1));
n.getControl(RigidBodyControl.class).setKinematic(true);
bulletAppState.getPhysicsSpace().add(n);
rootNode.attachChild(n);
bulletAppState.setDebugEnabled(true);
}
use of com.jme3.bullet.control.RigidBodyControl in project jmonkeyengine by jMonkeyEngine.
the class TestQ3 method simpleInitApp.
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
flyCam.setMoveSpeed(100);
setupKeys();
this.cam.setFrustumFar(2000);
DirectionalLight dl = new DirectionalLight();
dl.setColor(ColorRGBA.White.clone().multLocal(2));
dl.setDirection(new Vector3f(-1, -1, -1).normalize());
rootNode.addLight(dl);
AmbientLight am = new AmbientLight();
am.setColor(ColorRGBA.White.mult(2));
rootNode.addLight(am);
// load the level from zip or http zip
if (useHttp) {
assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/quake3level.zip", HttpZipLocator.class);
} else {
assetManager.registerLocator("quake3level.zip", ZipLocator.class);
}
// create the geometry and attach it
MaterialList matList = (MaterialList) assetManager.loadAsset("Scene.material");
OgreMeshKey key = new OgreMeshKey("main.meshxml", matList);
gameLevel = (Node) assetManager.loadAsset(key);
gameLevel.setLocalScale(0.1f);
// add a physics control, it will generate a MeshCollisionShape based on the gameLevel
gameLevel.addControl(new RigidBodyControl(0));
player = new PhysicsCharacter(new SphereCollisionShape(5), .01f);
player.setJumpSpeed(20);
player.setFallSpeed(30);
player.setGravity(30);
player.setPhysicsLocation(new Vector3f(60, 10, -60));
rootNode.attachChild(gameLevel);
getPhysicsSpace().addAll(gameLevel);
getPhysicsSpace().add(player);
}
use of com.jme3.bullet.control.RigidBodyControl in project jmonkeyengine by jMonkeyEngine.
the class TestWalkingChar method createTerrain.
private void createTerrain() {
matRock = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
matRock.setBoolean("useTriPlanarMapping", false);
matRock.setBoolean("WardIso", true);
matRock.setTexture("AlphaMap", 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("DiffuseMap", grass);
matRock.setFloat("DiffuseMap_0_scale", 64);
Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
dirt.setWrap(WrapMode.Repeat);
matRock.setTexture("DiffuseMap_1", dirt);
matRock.setFloat("DiffuseMap_1_scale", 16);
Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
rock.setWrap(WrapMode.Repeat);
matRock.setTexture("DiffuseMap_2", rock);
matRock.setFloat("DiffuseMap_2_scale", 128);
Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg");
normalMap0.setWrap(WrapMode.Repeat);
Texture normalMap1 = assetManager.loadTexture("Textures/Terrain/splat/dirt_normal.png");
normalMap1.setWrap(WrapMode.Repeat);
Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png");
normalMap2.setWrap(WrapMode.Repeat);
matRock.setTexture("NormalMap", normalMap0);
matRock.setTexture("NormalMap_1", normalMap2);
matRock.setTexture("NormalMap_2", normalMap2);
AbstractHeightMap heightmap = null;
try {
heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f);
heightmap.load();
} catch (Exception e) {
e.printStackTrace();
}
terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
List<Camera> cameras = new ArrayList<Camera>();
cameras.add(getCamera());
TerrainLodControl control = new TerrainLodControl(terrain, cameras);
terrain.addControl(control);
terrain.setMaterial(matRock);
terrain.setLocalScale(new Vector3f(2, 2, 2));
terrainPhysicsNode = new RigidBodyControl(CollisionShapeFactory.createMeshShape(terrain), 0);
terrain.addControl(terrainPhysicsNode);
rootNode.attachChild(terrain);
getPhysicsSpace().add(terrainPhysicsNode);
}
Aggregations