use of com.jme3.scene.shape.Box in project jmonkeyengine by jMonkeyEngine.
the class TestSimplePhysics method simpleInitApp.
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
// Add a physics sphere to the world
Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
rootNode.attachChild(physicsSphere);
getPhysicsSpace().add(physicsSphere);
// Add a physics sphere to the world using the collision shape from sphere one
Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, physicsSphere.getControl(RigidBodyControl.class).getCollisionShape(), 1);
physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0));
rootNode.attachChild(physicsSphere2);
getPhysicsSpace().add(physicsSphere2);
// Add a physics box to the world
Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1);
physicsBox.getControl(RigidBodyControl.class).setFriction(0.1f);
physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f));
rootNode.attachChild(physicsBox);
getPhysicsSpace().add(physicsBox);
// Add a physics cylinder to the world
Node physicsCylinder = PhysicsTestHelper.createPhysicsTestNode(assetManager, new CylinderCollisionShape(new Vector3f(1f, 1f, 1.5f)), 1);
physicsCylinder.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2, 2, 0));
rootNode.attachChild(physicsCylinder);
getPhysicsSpace().add(physicsCylinder);
// an obstacle mesh, does not move (mass=0)
Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);
node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f));
rootNode.attachChild(node2);
getPhysicsSpace().add(node2);
// the floor mesh, does not move (mass=0)
Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new PlaneCollisionShape(new Plane(new Vector3f(0, 1, 0), 0)), 0);
node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
rootNode.attachChild(node3);
getPhysicsSpace().add(node3);
// Join the physics objects with a Point2Point joint
// PhysicsPoint2PointJoint joint=new PhysicsPoint2PointJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0));
// PhysicsHingeJoint joint=new PhysicsHingeJoint(physicsSphere, physicsBox, new Vector3f(-2,0,0), new Vector3f(2,0,0), Vector3f.UNIT_Z,Vector3f.UNIT_Z);
// getPhysicsSpace().add(joint);
}
use of com.jme3.scene.shape.Box in project jmonkeyengine by jMonkeyEngine.
the class TestSoftParticles method simpleInitApp.
@Override
public void simpleInitApp() {
cam.setLocation(new Vector3f(-7.2221026f, 4.1183004f, 7.759811f));
cam.setRotation(new Quaternion(0.06152846f, 0.91236454f, -0.1492115f, 0.37621948f));
flyCam.setMoveSpeed(10);
// -------- floor
Box b = new Box(10, 0.1f, 10);
Geometry geom = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Gray);
mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
geom.setMaterial(mat);
rootNode.attachChild(geom);
Box b2 = new Box(1, 1, 1);
Geometry geom2 = new Geometry("Box", b2);
Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat2.setColor("Color", ColorRGBA.DarkGray);
geom2.setMaterial(mat2);
rootNode.attachChild(geom2);
geom2.setLocalScale(0.1f, 0.2f, 1);
fpp = new FilterPostProcessor(assetManager);
tbf = new TranslucentBucketFilter(true);
fpp.addFilter(tbf);
int samples = context.getSettings().getSamples();
if (samples > 0) {
fpp.setNumSamples(samples);
}
viewPort.addProcessor(fpp);
particleNode = new Node("particleNode");
rootNode.attachChild(particleNode);
createParticles();
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (isPressed && name.equals("toggle")) {
// tbf.setEnabled(!tbf.isEnabled());
softParticles = !softParticles;
if (softParticles) {
viewPort.addProcessor(fpp);
} else {
viewPort.removeProcessor(fpp);
}
}
}
}, "toggle");
inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
// emit again
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (isPressed && name.equals("refire")) {
//fpp.removeFilter(tbf); // <-- add back in to fix
particleNode.detachAllChildren();
createParticles();
//fpp.addFilter(tbf);
}
}
}, "refire");
inputManager.addMapping("refire", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
}
use of com.jme3.scene.shape.Box in project jmonkeyengine by jMonkeyEngine.
the class HelloAssets method simpleInitApp.
@Override
public void simpleInitApp() {
/** Load a teapot model (OBJ file from test-data) */
Spatial teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
Material mat_default = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
teapot.setMaterial(mat_default);
rootNode.attachChild(teapot);
/** Create a wall (Box with material and texture from test-data) */
Box box = new Box(2.5f, 2.5f, 1.0f);
Spatial wall = new Geometry("Box", box);
Material mat_brick = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat_brick.setTexture("ColorMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
wall.setMaterial(mat_brick);
wall.setLocalTranslation(2.0f, -2.5f, 0.0f);
rootNode.attachChild(wall);
/** Display a line of text (default font from test-data) */
setDisplayStatView(false);
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
BitmapText helloText = new BitmapText(guiFont, false);
helloText.setSize(guiFont.getCharSet().getRenderedSize());
helloText.setText("Hello World");
helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
guiNode.attachChild(helloText);
/** Load a Ninja model (OgreXML + material + texture from test_data) */
Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
ninja.scale(0.05f, 0.05f, 0.05f);
ninja.rotate(0.0f, -3.0f, 0.0f);
ninja.setLocalTranslation(0.0f, -5.0f, -2.0f);
rootNode.attachChild(ninja);
/** You must add a light to make the model visible */
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
rootNode.addLight(sun);
}
use of com.jme3.scene.shape.Box in project jmonkeyengine by jMonkeyEngine.
the class HelloAudio method simpleInitApp.
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(40);
/** just a blue box floating in space */
Box box1 = new Box(1, 1, 1);
player = new Geometry("Player", box1);
Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.Blue);
player.setMaterial(mat1);
rootNode.attachChild(player);
/** custom init methods, see below */
initKeys();
initAudio();
}
use of com.jme3.scene.shape.Box in project jmonkeyengine by jMonkeyEngine.
the class TestPhysicsReadWrite method simpleInitApp.
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
physicsRootNode = new Node("PhysicsRootNode");
rootNode.attachChild(physicsRootNode);
// Add a physics sphere to the world
Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
rootNode.attachChild(physicsSphere);
getPhysicsSpace().add(physicsSphere);
// Add a physics sphere to the world using the collision shape from sphere one
Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, physicsSphere.getControl(RigidBodyControl.class).getCollisionShape(), 1);
physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0));
rootNode.attachChild(physicsSphere2);
getPhysicsSpace().add(physicsSphere2);
// Add a physics box to the world
Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1);
physicsBox.getControl(RigidBodyControl.class).setFriction(0.1f);
physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f));
rootNode.attachChild(physicsBox);
getPhysicsSpace().add(physicsBox);
// Add a physics cylinder to the world
Node physicsCylinder = PhysicsTestHelper.createPhysicsTestNode(assetManager, new CylinderCollisionShape(new Vector3f(1f, 1f, 1.5f)), 1);
physicsCylinder.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2, 2, 0));
rootNode.attachChild(physicsCylinder);
getPhysicsSpace().add(physicsCylinder);
// an obstacle mesh, does not move (mass=0)
Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);
node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f));
rootNode.attachChild(node2);
getPhysicsSpace().add(node2);
// the floor mesh, does not move (mass=0)
Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new PlaneCollisionShape(new Plane(new Vector3f(0, 1, 0), 0)), 0);
node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
rootNode.attachChild(node3);
getPhysicsSpace().add(node3);
// Join the physics objects with a Point2Point joint
HingeJoint joint = new HingeJoint(physicsSphere.getControl(RigidBodyControl.class), physicsBox.getControl(RigidBodyControl.class), new Vector3f(-2, 0, 0), new Vector3f(2, 0, 0), Vector3f.UNIT_Z, Vector3f.UNIT_Z);
getPhysicsSpace().add(joint);
//save and load the physicsRootNode
try {
//remove all physics objects from physics space
getPhysicsSpace().removeAll(physicsRootNode);
physicsRootNode.removeFromParent();
//export to byte array
ByteArrayOutputStream bout = new ByteArrayOutputStream();
BinaryExporter.getInstance().save(physicsRootNode, bout);
//import from byte array
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
BinaryImporter imp = BinaryImporter.getInstance();
imp.setAssetManager(assetManager);
Node newPhysicsRootNode = (Node) imp.load(bin);
//add all physics objects to physics space
getPhysicsSpace().addAll(newPhysicsRootNode);
rootNode.attachChild(newPhysicsRootNode);
} catch (IOException ex) {
Logger.getLogger(TestPhysicsReadWrite.class.getName()).log(Level.SEVERE, null, ex);
}
}
Aggregations